import std.math; + import std.typecons; /* We have an array 'arr' of N integers arr[1], arr[2], ..., arr[N].The - numbers in the array will be randomly ordered. Your task is to determine if ? ---- + numbers in the array will be randomly ordered. Your task is to determine if - it is possible to get an array sorted in non-decreasing order by performing ? ---- + it is possible to get an array sorted in non-decreasing order by performing - the following operation on the given array: ? ---- + the following operation on the given array: - You are allowed to perform right shift operation any number of times. ? ---- + You are allowed to perform right shift operation any number of times. - - One right shift operation means shifting all elements of the array by one ? ---- + One right shift operation means shifting all elements of the array by one - position in the right direction. The last element of the array will be moved to ? ---- + position in the right direction. The last element of the array will be moved to - the starting position in the array i.e. 0th index. ? ---- + the starting position in the array i.e. 0th index. - - If it is possible to obtain the sorted array by performing the above operation ? ---- + If it is possible to obtain the sorted array by performing the above operation - then return true else return false. ? ---- + then return true else return false. - If the given array is empty then return true. ? ---- + If the given array is empty then return true. - - Note: The given array is guaranteed to have unique elements. ? ---- + Note: The given array is guaranteed to have unique elements. - - For Example: ? ---- + For Example: - - >>> move_one_ball([3L, 4L, 5L, 1L, 2L]) ? ---- + >>> move_one_ball([3L, 4L, 5L, 1L, 2L]) - true + true - Explanation: By performin 2 right shift operations, non-decreasing order can ? ---- + Explanation: By performin 2 right shift operations, non-decreasing order can - be achieved for the given array. ? ---- + be achieved for the given array. - >>> move_one_ball([3L, 5L, 4L, 1L, 2L]) ? ---- + >>> move_one_ball([3L, 5L, 4L, 1L, 2L]) - false + false - Explanation:It is not possible to get non-decreasing order for the given ? ---- + Explanation:It is not possible to get non-decreasing order for the given - array by performing any number of right shift operations. ? ---- + array by performing any number of right shift operations. - - */ bool move_one_ball(long[] arr)