I am solving the puzzle and for some of the test cases I do not see a possible solution.
For instance it seems that for test 4 the highest number of consecutive characters is 3 - “ttt”, and I do not understand how counting to 18 in any direction can result in the right answer which is 46.
Can anybody please clarify the puzzle statement a bit.
Thanks in advance.
The puzzle is after the longest substring that contains at most K unique letters (eg if K was 26 then it would always be the entire string). There isn’t any mention of consecutive identical characters.
Thanks for the clarification.
I misinterpreted the statement, counting the length of the substring resulting after K unique characters are encountered and aborting afterwards.
It works as expected now.
Please indicate a convenient time for you for an interview for the position of Lead Programmer in the High-Load Systems Development and Optimization Department.
A string is called KGood if and only if it has no more than (ie. less than or equal to) K different characters (lowercase letters of English alphabet).
Also, O(n) means the complexity of your code : O(n) is a linear complexity, as it’s duration is directly proportionnal to the length of the input (it means it pass only once through the input).
I understand this sentence to mean that a string is good if it contains no more than K different lowercase letters, which does not actually exclude the presence of other symbols in it.
This puzzle was nice, but I think the test cases leave a bit to be desired. To justify the “hard” classification, I think there should have been test cases that required a O(n) solution to avoid timeout.
I completely agree. Although I solved it faster (>5min) than some puzzles in the Easy section. Many interesting puzzles lack test cases that require an optimal solution.
Stumbling on the same problem of failing validator 1, I probably misinterpreted something but I can’t find a test failing on my code
I’ve tried multiples tests cases like “aaaaa” or “abbba” and my code return 5 or 3 which is ok I think for K=1 (for k>1 it return 5 for both cases).
I’d really appreciate a similar case as the validator to understand where my code fail as I really can not find the flaw actually.