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

| You are given a board of size M Γ— N where each cell can be either empty ('O') o… |
| Undirected Coloured Graph Shortest Path You are given an undirected weight… |
| Village Voyage A computer game "Village Voyage" has N villages (labeled 1 to… |
| Academic Decathlon Students are being selected for an academic decathlon tea… |
| Sum of Arrays Given two arrays each of length n, arr1 and arr2, in one opera… |
| Count Swaps During Custom Sorting Analyze the efficiency of the following so… |