Deja Vu Challenge | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Deja Vu Challenge

Hi i Need help With my Code. 4 out of 5 cases are Succesful, only the Last case fails… i dont get the mistake to be honest 🙈 #include <iostream> using namespace std; int main() { bool DejaVu = false; string random, buffer; cin>>random; for(int i = 0; i<=random.size(); i++) { if(buffer.find(random[i]) == string::npos) { buffer += random[i]; } else { cout<<"Deja Vu"; DejaVu = true; } } if(DejaVu == false) { cout<<"Unique"; } return 0; }

26th Jul 2021, 7:43 PM
Nico Philipp
Nico Philipp - avatar
2 Answers
+ 4
For a character in a string repeating more than 1 time it outputs that many "Deja Vu".So , breaking the for loop after first repeating character is found , should do the work.
26th Jul 2021, 8:21 PM
Abhay
Abhay - avatar
+ 1
That was the error 🙄 Thank You so much 🎉🎉 I hadnt this possibility in mind at all 🙈
26th Jul 2021, 8:36 PM
Nico Philipp
Nico Philipp - avatar