I solved it using a list initialized to 1 through n and an array to keep track of the position of each integer in the final permutation.
while the list does not match the final permutation:
First see if a type 1 operation needs to be performed. This can be done in constant time by checking if the first two elements are not in the same order as they should be in the final permutation.
Perform a type 2 operation.
Check input and AC output for thousands of problems on uDebug!