Posts

Showing posts from October, 2021

Google CodeJam

REVERSORT Problem Note: The main parts of the statements of the problems "Reversort" and "Reversort Engineering" are identical, except for the last paragraph. The problems can otherwise be solved independently. Reversort is an algorithm to sort a list of distinct integers in increasing order. The algorithm is based on the "Reverse" operation. Each application of this operation reverses the order of some contiguous part of the list. The pseudocode of the algorithm is the following: Reversort(L): for i := 1 to length(L) - 1 j := position with the minimum value in L between i and length(L), inclusive Reverse(L[i..j]) After  i − 1 i − 1  iterations, the positions  1 , 2 , … , i − 1 1 , 2 , … , i − 1  of the list contain the  i − 1 i − 1  smallest elements of L, in increasing order. During the  i i -th iteration, the process reverses the sublist going from the  i i -th position to the current position of the  i i -th minimum element. Tha...