Interview Q&A / Data Structures & Algorithms

INTERVIEW Q&A · 55 QUESTIONS

Data Structures & Algorithms interview questions

Arrays, linked lists, hashing, trees and patterns, with line-by-line code and complexity.

  1. What is the difference between a stack and a queue, with real examples?

    A stack is last in, first out (LIFO): you add and remove at the same end. A queue is first in, first out (FIFO): you add at the back and remove from the front.

    BeginnerQuick answer1 min read
  2. How do you implement a queue using two stacks?

    Push new items onto an input stack. When you need to dequeue and the output stack is empty, pour everything from the input stack into the output stack, which reverses the order, then pop from the output stack.

    IntermediateQuick answerCoding1 min read
  3. How do you find the maximum in every sliding window of size k?

    Keep a deque of indices whose values are in decreasing order. Drop indices that left the window from the front, drop smaller values from the back before adding the new index, and the front is always the window maximum.

    AdvancedQuick answerCoding1 min read