Back

Software Engineer

Questions

 192 Questions
Question 1 of 192

1. Implement a stack from scratch and include a min() function that performs at O(1) time.


Overview
This question is designed to test a candidate's knowledge of data structures and their ability to implement them.
Interview Expectations
Coding ability
Data structure knowledge
Problem-solving abilit
Sample Answer
I would create a class called Stack that would have two private variables: a pointer to the top of the stack and an integer that represents the number of items in the stack. The constructor would take two parameters: the number of items in the stack and the pointer to the top of the stack. The push() method would take a single parameter, which is the item to be added to the stack. The pop() method would take no parameters and return an item from the stack. The min() function would take no parameters and return an integer representing the minimum value in the stack.