Data Structures & AlgorithmsModerateTCS NQT · Infosys
In the list ['listen', 'silent', 'enlist', 'google', 'gooegl', 'cat', 'act', 'tac', 'dog'], how many unordered pairs of different positions (i < j) form anagrams of each other?
- A. 9
- B. 4
- C. 7
- D. 10
Correct answer: C. 7
Group the words by their sorted letters (or a letter-count signature); each group of size g contributes g·(g−1)/2 pairs. Counting groups instead of pairs answers how many distinct anagram classes exist.
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 index pairs (i < j) of the list [1, 3, 2, 3, 4, 5, 3, 1, 2, 5] satisfy a[i] + a[j] = 6? Equal values at different positions count…
- How many unordered pairs of distinct positions in [2, 3, 4, 6, 8, 9, 12] have a product divisible by 6?
- How many DISTINCT substrings of length exactly 3 does "abcabcbb" contain?
- How many substrings of "aeixoaeiuxoaeiou" consist only of vowels AND contain all five vowels a, e, i, o, u at least once?
- Consider the pattern-matching algorithms: naive, KMP, Rabin–Karp (polynomial rolling hash), Z-function. Which statement is correct?
- A polynomial rolling hash with a fixed modulus M and random base B is used to compare two different strings of length L. Which statement…