Data Structures & AlgorithmsVery hard
A stream arrives one character at a time: a a b c b d. After each character, report the FIRST character (in arrival order) that has appeared exactly once so far, or # if none. Give the reports as a space-separated string of six symbols.
- A. a # b c c d
- B. a # b b c c
- C. a # b b c d
- D. a # a a a a
Correct answer: B. a # b b c c
Keep the characters in a queue and remove the front while it is repeated; the front is then the first non-repeating character. Reporting the last unique character, or reusing a stale answer, produces a different string.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- A linked list holds 1 through 10 in order. Going from the head, reverse the first 3 nodes, leave the next 3 unchanged, reverse the next 3…
- How many pairs of positions i < j in the array 12 21 3 30 111 24 42 have DIGIT SUMS that are equal?
- In the string "((a)(b(c)))d((e))", what is the maximum nesting depth of round brackets (the number of brackets open at the deepest point)?
- How many contiguous subarrays of 1 4 2 6 3 5 have an AVERAGE that is at least 3?
- What is the maximum sum of a contiguous subarray of -3 4 -1 2 5 -6 3 1 whose LENGTH is between 2 and 3 inclusive?
- How many contiguous subarrays of 5 1 9 4 8 3 7 have (maximum − minimum) at least 3?