From 5b81272c2665d79600546b67111b2c3f467aadeb Mon Sep 17 00:00:00 2001 From: Satyam Tripathi Date: Fri, 1 Oct 2021 01:24:49 +0530 Subject: [PATCH 1/2] Add files via upload --- gfg/Kth Smallest Element/Kth smallest element.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 gfg/Kth Smallest Element/Kth smallest element.py 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 From 71100267c7c57b196f560a35a104538c99279e70 Mon Sep 17 00:00:00 2001 From: Satyam Tripathi Date: Fri, 1 Oct 2021 01:40:33 +0530 Subject: [PATCH 2/2] Add files via upload --- LeetCode/string/Special Binary String.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 LeetCode/string/Special Binary String.py 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