Data Structures & AlgorithmsVery hardTCS NQT · Infosys
How many distinct values v in the array [1, 2, 2, 3, 3, 3, 4, 4, 4, 4] occur exactly v times?
- A. 5
- B. 3
- C. 6
- D. 4
Correct answer: D. 4
Build a frequency map, then check for each value whether its count equals the value itself. All four values satisfy this, so the answer is the number of such 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
- 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?
- Two people in a circle of 5 are numbered 1 to 5 and eliminated by repeatedly removing every second person (starting by removing person 2)…
- How many index pairs i < j in the array [1, 2, 3, 4, 5, 6] satisfy gcd(a[i], a[j]) = 1 and a[i] + a[j] is odd?