r/dailyprogrammer • u/nint22 1 2 • Jun 10 '13
[Easy] Longest Two-Character Sub-String
(Easy): Longest Two-Character Sub-String
This programming challenge is a classic interview question for software engineers: given a string, find the longest sub-string that contains, at most, two characters.
Author: /u/Regul
Formal Inputs & Outputs
Input Description
Through standard console input, you will be given a string to search, which only contains lower-case alphabet letters.
Output Description
Simply print the longest sub-string of the given string that contains, at most, two unique characters. If you find multiple sub-strings that match the description, print the last sub-string (furthest to the right).
Sample Inputs & Outputs
Sample Inputs
abbccc
abcabcabcabccc
qwertyytrewqSample Outputs
bbccc
bccc
tyyt
62
Upvotes
1
u/iche0815 Jun 13 '13 edited Jun 13 '13
I'm starting to learn C++ and was reading through your code trying to understand it. I think I get most of it, I just have a question regarding your second if structure:
Would there be a difference to this:
? Since the break only goes back out of the if structure and nothing else is written in the else part, so if there would not be the else part the program would also go out of the if structure.
edit: YAY, cake day :)