Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions LeetCode/string/Special Binary String.py
Original file line number Diff line number Diff line change
@@ -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)
14 changes: 14 additions & 0 deletions gfg/Kth Smallest Element/Kth smallest element.py
Original file line number Diff line number Diff line change
@@ -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