Stacks and Queues

Categories: Code Problem / Data Structures and Algorithms / Recursion (32) Code Problem / Data Structures and Algorithms / Binary Search (30) Code Problem / Data Structures and Algorithms / Linked Lists (26) Code Problem / Data Structures and Algorithms / Backtracking (26) Code Problem / Data Structures and Algorithms / Stacks and Queues (25) Code Problem / Data Structures and Algorithms / Hashing (24) Databases / SQL / Backup and Recovery (19) Code Problem / Data Structures and Algorithms / Arrays and Strings (19) Databases / SQL / Database Normalization (18) Code Problem / Data Structures and Algorithms / Time Complexity (17) Databases / SQL / Locking (16) Databases / SQL / Replication (15) Databases / SQL / SQL Queries (13) Code Problem / Data Structures and Algorithms / Graphs (13) Databases / SQL / Database Security (13)  More...

Recent solutions:

Check these solutions from our community:
Code Problem / Data Structures and Algorithms DifficultyMedium C++
This problem deals with printing the median of a stream of integers. At each time step, the median of the integers received so far is printed out.
About this solution: The candidate's solution is complete and solves the problem. The approach is to use two priority queues, one for the max heap and one for the min heap. The max heap is used to store the smaller half of the numbers and the min heap is used to store the larger half of the numbers. This approach ensures that the median can be calculated in O(1) time.
Dec 01
Code Problem / Data Structures and Algorithms DifficultyMedium C#
This problem asks you to write a function that takes in a list of integers and returns the sum of the integers at even indices. For example, given the input list [1, 2, 3, 4, 5], the function should return 6 (2 + 4).
About this solution: The candidate's solution does not demonstrate a level of completeness and does not solve the problem. The general approach is not clear.
Nov 30
Code Problem / Data Structures and Algorithms DifficultyMedium C#
Implement a queue using two stacks. This means that when you enqueue an item, it goes onto one of the stacks, and when you dequeue an item, it comes off of the other stack.
About this solution: The candidate's solution correctly implements a queue using two stacks. However, the code could be more concise. For example, the ShiftStacks method can be simplified. Additionally, the candidate does not provide any comments explaining the code.
Nov 29
Code Problem / Data Structures and Algorithms DifficultyMedium JavaScript
Given a string of parentheses, this function determines whether the string is balanced. A string is balanced if each opening parentheses is matched by a closing parentheses. For example, the input "(())" would return True, while the input "())(" would return False.
About this solution: This is a great solution! The candidate has thought through the problem and has come up with a very efficient solution.
Nov 28
Code Problem / Data Structures and Algorithms DifficultyMedium Python
The problem is to find the sum of all the integers in a stack. An example input is given, as well as the expected output.
About this solution: This solution is complete and solves the problem. The approach is straightforward and easy to follow.
Nov 28
Code Problem / Data Structures and Algorithms DifficultyMedium C++
This problem asks you to reverse a string using a stack. An example input and output are provided.
About this solution: The candidate's solution is correct and uses a stack to reverse the string as required. The candidate's code is clean and easy to read. Well done.
Nov 27
Code Problem / Data Structures and Algorithms DifficultyMedium C++
This problem asks you to reverse a string using a stack. An example input would be "abc" and the corresponding output would be "cba".
About this solution: The candidate's solution is optimal because it uses a stack to reverse the string. The candidate's approach is also clear and easy to follow.
Nov 26
Code Problem / Data Structures and Algorithms DifficultyMedium C++
This problem is about determining if a string is balanced, meaning that every open parenthesis has a corresponding close parenthesis, and vice versa. An example of an input string that would return " true" is "(()())". An example of an input string that would return "false" is "())(".
About this solution: The candidate's solution is complete and solves the problem. The candidate's approach is to use a stack to keep track of the parentheses. Every time the candidate encounters an open parenthesis, they push it onto the stack. Every time the candidate encounters a close parenthesis, they pop off the top element of the stack. If the stack is ever empty when they encounter a close parenthesis, then they know that the string is not balanced. If the stack is not empty when they reach the end of the string, then they know that the string is not balanced.
Nov 24