Data Structures & AlgorithmsVery hardGATE CS · TCS NQT
In [3, 8, 1, 8, 5], you move the rightmost occurrence of the maximum to the last position using adjacent swaps. How many adjacent swaps are needed?
- A. 2
- B. 1
- C. 0
- D. 3
Correct answer: B. 1
The rightmost maximum is at index 3, and one adjacent swap moves it past the 5 to the last position.
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 unordered pairs of distinct words in ["abc", "aba", "cdc", "xyz", "axa", "cd"] share both the same first letter and the same last…
- How many index pairs i < j of [1, 2, 5, 7, 10] have absolute difference at least 3?
- Numbers 1, 2, 3, 4 are pushed in this order onto a stack. Can the pop sequence 3, 4, 2, 1 be produced?
- How many length-3 substrings of "abcabc" are rotations of "abc" (namely abc, bca or cab)?
- What is the sum of the decimal digits of 2^20?
- Among intervals [1,6], [4,9], [5,5], [2,8], [5,7], [3,6] that contain the point 5, what is the largest number that are pairwise disjoint…