Data Structures & AlgorithmsHardTCS NQT · Infosys
How many pairs of positions i < j in the string aabbab have s[i] = a and s[j] = b (the letters need not be adjacent)?
- A. 7
- B. 8
- C. 9
- D. 11
Correct answer: A. 7
Each a contributes the number of b positions after it: the two a's at 0 and 1 see 3 b's each, and the a at 4 sees 1.
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 the prefix-function values pi[0] through pi[n-1] of the string abacabab?
- What is the sum of lcm(i, i+1) for i = 1 to 9?
- What is the smallest positive integer n such that n! has exactly 10 trailing zeros?
- How many integers x in [1, 1000] have exactly 3 positive divisors?
- What is 2^50 mod 13?
- A frog at 0 wants to reach exactly 12 by jumps of length 2 or 3 to the right. How many different jump sequences take it there?