Check Array Rotation
You have been given an integer array/list(ARR) of size N. It has been sorted(in increasing order) and then rotated by some number 'K' in the clockwise direction.
Your task is to write a function that returns the value of 'K', that means, the index from which the array/list has been rotated.
Input format :
Output Format :
Constraints :
Sample Input 1:
Sample Output 1:
Sample Input 2:
Sample Output 2:
#include <iostream>
using namespace std;
#include "solution.h"
#include<climits>
int arrayRotateCheck(int *input, int size)
{
//Write your code here
int min=12000;
int i;
int j=0;
for( i=0;i<size;i++){
if(input[i]<min){
min=input[i];
j=i;
}
}
return j;
}
int main()
{
int t;
cin >> t;
while (t--)
{
int size;
cin >> size;
int *input = new int[size];
for (int i = 0; i < size; i++)
{
cin >> input[i];
}
cout << arrayRotateCheck(input, size) << endl;
delete[] input;
}
return 0;
}
Comments
Post a Comment