Data Structures & AlgorithmsVery hardTCS NQT · Accenture
How many distinct anagram classes are there among the words eat, tea, tan, ate, nat and bat (two words are in the same class if one is a rearrangement of the other)?
- A. 3
- B. 4
- C. 5
- D. 7
Correct answer: A. 3
Sort each word's letters to get a canonical key: aet (eat, tea, ate), ant (tan, nat), abt (bat). Three keys give three classes.
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 values x in [2, 4, 6, 7, 8] have both x - 1 and x + 1 present in the array?
- What is the length of the longest palindromic subsequence of the string agbdba?
- How many substrings of abbaba contain an equal number of letters a and b (substrings of length at least 2)?
- Given the words ba, b and a, concatenate all three in some order. What is the lexicographically smallest resulting string?
- How many ways are there to write 10 as an ordered sum of 1s and 2s (for example 2+1+1+... counts differently from 1+2+...)?
- What is the multiplicative order of 2 modulo 17 (the smallest k > 0 with 2^k ≡ 1 mod 17)?