Data Structures & AlgorithmsVery hardGATE CS · TCS NQT
How many inversions does the array [-3, -1, -2] have (pairs i < j with a[i] > a[j])?
- A. 2
- B. 1
- C. 3
- D. 0
Correct answer: B. 1
Negation reverses the order of values, so the inversions of [3,1,2] become non-inversions. Negating gives [-3, -1, -2], whose only inversion is the pair (-1, -2).
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
- In "abcabdabc", how many positions i >= 1 start an occurrence of the prefix "abc" (the first three characters)?
- What is the sum of all integers from 1 to 50 inclusive that are coprime to 50?
- Let L be the length of the longest common subsequence of "ABCBDAB" and "BDCABA". How many different index-selections in "ABCBDAB" give a…
- What is the length of the longest common subsequence of "dbacabb" and its cyclic rotation by one position (the string with its first…
- Using only insertions and deletions (no substitutions), what is the minimum number of operations needed to turn "heat" into "hit"?
- How many permutations of the numbers 1 to 6 have a longest increasing subsequence of length exactly 3?