Check if a Matrix is Reverse Bitonic or Not | C ++ Program to check if a matrix is Reverse Bitonic or not ; Function to check if an array is Reverse Bitonic or not ; Check for decreasing sequence ; Check for increasing sequence ; Function to check whether given matrix is bitonic or not ; Check row - wise ; Check column wise ; Generate an array consisting of elements of the current column ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; const int N = 3 , M = 3 ; bool checkReverseBitonic ( int arr [ ] , int n ) { int i , j , f = 0 ; for ( i = 1 ; i < n ; i ++ ) { if ( arr [ i ] < arr [ i - 1 ] ) continue ; if ( arr [ i ] == arr [ i - 1 ] ) return false ; else { f = 1 ; break ; } } if ( i == n ) return true ; for ( j = i + 1 ; j < n ; j ++ ) { if ( arr [ j ] > arr [ j - 1 ] ) continue ; if ( arr [ i ] == arr [ i - 1 ] ) return false ; else { if ( f == 1 ) return false ; } } return true ; } void check ( int arr [ N ] [ M ] ) { int f = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( ! checkReverseBitonic ( arr [ i ] , M ) ) { cout << " No " << endl ; return ; } } for ( int i = 0 ; i < N ; i ++ ) { int temp [ N ] ; for ( int j = 0 ; j < N ; j ++ ) { temp [ j ] = arr [ j ] [ i ] ; } if ( ! checkReverseBitonic ( temp , N ) ) { cout << " No " << endl ; return ; } } cout << " Yes " ; } int main ( ) { int m [ N ] [ M ] = { { 2 , 3 , 4 } , { 1 , 2 , 3 } , { 4 , 5 , 6 } } ; check ( m ) ; return 0 ; }