• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Logical Question to solve

 
Ranch Hand
Posts: 41
Netscape Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Suppose Their is a String abc ="asddffgghmmaanniisshhssdfg";

and the user gives the input as "masinh"

We need to find the first index of that input from abc and the condition is :-

1) The letters can be repeated
2) The letters might be in a shuffled way , however the letters must be together and no other letter can be in between them.

Suppose abc = "aghamaanniisshhssdfg";
User input = "masinh"

Output will be :- 4

example 2 :-

if abc = "aghmmaanniisshhssdfg"
User Inout = "hs"

Output will be :-13

How should i go about it ?



 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

manish sahni wrote:How should i go about it ?


Well, the first thing to do is don't write any code until you understand the problem.

Second: This is NOT a Java problem, it is a string searching, or character matching, problem.

Third: Define the rules precisely: What if, instead of "masinh", the user supplies "mmasiiinh". What does that mean?

Fourth: (a tip; and only for when you have the rules down exactly) Given a string and user input, how will you know when you DON'T have match?

HIH

Winston
 
when your children are suffering from your punishment, tell your them it will help them write good poetry when they are older. Like this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic