Oracle Interview Question: Sort Binary Arrays - {0,1,0,1... | Glassdoor.co.in

Interview Question

Test Automation Engineer Interview Bengaluru

Sort Binary Arrays - {0,1,0,1,1,1,0,0,0,1}

Answer

Interview Answer

7 Answers

2

public static void SortBinaryArrays(int[] Binary) {
        int[] sorrtedArray = new int[Binary.length];
        int i = 0;
        for (int a : Binary) {
            if (a == 0) {
                sorrtedArray[i] = a;
                i++;
            }
        }
        for (int a : Binary) {
            if (a == 1) {
                sorrtedArray[i] = a;
                i++;
            }
        }
        for (int a : sorrtedArray) {
            System.out.print(a + " ");
        }
    }

Keshav Sharma on 01-Jun-2018
1

int [] a= {1,0,1,0,1,1,1,0,0,0};

        int [] arr= new int[a.length];

        int left=0; int right=a.length-1;

        while (left

Learner on 09-Dec-2018
0

public static void main(String[] args) {

        int [] a= {1,0,1,0,1,1,1,0,0,0};

        int [] arr= new int[a.length];

        int left=0; int right=a.length-1;

        while (left

Learner on 09-Dec-2018
1

public static void main(String[] args) {

        int [] a= {1,0,1,0,1,1,1,0,0,0};

        int [] arr= new int[a.length];

        int left=0; int right=a.length-1;

        while (left

xyz on 09-Dec-2018
0

int[] a={0,1,0,1,1,1,0,0,0,1};
int index=0;
public static int[] sortBinaryArray(int[] a)
{
for(int i=0;i

Anonymous on 06-May-2020
0

public static int[] sortBinaryArray(int[] a)
    {
        int leftptr=0;
        int rightptr=a.length-1;
        while(true)
        {
        while(a[leftptr]==0)
        {
            leftptr++;
        }
        while(a[rightptr]==1)
        {
            rightptr--;
        }
        if(leftptr

Shabana Khan on 16-May-2020

One or more comments have been removed.
Please see our Community Guidelines or Terms of Service for more information.

Add Answers or Comments

To comment on this, Sign In or Sign Up.