Top LeetCode Hard Questions πŸ”’

Go Careers
2 min readApr 19, 2024

--

List of 20 challenging β€œhard” level questions from LeetCode that are great for sharpening your problem-solving skills and preparing for tough coding interviews:

1. Hard Candy 🍬 β€” Allocate candies to children so that each child gets at least one candy and children with a higher rating get more candies than their neighbors.

2. Trapping Rain Water 🌧️ β€” Calculate the amount of water that can be trapped after raining.

3. Regular Expression Matching 🧡 β€” Implement regular expression matching with support for β€˜.’ and β€˜*’.

4. Median of Two Sorted Arrays πŸ“Š β€” Find the median of the two sorted arrays.

5. Binary Tree Maximum Path Sum 🌲 β€” Find the maximum path sum in a binary tree.

6. Longest Valid Parentheses πŸ“ β€” Determine the length of the longest valid (well-formed) parentheses substring.

7. First Missing Positive πŸ”’ β€” Find the smallest missing positive integer from an unsorted array.

8. Minimum Window Substring πŸͺŸ β€” Find the minimum window in a string which will contain all the characters in another string.

9. Substring with Concatenation of All Words 🧩 β€” You are given a string and a list of words, find all the starting indices of substring(s) that is a concatenation of each word in the list exactly once.

10. Palindrome Partitioning II πŸ”ͺ β€” Minimize the number of cuts needed for palindrome partitioning.

11. Word Ladder II πŸͺœ β€” Find all shortest transformation sequences from a start word to an end word.

12. Maximal Rectangle πŸ”³ β€” Given a 2D binary matrix filled with 0’s and 1’s, find the largest rectangle containing only 1’s and return its area.

13. Distinct Subsequences πŸ”’ β€” Given a string S and a string T, count the number of distinct subsequences of S which equals T.

14. Best Time to Buy and Sell Stock IV πŸ“ˆ β€” You can complete at most k transactions, what’s the maximum profit you can make?

15. Longest Consecutive Sequence πŸ”— β€” Given an unsorted array of integers, find the length of the longest consecutive elements sequence.

16. Largest Rectangle in Histogram πŸ“ β€” Given an array of integers heights representing the histogram’s bar height where the width of each bar is 1, find the area of the largest rectangle in the histogram.

17. Interleaving String 🧩 β€” Given three strings A, B, and C, check whether C is an interleaving of A and B.

18. Sliding Window Maximum πŸͺŸ β€” Given an array and an integer k, find the maximum for each and every contiguous subarray of size k.

19. Serialize and Deserialize Binary Tree 🌳 β€” Design an algorithm to serialize and deserialize a binary tree.

20. Largest Divisible Subset πŸ”’ β€” Given a set of distinct positive integers, find the largest subset such that every pair of elements in the subset is divisible by each other.

These questions cover a broad range of topics, including arrays, strings, dynamic programming, and graph theory, providing a comprehensive challenge for advanced problem solvers.

--

--