Today's objective is to create a function that takes in a string and returns the first non-repeated character. For instance, in the string 'abcdab', your function should return 'c'. Bonus points for a solution that solves this in linear run time.
Today's objective is to create a function that takes in a string and returns the first non-repeated character. For instance, in the string 'abcdab', your function should return 'c'. Bonus points for a solution that solves this in linear run time.
Permalink: http://problemotd.com/problem/no-repeat/
Content curated by @MaxBurstein
Comments:
Foppe - 10 years, 2 months ago
reply permalink
Chuisi - 10 years, 2 months ago
Similar but using dictionaries to provide linear insertion and search times to drop the overall time from O(n2 ) to O(n)
reply permalink
Driphter - 10 years, 2 months ago
Clojure!
reply permalink
Driphter - 10 years, 2 months ago
c#
c# (Linq)
reply permalink
rossthebossperot - 10 years, 2 months ago
Python. Pretty sure this would be linear. I'm not 100% clear how Python's string.count function works.
reply permalink
Max Burstein - 10 years, 2 months ago
I don't think this would find the first repeated character though I'm not sure about string.count either. You could run in to a case like 'abaab' where a is still the right answer.
reply permalink
Walker Crouse - 10 years, 2 months ago
reply permalink
asheehan - 10 years, 2 months ago
in Ruby
reply permalink