Data Structures & AlgorithmsHardCodeforces Div2 C · GATE CS
What is the minimum number of swaps of any two positions needed to make [2, 1, 2, 1, 3, 3, 1] sorted in non-decreasing order?
- A. 4
- B. 2
- C. 5
- D. 3
Correct answer: D. 3
Minimum swaps for a multiset arrangement is found by BFS over states, or by the mismatch-matrix count for two values. The adjacent-descent count is a different measure that over-counts for this array.
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
- Concatenate "abba" and "baab" into one string, then count its distinct substrings of length 2.
- In the text "abcabdabc", how many positions match the pattern "a?c" where '?' matches any single character?
- Sum, over the queries x = 3, 6, 9 on the sorted array [1, 3, 3, 5, 8, 9, 12], of the number of elements that are less than or equal to x…
- How many index pairs i < j in [1, 3, 5, 7, 9, 15] have a sum that is a power of two?
- From tasks (value, cost) = (5, 4), (6, 2), (3, 1), (7, 5) you may choose any subset whose total cost is at most 7. What is the maximum…
- How many trailing zeros does 2^7 5^4 10 have in decimal?