Segregate 0s and 1s in an Array – Java Code

How to Segregate 0s and 1s in an Array.

Given an array of 0s and 1s in a random order. We have to write a code to segregate 0s on the left side and 1s on the right side of the array.

Basically, we have to sort an array of 0s and 1s.

For example –

Input array   =  [0, 1, 0, 1, 0, 0, 1]
Output array = [0, 0, 0, 0, 1, 1, 1]

In an input array 0s and 1s are in an unsorted order. The output is the sorted order of 0s and 1s.

Find Common Elements in Three Sorted Arrays – Java Code

Write a java program to find common elements in three sorted arrays.

Given three sorted arrays, write a code to print intersection of three sorted arrays.

For example –

arr1 = {1, 5, 10, 20, 40, 80};
arr2 = {6, 7, 20, 80, 100};
arr3 = {3, 4, 15, 20, 30, 70, 80, 120};

Output : {20, 80}

20 and 80 are the common elements in 3 arrays. These two elements are the intersection of 3 sorted arrays.