Skip to main content

10.11 Exercises

Basic Difficulty​

566. Reshape the Matrix​

This problem is not particularly challenging; it only requires some patience.


225. Implement Stack using Queues​

Using a similar approach, we can also implement a stack using queues.


503. Next Greater Element II​

A variant of the Daily Temperatures problem.


217. Contains Duplicate​

Which data structure would allow us to quickly check for duplicates?


697. Degree of an Array​

How can we preprocess an array to correctly and efficiently compute the length of a subarray?


594. Longest Harmonious Subsequence​

A variant of the Longest Consecutive Sequence problem.


15. 3Sum​

Since the complexity of sorting is O(nlog⁡n)<O(n2)O(n \log n) < O(n^2), we can either sort the array first and then perform an O(n2)O(n^2) pointer search, or directly use a hash table for an O(n2)O(n^2) search.


Advanced Difficulty​

287. Find the Duplicate Number​

A variant of the Find Missing Number problem. Besides marking negative values, are there any other algorithms to solve this?


313. Super Ugly Number​

Try solving this using a priority queue.


870. Advantage Shuffle​

If we need to compare relative sizes and the same number can appear multiple times, which data structure should we use?


307. Range Sum Query - Mutable​

A variant of the Prefix Sum problem. I admit this might be slightly advanced; you might want to look up what a Segment Tree is.