Data Structures & AlgorithmsVery hardGATE CS · Codeforces Div2 B
What is the length of the longest contiguous subarray of [4, 2, 4, 5, 6, 2, 4, 1] that contains no repeated value?
- A. 4
- B. 5
- C. 6
- D. 7
Correct answer: B. 5
Use a sliding window with the last-seen index of each value, moving the left end past the previous occurrence. The repeated 4 at the start forces the window to begin after index 0.
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 contiguous subarrays of [4, 5, 0, -2, -3, 1] have a sum divisible by 4?
- How many distinct values v in the array [1, 2, 2, 3, 3, 3, 4, 4, 4, 4] occur exactly v times?
- What is the length of the longest common prefix of the strings interstellar, internet, interval and intern?
- How many integers x with 1 <= x <= 100 satisfy x mod 3 = 2 and x mod 5 = 3?
- How many contiguous subarrays of [7, 1, 6, 13, 8, 2] have a sum congruent to 0 modulo 7?
- How many positive divisors of 720 are perfect squares?