Data Structures & AlgorithmsVery hardCodeforces Div2 B-D · ICPC regional
What is the length of the longest contiguous subarray of [1, 2, 1, 3, 4, 3, 5] in which at most one element is a repeat of an earlier element (counting extra copies)?
- A. 6
- B. 7
- C. 2
- D. 1
Correct answer: A. 6
Shrink the window while it holds more than one extra copy: [2, 1, 3, 4, 3, 5] has one extra 3 and length 6. The whole array (7) has two extra copies (1 and 3), 2 counts those extra copies, and 1 is k itself.
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 trailing zeros does 50! (50 factorial) have in decimal?
- How many palindromic substrings of length at least 3 does "racecarxyzzyx" contain (counted by position)?
- For each value n in [10, 27, 50], count the positive integers x with x^3 <= n, then add the three counts. What is the total?
- How many adjacent positions in [3, 9, 4, 7, 1] have a[i] > a[i+1]?
- What is the minimum number of characters that must be inserted at the front of "abcdc" to make it a palindrome?
- Remove exactly one element from [5, -4, 3, -7, 2], then take the maximum product of two distinct remaining elements. What is that maximum…