educative.io

Using queue in this situation seems too much. Can be implemented with simple array push

function findBin(number) {
    let result = []
    result.push("1")
    for(let i = 0;  result.length < number; i++){
        let s1 = result[i] + "0"
        let s2 = result[i] + "1"
        result.push(s1, s2)
    }
    if (result.length > number) result.pop();
    return result;
}

Above solution simply uses array push and pop.
Why complicate this question with queue implementation? The only catch here seems to be adding 0 and 1 stuff,

We have added this solution to show you the application of the queue. You are absolutely right that we can do the same thing using built-in push() and pop() functions but we don’t have such flexibility in other languages. That’s why we feel a need to add this solution here.

Happy learning!

Maida Ijaz | Developer Advocate
educative.io