Sorted Subsegments

  • + 0 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]