Data Structures & AlgorithmsVery hardTCS NQT · Infosys
What is the length of the longest contiguous subarray of [1, 2, 1, 2, 3] that contains at most two distinct values?
- A. 4
- B. 5
- C. {C-1}
- D. 6
Correct answer: A. 4
The subarray 1, 2, 1, 2 has two distinct values and length 4; adding the 3 would make three distinct values.
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 adjacent position pairs in the string abbaabab are equal to ab or ba (overlapping adjacent pairs counted)?
- What is the lexicographically smallest rotation of the string bca?
- What is the sum of all integers x in [1, 50] that are divisible by 4 or by 6?
- How many positive divisors of 360 are odd?
- What is the largest n such that 1 + 2 + ... + n does not exceed 1000?
- How many primes p with 2 <= p <= 30 satisfy p ≡ 1 (mod 4)?