Showing 10 questions
Implement a circular queue data structure with a fixed size. You'll need to handle enqueueing, dequeueing, and checking if the queue is full or empty efficiently.
#1. Design Circular Queue
Find all unique triplets in an array that sum to zero. You'll need to consider the potential for duplicate numbers and avoid duplicate triplets in your solution.
#2. 3Sum
Find all unique quadruplets in an array that sum to a target value. You'll need to efficiently search for combinations of four numbers that satisfy the given condition.
#3. 4Sum
Starting from (0, 0), can you reach a target point (tx, ty) by repeatedly applying the transformation (x, y) -> (x, x+y) or (x, y) -> (x+y, y)? Determine if it's possible.
#4. Reaching Points
Design a stack data structure with a fixed size. Implement push, pop, and an increment operation that adds a value to the bottom k elements of the stack.
#5. Design a Stack With Increment Operation
Design a data structure that acts as a Least Recently Used (LRU) cache. Implement methods to get and put key-value pairs, evicting the least recently used entry when the cache is full.
#6. LRU Cache
Design a hit counter to track the number of hits recorded in the past 5 minutes. Implement methods to record a hit and retrieve the total hits in the past 5 minutes.
#7. Design Hit Counter
Given a grid representing land and water, count the number of distinct islands. An island is formed by connected land cells.
#8. Number of Islands
Write a program that prints numbers from 1 to n, replacing multiples of 3 with "Fizz", multiples of 5 with "Buzz", and multiples of both with "FizzBuzz".
#9. Fizz Buzz
Simulate the Game of Life, updating the state of a board based on the rules of cell survival and death in each generation. Modify the board in place to represent the next generation.
#10. Game of Life