Wells FargoOA #5
Get Substring
Estimated MediumJudge-ready
Topics (AI-labelled)Two PointersStrings
In a string containing only 0/1, find a substring with exactly k 1s; first minimize the length, and among equal lengths take the lexicographically smallest. The statement guarantees an answer exists.
Input
The first line is the binary string s; the second line is k. Source range: 1≤k≤|s|≤1000, and s contains at least k 1s.
Output
Output the chosen substring (without quotes).
Example 1
Input:
0101101
3
Output:
1011
Example 2
Input:
101
1
Output:
1
Example 3
Input:
1011
2
Output:
11
Editorial
Loading solution…