Data Structures & AlgorithmsVery hardGATE CS · TCS NQT
Array [5, 2, 8, 1, 9, 3] is processed in one left-to-right pass: each node is deleted if its value is strictly greater than the value of the node immediately after it in the original list (the last node is always kept). How many nodes remain?
- A. 4
- B. 2
- C. 3
- D. 5
Correct answer: C. 3
Compare each node with its original successor, not with the node that survived before it. Deleting based on the updated neighbour changes the count.
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 singly linked list holds 1, 2, 3, 4, 5, 6, 7. Adjacent pairs are swapped in one pass (node 1 with 2, node 3 with 4, and so on; an…
- How many index pairs i < j in the array [1, 2, 3, 1, 2, 3] make a[i] a[j] = 6?
- How many contiguous subarrays of [2, -2, 3, 1, -4, 2, -1] have sum 0?
- How many index pairs i < j in the array [1, 3, 5, 7, 2, 6, 8] have a[i] + a[j] equal to a power of 2?
- The string (()(()(( is scanned left to right: '(' opens and ')' closes the most recent unmatched '('. How many characters are unmatched in…
- What is the minimum number of brackets that must be inserted into ())(()(( to make it a balanced sequence?