Data Structures & AlgorithmsHardGATE CS · TCS NQT
What is the length of the shortest contiguous subarray which, if sorted in place, makes the whole array [2, 6, 4, 8, 10, 9, 15] sorted?
- A. 6
- B. 5
- C. 4
- D. 7
Correct answer: B. 5
Compare the array with its sorted copy: the first and last mismatched positions bound the subarray. Here the mismatches run from index 1 to index 5, giving length 5.
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 number of trailing zeros in the decimal representation of the product 10 25 4 15 50?
- How many distinct sums appear over all non-empty contiguous subarrays of [2, 1, 3, 1]?
- Ropes of lengths 4, 3, 2 and 6 must be joined pairwise into one rope; joining costs the sum of the two lengths and you may join any two…
- How many distinct palindromic strings of length 3 occur as subsequences of "abcba"?
- How many unordered pairs of words in ["listen", "silent", "enlist", "google", "gogole", "cat", "act"] are anagrams of each other?
- Replace every element simultaneously by (a[i] + a[i-1]) mod 10, indices cyclic, on [1, 2, 3, 4]. What is the resulting array?