diff --git a/LeetCode/string/Special Binary String.py b/LeetCode/string/Special Binary String.py new file mode 100644 index 0000000..bc85ea7 --- /dev/null +++ b/LeetCode/string/Special Binary String.py @@ -0,0 +1,14 @@ +class Solution: + def makeLargestSpecial(self, s: str) -> str: + l=r=0 + res=[] + for i in range(len(s)): + if s[i]=='0': + r-=1 + else: + r+=1 + if r == 0: + res.append("1"+self.makeLargestSpecial(s[l+1:i])+"0") + l=i+1 + res.sort(reverse=True) + return "".join(res) \ No newline at end of file diff --git a/gfg/Kth Smallest Element/Kth smallest element.py b/gfg/Kth Smallest Element/Kth smallest element.py new file mode 100644 index 0000000..f896b11 --- /dev/null +++ b/gfg/Kth Smallest Element/Kth smallest element.py @@ -0,0 +1,14 @@ +from heapq import * +class Solution: + def kthSmallest(self, arr, l, r, k): + heap = [] + for item in arr[:k]: + heappush(heap, -item) + + for item in arr[k:]: + if item < -heap[0]: + heappush(heap, -item) + heappop(heap) + + temp = heappop(heap) + return -temp \ No newline at end of file