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".
R or L
- 10
Locked
Comments (45)
- Popular
- New
- Old
You must be signed in to leave a comment
Xavi MartinExpert
25 October 2022, 07:12
The statement is not well explained and I do not understand the solution because it does not explain why it does one thing or another.
0
Andrew Evans
2 February 2022, 03:09
Hint: don't (int i = 0; i < list.size(); i++), do (int i = size() - 1; i >= 0 ; i++)
If you're here it means you know that you are stuck on the part regarding removal.
0
Dinesh Full Stack Developer at Byndr Technologies
9 October 2021, 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.
+1
Aisuluu Zhumabaeva SDET at Capgemini
17 June 2021, 18:04
This task requirement is to solve without using keyboard, but the solution read data from keyboard.
0
sgubow
28 April 2021, 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.
+1
ImDevin
21 April 2021, 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.
+3
JF
21 July 2021, 16:22
Thanks! This helped me a lot! :)
0
Jurij Thmsn
13 January 2021, 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.
+2
Usman Full Stack Developer at QA
6 July 2021, 13:00
youre doing great!
0
Joe M
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.
0
MIHAI
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 :) ....
0
ъуъ
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!
+16
Maria
5 November 2020, 10:26
thank you a lot!!!
+3