Find the minimum operations to sort a permutation using reverse and rotate.
Unlock detailed company stats for this questionUpgrade
Given a permutation arr of size n (a sequence of integers from 1 to n, each exactly once), sort it in increasing order using only two operations: reverse the entire permutation, or move the first element to the last position. Return the minimum number of operations needed. The permutation is guaranteed to be sortable with these two operations. Array size was up to 5*10^5. Example: n = 10, arr = [2,3,4,5,6,7,8,9,10,1]. Reverse to get [1,10,9,...,2], move the first element to the end to get [10,9,...,1], reverse to get [1,2,...,10]. The minimum is 3 operations.
Format · Amazon SDE-2 OA.
Community answers
No answers contributed by the community yet.
Related questions
Minimum operations to sort a permutation.Find the minimum operations to reduce n to zero using powers of two.Minimum operations to sort a string.Related courses

Course

Course
Course
