Data Structures & AlgorithmsVery hardTCS NQT · Infosys
How many contiguous subarrays of length 3 in the array [1, 2, 3, 1, 2, 3, 3] have all three elements distinct?
- A. 5
- B. 4
- C. 3
- D. 6
Correct answer: B. 4
Check each window of length 3 for distinct values. Windows of equal values at the end are excluded, so only the first few windows qualify.
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 [1, 2, 3, 4, 5] have a bitwise XOR less than 4?
- How many integers x with 1 <= x <= 200 satisfy gcd(x, 180) = 1?
- What is the smallest x such that lcm(1, 2, ..., x) exceeds 1,000,000?
- How many integers x with 1 <= x <= 100 satisfy x^2 mod 24 = 1?
- How many ordered pairs (i, j) with 1 <= i, j <= 18 have i j divisible by 18?
- How many contiguous subarrays of [2, 8, 3, 3, 2, 6] have a product that is a perfect square?