Question: Given An Array Of Words, Return The Array After Trimming Each Word. * For The I-Th Word, The Trimming Rules Are: * * Rule 1:

Given An Array Of Words, Return The Array After Trimming Each Word. * For The I-Th Word, The Trimming Rules Are: * * Rule 1: If The Length Of The Word Is Smaller Than Or Equal To I, Or The Word Is \"Lololol\", Then You Don't Have To Trim It. * * Rule 2: Compare The First Letter And The Last Letter Of The Word, Remove The Smaller One From The

* Given an array of words, return the array after trimming each word.

* For the i-th word, the trimming rules are:

* * Rule 1: If the length of the word is smaller than or equal to i, or the word is \"lololol\", then you don't have to trim it.

* * Rule 2: Compare the first letter and the last letter of the word, remove the smaller one from the word.

* If these two letters are the same, then remove the first one.

* Keep doing this until the word meets rule 1.

* ------------

* Example 1:

* Input: words = [\"a\", \"cdm\", \"lololol\", \"asd\", \"ooooooooooo\"]

* Output: [\"a\", \"dm\", \"lololol\", \"asd\", \"ooooo\"]

* Example 2:

* Input: words = []

* Output: []

* Example 3:

* Input: words = [\"\"]

* Output: [\"\"]

* ------------

* Constraints:

* * 0 =>=>

* * 0 =>=>

* * words[i] only contains lowercase English letters

*

* @param words target array of words

* @return array of words after trimming

*/

public String[] trimWords(String[] words) {

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!