Check if given permutation of 1 to N can be counted in clockwise or anticlockwise direction | C ++ program to check Clockwise or counterclockwise order in an array ; Comparing the first and last value of array ; If the Count is greater than 1 then it can 't be  represented in required order ; Driver function
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool check_order ( vector < int > arr ) { int cnt = 0 ; for ( int i = 0 ; i < arr . size ( ) - 1 ; i ++ ) { if ( abs ( arr [ i + 1 ] - arr [ i ] ) > 1 ) cnt ++ ; } if ( abs ( arr [ 0 ] - arr [ arr . size ( ) - 1 ] ) > 1 ) cnt ++ ; if ( cnt > 1 ) return false ; return true ; } int main ( ) { vector < int > arr = { 2 , 3 , 4 , 5 , 1 } ; if ( check_order ( arr ) ) cout << " YES " ; else cout << " NO " ; return 0 ; }