COGNIZANT Coding Question – Solved

2 Live
Stemming is the process of extracting the base word from a word. For instance, the base for "worked" is "work". Use the following algorithm to stem a word: 1. If the word ends in 'ed', 'ly', or 'ing', remove the suffix. 2. If the resulting word is longer than 8 letters, keep the first 8 letters. Implement a function that takes a string of space-separated words and returns its stemmed counterpart. Example: text = 'an extremely dangerous dog is barking' 'an' does not end in one of the suffixes and is less than 8 letters. 'extremely' is 'extreme' after removing the suffix. 'extreme' is less than 8 letters. 'dangerous' is 9 letters long, so reduce it to 8 letters: 'dangerou'. 'dog' and 'is' are unchanged. 'barking' is 'bark' after removing the suffix, and is. Return 'an extreme dangerou dog is bark'. Function Description: Complete the function stemmer in the editor below. stemmer has the following parameter(s): string text: the input text Returns: string: the input text with each of the words replaced by its stem Constraints: Every character in text is either an English lowercase letter or a space character. text starts and ends with a letter. No two consecutive characters are spaces. text contains at most 100 words. No word is longer than 18 letters. Function Input Format Format for Custom Testing Sample Case 0 Sample Input 0 STDIN

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… |