Data Structures & AlgorithmsModerateTCS NQT · Codeforces Div2 B
Positions [15, 3, 22, 9, 40, 27] are given in arbitrary order. What is the largest difference between two consecutive positions when the positions are sorted?
- A. 31
- B. 10
- C. 37
- D. 13
Correct answer: D. 13
Sort, then take the maximum adjacent difference; the bound is at least (max − min)/(n − 1), but the answer needs sorted neighbours, not the input's neighbours. The overall range is always at least the answer and is not the same quantity.
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
- How many subsets (chosen by position, the empty subset included) of [6, 1, 3, 5, 2] have a bitwise XOR equal to 4?
- What is the length of the shortest contiguous subarray of [2, -1, 2, 3, -4, 5, 1] whose sum is at least 6? Negative numbers are present…
- A sorted array of distinct values was rotated some number of times. Which technique finds the minimum element in O(log n) time, and why…
- In one operation you may increase any single element by 1. What is the minimum total number of operations needed to make the array [1, 1…
- Choose two NON-OVERLAPPING non-empty contiguous subarrays of [4, -1, 2, 6, -3, 5, -2] (the first must end before the second starts) and…
- In how many ways can a 2 × 9 board be tiled exactly with 2 × 1 dominoes (placed vertically) and 2 × 2 squares, with no overlaps and no…