gona
BAN USER
Comments (4)
Reputation 0
Page:
1
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
0
of 0 vote
1. Take two integer arrays A & B of size 256 (or as many characters possible).
2. For each character in the stream,
a. increment the count in array A and do one of the following:
b. If count is 1, store position of the character in B
c. if count is =2, reset the position of character in B
d. if count >2, do nothing
At the end of stream, get the index of B with minimum position value.
Comment hidden because of low score. Click to expand.
Page:
1
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
We can actually solve this with one integer array A initialize to -1 initially.
- gona November 19, 2012Now if we are seeing a char for the first time (A[char]==-1), set A[char] = position
if we are seeing a char second time (A[char] > -1), set A[char]=-2
if we have seen a char more than once (A[char]==-2), do nothing
take min position ignoring all elements < 0.