×

Learn basic concept of c , c++ and python programming in regularcodes.com

# Segregate 0s and 1s in an array

Given an array, and there are contain data in 0s and 1s in un-sorted form. Our goal is to arrange this 0s and 1s data in separate group.

**Example:**

Given a two method to solve this problem.

1) Simplest method : In this method count all number of 1's. and put all 1's at beginning of array and remaining are 0s. time complexity is O(n).

This function are separating 1s and 0s.

2) Special method : This method use two integer variable start_index and end_index. start_index are initialize 0 and end_index are initialize (size of array -1). Use only one while loop.

This function are separating 1s and 0s.

### Program

### Output

Code execution process.

View comments and participate Discussion