R or L

  • 10
  • Locked
Our friends from Planet Chi-Knees have an unusual problem: they have a really hard time distinguishing between the letters "r" and "l". We decided to help them with this task. The experimental fix method will remove from a string list all words containing the letter "r", and it will duplicate all words containing the letter "l".
You can't complete this task, because you're not signed in.
Comments (43)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Dinesh Full Stack Developer at Byndr Technologies
9 October, 04:21
This is simple one: 1. declare two lists, one to add all the removed elements and one for adding all the duplicating elements. populate these two lists using loop. 2. from the original list remove one list and add other list. simple.
Aisuluu Zhumabaeva SDET at Capgemini
17 June, 18:04
This task requirement is to solve without using keyboard, but the solution read data from keyboard.
Level 10 , Forest Grove, United States
28 April, 17:09
Here is a great link to help you understand how to search characters in a string, helped me out a ton: https://www.geeksforgeeks.org/searching-for-character-and-substring-in-a-string/ I'm sure you can compile a satisfactory solution after reading & understanding character functions.
Level 15 , Old Town, United States
21 April, 03:32
the most difficult/important part of the solution is using extra i++ and i-- once. Took a while to understand why these were necessary, but it's important b/c the logic fails without them, never mind the checker.
Level 9
21 July, 16:22
Thanks! This helped me a lot! :)
Jurij Thmsn
Level 28 , Flensburg, Germany
13 January, 10:22
Hardest exercise so far. I spent 6 hours on this and had to get help to be able to resolve it. Still don't really understand why. Feels disappointing.
Usman Full Stack Developer at QA
6 July, 13:00
youre doing great!
Joe M
Level 11 , Owings Mills, United States
22 November 2020, 02:23
Oh man this is tough to understand....I downloaded solution :(. Thanks to all who triedit. I looked at your tries and learned something.
Level 9 , Timisoara, Romania
18 November 2020, 10:19
I think there is a problem of explanation of this exercise, should be rectified from the admin ... how can be the point 2.1 before 2.3??? if you remove all the words with containing "r" at the point 2.1 how does the point 2.3 be fulfilled??? so the paragraph 2.3 should be 2.1 :) ....
Level 9 , Vilnius, Lithuania
7 October 2020, 13:56
A hint how I did it: 1. For a fix method use "for loop" (int i = 0; i < list.size();) to iterate through the list, but don't specify the 3rd argument (i++). 2. Inside the loop use 3 if / else if statements: 2.1. if ((string contains "r" AND "l") OR (doesn't contain "r" AND "l) proceed iteration (i++); 2.2. else if a string contains "r" use .remove but don't iterate further (leave i unchanged); 2.3. else if a string contains "l" use .add to duplicate the string, but make sure to place at exact index iteration is at ( .add(i, list.get(i)) ). Iterate further 2 steps (i+= 2); 3. And lastly don't forget to change return statement so it returns the list, not null. I hope it helps. Good Luck!
Level 22 , Moscow, Russian Federation
5 November 2020, 10:26
thank you a lot!!!
ziv fisher
Level 9 , Petah Tikva, israel
2 October 2020, 19:41
A hint for the ones who choses to use a new ArrayList<String>. In the end, right before the "return" statement use: Collections.reverse(yourNewArrayList); // To rearrange yourNewArrayList backwards.
Level 14 , United Kingdom
11 August 2020, 13:22
Managed to complete the task by creating and returning inner list within a method.