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:

## C++

`// 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*

## Java

`// Java to check whether given ` `// array is breakable or not ` ` ` `class` `GFG ` `{ ` ` ` `// Function to check ` `static` `int` `checkArray(` `int` `[]arr, ` `int` `n) ` `{ ` ` ` `// Check the result by processing ` ` ` `// the first & last element and size ` ` ` `return` `((arr[` `0` `] % ` `2` `) > ` `0` `&& ` ` ` `(arr[n - ` `1` `] % ` `2` `) > ` `0` `&& ` ` ` `(n % ` `2` `) > ` `0` `) ? ` `1` `: ` `0` `; ` `} ` ` ` `// Driver code ` `public` `static` `void` `main(String[] args) ` `{ ` ` ` `int` `[]arr = { ` `1` `, ` `2` `, ` `3` `, ` `4` `, ` `5` `}; ` ` ` `int` `n = arr.length; ` ` ` `System.out.println(checkArray(arr, n)); ` `} ` `} ` ` ` `// This code contributed by Rajput-Ji ` |

*chevron_right*

*filter_none*

## Python3

`# Python3 to check whether given ` `# array is breakable or not ` ` ` `# Function to check ` `def` `checkArray(arr, n): ` ` ` ` ` `# Check the result by processing ` ` ` `# the first & last element and size ` ` ` `return` `((arr[` `0` `] ` `%` `2` `) ` `and` ` ` `(arr[n ` `-` `1` `] ` `%` `2` `) ` `and` `(n ` `%` `2` `)) ` ` ` `# Driver code ` `arr ` `=` `[` `1` `, ` `2` `, ` `3` `, ` `4` `, ` `5` `] ` `n ` `=` `len` `(arr); ` `if` `checkArray(arr, n): ` ` ` `print` `(` `1` `) ` `else` `: ` ` ` `print` `(` `0` `) ` ` ` `# This code is contributed ` `# by Mohit Kumar ` |

*chevron_right*

*filter_none*

## C#

`// C# to check whether given ` `// array is breakable or not ` `using` `System; ` ` ` `class` `GFG ` `{ ` ` ` `// Function to check ` `static` `int` `checkArray(` `int` `[]arr, ` `int` `n) ` `{ ` ` ` `// Check the result by processing ` ` ` `// the first & last element and size ` ` ` `return` `((arr[0] % 2) > 0 && ` ` ` `(arr[n - 1] % 2) > 0 && ` ` ` `(n % 2) > 0) ? 1 : 0; ` `} ` ` ` `// Driver code ` `static` `void` `Main() ` `{ ` ` ` `int` `[]arr = { 1, 2, 3, 4, 5 }; ` ` ` `int` `n = arr.Length; ` ` ` `Console.WriteLine(checkArray(arr, n)); ` ` ` `} ` `} ` ` ` `// This code is contributed by mits ` |

*chevron_right*

*filter_none*

## PHP

`<?php ` `// PHP to check whether given ` `// array is breakable or not ` ` ` `// Function to check ` `function` `checkArray(` `$arr` `, ` `$n` `) ` `{ ` ` ` `// Check the result by processing ` ` ` `// the first & last element and size ` ` ` `return` `(` `$arr` `[0] % 2) && ` ` ` `(` `$arr` `[` `$n` `- 1] % 2) && (` `$n` `% 2); ` `} ` ` ` `// Driver code ` `$arr` `= ` `array` `( 1, 2, 3, 4, 5 ); ` `$n` `= sizeof(` `$arr` `); ` `echo` `checkArray(` `$arr` `, ` `$n` `); ` ` ` `// This code is contributed by Ryuga ` `?> ` |

*chevron_right*

*filter_none*

‘

**Output:**

1

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the **DSA Self Paced Course** at a student-friendly price and become industry ready.

## Recommended Posts:

- Count of ways to split a given number into prime segments
- Partition into two subarrays of lengths k and (N - k) such that the difference of sums is maximum
- Divide an array into k segments to maximize maximum of segment minimums
- Partition an array such into maximum increasing segments
- Partition the array into three equal sum segments
- Maximum sum of the array after dividing it into three segments
- Check if a large number can be divided into two or more segments of equal sum
- Minimum splits required to convert a number into prime segments
- Split array into K disjoint subarrays such that sum of each subarray is odd.
- Check if it is possible to split given Array into K odd-sum subsets
- Divide N segments into two non-empty groups such that given condition is satisfied
- Equation of straight line passing through a given point which bisects it into two equal line segments
- Sort an array of strings according to string lengths using Map
- Split an Array A[] into Subsets having equal Sum and sizes equal to elements of Array B[]
- Number of triangles possible with given lengths of sticks which are powers of 2
- Split Array into min number of subsets with difference between each pair greater than 1
- Split array into minimum number of subarrays having GCD of its first and last element exceeding 1
- Split array into two equal length subsets such that all repetitions of a number lies in a single subset
- Split array into minimum number of subsets having maximum pair sum at most K
- Maximum sum of lengths of non-overlapping subarrays with k as the max element.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.