All Questions
Tagged with stack javascript
15 questions
3
votes
2
answers
208
views
Check for max value in stack
Got this problem in a coding interview -
Get the max value of a stack in O(1).
The stack contains numbers only.
Please review my solution.
...
4
votes
2
answers
1k
views
Stack Implementation in JavaScript
I am learning data structures and below is my implementation of a stack in JavaScript. I didn't want to use built in functions for an array because in JavaScript that would be too easy, so I made my ...
3
votes
3
answers
1k
views
JavaScript Sort Stack Coding Challenge
A coding challenge to write a function sortStack that receives a stack of integers into ascending order (with largest integers on top) and returns another stack ...
5
votes
2
answers
941
views
Create a min stack
The task
is taken from leetcode
Design a stack that supports push, pop, top, and retrieving the
minimum element in constant time.
push(x) -- Push element x onto stack.
pop() -- Removes ...
4
votes
0
answers
154
views
All the paths from the root to the leaves
Given a binary tree, return all root-to-leaf paths.
Example:
-- 1
/ \
2 3
\
5
Output should be: ["1->2->5", "1->3"]
My approach: I walk the branches ...
0
votes
1
answer
891
views
Iteratively determine the diameter of a binary tree
Can the performance of the iterative approach be improved? I find that this approach lags behind many recursive options. no recursive answers, please.
Baseline recursive approach: takes 52 steps ...
6
votes
1
answer
1k
views
Multiple stacks implemented via a linked lists on top of single fixed-size array
Problem Statement
Originally, the problem is defined in the book as following:
Describe how you could use a single array to implement three stacks. — Cracking the Coding Interview (6th edition)
...
3
votes
3
answers
4k
views
HackerRank (Stacks) - Maximum element solution gets a timeout
Apparently my solution is really slow. Can someone help me with why my solution passes a little over half the test cases for this question?
Here is my solution:
...
2
votes
1
answer
75
views
JavaScript Queue Attempt #2
This is a follow-up review to JavaScript queue implementation using linked list
I've run the code through a linter, fixed every style error, added const where it ...
4
votes
2
answers
1k
views
JavaScript animation effect stack
I am building a library that uses animations in a canvas.
I need to apply effects to some objects in the canvas and I came up with an effect stack that contains each effect to be executed on a ...
6
votes
2
answers
5k
views
Hackerrank CTCI "Stacks: Balanced Brackets" Javascript Solution
Here is the original problem, and below is my solution. I wonder what can be improved? Or is there a fundamentally better algorithm out there? Thank you! My intuition is telling me that it can be more ...
6
votes
1
answer
281
views
Balancing Brackets Algorithm: Stack Data Structure
I am currently refining my understanding of data structures and as such, decided to implement a popular application of the Stack. Below you will find my implementation of the Balancing Symbols ...
3
votes
1
answer
608
views
Stack which finds the minimum element
Write a program to implement stack which implements min a method
which gives the minimum element below the top element in the stack.
...
4
votes
2
answers
784
views
Stack implementation in ES6
Finally happy to see that now we can have iterators and generators. I also need to try to have private properties too so that we have well encapsulated data structures and I see that there are Proxies ...
44
votes
2
answers
40k
views
Balanced parentheses
Given an expression string exp, write a program to examine whether the
pairs and the orders of
"{","}","(",")","[","]"
are correct in exp.
For example,...