Design and Implement an LRU Cache

Medium
24 views 22 Dec 2025
Design an LRU (Least Recently Used) Cache that supports get(key) and put(key, value) operations in constant time O(1). The cache should automatically remove the least recently accessed item when the c...

Design a Stack with Constant-Time Minimum Retrieval

Medium
29 views 22 Dec 2025
Design a stack data structure that supports standard stack operations such as push, pop, and top, along with an additional operation getMin() that returns the minimum element present in the stack at a...

Implement Trie for Prefix-Based Search

Medium
22 views 22 Dec 2025
Implement a Trie (Prefix Tree) data structure that supports insertion of words and searching for complete words as well as prefixes. Explain how the Trie improves search efficiency compared to a norma...

Union-Find with Path Compression

Medium
24 views 22 Dec 2025
Implement the Disjoint Set Union (Union-Find) data structure with path compression and union by rank. Explain how these optimizations reduce the time complexity of find and union operations in large d...

Segment Tree for Range Sum Queries

Medium
16 views 22 Dec 2025
Design and implement a Segment Tree to efficiently answer range sum queries on an array. The structure should also support point updates. Explain how segment trees divide the problem space and why the...

Fenwick Tree (Binary Indexed Tree)

Medium
20 views 22 Dec 2025
Implement a Fenwick Tree (Binary Indexed Tree) to handle prefix sum queries and updates efficiently. Compare its performance and memory usage with a Segment Tree....

Design a Sliding Window Maximum Structure

Medium
22 views 22 Dec 2025
Given an array and a window size k, design a data structure that efficiently finds the maximum element in every sliding window. Explain how a deque helps achieve linear time complexity....

Implement a Priority Queue using Heap

Medium
15 views 22 Dec 2025
Implement a Priority Queue using a binary heap. Explain how insertion and deletion operations maintain the heap property and why heaps are suitable for priority-based processing....

Design a Data Structure for Median of a Stream

Medium
20 views 22 Dec 2025
Design a data structure that continuously receives numbers from a data stream and returns the median at any time. Explain how two heaps can be used to balance the elements and compute the median effic...

LRU Cache vs LFU Cache

Medium
24 views 22 Dec 2025
Explain the difference between LRU (Least Recently Used) and LFU (Least Frequently Used) caching strategies. Discuss scenarios where one strategy is preferred over the other and the data structures re...

Range Minimum Query with Range Updates

Easy
23 views 22 Dec 2025
You are given an array of integers and need to handle two types of queries efficiently:

Range Update: Add a value to all elements in a given range [l, r]

Range Query: Find the minimum value in a...