Challenge: Generate Binary Numbers from 1 to n Using a Queue
Can you generate binary numbers from 1 to any given number "n"? A solution is placed in the "solution" section to help you, but we would suggest you try to solve it on your own first.
We'll cover the following
Problem Statement #
In this problem, using a queue, you have to implement the String[] findBin(int number)
method to generate binary numbers from 1 to any given number (n). An illustration is also provided for your understanding.
Method Prototype #
String[] findBin(int number)
Input #
A positive integer n.
Output #
It returns binary numbers up to n.
Sample Input #
n = 3
Sample Output #
result = {"1","10","11"}
Level up your interview prep. Join Educative to access 70+ hands-on prep courses.