Data Structures & AlgorithmsHard
Remove duplicate values from the unsorted list 4 2 4 1 2 5 1 so that only ONE copy of each value remains, keeping the copy that appears LAST in the original order. Give the remaining sequence.
- A. 4 2 5 1
- B. 4 2 1 5
- C. 1 2 4 5
- D. 5
Correct answer: A. 4 2 5 1
Scanning from the right and keeping a value only at its final occurrence retains the last copy in original relative order. Keeping the first occurrence, sorting, or deleting every repeated value gives the other sequences.
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 single stack, starting empty, is used to sort the input permutation of 1..4 into 1, 2, 3, 4 at the output (each input element is pushed…
- Two sorted lists A = 10 30 50 and B = 5 40 60 80 90 are merged by taking nodes ALTERNATELY (first from A, then from B, and so on) until…
- From the array 3 -1 8 2 -4 6 5 you may take exactly 3 elements, each taken from the LEFT end or from the RIGHT end of what remains. What…
- In one operation you increase ALL elements of the array 1 2 4 except one chosen element by 1. What is the minimum number of operations…
- 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…
- 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…