We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
The below code fails in 11 test cases only it pases 22 cases successfully. I think there is small issue in it if anyone can resolve it resolve. A simple approach but better results.....
def sortedSubsegments(k, a, queries):
s = []
for st, end in queries:
if st <= k <= end:
s.append(st)
s.append(end)
idx=max(s)
a[:idx]=sorted(a[:idx+1])
return a[k]
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Sorted Subsegments
You are viewing a single comment's thread. Return to all comments →
The below code fails in 11 test cases only it pases 22 cases successfully. I think there is small issue in it if anyone can resolve it resolve. A simple approach but better results.....
def sortedSubsegments(k, a, queries): s = [] for st, end in queries:
if st <= k <= end:
s.append(st) s.append(end) idx=max(s) a[:idx]=sorted(a[:idx+1]) return a[k]