COGNIZANT Coding Question – Solved

3 Live
On a popular discussion platform, some users with harmful intentions use anagram-based methods to hide certain banned terms. An anagram is a word or phrase created by rearranging the letters of another word or phrase, using all the original letters exactly once. Implement a function to identify and group anagrams within the network's data log to detect these concealment attempts. Write a Python function named groupAnagrams that takes a list of words (network log entries) as input and groups them into sets of anagrams. Example: word_list = ['debitcard', 'badcred[s', 'cat', 'tac', 'act'] After grouping the anagrams, return [['debitcard', 'badcredit'], ['cat', 'tac', 'act']]. The provided code sorts the results and prints [['act', 'cat', 'tac'], ['badcredit', 'debitcard']]. Function Description: Complete the function group_anagrams in the editor with the following parameter(s): string words_list[n]: a list of words to group Constraints: Each word_list[i] consists only of characters in the range ascii[a-z]. Input Format For Custom Testing: Sample Case 0 Sample Input For Custom Testing: 2 act kitchen ran cat listen silent enlist heart earth hater good dog Sample Output: [['act', 'cat'], ['kitchen'], ['ran']] [['dog'], ['good'], ['earth', 'hater', 'heart'], ['enlist', 'listen', 'silent']] Explanation: Words that are anagrams are grouped into lists, e.g., 'act' and 'cat' in the first list of words. Note that 'dog' and 'good' do not have anagrams. Sample Case 1 Sample Input For Custom Testing

Asked in: COGNIZANT

Image of the Question

Question Image Question Image

All Testcases Passed βœ”



Passcode Image

Solution


Please login to view the solution


Related Questions

| Given an n x m grid, where rows are numbered from 7 to n and columns from 1 to … |
| There are 'N' coders standing in a line, where i denotes the ith position of a … |
| A birthday party was attended by N number of kids, and each kid was given a uni… |
| Given a matrix of size m * n, where m denotes the number of rows (starting with… |
| A traveler is traveling from the city of Zeta to Omega. He starts with X amount… |
| As an operations engineer at Amazon, you are responsible for organizing the dis… |