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.
Answer

Interview Answer

2 Answers

0

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
0

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
print(a)

Anonymous on Dec 16, 2017

Add Answers or Comments

To comment on this, Sign In or Sign Up.