Intuitive Java Solution : Beginner friendly
IntuitionExactly k ones -> leads to a sliding window intuition.
format of code is usually :Approach
Lexicographic comparison means using str1.compareTo(str2) in
# Intuition
Exactly k ones -> leads to a sliding window intuition. 
format of code is usually : 

```
while(r < n){
    while(condition){
        // shrink window
        l++;
    }
    if(condition){
        // calculate ans according to requirements     
    }
    r++;
}

```

# Approach

1. Lexicographic comparison means using str1.compareTo(str2) in java. 
2. Keeping a count of ones to satisfy beautiful string condition. 
3. Need to remove unnecessary trailing zeroes. 

# Complexity
- Time complexity:
O(n) - for sliding window approach
- Space complexity: 
O(n) - for the answer variable.

# Code
```java []
class Solution {
    public String shortestBeautifulSubstring(String s, int k) {
        char[] str = s.toCharArray(); 
        int n = str.length;
        String ans = ""; 
        int count = 0; 

        int l = 0, r = 0; 
        while(r < n){
            if(str[r] == '1'){
                count++;
            }

            while(count > k || (count == k && str[l] == '0')){
                if(str[l] == '1'){
                    count--;
                }
                l++;
            }

            if(count == k){
                if((r - l + 1) < ans.length() || ans.length() == 0){
                    ans = s.substring(l, r+1);
                }
                if((r-l+1) == ans.length()){
                    String temp = s.substring(l, r+1);
                    if(temp.compareTo(ans) < 0){
                        ans = temp;
                    }
                }
            }
            r++;
        }
        return ans;
    }
}
```
['Java']