This is the code given in the solution -
public static String[] findBin(int number) {
String[] result = new String[number];
Queue<String> queue = new Queue<String>(number + 1);
queue.enqueue("1");
for (int i = 0; i < number; i++) {
result[i] = queue.dequeue();
String s1 = result[i] + "0";
String s2 = result[i] + "1";
queue.enqueue(s1);
queue.enqueue(s2);
}
return result; //For number = 3 , result = {"1","10","11"};
}
This is an excerpt from the solution explanation -
The queue takes integer values, so before enqueueing, the solution makes sure to convert the string to an integer.
-
How exactly does the queue “take integer values”, if it is declared to be of type String?
Queue<String> queue = new Queue<String>(number + 1);
-
The solution makes sure to convert the string to an integer - where exactly is the conversion happening? You’re starting off by enqueing a string “1”, then creating new strings by appending “0” and “1” and enqueing both strings directly.
Yet another example of poorly written solution explanation.
Course: Data Structures for Coding Interviews in Java - Learn Interactively
Lesson: https://www.educative.io/courses/data-structures-coding-interviews-java/B890P4RJ4xo