Data Structures & AlgorithmsHardProduct placement · Amazon/Microsoft
For [7, 3, 5, 3, 7, 2, 5], definition A returns the element whose FIRST occurrence is earliest among all repeating elements; definition B returns the element whose SECOND occurrence comes first while scanning. What do A and B return?
- A. A: 5, B: 3
- B. A: 3, B: 7
- C. A: 7, B: 7
- D. A: 7, B: 3
Correct answer: D. A: 7, B: 3
A needs counts first (7 repeats and appears at index 0). B stops at the first value already in the seen-set: 3 at index 3. The two definitions often differ, so read the question's wording carefully.
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
- nums1 = [2, 5, 8, 0, 0, 0] (3 real values plus 3 buffer slots) and nums2 = [3, 6, 9] are merged in place by filling nums1 from the BACK…
- What is the sum of the minimum value of every contiguous window of length 3 in the array [4, 2, 12, 11, -5, 3, 7]?
- For each index i, let di be (index of the nearest element to the right that is strictly greater than a[i]) minus i, or 0 if no such…
- How many permutations of 1, 2, 3, 4, 5 can be sorted into increasing order by a single stack, where each input element is pushed in order…
- In the Josephus game, 41 people stand in a circle numbered 1 to 41. Starting from person 1, every 3rd person is removed (counting…
- What is the area of the largest rectangle that fits in a histogram whose bar heights are 2, 1, 5, 6, 2, 3 (each bar has width 1)?