Custom Sorting || Sliding window || 0ms || Easy Approach and Solution 
ApproachWe need to find the shortest substring of a given binary string s that contains exactly k ones. If multiple substrings of the shortest length exist, we

# Approach
<!-- Describe your approach to solving the problem. -->
We need to find the shortest substring of a given binary string s that contains exactly k ones. If multiple substrings of the shortest length exist, we return the lexicographically smallest one.

**Breakdown of the Approach**
1. Identify the positions of ‘1’s in the string and store their indices.

1. Find all possible valid substrings that contain exactly k ones.

1. Sort the substrings by their length first and lexicographically second.

1. Return the smallest valid substring, or an empty string if no valid substring exists.

# Step-by-Step Implementation
1. **Finding indices of ‘1’s**
    - We first iterate through the string s and store the indices where '1' appears in a list ind. This helps in efficiently locating substrings containing exactly k ones.

```python3 []
ind = []
for i in range(len(s)):
    if s[i] == '1':
        ind.append(i)
```
2. **Extracting all substrings with exactly k ones**

    - We iterate over ind and extract substrings that start from ind[i] and end at ind[i + k - 1], ensuring each substring contains exactly k ones.

```python3 []
a = []
for i in range(len(ind) - k + 1):
    a.append([ind[i], ind[i + k - 1]]) 
```
Each element in a represents the start and end index of a substring that contains exactly k ones.

3. **Generating substrings**
    - Using the start and end indices stored in a, we extract substrings from s:
```python3 []
st = []
for i, j in a:
    st.append(s[i:j + 1])
```
4. **Sorting substrings**
We sort the substrings based on:
    - Length (ascending order) → Ensures we get the shortest valid substring.
    - Lexicographical order → Ensures that if multiple substrings have the same length, we pick the smallest one.

```python3 []
st.sort(key=lambda x: (len(x), x))
```
5. **Returning the result**
If no valid substring is found, return "". Otherwise, return the first element in st (which is the shortest and lexicographically smallest substring).

```python3 []
if not st:
    return ''
return st[0]
```

# Complexity
- Time complexity: O(n log n)
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity: O(n^2)
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```python3 []
class Solution:
    def shortestBeautifulSubstring(self, s: str, k: int) -> str:
        c=0
        ind=[]
        for i in range(len(s)):
            if s[i]=='1':
                ind.append(i)
        a=[]
        for i in range(len(ind)-k+1):
           a.append([ind[i],ind[i+k-1]]) 
        st=[]
        for i,j in a:
            st.append(s[i:j+1])
        st.sort(key=lambda x:(len(x),x))
        if not st:
            return ''
        return st[0]


```
['String', 'Sliding Window', 'Sorting', 'Python3']