Redis Coding Interview Questions
25 Redis coding interview problems with full optimal solutions — 8 easy, 12 medium, 5 hard. Every problem ships with multiple approaches (brute-force first, then the optimal), complexity tables for each, company-specific tips on what an Redis interviewer values, and a FAQ section.
Showing 25 problems of 25
- #1easyfoundational
1. Two Sum
Find two indices whose values sum to a target; the canonical hash-map warmup at Redis where interviewers probe your fluency with O(1) lookups.
- #2easyfoundational
2. Best Time to Buy and Sell Stock
Find the maximum profit from one buy-sell transaction over a price stream, a warm-up Redis uses to gauge single-pass thinking.
- #3easyfoundational
3. Single Number
Find the one element that appears once when every other appears twice; Redis uses it to probe XOR-trick fluency relevant to bitmap operations.
- #4easyfoundational
4. Majority Element
Find the element that appears more than n/2 times; Redis interviewers use it to test Boyer-Moore voting, a constant-space pattern that maps onto stream-processing.
- #5easyfoundational
5. Reverse Linked List
Reverse a singly linked list in place; Redis uses it as a warm-up before diving into Redis list internals like the quicklist and listpack.
- #6easyfoundational
6. Invert Binary Tree
Mirror a binary tree in place; Redis screens with this to confirm clean recursion and traversal hygiene before discussing skiplist traversal.
- #7easyfoundational
7. Diameter of Binary Tree
Find the longest path between any two nodes; Redis uses it to gauge post-order recursion which mirrors how the engine walks command call trees.
- #8easyfoundational
8. Binary Search
Implement classic binary search on a sorted array; Redis uses it to confirm log-time intuition before discussing skiplist random-level shortcuts.
- #9mediumfoundational
9. LRU Cache
Design a fixed-capacity Least-Recently-Used cache with O(1) get/put; this is the most asked Redis interview question because it mirrors maxmemory-policy allkeys-lru.
- #10mediumfoundational
10. Number of Islands
Count connected '1' regions in a 2D grid; Redis uses it to verify clean BFS/DFS hygiene before discussing cluster-partition reconnection.
- #11mediumfoundational
11. Kth Largest Element in an Array
Find the kth largest value; Redis interviewers use it to probe heap intuition that mirrors how ZSETs maintain top-K rankings.
- #12mediumfoundational
12. Top K Frequent Elements
Return the k most frequent integers; Redis uses it to probe bucket-sort and heap thinking, the same patterns powering Redis Streams XAUTOCLAIM and ZSET top-K queries.
- #13mediumfoundational
13. Design Twitter
Implement a simplified Twitter with postTweet, getNewsFeed, follow, unfollow; Redis loves it because the optimal solution is the Redis fan-out-on-read pattern.
- #14mediumfoundational
14. Insert Delete GetRandom O(1)
Design a set supporting insert, remove and getRandom all in O(1); Redis loves it because SRANDMEMBER and dict-table sampling use the same trick.
- #15hardfoundational
15. LFU Cache
Implement a Least-Frequently-Used cache with O(1) get and put; Redis loves it because LFU eviction (allkeys-lfu) is one of its native maxmemory policies.
- #16mediumfoundational
16. Task Scheduler
Compute the minimum CPU cycles to execute tasks with a cool-down constraint; Redis uses it to probe scheduling logic that mirrors expiration sampling in cron.c.
- #17mediumfoundational
17. Snapshot Array
Implement an array with O(1) set/snap and O(log) snapshot reads; Redis uses it because the data structure mirrors how RDB snapshots cooperate with copy-on-write forks.
- #18mediumfoundational
18. Design Underground System
Track passenger check-in/check-out and compute average travel times; Redis uses it to test hash and counter aggregation patterns close to Streams + HINCRBYFLOAT.
- #19mediumfoundational
19. Time Based Key-Value Store
Implement a KV store that returns the most recent value with timestamp <= query; Redis loves it because it mirrors ZADD + ZREVRANGEBYSCORE patterns for time-series.
- #20mediumfoundational
20. Subarray Sum Equals K
Count the number of contiguous subarrays that sum to k; Redis uses it to test prefix-sum + hashmap intuition, the same trick that powers GETSET cumulative counters.
- #21mediumfoundational
21. Word Break
Decide whether a string can be segmented into space-separated dictionary words; Redis uses it as a DP/memoization probe that overlaps with how the engine matches CONFIG GET glob patterns.
- #22hardfoundational
22. Find Median from Data Stream
Maintain a running median over a stream of numbers; Redis interviewers love it because two-heap balancing mirrors how Redis Streams hold per-consumer-group offsets.
- #23hardfoundational
23. Sliding Window Maximum
Find the max of every window of size k as it slides across an array; Redis uses it to probe deque/monotonic intuition that mirrors LPUSH/RPOP patterns on Redis Lists.
- #24hardfoundational
24. All O`one Data Structure
Design a data structure supporting inc, dec, getMaxKey and getMinKey all in O(1); Redis loves this because it is the exact LFU-counter primitive used internally for eviction sampling.
- #25hardfoundational
25. Design Skiplist
Implement a probabilistic skiplist supporting search, add and erase in O(log n) average; Redis loves it because the skiplist is the storage layer behind every ZSET in the engine.