Data Structures & AlgorithmsModerateTCS NQT · Codeforces Div2 B
For the array [7, 3, 9, 3, 5, 9, 1, 7], what is the maximum value of (j − i) over pairs of positions i < j with a[i] = a[j]?
- A. 8
- B. 5
- C. 4
- D. 7
Correct answer: D. 7
For each value, the farthest pair is its first and last occurrence, so record the first index of every value and measure each new occurrence against it. Comparing only adjacent equal values finds much smaller gaps.
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 length of the longest contiguous block of [2, 3, 5, 4, 6, 7, 8, 1, 2, 3] in which every element is strictly larger than the…
- A frog starts on stone 0 with heights [10, 30, 40, 20, 25, 10]. It can jump to stone i+1 or i+2, and the cost of a jump is the absolute…
- Grid [[3, 1, 4, 1], [5, 9, 2, 6], [5, 3, 5, 8], [9, 7, 9, 3]]. Starting from any cell in the top row, each step goes to the cell directly…
- In how many ways can a 3 × 8 rectangle be tiled exactly with 2 × 1 dominoes (horizontal or vertical)?
- How many DIFFERENT values can the sum of three distinct integers chosen from 1 to 9 take?
- What is the length of the longest substring of "aebcdiouxyab" in which the number of vowels (a, e, i, o, u) equals the number of non-vowels?