Data Structures & AlgorithmsModerateGATE CS · Codeforces Div2 D
How many pairs of positions (i < j) in [5, 2, 7, 2, 9, 1, 6] have a[i] < a[j]?
- A. 11
- B. 3
- C. 19
- D. 10
Correct answer: D. 10
Count with a merge sort or a BIT over compressed values: each element adds the number of earlier values that are smaller. Checking only adjacent pairs gives the count of consecutive rises, not all pairs.
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
- Items as (weight, value) are [(4, 6), (2, 3), (5, 9), (3, 4), (6, 10), (1, 1)]. You must take EXACTLY 3 different items with total weight…
- In one operation you may choose a contiguous subarray and increase every element in it by 1. Starting from [0, 0, 0, 0], what is the…
- How many contiguous subarrays of [1, 2, 1, 3, 3, 2, 4, 1] contain EXACTLY 2 distinct values?
- Evaluate 3 + 5 2 - 8 / 4 using standard precedence and integer division. What is the result?
- The exponent operator ^ is right-associative. What is the value of 2 ^ 3 ^ 2?
- How many valid (balanced) bracket sequences of length 8 are there using one type of bracket?