+ 1

Please help me with this exercise.

What's wrong with this code. I cannot view test case 5 which is wrong. Please help. Code : #include <iostream> using namespace std; int main() { string inp, inp2; cin >> inp; inp2 = inp; bool isUnique = true; for (int i=0; ihttps://code.sololearn.com/cK3TeZZK9Dj9/?ref=app

8th May 2021, 8:25 AM
Parth Shendge
3 Answers
+ 3
Parth Shendge Break statement breaks the inner loop but not the outer loop. You can use this code. https://code.sololearn.com/ceX80apj3Ef0/?ref=app
8th May 2021, 12:00 PM
Indian - avatar
+ 1
Breaking from the inner loop is not going to terminate the outer loop. As a consequence, you print "Deja Vu" multiple times if the same letter has more occurences than two, or multiple different letters have duplicates. You could modify the condition of your outer loop to prevent this, for example: for ( ...; i < inp.size() && isUnique; ... ) { ... } This way, you would correctly exit both loops as soon as a duplicate letter has been found.
8th May 2021, 9:49 AM
Shadow - avatar
Oh ! Thanks I forgot to do that .
9th May 2021, 11:16 AM
Parth Shendge