Given an array of n length. The task is to check if the given array can be split into an odd number of sub-segment starting with odd integer and also the length of sub-segment must be odd. If possible the print ‘1’ else print ‘0’.

**Examples:**

Input:arr[] = {1, 3, 1}

Output:1

1, 3, 1, can be split into 3 sub-segments of length odd i.e. 1

with starting and ending elements as odd.

Input:arr[] = {1, 3, 1, 1}

Output:0

**Approach:**

Points to think before proceeding the actual solution:

- Order of sets made by adding an even number of the set with odd order is always even and vice-versa.
- Order of sets made by adding an odd number of the set with odd order is always odd and vice-versa.

Using the above lemma of number theory, the solution of the given problem can be easily calculated with below-proposed logic:

If the given array starts and ends with an odd integer and also the size of the array is odd then only the given array can be broken down into an odd number of sub-segments starting & ending with an odd number with odd size, else not.

Below is the implementation of the above approach:

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

*chevron_right*

*filter_none*

**Output:**

1

## Recommended Posts:

- Partition an array such into maximum increasing segments
- Divide an array into k segments to maximize maximum of segment minimums
- Number of segments where all elements are greater than X
- Check if a large number can be divided into two or more segments of equal sum
- Split the array and add the first part to the end
- Split the array and add the first part to the end | Set 2
- Number of horizontal or vertical line segments to connect 3 points
- Minimum number of segments required such that each segment has distinct elements
- Split an array into two equal Sum subarrays
- Ways to split array into two groups of same XOR value
- Split array in three equal sum subarrays
- Split the array into equal sum parts according to given conditions
- Minimum number of cuts required to make circle segments equal sized
- Split array to three subarrays such that sum of first and third subarray is equal and maximum
- Minimum positive integer required to split the array equally