• 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

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
 
I found a beautiful pie. And a tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic