KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
What would be the best space and time efficient solution to find the first non repeating character for a string like aabccbdcbe ? The answer here is d. So the point that strikes me is that it can be done in two ways: For every index i loop i-1 times and check if that character occurs ever again. But this is not efficient: growth of this method is O(N^2) where N is the length of the string. Another possible good way could be if I could form a tree or any other ds such that I could order the character based on the weights (the occurrence count). This could take me just one loop of length N through the string to form the structure. That is just O(N) + O(time to build tree or any ds).
Tags (comma-separated)
Save Edits
Cancel