• Asked to answer
    + 2 comments

    I dont think that it depends on language its just simply the concept of converting an array in a tree .

    Now why i said to convert an array in a tree? Its just because operations in a tree are much more efficient than on array (specifically in this question).

    Now what if you create a tree but that got skewed ? So try to use the concept of treaps.(Its nothing but using random numbers as priority of array elements to create a tree from an array).

    After that is done You can simply do the operations by splitting the tree according to your indexes and then merging them acording to type 1 or type 2.

    I think I have tried to simplify the concept.

    tell me if you require any further help.

    Never tried in Javascript and Python. :P