K Smallest Substring
Problem Overview
- Find the substring with exactly k '1's, minimal length, and if tied, lexicographically smallest.
- Inputs: binary string input_str and integer k; Output: the chosen substring; an answer is guaranteed.
- Constraints: 1 ≤ k ≤ |s| ≤ 10^3; s[i] ∈ {'0','1'}; count('1') ≥ k.
- Context: Binary string processing and substring selection; common coding interview interview question problem.
- Source: Asked in Akuna interviews.
Example
Unlock to view complete problem details
and practice with sample input/output
Was this article helpful?
View Test Cases & Run Code requires membership
Input Variables
Execution Result:
