Data Structures & AlgorithmsModerateTCS NQT · Infosys
An array is [1, 2, 1, 2, 1, 2] (indices 0 to 5). How many pairs of even-indexed positions i < j hold equal values?
- A. 4
- B. 3
- C. 5
- D. 7
Correct answer: B. 3
The even indices 0, 2, 4 all hold 1, which gives 3 equal pairs. The odd-indexed 2s are excluded by the restriction.
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 sum of all proper divisors of 220 (divisors less than 220)?
- How many integers in [1, 100] have an odd number of positive divisors?
- What is the last digit of 3^2024?
- How many strings of length 4 over the alphabet {0, 1, 2} have no two adjacent characters equal?
- What is the Z-function value sum over positions i = 1 to n-1 of the string abababab?
- How many index pairs i < j in [1, 2, 3, 4, 5, 6] satisfy that a[i] times a[j] equals a[i] plus a[j]?