That is exactly what I was doing. But the complexity of the code would not 
come up to be O(n). It would be O(n^2) in the worst case.

Worst case: String is of the form "abcdeabcde" ..Start with a..hash upto 
second 'a' encountered. (n/2 elements accessed). Reset hash. start afresh 
from b..hash upto second 'b' encountered.(n/2 elements.) and so on.. Thus in 
first n/2 calls, n/2 elements accessed in each call. O(n/2 + n/2...n/2 
times)= O(n^2/4) = O(n^2)

Correct if I am making any mistake.


regards,
Abhishek Khattri

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/IiCXmJSkWp0J.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to