Introduction
This challenge requires finding the length of the longest substring with at most k distinct characters in a given string.
This challenge requires finding the length of the longest substring with at most k distinct characters in a given string.
Given a string and an integer k, find the length of the longest substring that contains at most k distinct characters. A substring is a contiguous block of characters. For example, in the string "abcabcdefgghiij", the longest substring with at most 3 distinct characters is "abcabc". If there are multiple substrings with the same length, return any of them.
To solve this challenge, the following requirements must be met:
The following examples demonstrate the expected behavior of the code:
The code should handle invalid inputs gracefully, search case sensitively, and return an integer as the result. The code should be able to handle the input within memory limits.