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

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