Data Structures & AlgorithmsHardGATE CS · TCS NQT · Product Company SDE
A sorted array is [1, 9, 9, 10, 13, 14, 18, 23, 23, 25]. Using the standard two-pointer in-place duplicate-removal technique (a slow pointer marks the last unique position, a fast pointer scans ahead), how many elements remain after duplicates are removed?
- A. 7
- B. 9
- C. 8
- D. 10
Correct answer: C. 8
The slow pointer only advances on a new distinct value, so the final count equals the number of distinct values, 8 (there were 2 duplicate occurrence(s)).
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
- What is the time complexity of reading the element arr[i] from an array of n elements, given i?
- Which data structure works on the Last In, First Out (LIFO) principle?
- What is the worst-case time complexity of binary search on a sorted array of n elements?
- Which of these sorting algorithms is stable in its standard implementation?
- What is the time complexity of inserting a new node at the head of a singly linked list of n nodes?
- With a good hash function and a bounded load factor, what is the average time to search for a key in a hash table?