Data Structures & AlgorithmsHardGATE CS · TCS NQT
What is the number of elements remaining in the list after deleting each element that is smaller than the element immediately before it, applied once in a single left-to-right pass over the original list [5, 2, 8, 1, 9, 3, 7]?
- A. 5
- B. 2
- C. 4
- D. 6
Correct answer: C. 4
The first element always stays, and each later element stays unless it is smaller than its original predecessor. Comparing against the already-deleted 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
- How many NON-EMPTY subsets of [3, 6, 9, 12, 15, 4, 8, 11] (chosen by index, so equal values are different elements) have a sum divisible…
- How many subsets of {1, 2, 3, 4, 5, 6, 7, 8} have sum exactly 15? (The empty set is excluded, and each value is used at most once.)
- How many arrays of length 4 with values from {1, 2, ..., 3} have no two adjacent elements equal?
- Each step adds 1 to one element of [2, 2, 2, 5, 5, 1]. What is the minimum total number of steps so that every element becomes distinct?…
- A sorted array [1, 5, 10] is given. You may insert new positive integers into it. What is the minimum number of insertions so that every…
- What is the smallest positive integer that CANNOT be written as the sum of some subset (each element used at most once) of the sorted…