Skip to main content

All Questions

Filter by
Sorted by
Tagged with
3 votes
2 answers
186 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. ...
G.R's user avatar
  • 39
5 votes
1 answer
109 views

An alternative algorithm for sorting a stack using only one additional stack

From "Cracking the Coding Interview": Write a program to sort a stack in ascending order (with biggest items on top). You may use at most one additional stack to hold items, but you may not copy ...
Michael Wright's user avatar
1 vote
2 answers
488 views

Leetcode - find if BST is valid or not

Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as follows: The left subtree of a node contains only nodes with keys less than the node'...
Mosbius8's user avatar
  • 769
25 votes
3 answers
9k views

Leetcode: Valid parentheses

Leetcode: Valid parentheses Given a string containing just the characters (, ), {, ...
Gilad's user avatar
  • 5,253
3 votes
0 answers
914 views

Find redundant braces in an input string

I am solving interview questions from here. Problem : Write a program to validate if the input string has redundant braces Return 0/1 : ...
Latika Agarwal's user avatar
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) ...
Igor Soloydenko's user avatar
2 votes
1 answer
688 views

Stack using linked List

I have this problem with my interview. I was asked to implement a stack using a linked list. Gist ...
DataEngineer's user avatar
4 votes
3 answers
159 views

Implementation of a simple stack with min method

The problem statement: Implement a stack which has push and pop method and also min method whereas min method has \$O(1)\$ complexity. From an interview standpoint, what mistakes would you point ...
PnotNP's user avatar
  • 219
5 votes
2 answers
220 views

Stack class in Ruby to calculate maximum number, get the average, pop, push

Is the class optimized enough to accept 1 million items in the stack? ...
user2410723's user avatar
8 votes
6 answers
1k views

Implement queue using two stacks

Although it's a well-known algorithm, I thought to implement it from the perspective of a coding interview. I want to know if I can improve my code somehow. So, given the time constraint, is this a ...
CodeYogi's user avatar
  • 5,127
8 votes
2 answers
2k views

Implement 3 stacks using a single array in C++

One of the questions that is presented in Chapter 3 for Cracking the Coding Interview is this: Describe how you could use a single array to implement 3 stacks I'...
Mantracker's user avatar
2 votes
4 answers
2k views

Reverse Polish Notation Evaluation in Java

I would like to hear feedback about my code both in term of improving efficiency if possible or using other data structures. Also go ahead and let me know about code styles/patterns. ...
Mona Jalal's user avatar
4 votes
1 answer
4k views

Sort a stack in descending order

Maintain current element as the top element in the input stack. Pop all the elements on the ordered stack which are greater than the current element and push them in to the input stack and maintain a ...
saneGuy's user avatar
  • 363
11 votes
2 answers
2k views

Stack having push, pop and return min in O(1)

I am using a class which is taking care of minimum value so far. Please let me know of any improvements or suggestions. ...
Mosbius8's user avatar
  • 769
-3 votes
1 answer
212 views

Implemented Stack using array

I'm going to job interviews soon. How I can improve my coding style and write better code? ...
Amogh Antarkar's user avatar
5 votes
4 answers
2k views

Stack with a minimum

A practice interview question: How would you design a stack which, in addition to push and pop, also has a function getMin which returns the minimum element? Push, pop and min should all operate in ...
Tehan Frago's user avatar
4 votes
4 answers
2k views

Class that implements a queue using two stacks

I am looking for a review of my code that implements a MyQueue class which implements a queue using two stacks. ...
user avatar
16 votes
6 answers
35k views

Implementing a Stack in Java for a technical interview

This code is based off the Stack implementation in Chapter 3 of Cracking The Coding Interview. I modified the code to make it compile and give me the correct output. I'd appreciate any feedback on ...
mathonsunday's user avatar
6 votes
2 answers
2k views

Valid Parentheses

Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. The brackets must close in the correct order, "()" and "()[]{}" are all ...
Fihop's user avatar
  • 1,025