## Stacks and Queues

#### Recent solutions:

Check these solutions from our community:
Code Problem / Data Structures and Algorithms DifficultyMedium JavaScript
Given a stack of integers, the function returns the sum of the elements in the stack.
About this solution: The candidate's solution is correct and solves the problem. The approach is straightforward and easy to understand. The time complexity of the solution is O(n) and the space complexity is O(1).
Dec 11
Code Problem / Data Structures and Algorithms DifficultyMedium C#
This function takes in a string consisting only of parentheses and outputs whether or not the string is balanced. A string is balanced if every open parenthesis has a corresponding close parenthesis and there are no unmatched parentheses.
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.
Dec 10
Code Problem / Data Structures and Algorithms DifficultyMedium Python
This problem asks the programmer to return the sum of all integers at even indices in a given list. For example, given the list [1, 2, 3, 4, 5], the output would be 6 (2 + 4).
About this solution: This solution is correct and efficient. The candidate has demonstrated a good understanding of how to use the slice operator to get every other element in a list.
Dec 09
Code Problem / Data Structures and Algorithms DifficultyMedium Python
This problem asks you to reverse a string using a stack. An example input and output is provided.
About this solution: This is a good solution that uses a stack to reverse the string. The stack is a LIFO data structure, so the last character in the string will be the first character in the stack. The first character in the string will be the last character in the stack. The stack will be popped until it is empty, and the characters will be added to a new string. The new string will be the reversed string.
Dec 05
Code Problem / Data Structures and Algorithms DifficultyMedium JavaScript
A stack is a data structure that supports push, pop, and min operations in constant time.
About this solution: The candidate's solution is complete and solves the problem. The candidate's approach is to use a second stack to keep track of the minimum value. When a new value is pushed onto the stack, it is also pushed onto the min stack if it is less than or equal to the current min value. When a value is popped off the stack, it is also popped off the min stack if it is equal to the current min value. This way, the min stack will always have the current min value at the top. This solution is optimal because it allows for constant time min operations.
Dec 04
Code Problem / Data Structures and Algorithms DifficultyMedium Python
This technical problem deals with determining whether or not a given string consisting of only brackets is valid. A string is considered valid if the open brackets are closed by the same type of brackets in the correct order. An empty string is also considered valid.
About this solution: The candidate's solution is correct and uses a stack to keep track of the order of the brackets. The solution is also complete, with tests for all the different cases.
Dec 03
Code Problem / Data Structures and Algorithms DifficultyMedium Python
Given a list of integers, this code problem finds the largest integer in the list. For example, given the input [1, 2, 3, 4, 5], the output would be 5.
About this solution: This is a good solution that demonstrates a level of completeness and solves the problem. The approach is straightforward and easy to understand.
Dec 03
Code Problem / Data Structures and Algorithms DifficultyMedium JavaScript
Given a string, reverse the order of the words. Do not use any built-in reverse functions.
About this solution: This solution is correct and demonstrates a level of completeness. The approach is straightforward and easy to understand. The time and space complexity of the solution is also optimal.
Dec 01