6 kyu
Longest 2-character substring
152 of 329JDeBolt
Description:
Find the longest substring within a string that contains at most 2 unique characters.
substring("a") => "a"
substring("aaa") => "aaa"
substring("abacd") => "aba"
substring("abacddcd") => "cddcd"
substring("cefageaacceaccacca") => "accacca"
This function will take alphanumeric characters as input.
In cases where there could be more than one correct answer, the first string occurrence should be used. For example, substring('abc') should return 'ab' instead of 'bc'.
Although there are O(N^2) solutions to this problem, you should try to solve this problem in O(N) time. Tests may pass for O(N^2) solutions but, this is not guaranteed.
This question is much harder than some of the other substring questions. It's easy to think that you have a solution and then get hung up on the implementation.
Algorithms
Similar Kata:
Stats:
Created | Aug 1, 2015 |
Published | Aug 1, 2015 |
Warriors Trained | 906 |
Total Skips | 39 |
Total Code Submissions | 2691 |
Total Times Completed | 329 |
JavaScript Completions | 152 |
Python Completions | 188 |
Total Stars | 48 |
% of votes with a positive feedback rating | 94% of 110 |
Total "Very Satisfied" Votes | 99 |
Total "Somewhat Satisfied" Votes | 9 |
Total "Not Satisfied" Votes | 2 |