Challenge: Arrange a Binary List

Let's write a function to sort a binary list.

Problem statement

Implement a function sort_binary_list(lst) that takes a binary list of numbers and returns a sorted list.


A list having binary numbers


A sorted binary list

Sample input

lst = [1, 0, 1, 0, 1, 1, 0, 0]

Sample output

result = [0, 0, 0, 0, 1, 1, 1, 1]

Coding exercise

First, take a close look at this problem and design a step-by-step algorithm before jumping to the implementation. This problem is designed for your practice, so try to solve it on your own first. If you get stuck, you can always refer to the solution provided in the next section. Good luck!

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.