Skip to content
Optimal Lab

Practice · 5 problems

Queues & Design

0 of 5 solved on this device

Watch it first · interactiveLRU cache →
  1. 138Implement Queue using StacksImplement a FIFO queue using only two stacks. Support push(x), pop(), peek() and empty(). You may only use standard stack operations. Each operation should be O(1) AMORTIZED.Easy
  2. 139Design HashMapDesign a HashMap without using any built-in hash table library. Support put(key, value), get(key) returning -1 if absent, and remove(key).Easy
  3. 140Design Circular QueueDesign a circular queue of fixed capacity: enQueue(value), deQueue(), Front(), Rear(), isEmpty() and isFull(). The unused space in front of the queue must be reusable.Medium
  4. 141Flatten Nested List IteratorYou are given a nested list of integers, where each element is either an integer or a list whose elements are also integers or lists. Implement an iterator with next() and hasNext() that flattens it.Medium
  5. 142Design TwitterDesign a simplified Twitter: postTweet(userId, tweetId), getNewsFeed(userId) returning the 10 most recent tweet ids from the user and those they follow (most recent first), follow(followerId, followeeId) and unfollow(followerId, followeeId).Medium