Data Structures & AlgorithmsHardInfosys · Wipro pattern
The words stop, pots, opts, post, tops, spot, pot, top are grouped so that anagrams share a group (key = the sorted letters). How many groups are there, and how big is the largest?
- A. 2 groups, largest 6
- B. 1 group, largest 8
- C. 3 groups, largest 4
- D. 2 groups, largest 4
Correct answer: A. 2 groups, largest 6
The six 4-letter words all sort to 'opst'; pot and top sort to 'opt'. Words of different lengths can never be anagrams, so the 3-letter ones form their own group: 2 groups, sizes 6 and 2. Grouping by the SET of letters would wrongly merge all eight into one group.
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
- A stack is built from two queues with a costly push: enqueue x into the empty queue Q2, move every element of Q1 into Q2 one by one, then…
- With at most k = 2 character replacements, what is the length of the longest substring of 'AABCABBB' that can be turned into a single…
- What is the length of the longest contiguous subarray of [0, 1, 1, 0, 1, 1, 1, 0, 0, 0] with an equal number of 0s and 1s? (Map 0 to −1…
- What is the maximum sum of a non-empty contiguous subarray of the CIRCULAR array [5, −8, 3, 4, −2, 6, −9, 7] (a subarray may wrap from the…
- What is the maximum product of a non-empty contiguous subarray of [2, −3, 0, −2, −4, 3, −1]?
- What is the next lexicographic permutation of [1, 5, 8, 4, 7, 6, 5, 3, 1]?