sort-stack
This is a question that I was asked for during a job interview.
Sort a stack using a temporary stack.
I have made a video explaining the solution here https://www.youtube.com/watch?v=ocFJyyL3Yfc&t=78s
The code is in Typescript. I am actually using an array instead of a stack. But, I am accessing only the top element of the array. I have no time to implement an actual stack data structure. This will likely be acceptable in an actual interview.
1 | function sortStack(ip: number[]): number[]{ |
To run this code:
tsc filename.ts
npx filename.js