C++ | Sliding Window | TC: 0ms - 100%
Intuition
its a simple sliding window problem
we keep track of the sum of the digits to count the total number of 1s in the window
once we reach the sum k we ca
# Intuition
- its a simple sliding window problem 
- we keep track of the sum of the digits to count the total number of 1s in the window
- once we reach the sum `k` we can update our answer based on the current window
# Approach
- we keep two pointers for the window: `start` and `i`
- we also keep track of the current `sum`
- if the current sum exceeds k we start sliding the window by `++start`
- we also slide the window if the start is at a `0` as they don't contribute to anything and hence can be removed to get the substring of smallest length
- once we have a window with sum = `k` we can update our answer:
    - if the current window length < `min_length` we update `min_length` and store the new substring as the result
    - if the current window length = `min_length` we compare the previous answer with the current window substring and update accordingly

# Complexity
- Time complexity:
O(n)

- Space complexity:
O(n)

# Code
```cpp []
class Solution {
public:
    string shortestBeautifulSubstring(string s, int k) {
        int start = 0 , sum = 0 , min_len = INT_MAX ; 
        string res = "" ;
        for(int i = 0 ; i < s.length() ; i++){
            sum += s[i]-'0' ;
            while(sum > k || (s[start] == '0' && start <= i)){
                sum -= (s[start]-'0') ;
                ++start ;
            }
            if(sum == k){
                int len = i-start+1 ; 
                string curr = s.substr(start,len) ;
                if(len < min_len){
                    res = curr ;
                    min_len = len ;
                }
                else if(len == min_len && curr < res){
                    res = curr ;
                }
            }
        }
        return res ;
    }
};
```
['Sliding Window', 'C++']