Grokking the Coding Interview: Patterns for Coding Questions
Ask Author
Back to course home

0% completed

Vote For New Content
Darshana Hettiarachchi
Stack doesn't have a reverse method in js solution

Darshana Hettiarachchi

May 6, 2024

// Reverse the order of binary digits in the stack and join them into a binary string

return stack.reverse().join("");

should call pop and concat values

let bnum = '';

while(stack.length){ //idelay !stack.isempty()

bnum += stack.pop();

}

return bnum;

1

0

Comments
Comments
T
traviswlilleberg 5 days ago

I agree with this. I think reversing the array and then iterating over it creates more time complexity because you have to shift all the values in the array into different indexes and then iterate over it again to build the output.

Looping with array.pop doesn't alte...

On this page