Link Details

Link 1087279 thumbnail
User 1131839 avatar

By Javin_Paul
via javahungry.blogspot.com
Published: Dec 30 2013 / 01:17

first non repeated character in string
  • 9
  • 1
  • 820
  • 1055
User 166389 avatar

dxxvi replied ago:

0 votes Vote down Vote up Reply

Voted down for a bad solution (don't know why there were a lot of up votes). Rudy in the comment section was right.

User 1209937 avatar

javalearner9 replied ago:

0 votes Vote down Vote up Reply

Please understand the code written above is the most efficient code as the hashtable takes O(n) in look up for the element . Any one can do the above question through arrays also . But thats solution is not good as it will utilize more memory . In the post itself I clarified that this is interview question of Amazon and equivalent companies which always ask efficient algorithms . Hope you got my point . ,

User 166389 avatar

dxxvi replied ago:

0 votes Vote down Vote up Reply

If you think scanning the string twice is better then go ahead.

User 967813 avatar

kritzikratzi replied ago:

0 votes Vote down Vote up Reply

hashtable takes O(1) for lookup, not O(n)!

User 1209937 avatar

javalearner9 replied ago:

0 votes Vote down Vote up Reply

I was talkin about worst case scenario . O(1) is the best case scenario . If you are writing algorithm you are more concerned with th worst case scenario in real world .

User 967813 avatar

kritzikratzi replied ago:

0 votes Vote down Vote up Reply

here is a solution in mathematica. its more elegant imho, but also slower ( O(n^2) ) http://pastebin.com/94z7UbBd (can't paste mathematica code in here, sorry)

Add your comment


Html tags not supported. Reply is editable for 5 minutes. Use [code lang="java|ruby|sql|css|xml"][/code] to post code snippets.

Apache Hadoop
Written by: Piotr Krewski
Featured Refcardz: Top Refcardz:
  1. Play
  2. Akka
  3. Design Patterns
  4. OO JS
  5. Cont. Delivery
  1. Play
  2. Java Performance
  3. Akka
  4. REST
  5. Java