Split the array into odd number of segments of odd lengths | CPP to check whether given array is breakable or not ; Function to check ; Check the result by processing the first & last element and size ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool checkArray ( int arr [ ] , int n ) { return ( arr [ 0 ] % 2 ) && ( arr [ n - 1 ] % 2 ) && ( n % 2 ) ; } int main ( ) { int arr [ ] = { 1 , 2 , 3 , 4 , 5 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << ( int ) checkArray ( arr , n ) ; return 0 ; }