File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

general question

 
Andrew Lit
Ranch Hand
Posts: 135
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hallo,
i got an assignment, to write an efficient program that would select the longest substring of the same character from a string.
let's say character is 'a' and string is aasddaaa. So the resulting output is "aaa".
And here comes the question: how should i understand word efficient, is there an algorithm or smth. I would be very appreciated if someone claryfied it to me.
 
Paul Keohan
Ranch Hand
Posts: 411
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Efficient to me would mean code that runs most efficiently. There is very little overhead, no unnecessary objects instantiated, none left hanging around when not necessary.
From the sounds of your question though, I'd say you have to come up with the cleverest way of performing this with the least amount of written code.
 
Jeremy Thornton
Ranch Hand
Posts: 91
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd say that the aim of the assignment is to get you to think about problem solving a little rather than just writing code.
For this kind of problem, there are a range of "right" solutions but I'm guessing that whoever set the assignment just wants you to have a go at implementing what you perceive is a reasonably effective solution.
e.g. one way to solve it would be to step through the alphabet and count all the instances of each letter in the String... this would obviously work for strings using only the letters of the english language, but would require lots of unnecessary comparisons.
better to start with the first letter, count the instances...
For this kind of assignment, by far the best solution is to have a go, get something to work, analyse where code is redundant or calculations are lengthy and try to work on that part in isolation.
Have fun!
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use Java 1.4 regular expressions!
 
Preetham M
Greenhorn
Posts: 12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could use the Dynamic Programming Algoritham(LCS, Longest Common Sequence) to calculate the longest sub-string of a string.
 
Andrew Lit
Ranch Hand
Posts: 135
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you for your replies
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic