DevJourney · code I wrote while learning

README.md

1.2 KB

Smart Data Organizer

Single File Programming Question Problem Statement Riya is working on a smart data organizer that checks whether a given array is a rotated version of a strictly increasing sorted array. The array is allowed to rotate only in a clockwise direction (i.e., right rotation). If it can be rotated to become sorted, the program should print the number of right rotations required. If it's already sorted, print 0. If it's not possible through any rotation, print -1. She uses a class ArrayRotationChecker and a method readArray() and findRotationCount() to accomplish this task. Input format : The first line of input contains an integer n, representing the size of the array. The second line of input contains n space-separated integers. Output format : The output prints an integer representing the number of right rotations needed to sort the array. If not possible, print -1. Refer to the sample output for formatting specifications. Code constraints : The given testcases fall under the following constraints: 2 ≤ n ≤ 105 All elements are distinct −104 ≤ arr[i] ≤ 104 Sample test cases : Input 1 : 5 1 2 3 4 5 Output 1 : 0 Input 2 : 5 5 1 2 3 4 Output 2 : 4 Input 3 : 5 3 1 4 2 5 Output 3 : -1