[Timelimit Exceeding]Can someone please help me understand why this is happening for inplace merge


#1
int i = 0, j= 0;
while(i<A.size() && j<B.size()) {
    // increment first array counter
    if (A[i]<B[j]) {
        i++;
    } else {
        // Inserting B[j] at the ith index
        A.insert(A.begin()+i, B[j]);
        j++;
        i++;
    }
}


// Remaining array
if(j<B.size()) {
    while(j<B.size()) {
        A.push_back(B[j]);
        j++;
    }
}

#2

insert function also have time complexity of O(n). So overall it is O(n^2);