Bloomberg L.P. Interview Question: Given a list of ones and zero... | Glassdoor

Interview Question

Financial Software Developer Interview(Student Candidate)

Given a list of ones and zeros, how would you sort the list

  efficiently so the zeros are in the front and the ones are in the second half.

Interview Answer

2 Answers


I learned this a year ago in my C# class. We did insertion sort, merge sort, quick sort and selection sort.

Anonymous on Aug 28, 2017

a = [1,0,1,0,1]
i = 0
j = len(a)-1
while i 0 and a[j] != 0:
        j -= 1
    if a[i] == 1:
        a[j] ,a[i] = a[i], a[j]
    i += 1

Anonymous on Dec 16, 2017

Add Answers or Comments

To comment on this, Sign In or Sign Up.