接下來想要推薦一些hard題給看到這邊的讀者
會想要寫這一篇是因為之前在PTT看到某個上岸心得文
有人寫了一千多題medium,但是只寫了15題左右的hard
覺得好像有點極端
其實leetcode裡面是有非常多不錯的hard題目的
而且寫多了之後就會發現
可能2200以下的hard其實沒有真的那麼難以攻破
常常是兩三題medium的觀念的結合,
寫得再細心一點想得再深一點轉個彎可能就寫得出來
而且等於是寫一題hard賺到三題medium的知識量
筆者覺得是相當划算的(的然也要注意自己想要去面試的公司到底有沒有那麼常考hard)
leetcode目前總共 536題,筆者記錄上有AC的有217題
必須要說一開始寫的時候這些hard題對我而言還是蠻難的
有蠻大部分不是自己想出來的,但是題號超過1500之後,對於面試難度的hard題
(2000-2200),Leetcode好像越來越沒什麼花樣可變,後來隨著經驗累積,
慢慢就越來越能自己想出來(那些2400以下的)hard題目
筆者把這些不錯的想要推薦給大家的題目分為三類:
(除了第三類以外hard都不建議自己想(卡住也不要硬想),去看影片或解答會比較有效率)
有些超難有些還好,但寫過一次(或是看過解答就覺得很讚嘆)就忘不了
84. Largest Rectangle in Histogram (Monotonic stack經典)
127. Word Ladder
188. Best Time to Buy and Sell Stock IV(DP 經典)
218. The Skyline Problem(非線段數的multimap掃描線解法 如同LC 2158 非常經典
https://github.com/wisdompeak/LeetCode/tree/master/Others/2158.Amount-of-New-Area-Painted-Each-Day)
239. Sliding Window Maximum
295. Find Median from Data Stream (Two heap method 經典)
297. Serialize and Deserialize Binary Tree(經典)
312. Burst Balloons (區間型DP經典)
315. Count of Smaller Numbers After Self (BIT可作)
354. Russian Doll Envelopes
446. Arithmetic Slices II - Subsequence
460. LFU Cache (Design題經典)
493. Reverse Pairs
630. Course Schedule III (經典難題)
632. Smallest Range Covering Elements from K Lists (經典難題)
710. Random Pick with Blacklist
715. Range Module (經典難題)
741. Cherry Pickup (DP經典)
765. Couples Holding Hands
773. Sliding Puzzle
778. Swim in Rising Water
862. Shortest Subarray with Sum at Least K
864. Shortest Path to Get All Keys
871. Minimum Number of Refueling Stops
887. Super Egg Drop (DP經典難題)
895. Maximum Frequency Stack
940. Distinct Subsequences II
956. Tallest Billboard (DP經典)
968. Binary Tree Cameras(經典難題)
992. Subarrays with K Different Integers
1125. Smallest Sufficient Team(經典狀態壓縮)
1235. Maximum Profit in Job Scheduling (經典DP+二分搜)
1293. Shortest Path in a Grid with Obstacles Elimination
1349. Maximum Students Taking Exam(經典狀態壓縮)
1547. Minimum Cost to Cut a Stick
1713. Minimum Operations to Make a Subsequence
1847. Closest Room (offline演算法的練習)
85. Maximal Rectangle
407. Trapping Rain Water II (這題很厲害是因為以為會跟Trapping Rain Water第一題同作法但是其實不是)
1585. Check If String Is Transformable With Substring Sort Operations
1671. Minimum Number of Removals to Make Mountain Array
1770. Maximum Score from Performing Multiplication Operations
1955. Count Number of Special Subsequences
1970. Last Day Where You Can Still Cross
2030. Smallest K-Length Subsequence With Occurrences of a Letter
2106. Maximum Fruits Harvested After at Most K Steps
2179. Count Good Triplets in an Array
2281. Sum of Total Strength of Wizards (社群有說這是AZ出過最難的OA題目)
23. Merge k Sorted Lists
25. Reverse Nodes in k-Group
41. First Missing Positive
42. Trapping Rain Water
51. N-Queens
72. Edit Distance
76. Minimum Window Substring
115. Distinct Subsequences
124. Binary Tree Maximum Path Sum
174. Dungeon Game
220. Contains Duplicate III
329. Longest Increasing Path in a Matrix
502. IPO
732. My Calendar III
1383. Maximum Performance of a Team
1402. Reducing Dishes
1675. Minimize Deviation in Array
2050. Parallel Courses III
2147. Number of Ways to Divide a Long Corridor
2156. Find Substring With Given Hash Value
2197. Replace Non-Coprime Numbers in Array
2227. Encrypt and Decrypt Strings
2246. Longest Path With Different Adjacent Characters
筆者實際在G社面試遇到的延伸題確實是hard難度(大約1900-2100)
Amazon和Kronos的OA也有寫到差不多難度的題目
希望有時間有精力的讀者
如果目標是TierA以上的公司,不要因為看到是hard就跳過這些題目
也許哪一天第一題寫完之後的延伸題就考到了,而且這可能是hire/strong hire的分界線
題外話,leetcode測資不一定完善
筆者曾經在某題用了不對的演算法AC
但是在自己產生的小case上可以看到跟標準解答會跑出不一樣的答案
所以就算AC了也要去看看自己的想法跟解答區有沒有差很多
(打完發現type 2沒有放很多題)
歡迎讀者留言補充你覺得不錯的hard題~