CS_BASICS
pic_source








Cmd
# 1) (claude code) add time, space complexity to java class
claude
/add-time-space BinarySearch
/add-time-space BFS
# ....
Resource
-
LC classics problems
- Blind Curated 75
- Grind 75
- Grind 169
- leetcode wiki repo
- leetcode wiki
- LC 官神Github題目分類整理
- LC top 100 likes
- neetcode 150 LC list
- jiakaobo LC : LC code & video
- LC pattern @ blind : Curated-List-of-Top-100-LeetCode-Questions-to-Save-Your-Time
- LC Algorithm Problem Classification
- cheatsheet-leetcode-a4
- 14-patterns-to-ace-any-coding-interview-question
- grokking-the-coding-interview
-
LC experiences
- LC難度表
- 數字越高, 題目越難, 挑與自己LC排名接近的題庫
- (e.g. LC rank ~= 1600, pick 1600 problem)
- 代碼隨想錄
- Leetcode cookbook
- fucking-algorithm
- fucking-algorithm website
- FAANG 面試準備經驗與建議(一)
- FAANG 面試準備經驗與建議(二)
- LC 小知識
- Meta SWE isnterview prep
- 0到100的軟體工程師面試之路
- 來和大家聊聊我是如何刷題的 : pt1, pt2, pt3
- LC難度表
-
LC Flow
- high level idea : data structure, algorithm
- offer time & space complexity
- code implementation
- offer test case (consider edge case)
- discussion & follow up
- Resource.md -
Resourcefor coding interview (keep updating) - Teach yourself CS
- MindMapCodeInterview - Mind map for coding interview
- CodeInterviewCheatsheet - Coding interview cheetsheet
- repl.it - Coding online!
- Visualization
- Algorithms viz
- visualgo - DFS / BFS - DFS, BFS visualization
- visualgo - linkedlist - Linkedlist visualization
- visualgo - BST - binary search tree visualization
- toptal-sorting-algorithms- sorting algorithms online
- How to: Work at Google — Example Coding/Engineering Interview
- bit_manipulation.md - Bit Manipulation Cheat Sheet
- Py TimeComplexity - Py basic data structure
Time Complexityref - Py data model - Python data model doc
- pgexercises - Postgre exercises
- sqlservertutorial
- Books
- freecodecamp - data-structures
- LC interview-experience
- Cheatsheet
-
Data structure
-
System design
-
Tools
-
LC SQL resources
Algorithms content
- Bit Manipulation
- Array
- String
- Linked List
- Stack
- Queue
- Heap
- Tree
- Hash Table
- Math
- Two Pointers
- Scan Line
- Sort
- Recursion
- Binary Search
- Binary Search Tree
- Breadth-First Search
- Depth-First Search
- Backtracking
- Dynamic Programming
- Greedy
- Graph
- Geometry
- Prefix Sum
- Simulation
- Design
- Concurrency
Database
Shell
Progress
Note tags
The Note column of every problem table carries three kinds of tag, all written by
script/fix_readme_tags.py from vendored data — so fix the
data, not the row:
| Tag | Means | Source |
|---|---|---|
array, dp, two pointers, … |
the technique the row is filed under, plus LeetCode’s own topics for it | data/lc_topic_tags.json |
fb, amazon, apple, netflix, google (FAANG), plus microsoft, uber, linkedin, bloomberg |
companies known to ask it | data/company_lc_tags.json |
blind75, neetcode150, neetcode250, top100liked |
the curated lists it sits on | data/problem_lists.json |
The three NeetCode lists nest, so a row names only the narrowest one it is on:
blind75 already implies NeetCode 150 and 250, and neetcode150 implies 250.
top100liked is LeetCode’s own list and cuts across all three, so it stands on its own.
NeetCode’s full 972-problem catalogue is deliberately not tagged — it would mark 607
rows without saying which to do first.
python3 script/fix_readme_tags.py --report # what would change
python3 script/fix_readme_tags.py # rewrite the Note column
Data Structure
| # | Title | Solution | Use case | Comment | Status |
|---|---|---|---|---|---|
Linear |
|||||
| Array | Py | AGAIN* | |||
| Queue | Py (array), Py (linkedlist), JS | AGAIN* | |||
| Stack | Py, JS (linkedlist), JS (array) | OK | |||
| Hash table | Py, JS | usually for improving time complexity B(O) via extra space complexity (time-space tradeoff) |
good basic |
AGAIN**** | |
Linear, Pointer |
|||||
| LinkedList | Py, JS, Java | OK** | |||
| Doubly LinkedList | Python, JS | AGAIN | |||
Non Linear, Pointer |
|||||
| Tree | Py | AGAIN** | |||
| Binary search Tree (BST) | Python, JS, Java | AGAIN | |||
| Binary Tree | Py | AGAIN** | |||
| Trie | Py | AGAIN | |||
| Heap | heap.py, MinHeap.py, MaxHeap.py, MinHeap.java, MaxHeap.java | AGAIN | |||
| Priority Queue (PQ) | Py 1, Py 2, Py 3 | AGAIN | |||
Graph |
|||||
| Graph | Py, JS. Java1, Java2 | OK*** | |||
| DirectedEdge | Java | AGAIN |
Algorithm
| # | Title | Solution | Use case | Comment | Time complexity | Space complexity | Status |
|---|---|---|---|---|---|---|---|
| Binary search | Python | complexity ref | Best : O(1), Avg : O(log N), Worst : O(log N) |
AGAIN | |||
| Linear search | Python | AGAIN | |||||
| Breadth-first search (BFS) | Python | FIND SHORTEST PATH |
AGAIN*** | ||||
| Depth-first search (DFS) | Python | TO CHECK IF SOMETHING EXIST |
inorder, postorder, postorder (can recreate a tree) |
Adjacency List: O(V+E), Adjacency Matrix: O(V^2) |
O(V) (V:Vertices, E:Edges) |
AGAIN*** | |
| Bubble sort | Python | OK* (3) | |||||
| Insertion sort | Python, InsertionSort.java | stable sort |
work very fast for nearly sorted array |
Best :O(n), Average : O(n^2), Worst : O(n^2) |
Worst : O(1) | AGAIN | |
| Bucket sort | Python, BucketSort.java | AGAIN | |||||
| Quick sort | quick_sort.py, quick_sort_v2.py, QuickSort.java, QuickSortV2.java, QuickSortV3.java | NOTE !!!, avg is NLogN, worst is N**2, big O ref, big O ref 2 |
Best : O(N Log N), Avg : O(N Log N), Worst : O(N^2) |
AGAIN*** | |||
| Heap sort | Python | big O ref | Best : O(N Log N), Avg : O(N Log N), Worst : O(N Log N) |
AGAIN** | |||
| Merge sort | merge_sort.py, merge_sort_topdown.py, mergesort_bottomup.py, MergeSortTopDown.java, MergeSort.java SQL | Best : O(N Log N), Avg : O(N Log N), Worst : O(N Log N) |
O(N) | OK* (2) | |||
| Pancake sort | Python | AGAIN | |||||
| Selection sort | Python, JS | AGAIN | |||||
| Topological sort | Python, Java, Java V2 | Topological Sort is a algorithm can find “ordering” on an “order dependency” graph | AGAIN | ||||
| md5 | Python | AGAIN | |||||
| Union Find | Python 1, Python 2, Java 1, Java 2, Java 3 | AGAIN | |||||
| Dynamic programming | JS 1, fibonacci_dp JS | AGAIN | |||||
| Dijkstra | Python,Java 1, Java 2 | AGAIN*** | |||||
| Floyd-Warshall | Python, Java 1, Java 2 | LC 2642 | not start | ||||
| Bellman-Ford | Python | not start | |||||
| Quick Find | Python, Java | init : O(N), union : O(N), find : O(1) | simple, but slow | AGAIN | |||
| Quick Union | Java, Java v2 | init : O(N), union : O(N), find : O(N) | lazy approach, route compression, optimized Quick Find | AGAIN | |||
| Quick Union (Improvements) | lazy approach, path compression | AGAIN | |||||
Priority Queue (unsorted) |
Java | AGAIN | |||||
| LRU cache | Python | LC 146 | AGAIN | ||||
| LFU Cache | Python | LC 460 | AGAIN | ||||
| DifferenceArray | Java | LC 1109, 370 | AGAIN | ||||
| Kadane Algo | Java | LC 53, 152,918 | AGAIN | ||||
| Patience sorting (LIS) | Python | longest increasing subsequence in O(N log N), longest chainable run |
cheatsheet, the pile count is the LIS length (Dilworth), LC 300, 334, 354, 1964, 1713 | O(N log N) | O(N) | not start |
Array
| # | Title | Solution | Time | Space | Difficulty | Note | Status |
|---|---|---|---|---|---|---|---|
| 0004 | Median of Two Sorted Arrays | Python, Java | O(log(min(m, n))) | O(1) | Hard | binary search, binary search on partition, median, heapq (brute), amazon, google, apple, fb, microsoft, uber, linkedin, bloomberg, neetcode150, top100liked |
AGAIN* (1) |
| 0010 | Regular Expression Matching | Python, Java | O(m * n) | O(m * n) | Hard | dp, recursion, 2D dp, LC 44, fb, google, amazon, apple, microsoft, uber, bloomberg, neetcode150 |
AGAIN (not start) |
| 0015 | 3 Sum | Python, Java | O(n^2) | O(1) | Medium | two pointers, good basic, check with # 001 Two Sum, #018 4 sum, amazon, fb, google, apple, microsoft, uber, bloomberg, blind75, top100liked |
OK******* (7) |
| 0016 | 3 Sum Closest | Python, Java | O(n^2) | O(1) | Medium | two pointers, basic, good trick, 3 sum, google, fb, apple, microsoft, goldman sachs, amazon, uber, bloomberg |
AGAIN******* (3) |
| 0018 | 4 Sum | Python, Java | O(n^3) | O(1) | Medium | two pointers, k sum, check #016 3 sum, # 454 4 SUM II, good trick, fb, google, amazon, apple, microsoft, neetcode250 |
AGAIN******** (4) |
| 0026 | Remove Duplicates from Sorted Array | Python, Scala, Java | O(n) | O(1) | Easy | two pointers, MUST, basic, good trick, microsoft, fb, google, amazon, apple, uber, neetcode250 |
AGAIN************** (11) |
| 0027 | Remove Element | Python, Java | O(n) | O(1) | Easy | two pointers, MUST, amazon, google, fb, apple, microsoft, uber, neetcode250 |
AGAIN****** (2)(MUST) |
| 0031 | Next Permutation | Python, Scala, Java | O(n) | O(1) | Medium | array, good trick, 2 pointers, uber, goldman sachs, google, amazon, fb, apple, microsoft, bloomberg, top100liked |
AGAIN****************** (9) (MUST) |
| 0041 | First Missing Positive | Python, Java | O(n) | O(1) | Hard | array, good trick, hash key, amazon, fb, google, apple, uber, microsoft, bloomberg, neetcode250, top100liked |
OK** (2) |
| 0048 | Rotate Image | Python, Java | O(n^2) | O(1) | Medium | array, basic, i, j->j, i transpose matrix, garena, amazon, apple, google, fb, microsoft, uber, bloomberg, blind75, top100liked |
AGAIN************* (5) (MUST) |
| 0054 | Spiral Matrix | Python, Java | O(m * n) | O(1) | Medium | array, good basic, array boundary, matrix, amazon, google, fb, apple, microsoft, uber, linkedin, bloomberg, blind75, top100liked |
AGAIN**** (4) |
| 0056 | Merge Intervals | Python, Java | O(nlogn) | O(n) | Medium | interval, good trick, 057 Insert Interval, twitter, microsoft, uber, google, amazon, fb, apple, linkedin, bloomberg, blind75, top100liked, netflix |
OK********* (6) (but AGAIN) |
| 0057 | Insert Interval | Python, Java | O(n) | O(n) | Medium | interval, good basic, 056 Merge Intervals, java array, list basic, google, amazon, fb, apple, microsoft, uber, linkedin, blind75 |
AGAIN********** (5) (MUST!) |
| 0059 | Spiral Matrix II | Python, Java | O(n^2) | O(1) | Medium | array, check # 054 Spiral Matrix, amazon, google, fb, apple, microsoft, uber |
AGAIN** (2) |
| 0066 | Plus One | Python, Java | O(n) | O(1) | Easy | array, basic, digit, google, amazon, fb, apple, microsoft, neetcode150 |
AGAIN** (3) |
| 0073 | Set Matrix Zeroes | Python, Java | O(m * n) | O(1) | Medium | array, matrix, amazon, google, fb, apple, microsoft, blind75, top100liked |
OK* (4) |
| 0080 | Remove Duplicates from Sorted Array II | Python, Java | O(n) | O(1) | Medium | array, two pointers, AGAIN, basic, trick, fb, #26 Remove Duplicates from Sorted Array, google, amazon, apple, microsoft |
AGAIN************ (8) |
| 0118 | Pascal’s Triangle | Python, Java | O(n^2) | O(1) excluding output | Easy | array, trick, basic, google, amazon, fb, apple, microsoft, uber, bloomberg, top100liked |
AGAIN** (2) |
| 0119 | Pascal’s Triangle II | Python, Java | O(n^2) | O(n) | Easy | array, check with # 118 Pascal's Triangle, amazon, google, microsoft |
OK** (4) |
| 0121 | Best Time to Buy and Sell Stock | Python, Java | O(n) | O(1) | Easy | array, dp, basic, greedy, uber, microsoft, amazon, fb, google, apple, bloomberg, blind75, top100liked |
OK****** (7) (but again) |
| 0157 | Read N Characters Given Read4 | Python, Java | O(n) | O(1) | Easy | array, 🔒, buffer, google, amazon, fb, microsoft |
AGAIN**** (3) |
| 0163 | Missing Ranges | Python, Java | O(n) | O(1) | Medium | array, two pointer, 🔒, google, amazon, fb |
OK******* (4) |
| 0169 | Majority Element | Python, Java | O(n) | O(1) | Easy | array, Boyer-Moore majority vote, LC 229, basic, amazon, google, fb, apple, microsoft, neetcode250, top100liked |
OK* |
| 0189 | Rotate Array | Python, Java | O(n) | O(1) | Medium | array, k % len(nums), good basic, amazon, google, fb, apple, microsoft, bloomberg, neetcode250, top100liked |
OK* (7) (but again) |
| 0209 | Minimum Size Subarray Sum | Python, Java | O(n) | O(1) | Medium | array, good basic, sliding window, Binary Search, trick, 2 pointers, fb, google, amazon, apple, microsoft, uber, bloomberg, neetcode250 |
OK********** (7) (but again) |
| 0215 | Kth Largest Element in an Array | Python, Java | O(n) ~ O(n^2) | O(1) | Medium | array, EPI, quick sort, bubble sort, sort, amazon, fb, google, apple, microsoft, uber, linkedin, bloomberg, neetcode150, top100liked |
OK* (2) |
| 0228 | Summary Ranges | Python, Java | O(n) | O(1) | Easy | array, check # 163 Missing Ranges, good basic, google, amazon, fb, microsoft, uber |
OK********* (5) |
| 0229 | Majority Element II | Python, Java | O(n) | O(1) | Medium | array, Boyer-Moore majority vote (2 candidates), LC 169, good trick, amazon, google, apple, microsoft, bloomberg, neetcode250 |
OK |
| 0238 | Product of Array Except Self | Python, Java | O(n) | O(1) | Medium | array, left, right array, LintCode, good trick, apple, microsoft, amazon, fb, google, uber, linkedin, blind75, top100liked |
OK******* (but again)(6) |
| 0240 | Search a 2D Matrix II | Python, Java | O(m + n) | O(1) | Medium | array, LintCode, basic, matrix, trick, binary search, check # 74 Search a 2D Matrix, amazon, apple, google, fb, microsoft, uber, top100liked |
OK***** (7) (but again) |
| 0243 | Shortest Word Distance | Python, Java | O(n) | O(1) | Easy | array, 🔒, basic, google, amazon, microsoft, uber, linkedin |
OK* |
| 0245 | Shortest Word Distance III | Python, Java | O(n) | O(1) | Medium | array, 🔒, check Shortest Word Distance I II III, google, apple, microsoft, linkedin |
OK* |
| 0251 | Flatten 2D Vector | Python, Java | ctor: O(1), next: O(1) amortized | O(1) | Medium | design, 🔒, good basic, check# 341 Flatten Nested List Iterator, google, airbnb, twitter, amazon, fb, apple, uber |
AGAIN******** (5) |
| 0277 | Find the Celebrity | Python, Java | O(n) | O(1) | Medium | array, graph, 🔒, fb, amazon, trick, two pointers, interactive, google, apple, microsoft, uber, linkedin |
AGAIN********** (5) |
| 0287 | Find the Duplicate Number | Python, Java | O(n) | O(1) | Medium | two pointers, good trick, Floyd cycle detection, binary search on value, check # 142 Linked List Cycle II, amazon, google, fb, apple, microsoft, uber, bloomberg, neetcode150, top100liked |
OK* (2) |
| 0289 | Game of Life | Python, Java | O(m * n) | O(1) | Medium | array, simultaneous, matrix, complex, google, amazon, fb, apple, microsoft |
AGAIN*** (4) |
| 0293 | Flip Game | Python, Java | O(n^2) | O(n) | Easy | array, 🔒, basic, string, google |
AGAIN* |
| 0308 | Range Sum Query 2D - Mutable | Python, Java | ctor: O(m * n), update: O(logm * logn), query: O(logm * logn) | O(m * n) | Hard | array, LC 303, LC 304, pre-sum, binary indexed tree (BIT), segment tree, 🔒, google, fb |
AGAIN(1)***** not start |
| 0311 | Sparse Matrix Multiplication | Python, Java | O(m * n * l) | O(m * l) | Medium | array, 🔒, matrix, basic, fb, google, amazon, apple, linkedin |
OK**** (5) |
| 0334 | Increasing Triplet Subsequence | Python, Java | O(n) | O(1) | Medium | array, AGAIN, check LC 300, trick, fb, google, amazon, uber |
OK***** (but again) (4) |
| 0335 | Self Crossing | Java | O(n) | O(1) | Hard | array, geometry, google, amazon |
Again (not start) |
| 0370 | Range Addition | Python, Java | O(k + n) | O(n) | Medium | prefix sum, prefix, diff array, check # 598 Range Addition II, amazon, LC 1109, LC 1094, google |
AGAIN************** (4) (MUST) |
| 0384 | Shuffle an Array | Python, Java | ctor: O(n), shuffle: O(n) | O(n) | Medium | design, EPI, trick, google, amazon, fb, apple, microsoft, uber, linkedin |
OK* |
| 0396 | Rotate Function | Python, Java | O(n) | O(1) | Medium | array, can pass, math, trick, amazon, google, apple |
AGAIN*** (3) |
| 0412 | Fizz Buzz | Python, Scala, Java | O(n) | O(1) | Easy | array, basic, string, simulation, LC 1195, math, google, amazon, fb, apple, microsoft, linkedin |
OK |
| 0414 | Third Maximum Number | Python, Java | O(n) | O(1) | Easy | array, good basic, amazon, google, fb, apple, microsoft |
OK* (4) |
| 0419 | Battleships in a Board | Python, Java | O(m * n) | O(1) | Medium | array, matrix, count only top-left cell of each ship, no extra space, LC 200, amazon, google, fb, apple, microsoft |
AGAIN* |
| 0422 | Valid Word Square | Python, Java | O(m * n) | O(1) | Easy | array, 🔒, basic, matrix, google |
AGAIN* |
| 0442 | Find All Duplicates in an Array | Python, Java | O(n) | O(1) | Medium | array, index-as-hash (negative marking), LC 448, LC 41, good trick, amazon, google, fb, apple, microsoft |
OK* |
| 0448 | Find All Numbers Disappeared in an Array | Python, Java | O(n) | O(1) | Easy | array, index-as-hash (negative marking), LC 442, LC 41, good basic, google, amazon, fb, apple, microsoft |
OK |
| 0498 | Diagonal Traverse | Python, Java | O(m * n) | O(1) excluding output | Medium | array, matrix, Diagonal, google, fb, amazon, apple, microsoft |
AGAIN****** (5) |
| 0531 | Lonely Pixel I | Python, Java | O(m * n) | O(m + n) | Medium | array, 🔒, matrix, basic, google, microsoft |
AGAIN* |
| 0533 | Lonely Pixel II | Python, Java | O(m * n) | O(m * n) | Medium | array, 🔒, matrix, row-pattern hashing, LC 531, google |
AGAIN (not start*) |
| 0565 | Array Nesting | Python, Java | O(n) | O(1) | Medium | array, union find, dfs, apple, google |
AGAIN**** (1) |
| 0566 | Reshape the Matrix | Python, Java | O(m * n) | O(m * n) | Easy | array, basic, matrix, fb |
AGAIN** |
| 0581 | Shortest Unsorted Continuous Subarray | Python, Java | O(n) | O(1) | Easy | array, basic, google, amazon, fb, apple, microsoft, bloomberg |
AGAIN* |
| 0605 | Can Place Flowers | Python, Java | O(n) | O(1) | Easy | array, pass vs continue, amazon, fb, apple, microsoft, linkedin |
OK* |
| 0624 | Maximum Distance in Arrays | Python, Java | O(n) | O(1) | Easy | array, 🔒, track running max excluding the current array, good trick |
AGAIN* |
| 0643 | Maximum Average Subarray I | Python, Java | O(n) | O(1) | Easy | array, Math, basic, google, amazon, fb |
AGAIN* |
| 0661 | Image Smoother | Python, Java | O(m * n) | O(m * n) | Easy | array, matrix, basic, amazon, fb, apple, microsoft |
OK***** (4) (but again!) |
| 0665 | Non-decreasing Array | Python, Java | O(n) | O(1) | Easy | array, greedy, at most one modification, decide nums[i-1] vs nums[i+1], good trick, google, amazon, fb |
AGAIN (not start) |
| 0667 | Beautiful Arrangement II | Python, Java | O(n) | O(1) | Medium | array, math, construct k distinct diffs then run out, trick, google |
AGAIN (not start) |
| 0670 | Maximum Swap | Python, Java | O(n) | O(n) | Medium | array, good basic, n = number of digits, last-occurrence index, string + pointers, fb, math, greedy, google, amazon, apple, microsoft |
AGAIN************ (9) (MUST) |
| 0674 | Longest Continuous Increasing Subsequence | Python, Java | O(n) | O(1) | Easy | array, good basic, dp, 2 pointers, fb, google, amazon, apple, microsoft |
OK*** (5) |
| 0697 | Degree of an Array | Python, Java | O(n) | O(n) | Easy | array, hash table, degree + first/last index, good basic |
AGAIN (not start) |
| 0713 | Subarray Product Less Than K | Python, Java | O(n) | O(1) | Medium | array, basic, sliding window, good trick, google, amazon, fb, microsoft |
OK****** (3) (but again) |
| 0717 | 1-bit and 2-bit Characters | Python, Java | O(n) | O(1) | Easy | array, Greedy, google, amazon, apple |
AGAIN (not start) |
| 0723 | Candy Crush | Python, Java | O((R * C)^2) | O(1) | Medium | array, complex, google, fb, uber, bloomberg |
AGAIN (not start) |
| 0724 | Find Pivot Index | Python, Java | O(n) | O(1) | Easy | array, good basic, prefix-sum, google, amazon, fb, apple, microsoft, uber |
OK**** (2) |
| 0729 | My Calendar I | Python, Java | O(nlogn) | O(n) | Medium | array, good basic, interval, google, amazon, fb, apple, microsoft |
AGAIN**** (1) |
| 0731 | My Calendar II | Python, Java | O(n^2) | O(n) | Medium | array, trick, good trick, scanning line, google, amazon, microsoft |
AGAIN******** (4) |
| 0747 | Largest Number At Least Twice of Others | Python, Java | O(n) | O(1) | Easy | array, good basic, data structure, google |
OK* |
| 0755 | Pour Water | Python, Java | O(v * n) | O(1) | Medium | array, complex |
AGAIN (not start) |
| 0759 | Employee Free Time | Python, Java | O(nlogn) | O(n) | Hard | interval, LC 56 and LC 986, heap, merger intervals, scanning line, amazon, fb, google, uber, airbnb, apple, microsoft |
AGAIN********** (2) (not start) |
| 0766 | Toeplitz Matrix | Python, Java | O(m * n) | O(1) | Easy | array, basic, matrix, google, amazon, fb, apple |
AGAIN* (2) |
| 0769 | Max Chunks To Make Sorted | Python, Java | O(n) | O(1) | Medium | prefix sum, LC 768, good trick, stack, array, google, greedy, amazon, microsoft, uber |
AGAIN*** (2) |
| 0792 | Number of Matching Subsequences | Python, Java | O(n + w) | O(w) | Medium | hash table, basic, hash map, google, amazon, fb, apple |
AGAIN**** (2) |
| 0794 | Valid Tic-Tac-Toe State | Python, Java | O(1) | O(1) | Medium | array, complex, google, amazon, fb, apple, microsoft |
AGAIN |
| 0795 | Number of Subarrays with Bounded Maximum | Python, Java | O(n) | O(1) | Medium | array, count subarrays with max in [left, right], two pointers, trick, google, amazon, apple, microsoft |
AGAIN (not start*) |
| 0807 | Max Increase to Keep City Skyline | Python, Java | O(n^2) | O(n) | Medium | array, matrix, row max + col max, greedy, good basic, google, amazon |
AGAIN* |
| 0821 | Shortest Distance to a Character | Python, Java | O(n) | O(1) excluding output | Easy | array, basic, trick, google, apple |
AGAIN** |
| 0830 | Positions of Large Groups | Python, Java | O(n) | O(1) | Easy | array, basic, string, google |
AGAIN* |
| 0832 | Flipping an Image | Python, Java | O(n^2) | O(1) | Easy | array, matrix, reverse each row then invert, two pointers, basic, google, fb |
AGAIN* |
| 0835 | Image Overlap | Python, Java | O(n^4) | O(n^2) | Medium | array, matrix, brute-force all shifts, count overlaps with a delta hashmap, google |
AGAIN (not start) |
| 0840 | Magic Squares In Grid | Python, Java | O(m * n) | O(1) | Easy | array, complex, google |
AGAIN (not start) |
| 0842 | Split Array into Fibonacci Sequence | Python, Java | O(n^3) | O(n) | Medium | array, check # 306 Addictive Number, basic, dfs, fibonacci, string, backtracking, amazon |
AGAIN* (not start) |
| 0845 | Longest Mountain in Array | Python, Java | O(n) | O(1) | Medium | array, basic, 2 pointers expansion, google, amazon |
AGAIN************ (2)(MUST) |
| 0849 | Maximize Distance to Closest Person | Python, Java | O(n) | O(1) | Medium | array, basic, 2 pointers, LC 855, google, amazon, microsoft |
AGAIN********* (2) |
| 0860 | Lemonade Change | Python, Java | O(n) | O(1) | Easy | array, amazon, apple, neetcode250 |
OK* (2) |
| 0868 | Transpose Matrix | Python, Java | O(r * c) | O(r * c) | Easy | array, basic, bit manipulation |
OK* |
| 0885 | Spiral Matrix III | Python, Java | O(max(m, n)^2) | O(1) | Medium | array, basic, fb |
AGAIN* (not start) |
| 0888 | Fair Candy Swap | Python, Java | O(m + n) | O(m + n) | Easy | array, basic, trick, amazon, uber |
OK* |
| 0896 | Monotonic Array | Python, Java | O(n) | O(1) | Easy | array, all, fb, amazon |
OK |
| 0905 | Sort Array By Parity | Python, Java | O(n) | O(1) | Easy | array, custom sort, 2 pointers, google, amazon, fb, apple, microsoft |
AGAIN***** (1)(MUST) |
| 0909 | Snakes and Ladders | Python, Java | O(n^2) | O(n^2) | Medium | array, matrix, bfs, complex, amazon, google, apple, microsoft, uber |
AGAIN***** (3) |
| 0915 | Partition Array into Disjoint Intervals | Python, Java | O(n) | O(n) | Medium | array, basic, trick, amazon, microsoft |
AGAIN* (not start) |
| 0918 | Maximum Sum Circular Subarray | Python, Java | O(n) | O(1) | Medium | array, check # 053 Maximum Subarray, basic, trick, google, amazon, fb, uber, neetcode250 |
AGAIN** (2) |
| 0921 | Minimum Add to Make Parentheses Valid | Python, Java | O(n) | O(1) | Medium | array, basic, trick, string, stack, greedy, amazon, fb, microsoft |
AGAIN** |
| 0922 | Sort Array By Parity II | Python, Java | O(n) | O(1) | Easy | array, basic, amazon, microsoft |
AGAIN* |
| 0923 | 3Sum With Multiplicity | Python, Java | O(n^2) | O(n) | Medium | array, LC 15, count pairs with a Counter, combination math, trick |
AGAIN (not start) |
| 0932 | Beautiful Array | Python, Java | O(nlogn) | O(n) | Medium | array, divide and conquer, odd/even split, trick, google, fb |
AGAIN** (not start) (1) |
| 0941 | Valid Mountain Array | Python, Java | O(n) | O(1) | Easy | array, basic, good basic, google, amazon, uber |
AGAIN* |
| 0945 | Minimum Increment to Make Array Unique | Python, Java | O(nlogn) | O(n) | Medium | array, trick, good, uber |
AGAIN** |
| 0947 | Most Stones Removed with Same Row or Column | Python, Java | O(n * a(n)) | O(n) | Medium | array, Union Find on row/col keys, dfs, trick, google, hash table, amazon, apple, uber |
AGAIN** (1) (not start) |
| 0949 | Largest Time for Given Digits | Python, Java | O(1) | O(1) | Easy | array, brute force all 4! digit permutations, math, basic, google, amazon |
OK* |
| 0950 | Reveal Cards In Increasing Order | Python, Java | O(nlogn) | O(n) | Medium | array, sort + deque simulation, queue, 2 pointers, google, amazon |
AGAIN (not start) (2) |
| 0954 | Array of Doubled Pairs | Python, Java | O(n + klogk) | O(k) | Medium | array, counter, dict, trick, google, amazon, uber |
AGAIN** |
| 0961 | N-Repeated Element in Size 2N Array | Python, Java | O(n) | O(1) | Easy | array, LC 217, hash table / count, basic, apple |
OK |
| 0989 | Add to Array-Form of Integer | Python, Java | O(n) | O(1) | Easy | array, add xxx to sum, fb, google |
AGAIN (not start) |
| 1007 | Minimum Domino Rotations For Equal Row | Java | O(n) | O(1) | Medium | array, google, dp, amazon, apple |
AGAIN (1) |
| 1014 | Best Sightseeing Pair | Python, Java | O(n) | O(1) | Medium | array, dp, good basic, Spotify, google |
AGAIN (not start) |
| 1027 | Longest Arithmetic Subsequence | Python, Java | O(n^2) | O(n^2) | Medium | array, dp, hash table, trick, google, amazon, fb, microsoft, uber |
AGAIN*** (not start) |
| 1031 | Maximum Sum of Two Non-Overlapping Subarrays | Python, Java | O(n) | O(n) | Medium | array, prefix sum+slide window, good trick, google, amazon, fb |
AGAIN*************** (3)(MUST) |
| 1041 | Robot Bounded In Circle | Python, Java | O(n) | O(1) | Medium | array, math, amazon, string, simulation, google, apple, microsoft |
AGAIN** (2) |
| 1074 | Number of Submatrices That Sum to Target | Java | O(m^2 * n) | O(n) | Hard | array, hashmap, prefix sum, google, amazon, fb, apple, microsoft |
AGAIN (not start) |
| 1089 | Duplicate Zeros | Java | O(n) | O(1) | Easy | array, two pointers, in-place shift from the back, good trick, google, amazon, microsoft |
AGAIN (not start) |
| 1094 | Car Pooling | Python, Java | O(n + k) | O(k) | Medium | array, range addition, prefix sum, LC 370, google, amazon, fb, microsoft, neetcode250 |
AGAIN********** (5) (MUST) |
| 1109 | Corporate Flight Bookings | Python, Java | O(n + k) | O(n) | Medium | array, LC 370, difference array, good basic, amazon, google |
AGAIN********* (MUST) (3) |
| 1248 | Count Number of Nice Subarrays | Python, Java | O(n) | O(n) | Medium | array, LC 828, map, Prefix sum, exactly K with at most K, amazon |
AGAIN********************* (4) (MUST) |
| 1272 | Remove Interval | Java | O(n) | O(n) | Medium | array, google |
AGAIN (not start) |
| 1275 | Find Winner on a Tic Tac Toe Game | Python, Java | O(1) | O(1) | Easy | array, amazon, google, fb, apple, microsoft |
AGAIN (not start) |
| 1288 | Remove Covered Intervals | Java | O(nlogn) | O(1) | Medium | array, greedy, interval, amazon, fb, apple |
AGAIN (not start) |
| 1314 | Matrix Block Sum | Java | O(m * n) | O(m * n) | Medium | array, prefix sum, dp, matrix sum, google, amazon, fb, apple |
AGAIN (not start) |
| 1431 | Kids With the Greatest Number of Candies | Java | O(n) | O(1) excluding output | Easy | array, compare each candy count with the max, basic, google, amazon, uber |
AGAIN (not start) |
| 1470 | Shuffle the Array | Java | O(n) | O(1) excluding output | Easy | array, index mapping, 2 pointers, basic, google, amazon, apple, uber |
AGAIN (not start) |
| 1564 | Put Boxes Into the Warehouse I | Java | O(nlogn) | O(m) | Medium | array, google |
AGAIN (not start) |
| 1567 | Maximum Length of Subarray With Positive Product | Python, Java | O(n) | O(1) | Medium | array, good trick, dp, 2 pointers, amazon, microsoft |
AGAIN**** (1) (not start) |
| 1672 | Richest Customer Wealth | Java | O(m * n) | O(1) | Easy | array, row sum then max, matrix, basic, google, amazon, apple, uber |
OK |
| 1806 | Minimum Number of Operations to Reinitialize a Permutation | Java | O(n) | O(n) | Medium | array, brute force, google |
AGAIN (not start) |
| 1914 | Cyclically Rotating a Grid | Python, Java | O(m * n) | O(m * n) | Medium | array, brute force, dequeueamazon, amazon |
AGAIN (not start) |
| 1920 | Build Array from Permutation | Java | O(n) | O(1) excluding output | Easy | array, index mapping, basic, google, amazon, fb, apple, uber |
AGAIN (not start) |
| 1929 | Concatenation of Array | Java | O(n) | O(1) excluding output | Easy | array, concatenate, basic, google, neetcode250 |
AGAIN (not start) |
| 1991 | Find the Middle Index in Array | Java | O(n) | O(1) | Easy | array, prefix sum, LC 724, good basic |
AGAIN (not start) |
| 2033 | Minimum Operations to Make a Uni-Value Grid | Python | O(m * n * log(m * n)) | O(m * n) | Medium | array, feasible iff all values agree mod x, median minimizes sum of abs deviation, sort, math, LC weekly | AGAIN(1) |
| 2079 | Watering Plants | Java | O(n) | O(1) | Medium | array, google |
AGAIN (not start) |
| 2553 | Separate the Digits in an Array | Java | O(n * d) | O(1) excluding output | Easy | array, weekly 97 | OK |
| 2640 | Find the Score of All Prefixes of an Array | Java | O(n) | O(1) excluding output | Medium | array, lc weekly 102 | OK (1) |
| 2644 | Find the Maximum Divisibility Score | Java | O(n * m) | O(1) | Easy | array, sort | Again (1) |
| 3195 | Find the Minimum Area to Cover All Ones I | Java | O(m * n) | O(1) | Medium | array, LC weekly | AGAIN (1) |
| 3964 | Minimum Lights to Illuminate a Road | Python, Java | O(n) | O(n) | Medium | array, diff array, LC bi weekly | AGAIN (1) |
Set
| # | Title | Solution | Time | Space | Difficulty | Note | Status |
|---|---|---|---|---|---|---|---|
| 1316 | Distinct Echo Substrings | Java | O(n^2) | O(n^2) | Hard | set, set of substrings, rolling hash / Rabin-Karp for O(n^2), trick, string, trie, google |
Again (not start) |
| 1436 | Destination City | Java | O(n) | O(n) | Easy | set, set of outgoing cities, find the city with no outgoing path, basic, google |
Again (1) |
| 2357 | Make Array Zero by Subtracting Equal Amounts | Java | O(n) | O(n) | Easy | set, count distinct non-zero values, good trick |
Again (1) |
| 2657 | Find the Prefix Common Array of Two Arrays | Java | O(n) | O(n) | Medium | set, frequency array + running common count, good trick, weekly_103 | Again**** (1) |
| 2682 | Find the Losers of the Circular Game | Java | O(n) | O(n) | Easy | set, simulate the circular jumps until a friend repeats, hashset, basic |
Again (1) |
Slide Window
| # | Title | Solution | Time | Space | Difficulty | Note | Status |
|---|---|---|---|---|---|---|---|
| 0030 | Substring with Concatenation of All Words | Java | O(n * l) | O(m * l) | Hard | sliding window, hashmap word count, fixed-size window of l chars, LC 76, good trick, google, amazon, fb, apple, microsoft |
AGAIN(not start) |
| 0768 | Max Chunks To Make Sorted II | Java | O(n) | O(n) | Hard | sliding window, LC 769, prefix max vs suffix min, monotonic stack, good trick, array, greedy, google, amazon, microsoft |
AGAIN(not start) |
| 1004 | Max Consecutive Ones III | Java | O(n) | O(1) | Medium | sliding window, longest window with at most k zeros, LC 487, LC 424, good basic, google, amazon, fb, apple, microsoft |
Again (1) |
| 1423 | Maximum Points You Can Obtain from Cards | Python | O(n) | O(1) | Medium | slide window, window the complement: minimise the block you leave, good trick, google, amazon, apple, uber |
AGAIN(1) |
| 1461 | Check If a String Contains All Binary Codes of Size K | Python | O(n) | O(2^k) | Medium | slide window, rolling window as an int + set, pigeonhole early exit, bit manipulation, rolling hash, google |
AGAIN(1) |
| 1658 | Minimum Operations to Reduce X to Zero | Python, Java | O(n) | O(1) | Medium | sliding window, turn “remove from both ends” into “longest middle subarray with sum total-x”, good trick, google, amazon |
AGAIN******** (1)(MUST) |
| 1838 | Frequency of the Most Frequent Element | Java, Python | O(nlogn) | O(1) | Medium | sliding window, sort + sliding window with sum, binary search on the answer, good trick, amazon, microsoft |
AGAIN******** (1)(good) |
| 1839 | Longest Substring Of All Vowels in Order | Python, Java | O(n) | O(1) | Medium | sliding window, window must be non-decreasing and cover all 5 vowels, basic |
AGAIN** (1)(good) |
| 1888 | Minimum Number of Flips to Make The Binary String Alternating | Python | O(n) | O(1) | Medium | slide window, double the string = every rotation, score both alternating targets at once, good trick, google |
AGAIN(1) |
| 2555 | Maximize Win From Two Segments | Java | O(n) | O(n) | Medium | sliding window, best window ending at i + best window before i, prefix dp, weekly 97 | AGAIN (not start) |
| 2962 | Count Subarrays Where Max Element Appears at Least K Times | Java | O(n) | O(1) | Medium | sliding window, count windows containing the max at least k times, good trick, weekly 375 |
AGAIN************ (3) |
| 3090 | Maximum Length Substring With Two Occurrences | Java | O(n) | O(1) | Easy | sliding window, longest window where every char appears at most twice, weekly 390 | AGAIN (1) |
Hash Table
| # | Title | Solution | Time | Space | Difficulty | Note | Status |
|---|---|---|---|---|---|---|---|
| 0001 | Two Sum | Python, Java,Scala | O(n) | O(n) | Easy | hash table, good basic, apple, amazon, uber, grab, fb, google, microsoft, linkedin, bloomberg, blind75, top100liked |
OK*** (6) (but again) |
| 0003 | Longest Substring Without Repeating Characters | Python, Java | O(n) | O(1) | Medium | hash table, 2 pointers, optimized (SLIDING WINDOW + DICT), good trick, hashMap, MUST, apple, amazon, fb, google, microsoft, uber, bloomberg, blind75, top100liked |
AGAIN**************** (12) (but AGAIN) |
| 0036 | Valid Sudoku | Python, Java | O(9^2) | O(9^2) | Medium | hash table, array, hashset, uber, apple, amazon, google, fb, microsoft, neetcode150 |
OK**** (3) (again) |
| 0049 | Group Anagrams | Python, Scala, Java | O(n * glogg) | O(n * g) | Medium | hash table, good basic, dict, trick, dict + sort, uber, amazon, fb, google, apple, microsoft, bloomberg, blind75, top100liked |
OK ********** (6) |
| 0170 | Two Sum III - Data structure design | Python , Java | add: O(1), find: O(n) | O(n) | Easy | hash table, 🔒, trick, good basic, linkedin, fb |
OK*** (4) |
| 0187 | Repeated DNA Sequences | Python , Java | O(n) | O(n) | Medium | hash table, basic, trick, set, linkedin, google, amazon, apple |
AGAIN** |
| 0202 | Happy Number | Python , Java | O(k) | O(k) | Easy | hash table, twitter, airbnb, uber, google, amazon, fb, apple, microsoft, bloomberg, neetcode150 |
AGAIN** (4) |
| 0204 | Count Primes | Python , Java | O(nloglogn) | O(n) | Medium | hash table, Sieve of Eratosthenes, good trick, cache, microsoft, amazon, array, math, number theory, google, apple |
AGAIN******** (5) |
| 0205 | Isomorphic Strings | Python, Java | O(n) | O(1) | Easy | hash table, basic, trick, bloomberg, google, amazon, fb, apple, uber, linkedin |
AGAIN** |
| 0217 | Contains Duplicate | Python , Java | O(n) | O(n) | Easy | hash table, yahoo, airbnb, google, amazon, fb, apple, microsoft, uber, blind75 |
OK |
| 0219 | Contains Duplicate II | Python ,Java | O(n) | O(n) | Easy | hash table, basic, trick, google, amazon, fb, apple, neetcode250 |
AGAIN* |
| 0244 | Shortest Word Distance II | Python , Java | ctor: O(n), lookup: O(a + b) | O(n) | Medium | hash table, 🔒, amazon, uber, linkedin |
AGAIN (not start*) |
| 0246 | Strobogrammatic Number | Python, Java | O(n) | O(1) | Easy | hash table, 🔒, google, fb, microsoft |
OK* (5) |
| 0249 | Group Shifted Strings | Python , Java | O(n * l) | O(n * l) | Medium | hash table, LC 49, 🔒, hashmap, char, apple, uber, google, amazon, fb |
OK *****(6) (but again) |
| 0266 | Palindrome Permutation | Python , Java | O(n) | O(1) | Easy | hash table, 🔒, google, amazon, fb, microsoft, uber, bloomberg |
OK |
| 0288 | Unique Word Abbreviation | Python , Java | ctor: O(n), lookup: O(1) | O(k) | Medium | hash table, 🔒, ?, google, fb |
AGAIN (2)(not start) |
| 0290 | Word Pattern | Python , Java | O(n) | O© | Easy | hash table, basic, chcek # 205 Isomorphic Strings, good basic, for ptn, word in zip(pattern, words), dropbox, uber, google, amazon, fb, apple, microsoft |
AGAIN* (3) |
| 0299 | Bulls and Cows | Python , Java | O(n) | O(1) | Easy | hash table, trick, map(operator.eq, a, b), amazon, airbnb, google |
AGAIN* (3) |
| 0314 | Binary Tree Vertical Order Traversal | Python , Java | O(n) | O(n) | Medium | hash table, LC 987, 🔒, BFS, DFS, tree, trick, google, amazon, fb, microsoft, apple |
OK**** (6) |
| 0325 | Maximum Size Subarray Sum Equals k | Python, Java | O(n) | O(n) | Medium | hash table, prefix sum, 🔒, hashmap, good trick, dict, fb, google, amazon, apple, microsoft |
AGAIN***************** (8) (MUST) |
| 0336 | Palindrome Pairs | Java | O(n * l^2) | O(n * l) | Hard | hash table, LC 49, Anagrams, string op, hashmap, sub-string, google, amazon, fb, apple, uber |
Again******* (2)(again) |
| 0356 | Line Reflection | Python , Java | O(n) | O(n) | Medium | hash table, 🔒, Hash, Two Pointers, math, google, amazon |
AGAIN (not start) |
| 0359 | Logger Rate Limiter | Python, Java | O(1), amortized | O(k) | Easy | hash table, 🔒, google, amazon, fb, apple, microsoft, uber |
OK |
| 0387 | First Unique Character in a String | Python , Java | O(n) | O(n) | Easy | hash table, amazon, apple, fb, google, microsoft, bloomberg |
OK |
| 0388 | Longest Absolute File Path | Python , Java | O(n) | O(d) | Medium | hash table, stack, good trick, file system, google, string, dfs, amazon, fb, apple, uber |
AGAIN******* (3) |
| 0409 | Longest Palindrome | Python , Java | O(n) | O(1) | Easy | hash table, count char pairs, add 1 if any odd count remains, basic, google, amazon |
OK* |
| 0424 | Longest Repeating Character Replacement | Python, Java | O(n) | O(1) | Medium | hash table, hash map, max_freq, silding window, good trick, LC blind pattern, google, amazon, fb, apple, microsoft, uber, blind75 |
AGAIN**************** (10) (MUST) |
| 0438 | Find All Anagrams in a String | Python , Java | O(n) | O(1) | Medium | hash table, trick, AGAIN, sliding window, acc Counter, amazon, fb, apple, google, uber, yahoo, microsoft, bloomberg, top100liked |
AGAIN************** (11)(must) |
| 0447 | Number of Boomerangs | Python , Java | O(n^2) | O(n) | Easy | hash table, trick, google |
AGAIN (3) (not start) |
| 0454 | 4Sum II | Python , Java | O(n^2) | O(n^2) | Medium | hash table, check LC 018 4SUM, trick, basic, amazon, google, fb, apple, uber |
AGAIN** |
| 0463 | Island Perimeter | Python , Java | O(m * n) | O(1) | Easy | hash table, count cells then subtract shared edges, matrix, basic, google, fb, amazon, array, dfs, bfs, apple, microsoft, bloomberg, neetcode250 |
AGAIN** (2) |
| 0470 | Implement Rand10() Using Rand7() | Python , Java | O(1) | O(1) | Medium | hash table, trick, google, math, apple, microsoft, uber |
AGAIN** (3) |
| 0473 | Matchsticks to Square | Python , Java | O(n * s * 2^n) | O(n * (2^n + s)) | Medium | hash table, good trick, backtrack, array, dp, amazon, microsoft, neetcode250 |
AGAIN****** (2) |
| 0523 | Continuous Subarray Sum | Python , Java | O(n) | O(k) | Medium | hash table, sub array sum, check # 560 Subarray Sum Equals K, good trick, substring, AGAIN, microsoft, fb, apple, google, amazon |
AGAIN*************** (10) (MUST) |
| 0525 | Contiguous Array | Python, Java | O(n) | O(n) | Medium | hash table, sub-array sum, LC 560, 525, 974, good basic, array, hashmap, fb, amazon, google, apple |
AGAIN****************** (12) (MUST) |
| 0532 | K-diff Pairs in an Array | Python , Java | O(n) | O(n) | Medium | hash table, basic, collections.Counter(), a-b =k -> a = k + b , amazon, google, fb, apple, microsoft, uber, bloomberg |
AGAIN********** (6) |
| 0554 | Brick Wall | Python , Java | O(n) | O(m) | Medium | hash table, LC 252, gap map, trick, hash map, bloomberg, fb, grab, google |
AGAIN******** (6) |
| 0560 | Subarray Sum Equals K | Python, Java | O(n) | O(n) | Medium | hash table, LC 560, 525, 974, prefix sum, must check, check # 523 Continuous Subarray Sum, LC 1268, basic, substring, good trick, google, fb, amazon, apple, microsoft, uber, bloomberg, neetcode250, top100liked |
AGAIN***************** (8) (MUST) |
| 0561 | Array Partition I | Python , Java | O(nlogn) | O(1) | Easy | hash table, sort then sum every other element, greedy, good trick, array, amazon, apple |
OK |
| 0575 | Distribute Candies | Python , Java | O(n) | O(n) | Easy | hash table, min(distinct kinds, n / 2), hashset, basic, microsoft |
OK |
| 0594 | Longest Harmonious Subsequence | Python , Java | O(n) | O(n) | Easy | hash table, basic, good trick |
OK* (3) |
| 0599 | Minimum Index Sum of Two Lists | Python , Java | O((m + n) * l) | O(m * l) | Easy | hash table, yelp, apple |
OK* |
| 0609 | Find Duplicate File in System | Python , Java | O(n * l) | O(n * l) | Medium | hash table, collections.defaultdict(list), dropbox, google, amazon, fb, apple, microsoft |
OK* |
| 0657 | Robot Return to Origin | Python , Java | O(n) | O(1) | Easy | hash table, amazon, string, simulation, google |
OK (2) |
| 0710 | Random Pick with Blacklist | Java | ctor: O(b), pick: O(1) | O(b) | Hard | hash table, hashmap, google, amazon, uber |
AGAIN (not start) |
| 0748 | Shortest Completing Word | Python , Java | O(n) | O(1) | Easy | hash table, collections.Counter, google, linkedin |
AGAIN* (3) |
| 0760 | Find Anagram Mappings | Python , Java | O(n) | O(n) | Easy | hash table, basic, collections.defaultdict, google |
OK |
| 0771 | Jewels and Stones | Python , Java | O(m + n) | O(n) | Easy | hash table, amazon, google, fb, apple, uber |
OK (2) |
| 0811 | Subdomain Visit Count | Python , Java | O(n) | O(n) | Easy | hash table, indeed, bloomberg, google, amazon |
AGAIN (not start) |
| 0822 | Card Flipping Game | Python , Java | O(n) | O(n) | Medium | hash table, good basic |
AGAIN* (3) |
| 0825 | Friends Of Appropriate Ages | Python , Java | O(a^2 + n) | O(a) | Medium | hash table, good basic, counter, AGAIN, fb, array, two pointers, binary search |
AGAIN***** (5) |
| 0869 | Reordered Power of 2 | Python , Java | O(1) | O(1) | Medium | hash table, trick, basic, bit manipulation, bit |
AGAIN* |
| 0873 | Length of Longest Fibonacci Subsequence | Python , Java | O(n^2) | O(n) | Medium | hash table, trick, DP, Fibonacci, set, amazon, apple |
AGAIN** |
| 0957 | Prison Cells After N Days | Python , Java | O(1) | O(1) | Medium | hash table, trick, DP, mod, amazon, apple |
AGAIN (not start) |
| 0966 | Vowel Spellchecker | Python , Java | O(n) | O(w) | Medium | hash table, trick, dict, set, amazon |
AGAIN (not start) |
| 0974 | Subarray Sums Divisible by K | Python , Java | O(n) | O(k) | Medium | hash table, LC 560, 525, 974, prefix, hashmap, google, amazon, fb, apple |
AGAIN*************** (7)(MUST) |
| 0992 | Subarrays with K Different Integers | Python , Java | O(n) | O(k) | Hard | hash table, trick, hashmap, slide window, amazon, google, apple, uber |
AGAIN**** (1) |
| 1010 | Pairs of Songs With Total Durations Divisible by 60 | Python , Java | O(n) | O(1) | Medium | hash table, good basicm dict, array, amazon, google |
AGAIN********* (4) (MUST) |
| 1099 | Two Sum Less Than K | Python , Java | O(nlogn) | O(1) | Medium | hash table, dict, sort, amazon, array, two pointers, binary search, fb |
AGAIN* (1) (not start) |
| 1121 | Divide Array Into Increasing Sequences | Java | O(n) | O(1) | Hard | hash table, dict, google, array, counting |
Again (not start) |
| 1131 | Rank Transform of an Array | Python , Java | O(nlogn) | O(n) | Easy | hash table, dict, array, amazon, math, google, microsoft |
OK* (1) |
| 1170 | Compare Strings by Frequency of the Smallest Character | Java | O((m + n) * l + nlogn) | O(n) | Medium | hash table, hashmap, binary search, google, amazon |
AGAIN*** (1)s |
| 1257 | Smallest Common Region | Java | O(n) | O(n) | Medium | hash table, hashmap, good trick, lowest common ancestor (LCA), amazon |
AGAIN (not start) |
| 1296 | Divide Array in Sets of K Consecutive Numbers | Python , Java | O(nlogn) | O(n) | Medium | hash table, LC 846, dict, google |
AGAIN (not start) |
| 1726 | Tuple with Same Product | Python , Java | O(n^2) | O(n^2) | Medium | hash table, hashmap, sort, 2 pointers, brute force, good basic, google |
AGAIN**** (1)(MUST) |
| 1794 | Count Pairs of Equal Substrings With Minimum Difference | Java | O(m + n) | O(1) | Medium | hash table, first, last idx, hashmap, trick, google |
AGAIN**** (1)(not start) |
| 1923 | Longest Common Subpath | Python, Java | O(m * nlogn) | O(n) | Hard | hash table, hash, bit, amazon, array, binary search, rolling hash |
AGAIN (not start) |
| 2506 | Count Pairs Of Similar Strings | Java | O(n * l) | O(n) | Easy | hash table, hashmap, LC weekly | AGAIN (1) |
| 2592 | Maximize Greatness of an Array | Java | O(nlogn) | O(1) | Medium | hash table, Treemap, 2 pointers, LC weekly, array, greedy |
AGAIN (1) |
| 2615 | Sum of Distances | Python , Java | O(n) | O(n) | Medium | hash table, good basic, left-right dist, prefix sum, hashmap, LC weekly | AGAIN************** (5)(MUST) |
| 2766 | Relocate Marbles | Java | O(n + m) | O(n) | Medium | hash table, hashset, hashmap LC weekly, good trick | AGAIN******(1) |
| 2768 | Number of Black Blocks | Java | O(n) | O(n) | Medium | hash table, hashmap, LC weekly | AGAIN(1) (not srart) |
| 2870 | Minimum Number of Operations to Make Array Empty | Java | O(n) | O(n) | Medium | hash table, LC 2244, hashmap, count, LC weekly | AGAIN (1) |
| 2963 | Count the Number of Good Partitions | Java | O(n) | O(n) | Hard | hash table, LC weekly | AGAIN (1) (not start) |
| 3121 | Count the Number of Special Characters II | Java | O(n) | O(1) | Medium | hash table, greedy, hashmap | AGAIN(1) (not srart) |
| 4007 | Minimum Initial Strength to Defeat All Monsters | Python, Java | O(n + m + nlog(sum)) | O(n) | Medium | hash table, good trick, hashmap pair, LC weekly | AGAIN(1) (not srart) |
| 4038 | Count Integers Appearing in a Single Block | Python | O(n) | O(n) | Easy | hash table, hashmap, span == cnt trick, first/last idx, LC weekly |
AGAIN(1) |
Linked list
| # | Title | Solution | Time | Space | Difficulty | Note | Status |
|---|---|---|---|---|---|---|---|
| 0002 | Add Two Numbers | Python, Java | O(n) | O(1) | Medium | linked list, check # 445 Add Two Numbers II, basic, airbnb, amazon, fb, google, apple, microsoft, uber, linkedin, bloomberg, neetcode150, top100liked |
OK**** (6) (but again) |
| 0021 | Merge Two Sorted Lists | Python, Java | O(n) | O(1) | Easy | linked list, uber, amazon, apple, fb, google, microsoft, linkedin, bloomberg, blind75, top100liked |
OK******** (6) (but again) |
| 0023 | Merge k sorted lists | Python, Java | O(nlogk) | O(k) | Hard | linked list, check #21 Merge Two Sorted Lists, amazon, google, fb, apple, microsoft, uber, linkedin, bloomberg, blind75, top100liked |
OK**** (2) (but again !!! |
| 0024 | Swap Nodes in Pairs | Python, Java | O(n) | O(1) | Medium | linked list, GOOD basic, LC 100 like, uber, amazon, fb, google, apple, microsoft, bloomberg, top100liked |
AGAIN**************** (8) (MUST) |
| 0025 | Reverse Nodes in k-Group | Python, Java | O(n) | O(1) | Hard | linked list, good trick, reverse linkedlist, reverse K linkedlist, amazon, google, fb, microsoft, apple, uber, neetcode150, top100liked |
AGAIN********** (4) |
| 0061 | Rotate List | Python, Java | O(n) | O(1) | Medium | linked list, basic, amazon, apple, microsoft, linkedin |
AGAIN (2) |
| 0082 | Remove Duplicates from Sorted List II | Python, Java | O(n) | O(1) | Medium | linked list, good basic, check # 083 Remove Duplicates from Sorted List, google, amazon, fb, apple, microsoft, bloomberg |
AGAIN (3) ***** |
| 0083 | Remove Duplicates from Sorted List | Python, Java | O(n) | O(1) | Easy | linked list, basic, google, amazon, fb, apple, microsoft |
OK* |
| 0092 | Reverse Linked List II | Python, Java | O(n) | O(1) | Medium | linked list, LC 206, reverse k nodes, good trick, fb, apple, google, amazon, microsoft, bloomberg, neetcode250 |
AGAIN*************** (10) (MUST) |
| 0138 | Copy List with Random Pointer | Python, Java | O(n) | O(n) | Medium | linked list, trick, recursive, hash table, uber, microsoft, amazon, fb, google, apple, bloomberg, neetcode150, top100liked |
AGAIN******* (7) |
| 0160 | Intersection of Two Linked Lists | Python, Java | O(m + n) | O(1) | Easy | linked list, basic, hash table, 2 pointers, airbnb, amazon, fb, google, apple, microsoft, uber, linkedin, bloomberg, top100liked |
OK******* (7) (again!) |
| 0203 | Remove Linked List Elements | Python , Java | O(n) | O(1) | Easy | linked list, linked list basic, amazon, google, fb, apple, microsoft, bloomberg |
AGAIN**** (3) |
| 0206 | Reverse Linked List | Python, Java | O(n) | O(1) | Easy | linked list, good basic, amazon, fb, google, apple, microsoft, uber, bloomberg, blind75, top100liked |
OK*********** (9) (MUST again) |
| 0234 | Palindrome Linked List | Python, Java | O(n) | O(1) | Easy | linked list, amazon, fb, google, apple, microsoft, uber, top100liked |
OK (4) |
| 0237 | Delete Node in a Linked List | Python, Java | O(1) | O(1) | Easy | linked list, LintCode, apple, google, amazon, fb, microsoft |
OK * (1) (but again) |
| 0328 | Odd Even Linked List | Python, Java | O(n) | O(1) | Medium | linked list, basic, google, amazon, fb, apple, microsoft, bloomberg |
OK** (2) |
| 0369 | Plus One Linked List | Python, Java | O(n) | O(1) | Medium | linked list, 🔒, basic, google, amazon |
AGAIN****** (3) |
| 0430 | Flatten a Multilevel Doubly Linked List | Python, Java | O(n) | O(n) | Medium | linked list, good trick, doubly linked list, dfs, iterative, stack, fb, google, amazon, microsoft, uber, bloomberg |
AGAIN******** (6) |
| 0445 | Add Two Numbers II | Python, Java | O(m + n) | O(m + n) | Medium | linked list, trick, string, good basic, amazon, google, fb, apple, microsoft, uber, bloomberg |
AGAIN*** (3) |
| 0707 | Design Linked List | Python, Java | get/addAtIndex/deleteAtIndex: O(n), addAtHead/addAtTail: O(1) | O(n) | Medium | linked list, linked list basic OP, google, amazon, apple, microsoft |
AGAIN (1) |
| 0708 | Insert into a Cyclic Sorted List | Python, Java | O(n) | O(1) | Medium | linked list, AGAIN, cyclic linked list, good trick, google, amazon, fb, microsoft |
AGAIN******** (4) |
| 0725 | Split Linked List in Parts | Python, Java | O(n + k) | O(1) | Medium | linked list, mod, split linked list, good trick, amazon, google, apple |
AGAIN************ (6) (again) |
| 0817 | Linked List Components | Python, Java | O(m + n) | O(m) | Medium | linked list, set, array, google |
AGAIN** (1) |
| 1836 | Remove Duplicates From an Unsorted Linked List | Java | O(n) | O(n) | Medium | linked list, hashset of seen values, dummy head, good basic, microsoft |
AGAIN (not start) |
Stack
| # | Title | Solution | Time | Space | Difficulty | Note | Status |
|---|---|---|---|---|---|---|---|
| 0020 | Valid Parentheses | Python, Java | O(n) | O(n) | Easy | stack, good basic, fb, amazon, google, apple, microsoft, uber, linkedin, bloomberg, blind75, top100liked |
OK** (6) |
| 0032 | Longest Valid Parentheses | Python, Java | O(n) | O(n) | Hard | stack, brute force, dp, deque, amazon, fb, microsoft, google, apple, uber, top100liked |
AGAIN********** (3) |
| 0071 | Simplify Path | Python, Java | O(n) | O(n) | Medium | stack, basic, amazon, fb, google, apple, microsoft, uber, neetcode250 |
AGAIN******** (5) |
| 0085 | Maximal Rectangle | Python, Java | O(m * n) | O(n) | Hard | stack, top-100-like, brute force, dp, LC 84, google, amazon, apple, fb, microsoft, uber |
AGAIN (not start) |
| 0101 | Symmetric Tree | Python, Java | O(n) | O(h) | Easy | stack, good basic, bfs, dfs, linkedin, microsoft, amazon, fb, google, tree, apple, uber, bloomberg, top100liked |
AGAIN************* (7) |
| 0150 | Evaluate Reverse Polish Notation | Python, Java | O(n) | O(n) | Medium | stack, good trick, amazon, google, fb, apple, microsoft, uber, linkedin, neetcode150 |
AGAIN********* (5) |
| 0155 | Min Stack | Python, Java | O(1) per op | O(n) | Medium | stack, basic, data structure, amazon, google, fb, apple, microsoft, uber, linkedin, bloomberg, neetcode150, top100liked |
OK (but again)*********** (7) |
| 0173 | Binary Search Tree Iterator | Python, Java | ctor: O(h), next: O(1) amortized, hasNext: O(1) | O(h) | Medium | stack, good basic, tree, microsoft, linkedin, google, amazon, fb, apple, uber, bloomberg |
OK***** (5) |
| 0224 | Basic Calculator | Python, Java | O(n) | O(n) | Hard | stack, basic, trick, LC 227, 772, amazon, google, fb, apple, microsoft, uber |
AGAIN******* (3) |
| 0227 | Basic Calculator II | Python, Java | O(n) | O(n) | Medium | stack, delay op, LC 224, 772, good trick, airbnb, fb, amazon, google, apple, microsoft, uber |
AGAIN************** (8) (MUST) |
| 0232 | Implement Queue using Stacks | Python, Java | O(1), amortized | O(n) | Easy | stack, stack-queue, EPI, LintCode, amazon, google, fb, apple, microsoft, uber, bloomberg, neetcode250 |
AGAIN*** (3)(MUST) |
| 0255 | Verify Preorder Sequence in Binary Search Tree | Python, Java | O(n) | O(n) | Medium | stack, 🔒, uber |
AGAIN (not start) |
| 0321 | Create Maximum Number | Java | O(k^2 * (m + n)) | O(m + n) | Hard | stack, dp, greedy, mono-stack, google, amazon, apple |
AGAIN (not start) (2) |
| 0331 | Verify Preorder Serialization of a Binary Tree | Python, Java | O(n) | O(1) | Medium | stack, slot counting (no stack needed), preorder serialization, good trick, google |
AGAIN (not start) |
| 0341 | Flatten Nested List Iterator | Python, Java | O(n) | O(n) | Medium | stack, LC 284, 🔒 Iterator, generator, good basic, amazon, fb***, google, fb, apple, microsoft, uber, linkedin |
AGAIN********* (6) |
| 0385 | Mini Parser | Python, Java | O(n) | O(n) | Medium | stack, parse nested list, recursion, good basic, google |
AGAIN |
| 0394 | Decode String | Python, Java | O(n) | O(n) | Medium | stack, good basic!!!, pre num string, LC 224, 227, amazon, google, fb, apple, microsoft, uber, bloomberg, neetcode250, top100liked |
AGAIN******************* (10) (MUST) |
| 0439 | Ternary Expression Parser | Python, Java | O(n) | O(n) | Medium | stack, 🔒 | AGAIN (not start) |
| 0456 | 132 Pattern | Python, Java | O(n) | O(n) | Medium | stack, binary search, google, amazon, microsoft |
AGAIN (not start) |
| 0496 | Next Greater Element I | Python, Java | O(n) | O(n) | Easy | stack, good basic, mono stack, LC 739, LC 503, LC 406, google, amazon, fb, apple, microsoft, bloomberg |
OK*************** (6) (but again) |
| 0503 | Next Greater Element II | Python, Java | O(n) | O(n) | Medium | stack, good basic, LC 739, LC 503, LC 406, next_big_val_idx, google, amazon, fb, apple, microsoft, bloomberg |
AGAIN************* (7) |
| 0591 | Tag Validator | Java | O(n) | O(n) | Hard | stack, parse tags + CDATA, complex, string, google, amazon, microsoft, uber |
AGAIN (not start) |
| 0636 | Exclusive Time of Functions | Python, Java | O(n) | O(n) | Medium | stack, trick, AGAIN, uber, fb, google, amazon, apple, microsoft, linkedin |
AGAIN********** (4) |
| 0682 | Baseball Game | Python, Java | O(n) | O(n) | Easy | stack, good basic, amazon, google, neetcode250 |
OK* (3) |
| 0735 | Asteroid Collision | Python, Java | O(n) | O(n) | Medium | stack, good basic, microsoft, goldman sachs, fb, amazon, google, uber, neetcode250 |
AGAIN************** (5) |
| 0739 | Daily Temperatures | Python, Java | O(n) | O(n) | Medium | stack, LC 739, LC 503, LC 406, LC 496, LC 42, Monotonic stack, good trick, amazon, google, fb, apple, microsoft, uber, linkedin, bloomberg, neetcode150, top100liked |
AGAIN******************* (12) (MUST) |
| 0772 | Basic Calculator III | Java | O(n) | O(n) | Hard | stack, check LC 224, 227, google, amazon, fb, apple, microsoft, uber |
AGAIN (not start) |
| 0853 | Car Fleet | Python, Java | O(nlogn) | O(n) | Medium | stack, good basic, google, amazon, neetcode150 |
AGAIN********* (5) |
| 0856 | Score of Parentheses | Python, Java | O(n) | O(n) | Medium | stack, stack of scores, or count depth on each (), good trick, google, amazon, fb |
AGAIN (not start) |
| 0872 | Leaf-Similar Trees | Python, Java | O(n) | O(h) | Easy | stack, top down, bottom up dfs, good basic, tree, binary tree, google, amazon, fb |
AGAIN***** (MUST) |
| 0895 | Maximum Frequency Stack | Python, Java | push: O(1), pop: O(1) | O(n) | Hard | stack, good basic, heap, design, amazon, apple, linkedin, microsoft, twitter, google, fb, uber, neetcode250 |
AGAIN********** (1) (not start) |
| 0901 | Online Stock Span | Python, Java | O(n) | O(n) | Medium | stack, mono stack, good basic, google, amazon, fb, microsoft, neetcode250 |
AGAIN***** (2) |
| 0946 | Validate Stack Sequences | Python, Java | O(n) | O(n) | Medium | stack, simulate push/pop with one stack, good basic, google, amazon, fb, microsoft, linkedin |
AGAIN |
| 1028 | Recover a Tree From Preorder Traversal | Java | O(n) | O(n) | Hard | stack, brute force, google, string, tree, dfs, amazon, linkedin |
AGAIN (not start) |
| 1047 | Remove All Adjacent Duplicates in String | Python, Java | O(n) | O(n) | Easy | stack, good basic, LC 1209, fb, amazon, google, apple, microsoft, uber, bloomberg |
AGAIN************ (3) (MUST) |
| 1081 | Smallest Subsequence of Distinct Characters | Java | O(n) | O(n) | Medium | stack, LC 316, google, amazon |
AGAIN (1) |
| 1209 | Remove All Adjacent Duplicates in String II | Python, Java | O(n) | O(n) | Medium | stack, LC 1047, good basic, two pointers, greedy, fb, amamzon, apple, spotify, google, amazon, microsoft, bloomberg |
AGAIN***************** (4) (MUST) |
| 1544 | Make The String Great | Java | O(n) | O(n) | Easy | stack, LC 1047, remove adjacent opposite-case pairs, basic, google |
AGAIN(1) |
| 1703 | Minimum Adjacent Swaps for K Consecutive Ones | Python, Java | O(n) | O(n) | Hard | stack, heap, sliding window, amazon, array, greedy, google, microsoft |
AGAIN (not start) |
| 1896 | Minimum Cost to Change the Final Value of Expression | Python, Java | O(n) | O(n) | Hard | stack, complex, dp, dp+stack, dfs, amazon, google |
AGAIN (not start) |
| 2104 | Sum of Subarray Ranges | Python, Java | O(n) | O(n) | Medium | stack, LC 907, good basic, monotonic stack, brute force, dp, amazon |
AGAIN************ (5) |
| 2289 | Steps to Make Array Non-decreasing | Python, Java | O(n) | O(n) | Medium | stack, mono stack, mono stack + dp, good trick | AGAIN************ (2) (MUST) |
| 4045 | Count Robot Groups | Python | O(n) | O(1) | Medium | stack, car fleet (LC 853), right -> left scan, merge keeps the rightmost robot’s state, t=0 touch chains via the neighbour, LC weekly | AGAIN(1) |
Tree
| # | Title | Solution | Time | Space | Difficulty | Note | Status |
|---|---|---|---|---|---|---|---|
| 0094 | Binary Tree Inorder Traversal | Python, Java | O(n) | O(h) | Medium | tree, iteration, recursion, good basic, Morris Traversal, microsoft, fb, google, amazon, bloomberg, neetcode250, top100liked |
AGAIN********* (4) (MUST) |
| 0124 | Binary Tree Maximum Path Sum | Python, Java | O(n) | O(h) | Hard | tree, google, amazon, fb, microsoft, twitter, apple, uber, bloomberg, blind75, top100liked |
AGAIN*********** (6) (MUST) |
| 0144 | Binary Tree Preorder Traversal | Python, Java | O(n) | O(h) | Medium | tree, Morris Traversal, google, amazon, apple, uber, neetcode250 |
OK |
| 0145 | Binary Tree Postorder Traversal | Java | O(n) | O(h) | Medium | tree, Morris Traversal, google, amazon, fb, apple, neetcode250 |
OK |
| 0208 | Implement Trie (Prefix Tree) | Python, Java | insert/search/startsWith: O(l) | O(t) | Medium | tree, dict tree, LC 211, trie, amazon, fb, google, apple, microsoft, uber, bloomberg, blind75, top100liked |
AGAIN************** (7) (MUST) |
| 0211 | Design Add and Search Words Data Structure | Python, Java | add: O(l), search: O(n * l) worst | O(t) | Medium | tree, Trie, recursive, node, hashMap, do # 208 first, amazon, fb, google, apple, microsoft, uber, blind75 |
AGAIN*********** (9) (MUST) |
| 0226 | Invert Binary Tree | Python, Java | O(n) | O(h) | Easy | tree, good basic, google, amazon, fb, apple, microsoft, uber, bloomberg, blind75, top100liked |
OK******* (4) (but again) |
| 0250 | Count Univalue Subtrees | Python, Java | O(n) | O(h) | Medium | tree, LC 572, google, amazon, fb, bloomberg |
not start |
| 0297 | Serialize and Deserialize Binary Tree | Python, Java | O(n) | O(n) | Hard | tree, LC 449, BFS, DFS, Binary Tree, google, amazon, fb, apple, microsoft, uber, linkedin, bloomberg, blind75 |
again******* (4) |
| 0307 | Range Sum Query - Mutable | Python, Java | ctor: O(n), update: O(logn), query: O(logn) | O(n) | Medium | tree, LintCode, DFS, Segment Tree, BIT, check #303 Range Sum Query - Immutable, google, array, divide and conquer, design, amazon, fb |
AGAIN* (2)(not start) |
| 0427 | Construct Quad Tree | Java | O(n^2 * logn) | O(logn) | Medium | tree, Quadtrees, google, amazon, apple, microsoft, uber, neetcode250 |
again (not start) |
| 0508 | Most Frequent Subtree Sum | Python, Java | O(n) | O(n) | Medium | tree, dfs, bfs, good basic, amazon, google, apple |
OK*********** (4) (but again MUST) |
| 0536 | Construct Binary Tree from String | Python, Java | O(n) | O(h) | Medium | tree, 🔒, recursive, str->tree, check LC 606, amazon, google, fb |
AGAIN******** (6) |
| 0538 | Convert BST to Greater Tree | Python, Java | O(n) | O(h) | Medium | tree, good basic, dfs, BST, cum sum, amazon, fb, microsoft |
OK************** (6)(MUST) |
| 0543 | Diameter of Binary Tree | Python, Java | O(n) | O(h) | Easy | tree, dfs, trick, google, amazon, fb, apple, microsoft, bloomberg, neetcode150, top100liked |
AGAIN*********** (7)(MUST) |
| 0545 | Boundary of Binary Tree | Python, Java | O(n) | O(h) | Medium | tree, recursive, dfs, tree boundary, 🔒, good trick, amazon, google, fb, apple, microsoft, uber |
AGAIN********* (6) |
| 0548 | Split Array with Equal Sum | Python, Java | O(n^2) | O(n) | Medium | tree, 🔒, good trick, array, hash table, prefix sum, fb |
AGAIN*** (2) |
| 0563 | Binary Tree Tilt | Python, Java | O(n) | O(h) | Easy | tree, post-order dfs, subtree sum, good basic |
AGAIN |
| 0572 | Subtree of Another Tree | Python, Java | O(m * n) | O(h) | Easy | tree, LC 100, recursive call recursion func, good basic, dfs, bfs, amazon, fb, google, microsoft, bloomberg, blind75 |
OK************* (10) (but again) |
| 0606 | Construct String from Binary Tree | Python, Java | O(n) | O(h) | Easy | tree, good basic, tree->str, dfs, LC 536, amazon, fb |
OK************ (8) (again!) |
| 0617 | Merge Two Binary Trees | Python, Java | O(n) | O(h) | Easy | tree, dfs, bfs, good basic, amazon, google, fb, apple, microsoft, uber |
OK************* (7) (but again) |
| 0623 | Add One Row to Tree | Python, Java | O(n) | O(h) | Medium | tree, good basic, dfs, bfs, re-connect tree, microsoft |
AGAIN***************** (5)(MUST) |
| 0637 | Average of Levels in Binary Tree | Python, Java | O(n) | O(h) | Easy | tree, bfs, dfs, good basic, fb, google, amazon, microsoft |
OK*** (4) |
| 0652 | Find Duplicate Subtrees | Python, Java | O(n) | O(n) | Medium | tree, good basic, serialization, path, bfs, dfs, Hashmap, amazon, google, fb, microsoft, bloomberg |
AGAIN************** (9)(MUST) |
| 0653 | Two Sum IV - Input is a BST | Python, Java | O(n) | O(h) | Easy | tree, Two Pointers, 2 sum, bfs, dfs, amazon, fb, google, microsoft, uber |
OK******* (4) |
| 0654 | Maximum Binary Tree | Python, Java | O(n) ~ O(n^2) | O(n) | Medium | tree, LintCode, Descending Stack, good basic, google, amazon, fb, apple, microsoft |
AGAIN* (2) |
| 0655 | Print Binary Tree | Python, Java | O(n) | O(n) | Medium | tree, matrix, dfs, bfs, good basic, google, amazon, fb, uber, linkedin |
AGAIN****** (3) |
| 0662 | Maximum Width of Binary Tree | Python, Java | O(n) | O(n) | Medium | tree, tree width, bfs, dfs, trick, amazon, google, fb, apple, microsoft, bloomberg |
AGAIN************* (5)(MUST) |
| 0663 | Equal Tree Partition | Python, Java | O(n) | O(n) | Medium | tree, # LC 508, AGAIN, 🔒, Hash, dfs, trick, good trick, amazon, fb |
OK******** (8) |
| 0677 | Map Sum Pairs | Python, Java | insert: O(l), sum: O(p + t) | O(t) | Medium | tree, Trie, trick, hard, google |
AGAIN* (2) (not start) |
| 0683 | K Empty Slots | Python, Java | O(n) | O(n) | Hard | tree, BST, bucket, google, array, binary indexed tree, segment tree, amazon |
not start |
| 0684 | Redundant Connection | Python, Java | O(n) | O(n) | Medium | tree, dfs, graph, Union Find, basic, bfs, google, amazon, neetcode150 |
AGAIN****** (3) (not start) |
| 0687 | Longest Univalue Path | Python, Java | O(n) | O(h) | Medium | tree, dfs, good basic, path, google, amazon |
AGAIN********* (5) |
| 0701 | Insert into a Binary Search Tree | Python, Java, Java-followup | O(h) | O(h) | Medium | tree, good basic, BST, BFS, DFS, google, amazon, fb, microsoft, linkedin, neetcode250 |
OK***** (3) |
| 0814 | Binary Tree Pruning | Python, Java | O(n) | O(h) | Medium | tree, prune, good basic, DFS, basic, LC 1325, google, amazon, fb, apple |
AGAIN*********** (3)(MUST) |
| 0834 | Sum of Distances in Tree | Java | O(n) | O(n) | Hard | tree, DP, re-rooting pattern, google, amazon, apple |
AGAIN****** (1) (not start) |
| 0863 | All Nodes Distance K in Binary Tree | Python, Java | O(n) | O(n) | Medium | tree, LC 752, tree -> graph, radiate outward, DFS + BFS, good basic, amazon, google, fb, apple, microsoft, uber |
AGAIN**************** (5)(MUST) |
| 0865 | Smallest Subtree with all the Deepest Nodes | Python, Java | O(n) | O(h) | Medium | tree, LC 1123, LCA, dfs, basic, amazon, fb |
AGAIN***************** (6)(MUST) |
| 0889 | Construct Binary Tree from Preorder and Postorder Traversal | Python, Java | O(n) | O(h) | Medium | tree, DFS, stack, trick, recursive, google, amazon, fb, uber |
AGAIN** (2) (not start*) |
| 0897 | Increasing Order Search Tree | Python, Java | O(n) | O(h) | Easy | tree, DFS, good basic, inorder, google, amazon, fb, apple |
AGAIN** (2) |
| 0919 | Complete Binary Tree Inserter | Python, Java | ctor: O(n) insert: O(1) get_root: O(1) |
O(n) | Medium | tree, bst, google, amazon, fb, microsoft |
AGAIN** (2) |
| 0938 | Range Sum of BST | Python, Java | O(n) | O(h) | Easy | tree, DFS, check # 108 Convert Sorted Array to Binary Search Tree, google, amazon, fb, apple, microsoft |
OK* (2) |
| 0951 | Flip Equivalent Binary Trees | Python, Java | O(n) | O(h) | Medium | tree, recursion, DFS, google, amazon, fb |
AGAIN***s (3) |
| 0958 | Check Completeness of a Binary Tree | Python, Java | O(n) | O(w) | Medium | tree, BFS, DFS, basic, google, amazon, fb, microsoft |
AGAIN** (2) |
| 0965 | Univalued Binary Tree | Python, Java | O(n) | O(h) | Easy | tree, DFS, BFS, good basic, google |
AGAIN** (2) |
| 0971 | Flip Binary Tree To Match Preorder Traversal | Python, Java | O(n) | O(h) | Medium | tree, DFS, trick |
AGAIN** (2) (not start) |
| 0979 | Distribute Coins in Binary Tree | Python, Java | O(n) | O(h) | Medium | tree, DFS, trick, google, amazon, fb, microsoft |
AGAIN************ (3) (MUSTS) |
| 1032 | Stream of Characters | Java | ctor: O(t), query: O(l) | O(t) | Hard | tree, trie, node, google, amazon, fb, microsoft |
AGAIN****** (1) |
| 1157 | Online Majority Element In Subarray | Java | ctor: O(n), query: O(klogn) | O(n) | Hard | tree, google, array, binary search, design |
AGAIN (not start) |
| 1325 | Delete Leaves With a Given Value | Java, Python | O(n) | O(h) | Medium | tree, dfs, post-order, LC 450, 814, google, amazon, neetcode250 |
AGAIN********** (4)(MUST) |
| 1339 | Maximum Product of Splitted Binary Tree | Python, Java | O(n) | O(h) | Medium | tree, dfs, amazon |
AGAIN*** (1) (not start) |
| 1372 | Longest ZigZag Path in a Binary Tree | Python, Java | O(n) | O(h) | Medium | tree, dfs, bfs, post order, good trick, amazon |
AGAIN*** (1) (not start) |
| 1448 | Count Good Nodes in Binary Tree | Python, Java | O(n) | O(h) | Medium | tree, max in path, dfs, bfs, good trick, needcode, google, amazon, microsoft, neetcode150 |
AGAIN************* (3) (MUST) |
| 1522 | Diameter of N-Ary Tree | Java | O(n) | O(h) | Medium | tree, LC 543, fb, microsoft |
AGAIN (not start) |
| 1666 | Change the Root of a Binary Tree | Java | O(h) | O(h) | Medium | tree, LC 1448, good trick, google |
AGAIN (1) (not start) |
| 1740 | Find Distance in a Binary Tree | Python, Java | O(n) | O(h) | Medium | tree, LCA, node dist, DFS, good basic, google, amazon, apple |
AGAIN*************** (5)(MUST) |
| 2331 | Evaluate Boolean Binary Tree | Java | O(n) | O(h) | Easy | tree, DFS, good basic | OK (1)**** |
| 2415 | Reverse Odd Levels of Binary Tree | Java | O(n) | O(n) | Medium | tree, LC 226, dfs, bfs | AGAIN (not start) |
| 2509 | Cycle Length Queries in a Tree | Java | O(q * logn) | O(1) | Hard | tree, LC weekly | AGAIN (not start) |
| 2641 | Cousins in Binary Tree II | Java | O(n) | O(n) | Medium | tree, LC weekly, LC 993 | AGAIN (1) |
| 2707 | Extra Characters in a String | Java | O(n^2) | O(n + t) | Medium | tree, dp, Trie, neetcode250 |
AGAIN (not start) |
| 3093 | Longest Common Suffix Queries | Java | O(t + q * l) | O(t) | Hard | tree, Trie | AGAIN (not start) |
Heap
| # | Title | Solution | Time | Space | Difficulty | Note | Status |
|---|---|---|---|---|---|---|---|
| 0264 | Ugly Number II | Python, Java | O(n) | O(n) | Medium | heap, good trick, LC 263, LC 313, LintCode, DP, microsoft, google, amazon, apple |
AGAIN*********** (4) (MUST) |
| 0295 | Find Median from Data Stream | Python, Java | addNum: O(logn), findMedian: O(1) | O(n) | Hard | heap, priority queue, trick, stream, amazon, google, fb, apple, microsoft, uber, bloomberg, blind75, top100liked, netflix |
AGAIN****** (6) |
| 0313 | Super Ugly Number | Python, Java | O(n * k) | O(n + k) | Medium | heap, BST, array, math, dp, google, amazon, fb, apple |
AGAIN (not start*) |
| 0373 | Find K Pairs with Smallest Sums | Python, Java | O(k * log(min(n, m, k))) | O(min(n, m, k)) | Medium | heap, google, good basic, amazon, fb, apple, microsoft, uber, linkedin |
AGAIN******* (1) |
| 0378 | Kth Smallest Element in a Sorted Matrix | Python, Java | O(klogn) | O(k) | Medium | heap, binary search, matrix, LintCode, google, amazon, fb, apple, microsoft, uber |
AGAIN** (1) |
| 0502 | IPO | Java | O(nlogn) | O(n) | Hard | heap, PQ, amazon, uber, neetcode250 |
AGAIN (not start) |
| 0506 | Relative Ranks | Java | O(nlogn) | O(n) | Easy | heap, PQ, sort, hashmap, google |
AGAIN (not start) |
| 0703 | Kth Largest Element in a Stream | Python, Java | ctor: O(nlogk), add: O(logk) | O(k) | Easy | heap, priority queue, amazon, google, fb, apple, microsoft, neetcode150 |
AGAIN******** (5) |
| 0846 | Hand of Straights | Python, Java | O(nlogn) | O(n) | Medium | heap, LC 1296, good basic, PQ, Treemap, hashmap, google, array, greedy, apple, neetcode150 |
OK******** (3) |
| 0855 | Exam Room | Python, Java | seat: O(logn) leave: O(logn) |
O(n) | Medium | heap, treeSet, BST, Hash, trick, LC 849, google, fb, uber |
AGAIN* (3) (not start) |
| 1046 | Last Stone Weight | Python, Java | O(nlogn) | O(n) | Easy | heap, Priority Queue, google, amazon, neetcode150 |
OK |
| 1054 | Distant Barcodes | Java | O(nlogn) | O(n) | Medium | heap, PQ, LC 767, amazon |
Again (1) |
| 1130 | Minimum Cost Tree From Leaf Values | Python, Java | O(n) | O(n) | Medium | heap, LC 1167, monotonic stack (O(n)) or interval dp (O(n^3)), greedy, array, amazon |
not start |
| 1167 | Minimum Cost to Connect Sticks | Python, Java | O(nlogn) | O(n) | Medium | heap, LC 1130, good basic, amazon, google |
AGAIN***** (3) |
| 1353 | Maximum Number of Events That Can Be Attended | Python, Java | O(nlogn) | O(n) | Medium | heap, LC 252, 253, good trick, meeting room, PRIORITY QUEUE, fb, twitter, amazon, google, apple, microsoft |
AGAIN********* (4) MUST |
| 1383 | Maximum Performance of a Team | Java | O(nlogn) | O(n) | Hard | heap, PQ, amazon |
AGAIN***** (1) |
| 1405 | Longest Happy String | Python, Java | O(n) | O(1) | Medium | heap, PQ, most_freq, LC 767, amazon, microsoft, neetcode250 |
AGAIN************* (2) (MUST) |
| 1438 | Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit | Java | O(n) | O(n) | Medium | heap, PQ, treemap, dequeue, google, amazon, uber |
AGAIN (not start) |
| 1481 | Least Number of Unique Integers after K Removals | Python, Java | O(nlogn) | O(n) | Medium | heap, good trick, greedy, Counter, dict, amazon, array, fb |
AGAIN******** (3) |
| 1642 | Furthest Building You Can Reach | Python | O(nlogn) | O(n) | Medium | heap, min-heap keeps the ladders biggest climbs, pay bricks for the smallest, greedy, good trick, google, amazon, microsoft |
AGAIN(1) |
| 1647 | Minimum Deletions to Make Character Frequencies Unique | Java | O(nlogn) | O(n) | Medium | heap, greedy, PQ, good trick, hash table, string, amazon, apple, microsoft |
AGAIN***********(2) |
| 1675 | Minimize Deviation in Array | Java | O(nlogn * logM) | O(n) | Hard | heap, PQ, amazon |
AGAIN (not start) |
| 1834 | Single-Threaded CPU | Java | O(nlogn) | O(n) | Medium | heap, good trick, pq, google, fb, neetcode250 |
AGAIN***** (1) |
| 1882 | Process Tasks Using Servers | Python | O((n + m) * logn) | O(n) | Medium | heap, two heaps (free by weight / busy by free-time), wait branch clocks from free_at not j, LC 1834, google, amazon |
AGAIN(1) |
| 2406 | Divide Intervals Into Minimum Number of Groups | Python, Java | O(nlogn) | O(n) | Medium | heap, LC 253, PQ, sort, scan line, good basic | AGAIN********** (2) (MUST) |
| 2542 | Maximum Subsequence Score | Java | O(nlogn) | O(n) | Medium | heap, pq with pair, good trick, sort | AGAIN (1) |
| 2593 | Find Score of an Array After Marking All Elements | Java | O(nlogn) | O(n) | Medium | heap, good trick, pq, sort, slide window, LC weekly | AGAIN***** (1) |
| 3092 | Most Frequent IDs | Python, Java | O(nlogn) | O(n) | Medium | heap, PQ, lazy delete, hashmap, LC weekly | AGAIN********** (MUST) (1) |
Bit Manipulation
| # | Title | Solution | Time | Space | Difficulty | Note | Status |
|---|---|---|---|---|---|---|---|
| 0136 | Single Number | Python, Java | O(n) | O(1) | Easy | bit manipulation, airbnb, amazon, fb, google, apple, microsoft, uber, bloomberg, neetcode150, top100liked |
OK |
| 0137 | Single Number II | Python, Java | O(n) | O(1) | Medium | bit manipulation, LC 136, count bits mod 3 / ones-twos state machine, good trick, google, amazon, fb, apple, microsoft |
OK |
| 0190 | Reverse Bits | Python, Java | O(1) | O(1) | Easy | bit manipulation, bit, apple, google, amazon, fb, microsoft, blind75 |
AGAIN*** (2) |
| 0191 | Number of 1 Bits | Python, Java | O(1) | O(1) | Easy | bit manipulation, apple, google, amazon, fb, microsoft, blind75 |
OK* |
| 0201 | Bitwise AND of Numbers Range | Python, Java | O(1) | O(1) | Medium | bit manipulation, common binary prefix, shift right until m == n, trick, amazon, fb, neetcode250 |
AGAIN (not start) |
| 0231 | Power of Two | Python, Java | O(1) | O(1) | Easy | bit manipulation, good basic, amazon, google, apple, microsoft |
OK*** (3) |
| 0260 | Single Number III | Python, Java | O(n) | O(1) | Medium | bit manipulation, xor, ^=, ^, google, amazon, fb, apple |
AGAIN* |
| 0268 | Missing Number | Python, Java | O(n) | O(1) | Easy | bit manipulation, xor, amazon, fb, google, apple, microsoft, bloomberg, blind75 |
OK* (2) |
| 0318 | Maximum Product of Word Lengths | Python, Java | O(n^2 + n * l) | O(n) | Medium | bit manipulation, Counting Sort, Pruning, google |
AGAIN (not start) |
| 0342 | Power of Four | Python, Java | O(1) | O(1) | Easy | bit manipulation, power of num |
OK* |
| 0371 | Sum of Two Integers | Python, Java | O(1) | O(1) | Medium | bit manipulation, good basic, fb, amazon, apple, microsoft, uber, blind75 |
AGAIN********* (5) (bit op not start) |
| 0389 | Find the Difference | Python, Java | O(n) | O(1) | Easy | bit manipulation, amazon, google, fb |
OK (2) |
| 0393 | UTF-8 Validation | Python, Java | O(n) | O(1) | Medium | bit manipulation, utf-8 encoding, google, fb, amazon, apple |
AGAIN**** (not start*) (5) |
| 0401 | Binary Watch | Python, Java | O(1) | O(1) | Easy | bit manipulation, enumerate the 12 * 60 times or use bit count, brute force, basic, google, apple |
OK* |
| 0421 | Maximum XOR of Two Numbers in an Array | Python, Java | O(n) | O(n) | Medium | bit manipulation, Trie of bits or prefix hashset, greedy from the MSB, good trick, google, amazon, microsoft |
AGAIN (not start) |
| 0461 | Hamming Distance | Python, Java | O(1) | O(1) | Easy | bit manipulation, fb, google, amazon |
OK* (2) |
| 0462 | Minimum Moves to Equal Array Elements II | Python, Java | O(n) on average | O(1) | Medium | bit manipulation, median minimizes the sum of absolute diffs, quick select, sort, math, array, microsoft |
AGAIN* |
| 0477 | Total Hamming Distance | Python, Java | O(n) | O(1) | Medium | bit manipulation, fb, amazon |
AGAIN****** (not start*) (4) |
| 0645 | Set Mismatch | Python, Java | O(n) | O(1) | Easy | bit manipulation, amazon, fb |
OK* (3) |
| 0693 | Binary Number with Alternating Bits | Python, Java | O(1) | O(1) | Easy | bit manipulation, trick |
AGAIN* |
| 0762 | Prime Number of Set Bits in Binary Representation | Python, Java | O(1) | O(1) | Easy | bit manipulation, basic, prime number, amazon |
OK* (4) |
| 0868 | Binary Gap | Python, Java | O(1) | O(1) | Easy | bit manipulation, trick, linear scan |
AGAIN* |
| 0898 | Bitwise ORs of Subarrays | Python, Java | O(n * logM) | O(logM) | Medium | bit manipulation, set of distinct ORs per index (at most logM), good trick, amazon |
AGAIN (not start) |
| 1573 | Number of Ways to Split a String | Python, Java | O(n) | O(1) | Medium | bit manipulation, amazon, binary, math, string |
AGAIN** (not start) |
| 1915 | Number of Wonderful Substrings | Python, Java | O(n) | O(1) | Medium | bit manipulation, bit mask, bit, prefix sum, dp, amazon, google |
AGAIN*** (2) (not start) |
| 2683 | Neighboring Bitwise XOR | Java | O(n) | O(1) | Medium | bit manipulation, bit op, simulation LC weekly 345 | AGAIN*** (1) |
| 2871 | Split Array Into Maximum Number of Subarrays | Java | O(n) | O(1) | Medium | bit manipulation, bit op, LC weekly | AGAIN*** (1) |
| 3688 | Bitwise OR of Even Numbers in an Array | Java | O(n) | O(1) | Easy | bit manipulation, bit mask | OK |
String
| # | Title | Solution | Time | Space | Difficulty | Note | Status |
|---|---|---|---|---|---|---|---|
| 0005 | Longest Palindromic Substring | Python, Java | O(n^2) | O(1) | Medium | string, LC 647, good trick, 2 pointer, recursive, Manacher's Algorithm, LC 100 like, DP, uber, amazon, fb, google, apple, microsoft, bloomberg, blind75, top100liked |
AGAIN******************* (8)(MUST) |
| 0006 | ZigZag Conversion | Python, Java | O(n) | O(n) | Medium | string, simulate the rows, basic, trick, google, amazon, fb, apple, microsoft, uber |
AGAIN (not start) |
| 0008 | String to Integer (atoi) | Python, Java | O(n) | O(1) | Medium | string, string op, regular expression, uber, amazon, fb, google, apple, microsoft, linkedin, bloomberg |
AGAIN***** (5) |
| 0014 | Longest Common Prefix | Python, Java | O(n * k) | O(1) | Easy | string, good basic, LCP, prefix, binary search, scan, google, amazon, fb, apple, microsoft, uber, bloomberg, neetcode250 |
AGAIN !!! (5) |
| 0028 | Implement strStr() | Python, Java | O(n + k) | O(k) | Easy | string, KMP Algorithm, fb, google, amazon, apple, microsoft, uber, bloomberg |
OK (3) |
| 0028 | Find the Index of the First Occurrence in a String | Java | O(n + k) | O(k) | Easy | string, duplicate of LC 28, KMP Algorithm, Rabin-Karp Algorithm, two pointers, google, amazon, fb, apple, microsoft, uber, bloomberg |
OK (3) |
| 0038 | Count and Say | Python, Java | O(n * 2^n) | O(2^n) | Medium | string, recursion, iteration, basic, fb, google, amazon, apple, microsoft |
AGAIN*********** (5) |
| 0043 | Multiply Strings | Python, Java | O(m * n) | O(m + n) | Medium | string, twitter, fb, google, amazon, apple, microsoft, uber, neetcode150 |
AGAIN*** (3) |
| 0058 | Length of Last Word | Python, Java | O(n) | O(1) | Easy | string, scan from the end, basic, google, amazon, fb, microsoft |
OK |
| 0067 | Add Binary | Python, Java | O(n) | O(1) | Easy | string, bit op, good basic, fb, amazon, google, apple, microsoft, uber, neetcode250 |
OK***** (7) (but again) |
| 0076 | Minimum Window Substring | Python, Java | O(m + n) | O(k) | Hard | string, slide window, good pattern, google, amazon, fb, apple, microsoft, uber, linkedin, bloomberg, blind75, top100liked |
AGAIN*********** (3) |
| 0125 | Valid Palindrome | Python, Java | O(n) | O(1) | Easy | string, LC 680, amazon, fb, google, apple, microsoft, linkedin, bloomberg, blind75 |
OK |
| 0151 | Reverse Words in a String | Python, Java | O(n) | O(1) | Medium | string, amazon, fb, google, apple, microsoft, uber |
OK (2) |
| 0161 | One Edit Distance | Python, Java | O(m + n) | O(1) | Medium | string, 🔒, DP, 2 pointers, fb, google, amazon, apple, microsoft, uber |
AGAIN ************ (6)(MUST) |
| 0165 | Compare Version Numbers | Python, Java | O(n) | O(1) | Medium | string, good basic, amazon, apple, google, microsoft |
OK** (5) |
| 0186 | Reverse Words in a String II | Python, Java | O(n) | O(1) | Medium | string, LC 151, LC 557, 🔒, microsoft, uber, amazon, fb |
AGAIN* (3) |
| 0242 | Valid Anagram | Python, Java | O(n) | O(1) | Easy | string, LintCode, amazon, fb, google, apple, microsoft, uber, bloomberg, blind75 |
OK |
| 0271 | Encode and Decode Strings | Python, Java | O(n) | O(1) | Medium | string, decode-encode, string op, check # 394 Decode String, 🔒, google, fb, apple, microsoft, uber, blind75 |
AGAIN******* (4) |
| 0306 | Addictive Number | Python, Java | O(n^3) | O(n) | Medium | string, backtracking over the first two numbers, big-int add, dfs, LC 842, google |
AGAIN (not start*) |
| 0340 | Longest Substring with At Most K Distinct Characters | Python, Java | O(n) | O(k) | Hard | string, sliding window, google, amazon, fb, microsoft, uber, bloomberg |
not start |
| 0383 | Ransom Note | Python, Java | O(n) | O(1) | Easy | string, EPI, apple, google, amazon, fb, microsoft |
OK* |
| 0405 | Convert a Number to Hexadecimal | Python, Java | O(n) | O(1) | Easy | string, basics decimal -> Hexadecimal, google, amazon, fb |
AGAIN |
| 0408 | Valid Word Abbreviation | Python, Java | O(n) | O(1) | Easy | string, 🔒, google, fb |
AGAIN (not start) |
| 0415 | Add Strings | Python, Java | O(n) | O(1) | Easy | string, good basic, add xxx to sum, airbnb, google, fb, amazon, apple, microsoft, uber, bloomberg |
OK****** (4) |
| 0434 | Number of Segments in a String | Python, Java | O(n) | O(1) | Easy | string, count word starts, split, basic, apple |
OK |
| 0443 | String Compression | Python, Java | O(n) | O(1) | Easy | string, shoptify, basics, google, amazon, fb, apple, microsoft, bloomberg |
AGAIN** |
| 0459 | Repeated Substring Pattern | Python, Java | O(n) | O(n) | Easy | string, good basic, KMP Algorithm, amazon, google, fb, microsoft |
OK*** (6) |
| 0468 | Validate IP Address | Python, Java | O(1) | O(1) | Medium | string, ip basic, twitter, fb, amazon, google, microsoft |
AGAIN****** (5) |
| 0482 | License Key Formatting | Python, Java | O(n) | O(1) | Easy | string, basic, google, amazon |
OK** (4) (again) |
| 0520 | Detect Capital | Python, Java | O(l) | O(1) | Easy | string, three valid cases (all upper / all lower / leading capital), basic, google, amazon |
OK |
| 0521 | Longest Uncommon Subsequence I | Python, Java | O(min(a, b)) | O(1) | Easy | string, if the two strings differ the answer is max(len), trick, google |
OK* |
| 0522 | Longest Uncommon Subsequence II | Python, Java | O(l * n^2) | O(1) | Medium | string, sort, compare all pairs, LC 521, google, apple |
AGAIN (not start) |
| 0524 | Longest Word in Dictionary through Deleting | Python, Java | O(d * l + d * logd) | O(1) | Medium | string, good basic, sort, 2 pointers, subsequence check, google |
AGAIN*********** (2) |
| 0539 | Minimum Time Difference | Python, Java | O(nlogn) | O(n) | Medium | string, basic, map & zip trick, google, apple |
AGAIN** |
| 0541 | Reverse String II | Python, Java | O(n) | O(1) | Easy | string, reverse every 2k block, basic, google, amazon, apple, microsoft |
AGAIN**** (1) |
| 0551 | Student Attendance Record I | Python, Java | O(n) | O(1) | Easy | string, count A and 3 consecutive L, basic, google |
OK** |
| 0556 | Next Greater Element III | Python, Java | O(n) | O(n) | Medium | string, LC 31 next permutation applied to digits, good trick, amazon, fb, apple, microsoft |
AGAIN (not start) |
| 0557 | Reverse Words in a String III | Python, Java | O(n) | O(1) | Easy | string, split, reverse each word, basic, google, amazon, apple, microsoft |
OK |
| 0616 | Add Bold Tag in String | Python, Java | O(n * d * l) | O(n) | Medium | string, LC 758, 🔒, google, fb |
AGAIN (not start) |
| 0647 | Palindromic Substrings | Python, Java | O(n^2) | O(1) | Medium | string, LC 005, greedy, 2D DP, expand from center, 2 pointers, good basic, Manacher's Algorithm, linkedin, amazon, fb, google, apple, microsoft, uber, blind75 |
OK************** (10) (MUST) |
| 0648 | Replace Words | Python, Java | O(n) | O(t) | Medium | string, Trie, hashset, good basic, amazon, fb, uber |
AGAIN (2)******* |
| 0657 | Judge Route Circle | Python, Java | O(n) | O(1) | Easy | string, count moves per direction, LC 1041, basic, google, amazon |
OK |
| 0678 | Valid Parenthesis String | Python, Java | O(n) | O(1) | Medium | string, greedy, dp, stack, good trick, google, amazon, fb, apple, microsoft, uber, neetcode150 |
AGAIN********** (3) (MUST) |
| 0680 | Valid Palindrome II | Python, Java | O(n) | O(1) | Easy | string, LC 125, two pointers, good basic, Palindrome, fb, google, amazon, apple, microsoft, neetcode250 |
AGAIN************* (4) (MUST) |
| 0681 | Next Closest Time | Python, Java | O(1) | O(1) | Medium | string, subset of set, <=, strptime, google, fb, amazon, uber |
OK*** (5) |
| 0686 | Repeated String Match | Python, Java | O(n + m) | O(1) | Medium | string, brute force, math, Rabin-Karp Algorithm, google, amazon, fb |
AGAIN**** (3) |
| 0696 | Count Binary Substrings | Python, Java | O(n) | O(1) | Easy | string, good trick, linear scan, group sub-string, amazon, google |
AGAIN******* (3) (MUST) |
| 0720 | Longest Word in Dictionary | Python, Java | O(n * l) | O(t) | Medium | string, Trie, DFS, good trick, google, amazon, fb |
AGAIN**** (1) |
| 0722 | Remove Comments | Python, Java | O(n) | O(k) | Medium | string, google, amazon, fb, apple, microsoft, uber |
AGAIN (1) |
| 0734 | Sentence Similarity | Python , Java | O(n + p) | O(p) | Easy | string, good basic, graph, hash table, collections.defaultdict(set), google, fb |
OK***** (5) |
| 0751 | IP to CIDR | Python, Java | O(n) | O(1) | Medium | string, 🔒, bit manipulation, largest CIDR block that fits, ip, google |
AGAIN (not start*) |
| 0758 | Bold Words in String | Python, Java | O(n * l) | O(t) | Easy | string, 🔒, LC 616, variant of Add Bold Tag in String, google |
AGAIN (not start) |
| 0791 | Custom Sort String | Python, Java | O(n) | O(1) | Medium | string, good basic, sort, counter, amazon, fb, google, uber |
AGAIN************ (7) (MUST) |
| 0796 | Rotate String | Python, Java | O(n) | O(1) | Easy | string, good basic, KMP Algorithm, Rabin-Karp Algorithm, amazon, google, apple, microsoft, linkedin |
OK**** (2)(but again) |
| 0804 | Unique Morse Code Words | Python, Java | O(n) | O(n) | Easy | string, map letters to morse, hashset of transformations, basic, google, apple, microsoft |
OK* |
| 0806 | Number of Lines To Write String | Python, Java | O(n) | O(1) | Easy | string, greedy line filling, basic, google |
OK* |
| 0809 | Expressive Words | Python, Java | O(n + s) | O(l + s) | Medium | string, 2 pointers, group len, good basic, google, amazon, fb |
AGAIN****** (2) |
| 0816 | Ambiguous Coordinates | Python, Java | O(n^4) | O(n) | Medium | string, trick, google |
AGAIN**** (1) |
| 0819 | Most Common Word | Python, Java | O(m + n) | O(m + n) | Easy | string, regular expression, amazon, google, microsoft |
OK** (2) |
| 0820 | Short Encoding of Words | Python, Java | O(n) | O(t) | Medium | string, Trie, amazon |
AGAIN (not start) |
| 0824 | Goat Latin | Python, Java | O(n + w^2) | O(l) | Easy | string, string basic, fb, google |
OK |
| 0828 | Count Unique Characters of All Substrings of a Given String | Python, Java | O(n) | O(1) | Hard | string, LC 1248, count each char’s contribution (prev/next same char), dp, amazon, google |
AGAIN*** (2) |
| 0831 | Masking Personal Information | Python, Java | O(1) | O(1) | Medium | string, regular expression |
OK* |
| 0833 | Find And Replace in String | Python, Java | O(n + m) | O(n) | Medium | string, good basic, string op, hashmap, google, amazon, fb, microsoft, linkedin |
AGAIN****** (3) |
| 0848 | Shifting Letters | Python, Java | O(n) | O(1) | Medium | string, remainder, basic, amazon, fb |
AGAIN** |
| 0859 | Buddy Strings | Python, Java | O(n) | O(1) | Easy | string, compare differing positions, duplicate-char check, trick, google, fb |
AGAIN* |
| 0880 | Decoded String at Index | Python, Java | O(n) | O(1) | Medium | string, trick, amazon |
AGAIN (not start**) |
| 0884 | Uncommon Words from Two Sentences | Python, Java | O(m + n) | O(m + n) | Easy | string, collections Counter, trick, google, amazon, fb, microsoft |
OK* |
| 0890 | Find and Replace Pattern | Python, Java | O(n * l) | O(1) | Medium | string, hashmap, pattern, LC 49, google, amazon, apple |
AGAIN *** (3) |
| 0893 | Groups of Special-Equivalent Strings | Python, Java | O(n * l) | O(n) | Easy | string, sort even- and odd-indexed chars separately, hashset, trick, fb |
AGAIN* |
| 0916 | Word Subsets | Python, Java | O(m + n) | O(1) | Medium | string, max char count across all words in b, Counter, good trick, google, amazon, fb |
AGAIN (not start) |
| 0917 | Reverse Only Letters | Python, Java | O(n) | O(1) | Easy | string, good basic, stack, pointer, google, amazon, apple, microsoft |
AGAIN**** (1) |
| 0925 | Long Pressed Name | Python, Java | O(n) | O(1) | Easy | string, two pointer, basic, trick, google |
AGAIN* |
| 0929 | Unique Email Addresses | Python, Java | O(n * l) | O(n * l) | Easy | string, normalize local part (drop dots, cut at +), hashset, basic, google, amazon |
OK |
| 0939 | Minimum Area Rectangle | Python, Java | O(n^2) | O(n) | Medium | string, hashmap, brute force, google, array, math, amazon, fb, apple, microsoft |
AGAIN !!! (2) |
| 0942 | DI String Match | Python, Java | O(n) | O(1) | Easy | string, good basic, 2 pointers, google, amazon, microsoft, uber |
AGAIN*** (1) |
| 0944 | Delete Columns to Make Sorted | Python, Java | O(n * l) | O(1) | Easy | string, count columns that are not sorted, basic, google |
AGAIN (not start) |
| 0953 | Verifying an Alien Dictionary | Python, Java | O(n * l) | O(1) | Easy | string, map chars to the alien order then compare adjacent words, good basic, amazon, fb, apple, microsoft, uber, neetcode250 |
AGAIN********** (3) (MUST) |
| 0955 | Delete Columns to Make Sorted II | Python, Java | O(n * l) | O(n) | Medium | string, LC 944, greedy column keeping, good trick, google |
AGAIN (not start) |
| 1119 | Remove Vowels from a String | Python, Java | O(n) | O(n) | Easy | string, amazon |
OK |
| 4006 | Count Valid Prefixes | Python, Java | O(n) | O(1) | Easy | string, prefix, good basic, LC weekly | OK |
| 4043 | Count Rotations With Exactly K Equal Adjacent Pairs | Python | O(n) | O(1) | Easy | string, cyclic pairs, a rotation only cuts ONE pair so score is C or C-1, brute force O(n^2) as V0, LC weekly | AGAIN(1) |
Queue
| # | Title | Solution | Time | Space | Difficulty | Note | Status |
|---|---|---|---|---|---|---|---|
| 0239 | Sliding Window Maximum | Python, Java | O(n) | O(k) | Hard | queue, sliding window, heap, deque, good trick, amazon, google, fb, apple, microsoft, uber, bloomberg, neetcode150, top100liked |
AGAIN************ (6) |
| 0281 | Zigzag Iterator | Python, Java | O(n) | O(k) | Medium | queue, good basic, 🔒, google, fb, amazon, apple |
AGAIN******* (5) |
| 0346 | Moving Average from Data Stream | Python, Java | O(1) | O(w) | Easy | queue, 🔒, google, fb, amazon, apple, microsoft, uber, bloomberg |
OK** (6) |
| 0622 | Design Circular Queue | Python, Java | O(1) per op | O(k) | Medium | queue, good basic, array, linked list, design, circular queue, amazon, fb, apple, airbnb, microsoft, google, neetcode250 |
AGAIN************ (3) (MUST) |
| 0933 | Number of Recent Calls | Python, Java | O(1) on average | O(w) | Easy | queue, deque, drop pings older than t - 3000, basic, google |
AGAIN** |
Math
| # | Title | Solution | Time | Space | Difficulty | Note | Status |
|---|---|---|---|---|---|---|---|
| 0007 | Reverse Integer | Python, Java | O(1) | O(1) | Medium | math, 0x7FFFFFFF, amazon, apple, google, fb, microsoft, uber, bloomberg, neetcode150 |
OK* (3) |
| 0009 | Palindrome Number | Python, Java | O(1) | O(1) | Easy | math, amazon, google, fb, apple, microsoft, bloomberg |
OK |
| 0012 | Integer to Roman | Python, Java | O(1) | O(1) | Medium | math, math basic, twitter, fb, amazon, google, apple, microsoft, uber, linkedin, bloomberg |
AGAIN****** (4) |
| 0013 | Roman to Integer | Python, Java | O(n) | O(1) | Easy | math, good trick, map, uber, amazon, fb, google, apple, microsoft, linkedin, neetcode250 |
AGAIN***** (6) |
| 0029 | Divide Two Integers | Python, Java | O(logn) | O(1) | Medium | math, binary search, trick, fb, google, amazon, apple, microsoft, uber |
AGAIN***** (3) |
| 0050 | Pow(x, n) | Python, Java | O(logn) | O(logn) | Medium | math, good trick, amazon, fb, recursion, google, apple, microsoft, uber, linkedin, bloomberg, neetcode150 |
AGAIN****** (4) |
| 0060 | Permutation Sequence | Python, Java | O(n^2) | O(n) | Medium | math, Cantor Ordering, trick, amazon, google, fb, apple, microsoft |
AGAIN*** (2) |
| 0089 | Gray Code | Python, Java | O(2^n) | O(1) | Medium | math, bit op, amazon, google, microsoft |
AGAIN ********** (6) |
| 0149 | Max Points on a Line | Java | O(n^2) | O(n) | Hard | math, hashmap, google, amazon, apple, microsoft, uber, linkedin |
AGAIN(1) |
| 0166 | Fraction to Recurring Decimal | Python, Java | O(n) | O(n) | Medium | math, hashmap remainder -> index to detect the repeating cycle, good trick, google, amazon, fb, apple, uber |
AGAIN (not start) |
| 0168 | Excel Sheet Column Title | Python, Java | O(logn) | O(1) | Easy | math, trick, residual, AGAIN, fb, google, amazon, apple, microsoft, uber, neetcode250 |
AGAIN****** (5) |
| 0171 | Excel Sheet Column Number | Python, Java | O(n) | O(1) | Easy | math, base-26 accumulation, LC 168, basic, google, amazon, fb, apple, microsoft, uber |
AGAIN (not start) |
| 0172 | Factorial Trailing Zeroes | Python, Java | O(logn) | O(1) | Easy | math, basic, iteration, recursion, amazon, fb, microsoft, bloomberg |
AGAIN* (2) |
| 0223 | Rectangle Area | Python, Java | O(1) | O(1) | Easy | math, area sum minus the overlap, basic, amazon, fb, apple, microsoft |
AGAIN |
| 0258 | Add Digits | Python, Java | O(1) | O(1) | Easy | math, digital root: 1 + (n - 1) % 9, trick, google, amazon, apple, microsoft |
AGAIN |
| 0263 | Ugly Number | Python, Java | O(1) | O(1) | Easy | math, divide out 2, 3, 5, LC 264, basic, amazon, apple |
OK* (2) |
| 0273 | Integer to English Words | Python, Java | O(logn) | O(1) | Hard | math, amazon, passed, google, fb, apple, microsoft, uber, linkedin, bloomberg |
not start |
| 0292 | Nim Game | Python, Java | O(1) | O(1) | Easy | math, LintCode, google |
OK* |
| 0319 | Bulb Switcher | Python, Java | O(1) | O(1) | Medium | math, answer is floor(sqrt(n)) - only perfect squares have an odd divisor count, good trick, fb, apple, microsoft |
AGAIN |
| 0326 | Power of Three | Python, Java | O(1) | O(1) | Easy | math, loop divide by 3, or 3^19 % n == 0, LC 231, LC 342, basic, google, apple |
OK |
| 0338 | Counting Bits | Python, Java | O(n) | O(n) | Medium | math, dp, bit manipulation, dp[i] = dp[i >> 1] + (i & 1), good basic, google, amazon, fb, apple, uber, blind75 |
OK |
| 0343 | Integer Break | Python, Java | O(n^2) | O(n) | Medium | math, max product, split into 3s, trick, DP, google, amazon, fb, apple, neetcode250 |
AGAIN********** (3)(MUST) |
| 0365 | Water and Jug Problem | Python, Java | O(logn) | O(1) | Medium | math, Bézout's identity, google, microsoft, uber |
AGAIN (not start) |
| 0372 | Super Pow | Python, Java | O(n) | O(1) | Medium | math, modular fast power over the digit array | AGAIN |
| 0382 | Linked List Random Node | Python, Java | ctor: O(1), getRandom: O(n) | O(1) | Medium | math, Reservoir Sampling, google, amazon, fb |
AGAIN (not start) |
| 0386 | Lexicographical Numbers | Python, Java | O(n) | O(1) excluding output | Medium | math, pre-order DFS over the 10-ary number trie, iterative, good trick, google, amazon, microsoft, bloomberg |
AGAIN (not start) |
| 0390 | Elimination Game | Python, Java | O(logn) | O(1) | Medium | math, track head / step / remaining count, good trick, amazon, bloomberg |
AGAIN (not start) |
| 0398 | Random Pick Index | Python, Java | ctor: O(1), pick: O(n) | O(1) | Medium | math, Reservoir Sampling, hashmap of value -> indices, fb, google, amazon, microsoft |
OK* (4) |
| 0400 | Nth Digit | Python, Java | O(logn) | O(1) | Easy | math, count digits per length band then locate the number, google, amazon, fb |
AGAIN |
| 0413 | Arithmetic Slices | Python, Java | O(n) | O(1) | Medium | math, dp, count consecutive runs with the same diff, good basic, amazon, array, sliding window, fb |
OK*** (1) (but again) |
| 0423 | Reconstruct Original Digits from English | Python, Java | O(n) | O(1) | Medium | math, GCJ2016 - Round 1B | AGAIN (not start) |
| 0441 | Arranging Coins | Python, Java | O(logn) | O(1) | Easy | math, Binary Search on the row count, or the quadratic formula, amazon, apple |
OK |
| 0453 | Minimum Moves to Equal Array Elements | Python, Java | O(n) | O(1) | Easy | math, incrementing n-1 elements equals decrementing 1, sum - n * min, trick, amazon, apple |
AGAIN |
| 0458 | Poor Pigs | Python, Java | O(logn) | O(1) | Hard | math, information theory, (tests + 1) ^ pigs >= buckets, good trick |
AGAIN |
| 0469 | Convex Polygon | Python, Java | O(n) | O(1) | Medium | math, 🔒, cross-product sign must stay consistent, geometry, google |
AGAIN (not start) |
| 0470 | Implement Rand10() Using Rand7() | Python, Java | O(1) | O(1) | Medium | math, rejection sampling, LC 478, good trick, google, apple, microsoft, uber |
AGAIN (not start) |
| 0478 | Generate Random Point in a Circle | Python, Java | O(1) | O(1) | Medium | math, rejection sampling or inverse transform with sqrt, geometry, fb |
AGAIN (not start) |
| 0497 | Random Point in Non-overlapping Rectangles | Python, Java | ctor: O(n) pick: O(logn) |
O(n) | Medium | math, prefix sum of rectangle areas + binary search, good trick, google |
AGAIN (not start) |
| 0504 | Base 7 | Python, Java | O(logn) | O(logn) | Easy | math, base conversion, good basic, recursion, google |
AGAIN******** (1) |
| 0517 | Super Washing Machines | Python, Java | O(n) | O(1) | Hard | math, max of (max deficit, max single surplus), greedy, amazon, array, microsoft |
AGAIN (not start) |
| 0519 | Random Flip Matrix | Python, Java | ctor: O(1) pick: O(1) reset: O(n) |
O(n) | Medium | math, hashmap-based virtual Fisher-Yates swap, good trick, google |
AGAIN (not start) |
| 0528 | Random Pick with Weight | Python, Java | O(logn) | O(n) | Medium | math, good basic, binary search, prefix sum, google, amazon, fb, apple, microsoft, uber, linkedin |
AGAIN**** (1) |
| 0537 | Complex Number Multiplication | Python, Java | O(1) | O(1) | Medium | math, amazon |
OK (3) |
| 0553 | Optimal Division | Python, Java | O(n) | O(1) | Medium | math, string, amazon |
OK* (4) |
| 0573 | Squirrel Simulation | Python, Java | O(n) | O(1) | Medium | math, 🔒 | AGAIN (not start) |
| 0592 | Fraction Addition and Subtraction | Python, Java | O(nlogx) | O(n) | Medium | math, parse signed fractions, reduce with gcd / lcm | AGAIN |
| 0593 | Valid Square | Python, Java | O(1) | O(1) | Medium | math, google, fb |
AGAIN |
| 0598 | Range Addition II | Python, Java | O(p) | O(1) | Easy | math, answer is min(all a) * min(all b), trick, amazon |
AGAIN |
| 0625 | Minimum Factorization | Python, Java | O(loga) | O(1) | Medium | math, 🔒 | OK* |
| 0628 | Maximum Product of Three Numbers | Python, Java | O(n) | O(1) | Easy | math, amazon, google, fb, apple, microsoft, uber |
OK (2) |
| 0633 | Sum of Square Numbers | Python, Java | O(sqrt© * logc) | O(1) | Easy | math, two pointers from 0 to sqrt©, or test each a, basic, apple, linkedin |
OK* |
| 0634 | Find the Derangement of An Array | Python, Java | O(n) | O(1) | Medium | math, 🔒, amazon |
AGAIN (not start) |
| 0640 | Solve the Equation | Python, Java | O(n) | O(n) | Medium | math, regular expression, amazon, google, fb |
AGAIN*** (3) |
| 0651 | 4 Keys Keyboard | Python, Java | O(n) | O(n) | Medium | math, 🔒, DP, google, amazon, microsoft |
AGAIN (not start) |
| 0672 | Bulb Switcher II | Python, Java | O(1) | O(1) | Medium | math, only 6 distinct states after the first 3 lights, trick, microsoft |
AGAIN (not start) |
| 0728 | Self Dividing Numbers | Python, Java | O(n) | O(1) | Easy | math, check that each digit divides the number, basic |
AGAIN |
| 0754 | Reach a Number | Python, Java | O(logn) | O(1) | Medium | math, walk to the first triangular number >= target then fix parity, good trick, google, amazon |
OK* |
| 0775 | Global and Local Inversions | Python, Java | O(n) | O(1) | Medium | math, trick, string, amazon, google |
AGAIN** (not start) (3) |
| 0779 | K-th Symbol in Grammar | Python, Java | O(1) | O(1) | Medium | math, brute force, binary, recursion, fb, amazon, google, apple |
AGAIN*** (1) |
| 0781 | Rabbits in Forest | Python, Java | O(n) | O(n) | Medium | math, group rabbits by their answer, ceil division, good trick |
AGAIN (not start) |
| 0789 | Escape The Ghosts | Python, Java | O(n) | O(1) | Medium | math, compare Manhattan distances, trick, google |
AGAIN |
| 0800 | Similar RGB Color | Python, Java | O(1) | O(1) | Easy | math, 🔒, google |
AGAIN (not start) |
| 0812 | Largest Triangle Area | Python, Java | O(n^3) | O(1) | Easy | math, shoelace formula over all triples, geometry, google |
AGAIN (not start) |
| 0829 | Consecutive Numbers Sum | Python, Java | O(sqrt(n)) | O(1) | Medium | math, count factorizations n = k * m + k(k - 1) / 2, good trick, google, amazon, uber |
AGAIN |
| 0836 | Rectangle Overlap | Python, Java | O(1) | O(1) | Easy | math, similar as 223. Rectangle Area, amazon, google, fb, apple, microsoft, uber, bloomberg |
AGAIN (2) |
| 0858 | Mirror Reflection | Python, Java | O(1) | O(1) | Medium | math, LCM / parity reasoning, good trick, google, fb |
AGAIN (not start) |
| 0866 | Prime Palindrome | Python, Java | O(n^(1/2) * (logn + n^(1/2))) | O(logn) | Medium | math, generate palindromes then test primality, even-length ones divide by 11, amazon |
AGAIN*** |
| 0867 | Transpose Matrix | Java | O(m * n) | O(m * n) | Medium | math, duplicate of LC 868, matrix, basic, array, simulation, amazon, apple, neetcode250 |
AGAIN* |
| 0883 | Projection Area of 3D Shapes | Python, Java | O(n^2) | O(1) | Easy | math, xy = count of non-zero cells, yz = column max, zx = row max, matrix |
AGAIN |
| 0891 | Sum of Subsequence Widths | Python, Java | O(nlogn) | O(1) | Hard | math, sort, each element contributes as max/min weighted by powers of 2, amazon |
AGAIN (not start) |
| 0907 | Sum of Subarray Minimums | Python, Java | O(n) | O(n) | Medium | math, trick, LC 084, LC 2104, Ascending Stack, amazon, array, dp, google, uber |
AGAIN**** (1) |
| 0908 | Smallest Range I | Python, Java | O(n) | O(1) | Easy | math, max(0, max - min - 2k), basic |
OK* (2) |
| 0910 | Smallest Range II | Python, Java | O(nlogn) | O(1) | Medium | math, sort then try every split point, greedy, good trick, apple |
AGAIN (not start) |
| 0914 | X of a Kind in a Deck of Cards | Python, Java | O(nlogn) | O(n) | Easy | math, gcd of all group counts must be >= 2, Counter, google |
AGAIN (not start) |
| 0963 | Minimum Area Rectangle II | Python, Java | O(n^2) | O(n) | Medium | math, hashmap keyed by (center, diagonal length), geometry, google, amazon, fb |
AGAIN (not start) |
| 0970 | Powerful Integers | Python, Java | O((logn)^2) | O® | Easy | math, basic, amazon |
AGAIN* (2) |
| 1015 | Smallest Integer Divisible by K | Java | O(k) | O(1) | Medium | math, track remainder of 1, 11, 111 … mod k, pigeonhole, google, apple |
AGAIN (not start) |
| 1071 | Greatest Common Divisor of Strings | Java | O(m + n) | O(1) | Easy | math, if s1 + s2 == s2 + s1 the answer is the prefix of length gcd(m, n), good trick, amazon, neetcode250 |
AGAIN (not start) |
| 1342 | Number of Steps to Reduce a Number to Zero | Python, Java | O(logn) | O(1) | Easy | math, gra*, google, amazon, apple, microsoft |
ok |
| 1492 | The kth Factor of n | Python, Java | O(sqrt(n)) | O(1) | Medium | math, amazon |
AGAIN (not start) |
| 1979 | Find Greatest Common Divisor of Array | Python, Java | O(n + log(min)) | O(1) | Easy | math, GCD | not start |
| 2013 | Detect Squares | Java | add: O(1), count: O(n) | O(n) | Medium | math, hashmap of point counts, iterate the diagonal point, array, design, google, neetcode150 |
not start |
| 2028 | Find Missing Observations | Python | O(n + m) | O(n) | Medium | math, distribute the missing sum evenly: feasible iff n <= need <= 6 * n, divmod, LC weekly |
AGAIN (1) |
| 2029 | Stone Game IX | Python | O(n) | O(1) | Medium | math, game theory on counts mod 3, parity of c0 picks the rule, good trick, LC weekly |
AGAIN (1) |
| 2507 | Smallest Value After Replacing With Sum of Prime Factors | Java | O(logn * sqrt(n)) | O(1) | Medium | math, LC weekly | again (1) |
| 2614 | Prime In Diagonal | Java | O(n * sqrt(M)) | O(1) | Easy | math, diagonal matrix, good basic, LC weekly | again**** (1) |
| 2807 | Insert Greatest Common Divisors in Linked List | Java | O(n * log(maxV)) | O(1) | Medium | math, walk the list and insert gcd nodes, linked list, basic, neetcode250 |
OK |
| 2961 | Double Modular Exponentiation | Java | O(q * logE) | O(1) | Medium | math, weekly375 | AGAIN (1) |
| 3091 | Apply Operations to Make Sum of Array Greater Than or Equal to k | Java | O(1) | O(1) | Medium | math, LC weekly | AGAIN (1) |
| 3190 | Find Minimum Operations to Make All Elements Divisible by Three | Java | O(n) | O(1) | Easy | math, LC weekly | OK |
| 3194 | Minimum Average of Smallest and Largest Elements | Java | O(nlogn) | O(1) | Easy | math, LC weekly, array, two pointers, sort |
OK |
| 3993 | Maximum Value of an Alternating Sequence | Python, Java | O(1) | O(1) | Medium | math, LC weekly, good trick | again**** (1) |
Scan Line
| # | Title | Solution | Time | Space | Difficulty | Note | Status |
|---|---|---|---|---|---|---|---|
| 1943 | Describe the Painting | Java | O(nlogn) | O(n) | Medium | scan line, treeMap, delta, good basic, google, array, hash table, sort |
AGAIN***** (1)(MUST) |
Sort
| # | Title | Solution | Time | Space | Difficulty | Note | Status |
|---|---|---|---|---|---|---|---|
| 0075 | Sort Colors | Python, Java | O(n) | O(1) | Medium | sort, Tri Partition, two pointers, microsoft, fb, google, amazon, apple, uber, bloomberg, neetcode250, top100liked |
OK** (4) |
| 0088 | Merge Sorted Array | Python, Java | O(m + n) | O(1) | Easy | sort, good basic, merge, two pointers, microsoft, amazon, fb, google, apple, uber, linkedin, bloomberg, neetcode250 |
AGAIN************* (8) (MUST) |
| 0128 | Longest Consecutive Sequence | Python, Java | O(n) | O(n) | Medium | sort, 2 pointers, sliding window, O(N), amazon, array, hash table, union find, google, fb, apple, microsoft, uber, linkedin, bloomberg, blind75, top100liked |
AGAIN*************** (7) (MUST) |
| 0147 | Insertion Sort List | Python, Java | O(n^2) | O(1) | Medium | sort, trick, amazon, apple, microsoft |
AGAIN* (2) |
| 0148 | Sort List | Python, Java | O(nlogn) | O(logn) | Medium | sort, basic, check # 21 Merge Two Sorted Lists, google, amazon, fb, apple, microsoft, uber, top100liked |
AGAIN** (2) |
| 0164 | Maximum Gap | Java | O(n) | O(n) | Medium | sort, bucket sort / radix sort, pigeonhole on the gap, google, amazon, fb, apple, microsoft |
OK |
| 0179 | Largest Number | Python, Java | O(nlogn) | O(n) | Medium | sort, good basic, sort with lambda, amazon, google, fb, apple, microsoft, uber |
AGAIN************ (3) |
| 0252 | Meeting Rooms | Python, Java | O(nlogn) | O(n) | Easy | sort, LC 554, uber, amazon, fb, google, microsoft, bloomberg, blind75 |
OK*** (4) (but again) |
| 0253 | Meeting Rooms II | Python, Java | O(nlogn) | O(n) | Medium | sort, LC 2406, priority queue (min-heap), scanning line, trick, booking.com, good, uber, amazon, google, fb, apple, microsoft, bloomberg, blind75 |
AGAIN************ (5) (MUST) |
| 0274 | H-Index | Python, Java | O(n) | O(n) | Medium | sort, Counting Sort, good trick, fb, google, amazon, apple, bloomberg |
AGAIN***** (3) |
| 0280 | Wiggle Sort | Python, Java | O(n) | O(1) | Medium | sort, 🔒, google, fb, amazon, microsoft |
OK*** (3) |
| 0324 | Wiggle Sort II | Python, Java | O(n) on average | O(1) | Medium | sort, variant of Sort Colors, Tri Partition, google, amazon, fb |
AGAIN** (2) |
| 0327 | Count of Range Sum | Java | O(nlogn) | O(n) | Hard | sort, merge sort with counting, BIT, segment tree, array, binary search, divide and conquer, google, amazon |
AGAIN (not start) |
| 0347 | Top K Frequent Elements | Python, Java | O(n) | O(n) | Medium | sort, HashMap, Heap, yelp, amazon, fb, GOOD basic, google, apple, microsoft, uber, linkedin, bloomberg, blind75, top100liked |
AGAIN******** (4) |
| 0406 | Queue Reconstruction by Height | Python, Java | O(n^2) | O(n) | Medium | sort, basic, trick, sort by key, insert, google, next_big_val, amazon, fb, apple, microsoft, bloomberg |
AGAIN********* (5) |
| 0451 | Sort Characters By Frequency | Python, Java | O(nlogn) | O(n) | Medium | sort, collections.Counter(s).most_common, sorted(count_dict.items() with lambda, good basic, amazon, google, fb, apple, microsoft, uber, linkedin, bloomberg |
OK* (4) |
| 0493 | Reverse Pairs | Java | O(nlogn) | O(n) | Hard | sort, merge sort with counting, or BIT, good trick, array, binary search, divide and conquer, google, amazon, fb, microsoft, uber |
AGAIN (not start) |
| 0692 | Top K Frequent Words | Python, Java | O(n + klogk) on average | O(n) | Medium | sort, good basic, Quick Select, Heap, Bucket Sort, heapq, yelp, uber, amazon, fb, google, apple, microsoft, linkedin, bloomberg |
OK***** (5) |
| 0912 | Sort an Array | Python, Java | O(nlogn) | O(n) | Medium | sort, merge sort, quick sort, apple, amazon, microsoft, neetcode250 |
AGAIN** (1) |
| 0937 | Reorder Data in Log Files | Python, Java | O(nlogn * l) | O(n * l) | Medium | sort, good basic, string, amazon, google, apple |
OK**** (3)(again!!!) |
| 0969 | Pancake Sorting | Python, Java | O(n^2) | O(1) | Medium | sort, fb, google, amazon, apple, microsoft, uber |
AGAIN********** (4) |
| 0973 | K Closest Points to Origin | Python, Java | O(n) on average | O(1) | Medium | sort, good trick, sort with func, PQ, Heap, amazon, google, fb, apple, microsoft, uber, linkedin, neetcode150 |
OK***** (3)(but again) |
| 0976 | Largest Perimeter Triangle | Python, Java | O(nlogn) | O(1) | Easy | sort, sort descending then take the first valid triple, greedy, basic |
OK* (2) |
| 1057 | Campus Bike | Java | O(m * nlog(m * n)) | O(m * n) | Medium | sort, sort all (dist, worker, bike) triples or bucket by distance, google, amazon |
AGAIN |
| 1066 | Campus Bike II | Java | O(m * 2^n) | O(2^n) | Medium | sort, bitmask dp over bikes, min cost assignment, google, array, backtracking, amazon |
AGAIN |
| 1152 | Analyze User Website Visit Pattern | Python, Java | O(nlogn + u * m^3) | O(n + u * m^3) | Medium | sort, itertools.combinations, brute force, set, amazon |
AGAIN***** (2) (not start) |
| 1329 | Sort the Matrix Diagonally | Java | O(m * nlog(min(m, n))) | O(m * n) | Medium | sort, group cells by (i - j), sort each diagonal, PQ, hashMap, google, amazon, fb, microsoft |
AGAIN (not start) |
| 1877 | Minimize Maximum Pair Sum in Array | Java | O(nlogn) | O(1) | Medium | sort, good basic, google |
AGAIN*** (1) |
| 2021 | Brightest Position on Street | Python, Java | O(nlogn) | O(n) | Medium | sort, LC 253 meeting room II, PQ, prefix, diff array, scanning line, trick, amazon |
AGAIN*********** (3) (MUST) |
| 2284 | Sender With Largest Word Count | Java | O(n) | O(n) | Medium | sort, LC 347, hashmap, sort by (count, name), good basic, array, string |
OK |
| 2345 | Finding the Number of Visible Mountains | Java | O(nlogn) | O(n) | Medium | sort, monotonic stack, hashmap, interval cover | AGAIN (not start) |
| 2402 | Meeting Rooms III | Java | O(nlogn) | O(n) | Hard | sort, LC 253, two heaps (free rooms / busy rooms), sort by start, good trick, neetcode250 |
AGAIN (not start) |
| 2659 | Make Array Empty | Java | O(nlogn) | O(n) | Hard | sort, BIT / sorted index scan, good trick, weekly_103 |
AGAIN (not start) |
Two Pointers
| # | Title | Solution | Time | Space | Difficulty | Note | Status |
|---|---|---|---|---|---|---|---|
| 0019 | Remove Nth Node From End of List | Python, Java | O(n) | O(1) | Medium | two pointers, good basic, MUST, linked list, fb, google, amazon, apple, microsoft, uber, blind75, top100liked |
AGAIN********** (4) (MUST) |
| 0042 | Trapping Rain Water | Python, Java | O(n) | O(1) | Hard | two pointers, stack, prefix-suffix array, brute force, amazon, apple, google, fb, microsoft, uber, bloomberg, neetcode150, top100liked |
AGAIN******** (3) |
| 0086 | Partition List | Python, Java | O(n) | O(1) | Medium | two pointers, two dummy heads then splice, linked list, good basic, amazon, fb, apple, microsoft |
OK* |
| 0141 | Linked List Cycle | Python, Java | O(n) | O(1) | Easy | two pointers, basic, amazon, fb, linked list, check #142, google, apple, microsoft, linkedin, bloomberg, blind75, top100liked |
OK** (5) |
| 0142 | Linked List Cycle II | Python, Java | O(n) | O(1) | Medium | two pointers, linked list, check #141, google, amazon, fb, apple, microsoft, linkedin, top100liked |
AGAIN****** (4) (again!) |
| 0143 | Reorder List | Python, Java | O(n) | O(1) | Medium | two pointers, LC 021, 206, 876, good trick, inverse linkedlist, merge linkedlist, fb, amazon, google, apple, microsoft, uber, blind75 |
AGAIN************** (6) (MUST) |
| 0167 | Two Sum II - Input array is sorted | Python, Java | O(n) | O(1) | Medium | two pointers, dict, binary search, good basic, amazon, google, fb, apple, microsoft, neetcode150 |
OK* (6) |
| 0214 | Shortest Palindrome | Java | O(n) | O(n) | Hard | two pointers, KMP failure function on s + ‘#’ + reverse(s), good trick, string, rolling hash, google, amazon, fb, apple, microsoft |
AGAIN (not start) |
| 0259 | 3Sum Smaller | Python, Java | O(n^2) | O(1) | Medium | two pointers, 🔒, LintCode, good trick, google, fb, check #015 3 Sum, check #001 two sum |
AGAIN******** (4) |
| 0283 | Move Zeroes | Python, Java | O(n) | O(1) | Easy | two pointers, basic, trick, shopee, fb, google, amazon, apple, microsoft, uber, bloomberg, top100liked |
AGAIN********* (6) |
| 0344 | Reverse String | Python, Java | O(n) | O(1) | Easy | two pointers, swap from both ends in place, basic, google, amazon, fb, apple, microsoft, uber, linkedin, bloomberg, neetcode250 |
OK |
| 0345 | Reverse Vowels of a String | Python, Java | O(n) | O(1) | Easy | two pointers, google, amazon, fb, apple |
OK** (1) |
| 0349 | Intersection of Two Arrays | Python, Java | O(m + n) | O(min(m, n)) | Easy | two pointers, EPI, Hash, Binary Search, fb, google, amazon, apple, microsoft, linkedin |
OK |
| 0350 | Intersection of Two Arrays II | Python, Java | O(m + n) | O(1) | Easy | two pointers, EPI, Hash, Binary Search, good basic, fb, google, amazon, apple, microsoft, uber, linkedin |
OK** (3) |
| 0360 | Sort Transformed Array | Python, Java | O(n) | O(1) | Medium | two pointers, trick, 🔒, google, fb |
AGAIN*** (3) |
| 0457 | Circular Array Loop | Python, Java | O(n) | O(1) | Medium | two pointers, fast/slow pointers per start, same-direction check, good trick, google, amazon, apple, microsoft |
AGAIN (not start) |
| 0567 | Permutation in String | Python, Java | O(n) | O(1) | Medium | two pointers, sliding window, counter, hashmap, good basic, microsoft, fb, google, amazon, apple, uber, neetcode150 |
AGAIN********* (8)(MUST) |
| 0611 | Valid Triangle Number | Python, Java | O(n^2) | O(1) | Medium | two pointers, sort then two pointers, count valid triples, good trick, amazon, apple, microsoft, uber, linkedin, bloomberg |
AGAIN (not start) |
| 0777 | Swap Adjacent in LR String | Python, Java | O(n) | O(1) | Medium | two pointers, L only moves left, R only moves right, relative order preserved, good trick, google |
AGAIN (not start) |
| 0826 | Most Profit Assigning Work | Python, Java | O(mlogm + nlogn) | O(n) | Medium | two pointers, trick, good basic, zip+sorted, google, amazon, uber |
OK* |
| 0844 | Backspace String Compare | Python, Java | O(m + n) | O(1) | Easy | two pointers, good basic, stack, google, fb, amazon, apple, microsoft, uber |
OK* (4) |
| 0876 | Middle of the Linked List | Python, Java | O(n) | O(1) | Easy | two pointers, basic, amazon, apple, google, linkedlist, fb, microsoft |
OK* (2) |
| 0904 | Fruit Into Baskets | Python, Java | O(n) | O(1) | Medium | two pointers, slide window, google, array, hash table, amazon, apple |
AGAIN*** (1) |
| 0930 | Binary Subarrays With Sum | Python, Java | O(n) | O(1) | Medium | two pointers, trick, array, hash table, sliding window |
AGAIN* (2) (not start) |
| 0977 | Squares of a Sorted Array | Python, Java | O(n) | O(1) | Easy | two pointers, two pointers from both ends, LC 88, basic, google, amazon, fb, apple, microsoft, uber |
OK |
| 0986 | Interval List Intersections | Python, Java | O(n) | O(1) | Medium | two pointers, scanning line, good basic, google, amazon, fb, apple, uber |
AGAIN********* (1) (MUST) |
| 1023 | Camelcase Matching | Java | O(n) | O(1) | Medium | two pointers, dp, good basic, google, amazon |
AGAIN****** (1) |
| 1055 | Shortest Way to Form String | Python, Java | O(n * m) | O(1) | Medium | two pointers, google, fb |
again |
| 1147 | Longest Chunked Palindrome Decomposition | Java | O(n) | O(1) | Hard | two pointers, rolling hash, google |
again (not start) |
| 1151 | Minimum Swaps to Group All 1’s Together | Python, Java | O(n) | O(1) | Medium | two pointers, good basic, Deque (Double-ended Queue), amazon, array, sliding window |
AGAIN***** (not start ) |
| 1229 | Meeting Scheduler | Java | O(n) | O(1) | Medium | two pointers, sort amazon, google, amazon, apple, microsoft |
AGAIN***** (not start ) |
| 1498 | Number of Subsequences That Satisfy the Given Sum Condition | Python | O(nlogn) | O(n) | Medium | two pointers, sort (only min + max matter), 2^(r - l) per left end, precomputed powers, good trick, google, amazon, fb |
AGAIN(1) |
| 1768 | Merge Strings Alternately | Java | O(m + n) | O(m + n) | Easy | two pointers, merge two strings alternately then append the rest, basic, google, uber, neetcode250 |
OK |
| 1963 | Minimum Number of Swaps to Make the String Balanced | Python, Java | O(n) | O(1) | Medium | two pointers, good basic, greedy, stack, amazon, fb, microsoft |
AGAIN******** (2) |
| 3191 | Minimum Operations to Make Binary Array Elements Equal to One I | Java | O(n) | O(1) | Medium | two pointers, greedy flip a window of 3, sliding window, LC 995, good basic, array, bit manipulation, queue |
Again* (2) |
| 3192 | Minimum Operations to Make Binary Array Elements Equal to One II | Java | O(n) | O(1) | Medium | two pointers, LC 3191, greedy prefix flip with a running parity counter, good trick, array, dp |
Again* (2) |
Recursion
| # | Title | Solution | Time | Space | Difficulty | Note | Status |
|---|---|---|---|---|---|---|---|
| 0010 | Regular Expression Matching | Python, Java | O(m * n) | O(m * n) | Hard | recursion, dp, amazon, google, fb, apple, microsoft, uber, bloomberg, neetcode150 |
AGAIN (not start) |
| 0095 | Unique Binary Search Trees II | Python, Java | O(4^n / n^(3/2)) | O(4^n / n^(3/2)) | Medium | recursion, DP, # BSTs = combinations of left × right, amazon, google, apple, backtracking, tree, fb, microsoft |
AGAIN***************** (1)(MUST) |
| 0098 | Validate Binary Search Tree | Python, Java | O(n) | O(h) | Medium | recursion, bfs, dfs, BST, microsoft, amazon, fb, google, apple, linkedin, bloomberg, blind75, top100liked |
AGAIN****************** (11) |
| 0100 | Same Tree | Python, Java | O(n) | O(h) | Easy | recursion, dfs, bfs, good basic, amazon, tree, google, fb, apple, microsoft, linkedin, bloomberg, blind75 |
OK****** (5) (but again) |
| 0104 | Maximum Depth of Binary Tree | Python, Java | O(n) | O(h) | Easy | recursion, DFS, BFS, good basic, amazon, top down, bottom up, LC 111, tree, google, fb, apple, microsoft, uber, linkedin, bloomberg, blind75, top100liked |
AGAIN************ (5)(MUST) |
| 0105 | Construct Binary Tree from Preorder and Inorder Traversal | Python, Java | O(n) | O(n) | Medium | recursion, trick, check # 106, BST, microsoft, fb, google, amazon, apple, uber, bloomberg, blind75, top100liked |
AGAIN********* (9) |
| 0106 | Construct Binary Tree from Inorder and Postorder Traversal | Python, Java | O(n) | O(n) | Medium | recursion, trick, check # 105, BST, microsoft, fb, google, amazon |
AGAIN******* (6) |
| 0108 | Convert Sorted Array to Binary Search Tree | Python, Java | O(n) | O(logn) | Easy | recursion, good basic, BST, build tree from sorted array, DFS, LC 109, google, amazon, fb, apple, microsoft, bloomberg, top100liked |
AGAIN************* (2) (MUST) |
| 0109 | Convert Sorted List to Binary Search Tree | Python, Java | O(n) | O(logn) | Medium | recursion, list, BST, good concept, fb, google, amazon, microsoft, bloomberg |
AGAIN*** (3) |
| 0110 | Balanced Binary Tree | Python, Java | O(n) | O(h) | Easy | recursion, good trick, LC 104, dfs, bfs, amazon, fb, google, top-down, bottom-up recursion, tree, binary tree, apple, microsoft, bloomberg, neetcode150 |
AGAIN************** (8)(MUST) |
| 0111 | Minimum Depth of Binary Tree | Python, Java | O(n) | O(h) | Easy | recursion, good basic, dfs, BST, amazon, fb, LC 104, bfs, google, apple, microsoft |
AGAIN******** (5) |
| 0114 | Flatten Binary Tree to Linked List | Python, Java | O(n) | O(h) | Medium | recursion, good trick, Reverse Preorder DFS, dfs, microsoft, fb, linked list, stack, tree, google, amazon, apple, uber, bloomberg, top100liked |
AGAIN*************** (6)(MUST) |
| 0116 | Populating Next Right Pointers in Each Node | Python, Java | O(n) | O(1) | Medium | recursion, good basic, bfs, dfs, tree, AGAIN, fb, amazon, linked list, google, apple, microsoft, bloomberg |
AGAIN************ (6) |
| 0117 | Populating Next Right Pointers in Each Node II | Python, Java | O(n) | O(h) | Medium | recursion, good basic, prev node, Populating Next Right Pointers in Each Node I, bfs, linked list, amazon, fb, google, tree, dfs, microsoft, bloomberg |
AGAIN************* (4) |
| 0129 | Sum Root to Leaf Numbers | Python, Java | O(n) | O(h) | Medium | recursion, path sum, dfs, good basic, fb, tree, binary tree, google, amazon, apple, microsoft |
AGAIN******* (5) |
| 0156 | Binary Tree Upside Down | Python, Java | O(n) | O(1) | Medium | recursion, 🔒, tree, dfs, binary tree, linkedin |
AGAIN (not start) |
| 0241 | Different Ways to Add Parentheses | Python, Java | O(n * 4^n / n^(3/2)) | O(n * 4^n / n^(3/2)) | Medium | recursion, complex, dp, Memoization, google, amazon, fb, microsoft |
AGAIN (not start) |
| 0298 | Binary Tree Longest Consecutive Sequence | Python, Java | O(n) | O(h) | Medium | recursion, LC 437, good basic, prev node, bfs, dfs, tree, 🔒, google, binary tree, amazon, fb, uber |
AGAIN *************** (6) (MUST) |
| 0333 | Largest BST Subtree | Python, Java | O(n) | O(h) | Medium | recursion, 🔒, dfs, post-order, return (isBST, min, max, size), LC 98, dp, tree, google, amazon, fb, apple, microsoft |
AGAIN (not start) |
| 0337 | House Robber III | Python, Java | O(n) | O(h) | Medium | recursion, good trick, dp + dfs, tree DP, rob/not-rob state, LC 198, amazon, google, fb, microsoft, uber, neetcode250 |
AGAIN********** (3)(MUST) |
| 0395 | Longest Substring with At Least K Repeating Characters | Python, Java | O(26 * n) | O(1) | Medium | recursion, slide window, DIVIDE AND CONQUER, good trick, fb, google, amazon, apple, microsoft, uber |
AGAIN************ (4) |
| 0404 | Sum of Left Leaves | Python, Java | O(n) | O(h) | Easy | recursion, tree, bfs, dfs, amazon, google, fb, apple |
AGAIN**** (4) |
| 0437 | Path Sum III | Python, Java | O(n) | O(h) | Medium | recursion, LC 298, prefix sum, hashmap, dfs, path sum, good trick, uber, amazon, fb, tree, binary tree, google, apple,top100liked |
AGAIN*********** (5) (MUST) |
| 0501 | Find Mode in Binary Search Tree | Java | O(n) | O(h) | Medium | recursion, dfs, bfs, LC 98, tree, bst, google, amazon |
OK (1) |
| 0544 | Output Contest Matches | Python, Java | O(nlogn) | O(n) | Medium | recursion, 🔒, recursively pair first with last, string build, good trick, google |
AGAIN |
| 0549 | Binary Tree Longest Consecutive Sequence II | Python, Java | O(n) | O(h) | Medium | recursion, 🔒, tree, dfs, binary tree, google, amazon, fb, apple |
AGAIN (not start) |
| 0669 | Trim a Binary Search Tree | Python, Java | O(n) | O(h) | Medium | recursion, good basic, BST trim, dfs, amazon, google, fb, apple, microsoft, bloomberg |
AGAIN*********** (6)(MUST) |
| 0671 | Second Minimum Node In a Binary Tree | Python, Java | O(n) | O(h) | Easy | recursion, dfs, tree, binary tree, google, microsoft, uber, linkedin |
OK* (2) |
| 0753 | Cracking the Safes | Java | O(k^n * n) | O(k^n * n) | Hard | recursion, de Bruijn sequence, Hierholzer / dfs over states, google, string, graph, apple |
AGAIN (not start) |
| 1145 | Binary Tree Coloring Game | Java | O(n) | O(h) | Medium | recursion, tree, color, google, dfs, binary tree |
AGAIN***** (2) |
Binary Search
| # | Title | Solution | Time | Space | Difficulty | Note | Status |
|---|---|---|---|---|---|---|---|
| 0033 | Search in Rotated Sorted Array | Python, Java | O(logn) | O(1) | Medium | binary search, LC 153, 852, good basic, check # 81 Search in Rotated Sorted Array II, rotation array, uber, amazon, fb, google, apple, microsoft, linkedin, bloomberg, blind75, top100liked |
AGAIN************ (6) (MUST) |
| 0034 | Find First and Last Position of Element in Sorted Array | Python, Java | O(logn) | O(1) | Medium | binary search, amazon, fb, google, apple, uber, microsoft, linkedin, bloomberg, top100liked |
AGAIN************** (4) (MUST) |
| 0034 | Search for a Range | Python, Java | O(logn) | O(1) | Medium | binary search, duplicate of LC 34, lower bound + upper bound binary search, google, amazon, fb, apple, microsoft, uber, linkedin, bloomberg, top100liked |
AGAIN* |
| 0035 | Search Insert Position | Python, Java | O(logn) | O(1) | Medium | binary search, LC 436, binary search on left, good basic, google, amazon, fb, apple, bloomberg, neetcode250, top100liked |
AGAIN************ (2) (MUST) |
| 0069 | Sqrt(x) | Python, Java | O(logn) | O(1) | Medium | binary search, math, amazon, fb, google, apple, microsoft, uber, linkedin, bloomberg, neetcode250 |
OK* (4) |
| 0074 | Search a 2D Matrix | Python, Java | O(logm + logn) | O(1) | Medium | binary search, binary search in 2D array, flatten matrix, amazon, google, fb, apple, microsoft, uber, neetcode150, top100liked |
OK**** (BUT AGAIN)(3) |
| 0081 | Search in Rotated Sorted Array II | Python, Java | O(logn) | O(1) | Medium | binary search, check # 33 Search in Rotated Sorted Array first, array, fb, amazon, linkedin, google, apple, microsoft, bloomberg, neetcode250 |
OK***** (6) |
| 0153 | Find Minimum in Rotated Sorted Array | Python, Java | O(logn) | O(1) | Medium | binary search, LC 33, ascending array, good basic, amazon, google, fb, apple, microsoft, uber, linkedin, blind75, top100liked |
AGAIN**************** (10)(MUST) |
| 0154 | Find Minimum in Rotated Sorted Array II | Java | O(logn) | O(1) | Medium | binary search, LC 153, google, amazon, fb, microsoft, uber |
AGAIN (not start) |
| 0162 | Find Peak Element | Python, Java | O(logn) | O(1) | Medium | binary search, good trick, recursive, iterative binary search, microsoft, google, fb, amazon, apple, uber, bloomberg |
AGAIN********** (6) |
| 0222 | Count Complete Tree Nodes | Python, Java | O((logn)^2) | O(logn) | Easy | binary search, google, tree, amazon, fb, microsoft |
OK (again) |
| 0275 | H-Index II | Python, Java | O(logn) | O(1) | Medium | binary search, similar as # 274 H-Index, fb, google |
AGAIN**** (3) |
| 0278 | First Bad Version | Python, Java | O(logn) | O(1) | Easy | binary search, good basic, LintCode, fb, google, amazon, apple, microsoft, uber |
OK*** (5) (MUST) |
| 0300 | Longest Increasing Subsequence | Python, Java | O(nlogn) | O(n) | Medium | binary search, Patience Sorting, DP good basic, LintCode, 1D DP, LIS, amazon, fb, google, apple, microsoft, uber, blind75, top100liked |
AGAIN******************* (13) (MUST) |
| 0315 | Count of Smaller Numbers After Self | Python, Java | O(nlogn) | O(n) | Hard | binary search, BST, BIT, google, amazon, fb, apple, microsoft, uber |
again* |
| 0367 | Valid Perfect Square | Python, Java | O(logn) | O(1) | Easy | binary search, good basic, similar as # 69 Sqrt(x), google, amazon, fb, microsoft, linkedin |
OK* (3) |
| 0374 | Guess Number Higher or Lower | Python, Java | O(logn) | O(1) | Easy | binary search, classic binary search on the guess API, good basic, google, amazon, apple, neetcode250 |
OK* |
| 0410 | Split Array Largest Sum | Python, Java | O(nlog(sum)) | O(1) | Hard | binary search, google, LC 1231, 1552, amazon, fb, apple, uber, neetcode250 |
AGAIN (not start) |
| 0436 | Find Right Interval | Python, Java | O(nlogn) | O(n) | Medium | lower bound / binary search, LC 35, good basic, google, amazon |
AGAIN********** (3) (MUST) |
| 0475 | Heaters | Python, Java | O((m + n) * logn) | O(1) | Easy | binary search, sort houses and heaters, binary search the nearest heater, two pointers, google |
AGAIN (not start) |
| 0540 | Single Element in a Sorted Array | Python, Java | O(logn) | O(1) | Medium | binary search, binary search on even indices, pair-XOR check, good trick, google, amazon, fb, apple, microsoft |
OK* |
| 0564 | Find the Closest Palindrome | Java | O(n) | O(n) | Hard | binary search, n = number of digits, build 5 palindrome candidates around the prefix, google, math, string, amazon, fb, apple, microsoft |
AGAIN(not start) |
| 0658 | Find K Closest Elements | Python, Java | O(logn + k) | O(1) | Medium | binary search, good trick, PQ, binary search find window start point, amazon, fb, google, apple, microsoft, uber, bloomberg, neetcode250 |
AGAIN ********************** (9) (MUST) |
| 0704 | Binary Search | Python | O(logn) | O(1) | Easy | binary search, the closed-interval template, while l <= r, basic, google, amazon, fb, apple, microsoft, uber, neetcode150, neetcode250 |
AGAIN(1) |
| 0744 | Find Smallest Letter Greater Than Target | Python, Java | O(logn) | O(1) | Easy | binary search, upper bound binary search with wraparound, basic, amazon, linkedin |
OK* |
| 0774 | Minimize Max Distance to Gas Station | Python, Java | O(nlog(maxD / eps)) | O(1) | Hard | binary search, binary search on a real-valued answer, PQ, google |
AGAIN***** (1) |
| 0852 | Peak Index in a Mountain Array | Python, Java | O(logn) | O(1) | Medium | binary search, LC 162, LC 33, amazon, google, fb, apple, microsoft, uber |
AGAIN****** (2) |
| 0875 | Koko Eating Bananas | Python, Java | O(nlogr) | O(1) | Medium | binary search, left boundary, good basic, google, amazon, fb, apple, neetcode150 |
AGAIN******* (4)(MUST) |
| 0894 | All Possible Full Binary Trees | Python, Java | O(n * 4^n / n^(3/2)) | O(n * 4^n / n^(3/2)) | Medium | binary search, dfs + memoization, Catalan number, only odd n has a full binary tree, dp, recursion, google, amazon, apple |
AGAIN (not start) |
| 0911 | Online Election | Python, Java | ctor: O(n) query : O(logn) |
O(n) | Medium | binary search, prefix leader array + binary search on the query time, good basic, google, apple |
AGAIN (not start) |
| 0981 | Time Based Key-Value Store | Python, Java | set: O(1), get: O(logn) | O(n) | Medium | binary search, dict, treeMap, floorKey, sort, apple, microsoft, amazon, google, fb, uber, neetcode150 |
AGAIN****** (2) |
| 1011 | Capacity To Ship Packages Within D Days | Python, Java | O(nlog(sum)) | O(1) | Medium | binary search, good trick, amazon, apple, fb, microsoft, google, uber, neetcode250 |
AGAIN****** (3) |
| 1060 | Missing Element in Sorted Array | Java | O(logn) | O(1) | Medium | binary search, brute force, good trick, google, amazon, fb, apple, bloomberg |
AGAIN**** (2) |
| 1095 | Find in Mountain Array | Java | O(logn) | O(1) | Hard | binary search, LC 852 find the peak then binary search each side, MountainArray API, good trick, google, amazon, apple, neetcode250 |
AGAIN (not start)s |
| 1150 | Check If a Number Is Majority Element in a Sorted Array | Java | O(logn) | O(1) | Easy | binary search, lower + upper bound, count occurrences, fb |
AGAIN**** (1) |
| 1231 | Divide Chocolate | Java | O(nlog(sum)) | O(1) | Hard | binary search, google, LC 2616, Maximize Minimum, LC 410, amazon, fb |
AGAIN***** (not start) |
| 1283 | Find the Smallest Divisor Given a Threshold | Java | O(nlog(max)) | O(1) | Medium | binary search, binary search on the divisor, LC 875, good basic, google, amazon, uber |
AGAIN***** (not start) |
| 1292 | Maximum Side Length of a Square with Sum Less than or Equal to Threshold | Python, Java | O(m * nlog(min(m, n))) | O(m * n) | Medium | binary search, 2D prefix-sum, good trick, google, amazon |
AGAIN******* (2) |
| 1482 | Minimum Number of Days to Make m Bouquets | Java | O(nlog(max)) | O(1) | Medium | binary search, binary search on the day, greedily count adjacent runs, good basic, google |
AGAIN (not start) |
| 1552 | Magnetic Force Between Two Balls | Java | O(nlogn + nlog(max)) | O(1) | Medium | binary search, LC 410, can distribute, google, amazon, uber |
AGAIN (1) |
| 1760 | Minimum Limit of Balls in a Bag | Java | O(nlog(max)) | O(1) | Medium | binary search, binary search on the penalty, ceil(count / limit) - 1 operations, good trick |
AGAIN (1) |
| 1889 | Minimum Space Wasted From Packaging | Python, Java | O((m + n) * logn) | O(n) | Hard | binary search, heap, prefix sum, amazon |
AGAIN (not start) |
| 1891 | Cutting Ribbons | Java | O(nlog(max)) | O(1) | Medium | binary search, 🔒, binary search on the ribbon length, good basic, google, fb, uber |
AGAIN (not start) |
| 2009 | Minimum Number of Operations to Make Array Continuous | Python, Java | O(nlogn) | O(n) | Hard | binary search, sliding window, dequeue, bisect.bisect_right, amazon, uber |
AGAIN (not start) |
| 2554 | Maximum Number of Integers to Choose From a Range I | Java | O(n) | O(n) | Medium | binary search, hash set of banned values, greedily take the smallest, weekly 97 | AGAIN (not start) |
| 2594 | Minimum Time to Repair Cars | Java | O(nlog(maxT)) | O(1) | Medium | binary search, PQ, trick, weekly 100 | AGAIN***** (1) |
| 2616 | Minimize the Maximum Difference of Pairs | Java | O(nlogn + nlog(max)) | O(1) | Medium | binary search, LC weekly, good trick, Minimize the Maximum, LC 1231 | AGAIN******* (1) |
| 4008 | Minimum Initial Strength to Defeat All Monsters | Python, Java | O(n + m + nlog(sum)) | O(n) | Medium | binary search, LC weekly, good trick | AGAIN* (1) |
Binary Search Tree
| # | Title | Solution | Time | Space | Difficulty | Note | Status |
|---|---|---|---|---|---|---|---|
| 0099 | Recover Binary Search Tree | Python, Java | O(n) | O(h) | Medium | BST, good trick, BST swap, DFS, inorder, Morris traversal, google, amazon, fb, apple, microsoft, uber |
AGAIN******************** (5)(MUST) |
| 0220 | Contains Duplicate III | Python, Java | O(nlogk) | O(k) | Medium | BST, LC 219, sliding window with TreeSet or bucketing, good trick, array, sort, google, amazon, fb, apple, microsoft |
AGAIN (not start) |
| 0230 | Kth Smallest Element in a BST | Python, Java | O(max(h, k)) | O(min(h, k)) | Medium | BST, good basic BST basic, DFS, BFS, STACK, amazon, google, fb, apple, microsoft, uber, bloomberg, blind75, top100liked |
OK********* (4) |
| 0235 | Lowest Common Ancestor of a Binary Search Tree | Python, Java | O(h) | O(1) | Medium | BST, recursion, iteration, good basic, LCA, check # 236 Lowest Common Ancestor of a Binary Tree, amazon, fb, google, apple, microsoft, uber, linkedin, blind75 |
OK**************** (but again)(10) |
| 0270 | Closest Binary Search Tree Value | Python, Java | O(h) | O(1) | Easy | BST, good basic, 🔒, microsoft, google, fb, amazon, linkedin, bloomberg |
OK***** (5) |
| 0272 | Closest Binary Search Tree Value II | Java | O(h + k) | O(h + k) | Hard | BST, google, amazon, fb, closest val, binary search, linkedin |
AGAIN (1) |
| 0285 | Inorder Successor in BST | Python, Java | O(h) | O(1) | Medium | BST, dfs, good basic, 🔒, amazon, fb, google, microsoft |
OK** (4) |
| 0426 | Convert Binary Search Tree to Sorted Doubly Linked List | Python, Java | O(n) | O(h) | Medium | BST, recursion, tree, linked list, good basic UBER, lyft, amazon, google, fb, microsoft, uber |
AGAIN******* (5) (not start) |
| 0449 | Serialize and Deserialize BST | Python, Java | O(n) | O(h) | Medium | BST, LC 297, dfs, bfs, good trick, serizlize deserizlize, tree, amazon, fb, google, apple, microsoft, uber, linkedin |
AGAIN************* (9) (MUST) |
| 0450 | Delete Node in a BST | Python, Java | O(h) | O(h) | Medium | BST, good trick, tree, dfs, LC 1325, google, amazon, fb, apple, microsoft, uber, linkedin, neetcode250 |
AGAIN***************** (9) (MUST !!!) |
| 0510 | Inorder Successor in BST II | Java | O(h) | O(1) | Medium | BST, parent, google, fb, apple, microsoft, bloomberg |
AGAIN** (1) (not start) |
| 0530 | Minimum Absolute Difference in BST | Python, Java | O(n) | O(h) | Easy | BST, LC 783, google, apple |
AGAIN* |
| 0700 | Search in a Binary Search Tree | Python, Java | O(h) | O(h) | Easy | BST, good basic, recursion, iteration amazon, google, amazon, apple, microsoft, uber |
AGAIN*** (1) |
| 0776 | Split BST | Python, Java | O(h) | O(h) | Medium | BST, 🔒, recursive, iterative, DFS, split, trick, AGAIN, amazon, google, fb |
AGAIN************ (9)(MUST) |
| 0783 | Minimum Distance Between BST Nodes | Python, Java | O(n) | O(h) | Easy | BST, LC 530, google, amazon |
OK* |
| 0968 | Binary Tree Cameras | Python, Java | O(n) | O(h) | Hard | BST, node state, dfs, bottom up, post order, dp, greedy, microsoft, amazon, google, fb, apple |
AGAIN************* (3)(MUST) |
| 1022 | Sum of Root To Leaf Binary Numbers | Python, Java | O(n) | O(h) | Easy | BST, good basic, LC 257, bst path, dfs, bfs, amazon, binary tree, google, apple |
AGAIN******** (1) (MUST) |
| 1382 | Balance a Binary Search Tree | Python, Java | O(n) | O(n) | Medium | BST, LC 105, 106, inorder then rebuild, dfs, good trick, AVL tree, amazon, fb, apple |
AGAIN******** (2) |
| 1597 | Build Binary Expression Tree From Infix Expression | Python, Java | O(n) | O(n) | Hard | BST, LC 224, recursive, iteration, stack, amazon, google, string |
AGAIN*** (1) |
| 1644 | Lowest Common Ancestor of a Binary Search Tree 2 | Python, Java | O(n) | O(h) | Medium | BST, LC 235, 236, dfs, binary tree, google, amazon, fb, microsoft |
AGAIN (1) |
Breadth-First Search
| # | Title | Solution | Time | Space | Difficulty | Note | Status |
|---|---|---|---|---|---|---|---|
| 0102 | Binary Tree Level Order Traversal | Python, Java | O(n) | O(n) | Medium | bfs, GOOD basic, dfs, uber, apple, amazon, fb, LC 199, google, microsoft, linkedin, bloomberg, blind75, top100liked |
AGAIN******* (8) (must) |
| 0103 | Binary Tree Zigzag Level Order Traversal | Python, Java | O(n) | O(n) | Medium | bfs, amazon, fb, google, apple, microsoft, uber, linkedin, bloomberg |
OK |
| 0107 | Binary Tree Level Order Traversal II | Python, Java | O(n) | O(n) | Medium | bfs, same as # 102 Binary Tree Level Order Traversal, google, amazon, apple, microsoft |
OK* (3) |
| 0126 | Word Ladder II | Python, Java | O(n * l^2) | O(n * l) | Hard | bfs, complex, trick, dfs, dfs+bfs, check # 127 Word Ladder, amazon, google, fb, microsoft, uber, linkedin |
AGAIN*** (3) (not start) |
| 0127 | Word Ladder | Python, Java | O(n * d) | O(d) | Hard | bfs, good basic, set, LC 126 Word Ladder II, uber, amazon, microsoft, fb, google, apple, linkedin, bloomberg, neetcode150 |
AGAIN**************** (12)(MUST) |
| 0130 | Surrounded Regions | Python, Java | O(m * n) | O(m * n) | Medium | bfs, dfs, union find, good basic, amazon, google, fb, apple, microsoft, uber, neetcode150 |
AGAIN*********** (5) |
| 0133 | Clone Graph | Python, Java | O(n) | O(n) | Medium | bfs, good trick, LC 138, graph, dfs, uber, google, amazon, fb, apple, microsoft, linkedin, blind75 |
AGAIN**************** (11) (MUST) |
| 0207 | Course Schedule | Python, Java | O(V + E) | O(E) | Medium | bfs, Topological Sort, LC 210, good trick, dfs, amazon, fb, google, apple, microsoft, uber, linkedin, blind75, top100liked |
AGAIN**************** (15) (MUST) |
| 0210 | Course Schedule II | Python, Java | O(V + E) | O(E) | Medium | bfs, Topological Sort, LC 207, dfs, amazon, fb, google, apple, microsoft, uber, neetcode150 |
AGAIN********* (10) (again) |
| 0261 | Graph Valid Tree | Python, Java | O(V + E) | O(V + E) | Medium | bfs, union find, dfs, grpah, 🔒, graph, google, amazon, fb, microsoft, linkedin, blind75 |
AGAIN************* (12)(MUST) |
| 0286 | Walls and Gates | Python, Java | O(m * n) | O(g) | Medium | bfs, 🔒, dfs, good basic, google, amazon, fb, apple, microsoft, uber, neetcode150 |
AGAIN******** (8) |
| 0310 | Minimum Height Trees | Python, Java | O(n) | O(n) | Medium | bfs, good trick, undirected graph, topo sort, Kahn algo, google, amazon, fb, apple, microsoft, neetcode250 |
AGAIN******* (5) |
| 0317 | Shortest Distance from All Buildings | Java | O(m^2 * n^2) | O(m * n) | Hard | bfs, multi-source BFS, total Path, cnt matrix, good trick, google, amazon, fb, microsoft, uber |
AGAIN*********** (1)(must) |
| 0407 | Trapping Rain Water II | Java | O(m * nlog(m * n)) | O(m * n) | Hard | bfs, PQ, google, amazon, fb, apple, microsoft |
AGAIN (not start) |
| 0429 | N-ary Tree Level Order Traversal | Java | O(n) | O(n) | Medium | bfs, PQ, google, amazon, microsoft |
AGAIN*** (1) |
| 0433 | Minimum Genetic Mutation | Python, Java | O(n * b) | O(b) | Medium | bfs, check # 127 Word Ladder, good basic, google, amazon, uber |
AGAIN*** (3) |
| 0444 | Sequence Reconstruction | Python, Java | O(n + m) | O(n) | Medium | bfs, good trick, Topological Sort, google, airbnb, array, graph |
AGAIN******* (4) (not start) |
| 0490 | The Maze | Python, Java | O(max(r, c) * w) | O(w) | Medium | bfs, basic, dfs, amazon, fb, google, microsoft, uber |
AGAIN**** (5) |
| 0499 | The Maze III | Java | O(m * n * max(m, n) * log(m * n)) | O(m * n) | Medium | bfs, Dijkstra with lexicographically smallest path, roll until a wall, good trick, google, microsoft |
AGAIN (not start) |
| 0505 | The Maze II | Python, Java | O(max(r, c) * wlogw) | O(w) | Medium | bfs, Dijkstra, google, fb, amazon |
AGAIN********* (7)(MUST) |
| 0542 | 01 Matrix | Python, Java | O(m * n) | O(m * n) | Medium | bfs, multi-source BFS, BFS get min dist, google, LC 994, 1765, amazon, fb, apple, microsoft, uber |
AGAIN************* (MUST) (4) |
| 0666 | Path Sum IV | Python, Java | O(n) | O(n) | Medium | bfs, 🔒, encode (depth, position) into a hashmap then dfs, tree, array, fb |
AGAIN* (3) (not start) |
| 0675 | Cut Off Trees for Golf Event | Python, Java | O((m * n)^2) | O(m * n) | Hard | bfs, good trick, tree, mult-source BFS, shortest path, amazon, google, apple |
AGAIN**************** (3)(must) |
| 0742 | Closest Leaf in a Binary Tree | Python, Java | O(n) | O(n) | Medium | bfs, Graph, bfs+dfs, search, good trick, amazon, google, fb |
AGAIN************** (7)(MUST) |
| 0743 | Network Delay Time | Python, Java | O(E * logV) | O(V + E) | Medium | bfs, Dijkstra, Bellman-Ford, shortest path from one source, google, amazon, microsoft, uber, neetcode150 |
AGAIN **** (3) |
| 0752 | Open the Lock | Python, Java | O(k * n^k + d) | O(k * n^k + d) | Medium | bfs, LC 863, google, amazon, fb, apple, uber, neetcode250 |
AGAIN (not start) |
| 0787 | Cheapest Flights Within K Stops | Python, Java | O(E * logV) | O(E) | Medium | bfs, Dijkstra's algorithm, dfs, graph, priority queue, amazon, apple, google, airbnb, fb, microsoft, uber, bloomberg, neetcode150 |
AGAIN****** (4) |
| 0815 | Bus Routes | Python, Java | O(V + E) | O(V + E) | Hard | bfs, shortest route, graph, amazon, google, good trick, fb, uber |
AGAIN****** (3) |
| 0864 | Shortest Path to Get All Keys | Python, Java | O(m * n * 2^k) | O(m * n * 2^k) | Hard | bfs, Dijkstra, Permutations, amazon, google |
AGAIN (not start) |
| 0886 | Possible Bipartition | Python, Java | O(V + E) | O(V + E) | Medium | bfs, LC 785, graph, dfs, union find, fb, google, amazon, apple, microsoft |
AGAIN********** (6) |
| 0934 | Shortest Bridge | Python, Java | O(n^2) | O(n^2) | Medium | bfs, BFS+DFS, multi-src BFS, good trick, google, amazon, fb, apple, microsoft, uber |
AGAIN************* (2) |
| 0967 | Numbers With Same Consecutive Differences | Python, Java | O(2^n) | O(2^n) | Medium | bfs, good trick, uber |
AGAIN** (3) |
| 0994 | Rotting Oranges | Python, Java | O(m * n) | O(m * n) | Medium | bfs, dp amazon, good trick, LC 542, google, amazon, fb, apple, microsoft, neetcode150, top100liked |
AGAIN********* (MUST) (2) |
| 1091 | Shortest Path in Binary Matrix | Java | O(n^2) | O(n^2) | Medium | bfs, google, amazon, fb, microsoft, uber |
AGAIN (not start) |
| 1110 | Delete Nodes And Return Forest | Python, Java | O(n) | O(n) | Medium | bfs, pre+post order DFS, 2 states, prune, tree, google, array, hash table, amazon, fb |
AGAIN************ (4)(MUST) |
| 1136 | Parallel Courses | Python | O(V + E) | O(V + E) | Medium | bfs, Topological Sort, Kahn algo, BFS level == 1 semester, 🔒, LC 207, LC 210, graph, google |
AGAIN (1) |
| 1162 | As Far from Land as Possible | Python, Java | O(n^2) | O(n^2) | Medium | bfs, muti-source bfs, good basic, amazon, google, fb, microsoft |
AGAIN********* (3)(MUST) |
| 1197 | Minimum Knight Moves | Java | O(n^2) | O(n^2) | Medium | bfs, google, amazon, fb, apple, microsoft |
OK (1) |
| 1530 | Number of Good Leaf Nodes Pairs | Python, Java | O(n * d^2) | O(n) | Medium | bfs, DFS, node pair, graph, good trick, tree, binary tree, google |
AGAIN************ (2)(MUST) |
| 1730 | Shortest Path to Get Food | Python, Java | O(m * n) | O(m * n) | Medium | bfs, shortest path, amazon, google |
OK (2) |
| 1765 | Map of Highest Peak | Java | O(m * n) | O(m * n) | Medium | bfs, dp, LC 542, google, microsoft |
again (1)(not start) |
| 1905 | Count Sub Islands | Python, Java | O(m * n) | O(m * n) | Medium | bfs, dfs, amazon |
AGAIN (1) |
| 2115 | Find All Possible Recipes from Given Supplies | Java | O(n + e) | O(n + e) | Medium | bfs, dfs, topological sort, google, array, hash table, string |
OK (2) |
| 2684 | Maximum Number of Moves in a Grid | Java | O(m * n) | O(m * n) | Medium | bfs, top-down dp, bottom-up dp, LC weekly 345, array, matrix |
again (1) |
Depth-First Search
| # | Title | Solution | Time | Space | Difficulty | Note | Status |
|---|---|---|---|---|---|---|---|
| 0112 | Path Sum | Python, Scala, Java | O(n) | O(h) | Easy | dfs, good concept, amazon, recursion, google, fb, apple, microsoft, linkedin |
AGAIN** (2) |
| 0113 | Path Sum II | Python, Java | O(n) | O(h) | Medium | dfs, backtrack, LC 112, good basic, amazon, fb, google, apple, microsoft, linkedin, bloomberg |
AGAIN************ (8)(MUST) |
| 0199 | Binary Tree Right Side View | Python, Java | O(n) | O(h) | Medium | dfs, good basic, bfs, apple, amazon, fb, LC 102, google, microsoft, uber, bloomberg, neetcode150, top100liked |
OK*** (6) |
| 0200 | Number of Islands | Python, Java | O(m * n) | O(m * n) | Medium | dfs, bfs, good basic, check # 694, 711 Number of Distinct Islands, apple, goldman sachs, google, amazon, fb, LC 305, microsoft, uber, linkedin, bloomberg, blind75, top100liked |
OK****** (6) |
| 0236 | Lowest Common Ancestor of a Binary Tree | Python, Java | O(n) | O(h) | Medium | dfs, trick, EPI, LCA, LC 1644, 235, apple, amazon, linkedin, fb, google, microsoft, uber, bloomberg, top100liked |
AGAIN************* (9) |
| 0247 | Strobogrammatic Number II | Python, Java | O(n^2 * 5^(n/2)) | O(n) | Medium | dfs, 🔒, check #246 Strobogrammatic Number, good trick, google, fb, array, string, recursion, uber |
AGAIN******** (5) |
| 0257 | Binary Tree Paths | Python, Java | O(n * h) | O(h) | Easy | dfs, good basic, apple, google, amazon, fb, top down, bottom up, LC 112, 113, microsoft |
AGAIN************ (MUST) (7) |
| 0332 | Reconstruct Itinerary | Python, Java | O(E * logE) | O(E) | Hard | dfs, Hierholzer algo, yelp, google, amazon, fb, apple, microsoft, uber, bloomberg, neetcode150 |
AGAIN* (3) (not start) |
| 0339 | Nested List Weight Sum | Python, Java | O(n) | O(h) | Easy | dfs, 🔒, good basic, bfs, linkedin, fb, amazon, microsoft, uber |
AGAIN*** (3) |
| 0364 | Nested List Weight Sum II | Python, Java | O(n) | O(h) | Medium | dfs, 🔒, linkedin, fb |
AGAIN* |
| 0366 | Find Leaves of Binary Tree | Python, Java | O(n) | O(h) | Medium | dfs, 🔒, linkedin, google, amazon, apple |
AGAIN* |
| 0399 | Evaluate Division | Python, Java | O(q * (V + E)) | O(V + E) | Medium | dfs, union find, good trick, union find google, fb, google, amazon, apple, microsoft, uber, bloomberg, neetcode250 |
AGAIN************** (9)(MUST) |
| 0417 | Pacific Atlantic Water Flow | Python, Java | O(m * n) | O(m * n) | Medium | dfs, 2 direction dfs, matrix, microsoft, google, amazon, fb, apple, uber, blind75 |
AGAIN** (3) |
| 0464 | Can I Win | Python, Java | O(n * 2^n) | O(2^n) | Medium | dfs, DP, linkedin, math, bit manipulation, google, amazon |
AGAIN* (not start) |
| 0491 | Increasing Subsequences | Python, Java | O(n * 2^n) | O(n * 2^n) | Medium | dfs, trick, dfs good trick, dp, yahoo, fb, array, hash table, backtracking, google, apple |
AGAIN***** (2) |
| 0515 | Find Largest Value in Each Tree Row | Python, Java | O(n) | O(h) | Medium | dfs, good basic, linkedin, google, amazon, fb, apple, microsoft |
AGAIN* (3) |
| 0529 | Minesweeper | Python, Java | O(m * n) | O(m * n) | Medium | dfs, bfs, recursive update, amazon, google, fb, apple, microsoft, uber, bloomberg |
AGAIN******** (6) |
| 0547 | Friend Circles | Python, Java | O(n^2) | O(n) | Medium | dfs, graph, Union Find, bfs, check # 733 Flood Fill, bloomberg, fb, google, amazon, apple, microsoft, uber, linkedin |
AGAIN*** (3) (not start) |
| 0547 | Number of Provinces | Python, Java | O(n^2) | O(n) | Medium | dfs, bfs, graph, union find, good basic, apple, amazon, google, fb, microsoft, uber, linkedin |
AGAIN************ (2) (MUST) |
| 0582 | Kill Process | Python, Java | O(n) | O(n) | Medium | dfs, 🔒, BFS, good basic, google, amazon, microsoft, bloomberg |
AGAIN*********** (5) (MUST) |
| 0638 | Shopping Offers | Python, Java | O(n * 2^n) | O(n) | Medium | dfs, google, array, dp, backtracking, amazon, fb, apple |
AGAIN (not start*) |
| 0690 | Employee Importance | Python, Java | O(n) | O(h) | Easy | dfs, BFS, good basic, uber, google, amazon |
OK** (3) |
| 0694 | Number of Distinct Islands | Python, Java | O(m * n) | O(m * n) | Medium | dfs, LC200, LC711, path signature, good pattern, 🔒, amazon, google, fb, apple, microsoft, uber, linkedin |
AGAIN************* (7) (MUST) |
| 0695 | Max Area of Island | Python, Java | O(m * n) | O(m * n) | Medium | dfs, primitives in java, amazon, microsoft, linkedin, basic, google, fb, apple, bloomberg, neetcode150 |
AGAIN* (3) |
| 0711 | Number of Distinct Islands II | Python, Java | O(m * n * logn) | O(m * n) | Hard | dfs, complex, check # 200, 694 Number of Distinct Islands, amazon |
OK*** (3) |
| 0721 | Accounts Merge | Python , Java | O(nlogn) | O(n) | Medium | dfs, Disjoint Set Union (DSU), Union Find, path compression, complex, fb, google, amazon, microsoft, apple, twitter, uber, linkedin, neetcode250 |
AGAIN******* (4) (not start) |
| 0733 | Flood Fill | Python, Java | O(m * n) | O(m * n) | Easy | dfs, fb, amazon, good basic, google, apple, microsoft, uber, bloomberg |
OK**** (5) |
| 0737 | Sentence Similarity II | Python, Java | O(n + p) | O(p) | Medium | dfs, good basic, map, union find, dis-joint, google, amazon |
AGAIN************* (4)(MUST) |
| 0756 | Pyramid Transition Matrix | Python, Java | O(a^b) | O(a^b) | Medium | dfs, dfs over the allowed triples with memo, hashmap of (a, b) -> tops, string, backtracking, google, amazon |
AGAIN (3) (not start) |
| 0785 | Is Graph Bipartite? | Python, Java | O(V + E) | O(V) | Medium | dfs, LC 886, color, graph, bfs, fb, amazon, google, apple, microsoft, linkedin |
AGAIN******************* (8) |
| 0797 | All Paths From Source to Target | Python, Java | O(n * 2^n) | O(n * 2^n) | Medium | dfs, graph, dfs classics, good basic, google, amazon, fb, apple, microsoft, bloomberg |
AGAIN** (3) |
| 0802 | Find Eventual Safe States | Python, Java | O(V + E) | O(V) | Medium | dfs, Topological Sort, graph, google, amazon |
AGAIN********** (5) |
| 0827 | Making A Large Island | Java | O(m * n) | O(m * n) | Hard | dfs, union find(DSU), 2 pass DFS/BFS, complex, google, amazon, fb, apple, uber |
AGAIN**** (1) |
| 0841 | Keys and Rooms | Python, Java | O(n + e) | O(n) | Medium | dfs, google, bfs, good basic, amazon |
AGAIN*** (3) |
| 0851 | Loud and Rich | Python, Java | O(n + e) | O(n + e) | Medium | dfs, amazon, defaultdict, good basic |
AGAIN*** (3) |
| 0987 | Vertical Order Traversal of a Binary Tree | Java | O(nlogn) | O(n) | Hard | dfs, LC 314, bfs, tree map, google, amazon, fb, apple, microsoft, uber, linkedin, bloomberg |
AGAIN (not start) |
| 0988 | Smallest String Starting From Leaf | Java | O(n * h) | O(h) | Medium | dfs, bfs, google, apple |
AGAIN (not start) |
| 0990 | Satisfiability of Equality Equations | Python, Java | O(n * a(n)) | O(1) | Medium | dfs, union find, array, string, google, amazon |
AGAIN (not start) |
| 1020 | Number of Enclaves | Java | O(m * n) | O(m * n) | Medium | dfs, flood fill from the border then count what remains, LC 1254, good basic, google |
AGAIN (1) |
| 1087 | Brace Explansion | Python, Java | O(n * p) | O(n * p) | Medium | dfs, bfs, prefix sum, backtrack, good trick, Cartesian product, google, string, stack, amazon |
AGAIN************** (3)(MUST) |
| 1192 | Critical Connections in a Network | Python, Java | O(n + e) | O(n + e) | Hard | dfs, Tarjan’s algorithm, graph, fb, amazon, google, apple |
AGAIN** (1) (not start) |
| 1254 | Number of Closed Islands | Java | O(m * n) | O(m * n) | Medium | dfs, bfs, flood, good trick, 2 pass approach, google, amazon, fb, apple, uber |
AGAIN (1)********** |
| 1376 | Time Needed to Inform All Employees | Python | O(n) | O(n) | Medium | dfs, invert manager to children first, answer = slowest root-to-leaf path, iterative (n = 10^5), tree, google, amazon |
AGAIN(1) |
| 1466 | Reorder Routes to Make All Paths Lead to the City Zero | Java | O(n) | O(n) | Medium | dfs, bfs, google, amazon |
AGAIN (1) |
| 1644 | Lowest Common Ancestor of a Binary Tree II | Python, Java | O(n) | O(h) | Medium | dfs, LCA, LC 236, microsoft, fb, google, amazon |
AGAIN (not start) |
| 1650 | Lowest Common Ancestor of a Binary Tree III | Python, Java | O(h) | O(h) | Medium | dfs, parent node, good trick, set, dict, LCA, LC 236, amazon, google, spotify m$, fb, two pointers, tree, apple, microsoft |
AGAIN******** (2) (MUST) |
| 1676 | Lowest Common Ancestor of a Binary Tree IV | Python, Java | O(n) | O(h) | Medium | dfs, multi node LCA, LC 236, set, m$, amazon, microsoft |
AGAIN********* (1) (MUST) |
| 2049 | Count Nodes With the Highest Score | Python, Java | O(n) | O(n) | Medium | dfs, trick, graph, tree, google |
AGAIN**** (not start) |
| 2316 | Count Unreachable Pairs of Nodes in an Undirected Graph | Python, Java | O(n + e) | O(n + e) | Medium | dfs, bfs, union find, good trick | AGAIN******** (1) |
| 2658 | Maximum Number of Fish in a Grid | Java | O(m * n) | O(m * n) | Medium | dfs, bfs, weekly_103 | AGAIN (1) |
| 2685 | Count the Number of Complete Components | Java | O(n + e) | O(n + e) | Medium | dfs, good trick, bfs, union find, LC weekly 345 | AGAIN*** (2) |
| 2872 | Maximum Number of K-Divisible Components | Java | O(n) | O(n) | Hard | dfs, BFS, topological sort, good trick, post order | AGAIN*** (2) |
| 3319 | K-th Largest Perfect Subtree Size in Binary Tree | Java | O(nlogn) | O(n) | Medium | dfs, good trick, binary-tree, post order | AGAIN*** (2) |
| 3965 | Finish Time of Tasks I | Python, Java | O(n) | O(n) | Medium | dfs, max_small_val, LC bi-weekly | AGAIN******** (4)(MUST) |
| 3997 | Count Dominant Nodes in a Binary Tree | Python, Java | O(n) | O(h) | Medium | dfs, LC weekly | AGAIN*** (1) |
| 4015 | Weighted Sum of a Tree | Python, Java | O(n) | O(n) | Medium | dfs, LC weekly | AGAIN*** (1) |
Backtracking
| # | Title | Solution | Time | Space | Difficulty | Note | Status |
|---|---|---|---|---|---|---|---|
| 0017 | Letter Combinations of a Phone Number | Python, Java | O(n * 4^n) | O(n) | Medium | backtracking, dfs, good trick, uber, amazon, google, fb, apple, microsoft, bloomberg, neetcode150, top100liked |
AGAIN************* (11) (MUST) |
| 0022 | Generate Parentheses | Python, Java | O(4^n / n^(3/2)) | O(n) | Medium | backtracking, LC 20, good basic, stack, backtrac, Divide and Conquer, amazon, google, fb, apple, microsoft, uber, bloomberg, neetcode150, top100liked |
OK**************** (5) (but again, MUST) |
| 0037 | Sudoku Solver | Python, Java | O(9^m) | O(m) | Hard | backtracking, backtrack over the m empty cells, row/col/box bitsets, google, amazon, uber, fb, apple, microsoft |
AGAIN(not start) |
| 0039 | Combination Sum | Python, Java | O(k * n^k) | O(k) | Medium | backtracking, dfs, good basic, uber, airbnb, amazon, fb, google, apple, microsoft, linkedin, bloomberg, blind75, top100liked |
OK********* (7) (but again) |
| 0040 | Combination Sum II | Python, Java | O(k * C(n, k)) | O(k) | Medium | backtracking, LC 39, avoud duplicated, amazon, fb, apple, microsoft, uber, linkedin, neetcode150 |
AGAIN******* (4) (MUST) |
| 0046 | Permutations | Python, Java | O(n * n!) | O(n) | Medium | backtracking, LC #77, 78, good concept, microsoft, linkedin, amazon, fb, google, apple, uber, bloomberg, neetcode150, top100liked |
OK*********** (4) (AGAIN, MUST) |
| 0047 | Permutations II | Python, Java | O(n * n!) | O(n) | Medium | backtracking, LC 46, avoid same layer duplicated, apple, amazon, microsoft, fb, uber, linkedin, neetcode250 |
AGAIN***** (MUST) |
| 0051 | N-Queens | Python, Java | O(n!) | O(n^2) | Hard | backtracking, matrix, bitmask, google, amazon, fb, apple, microsoft, uber, neetcode150, top100liked |
AGAIN********* (2)(MUST) |
| 0052 | N-Queens II | Python, Java | O(n!) | O(n) | Hard | backtracking, matrix, amazon, neetcode250 |
AGAIN |
| 0077 | Combinations | Python, Java | O(k * C(n, k)) | O(k) | Medium | backtracking, good trick, google, amazon, fb, apple, microsoft, neetcode250 |
OK************* (5) (but again, MUST) |
| 0078 | Subsets | Python, Java | O(n * 2^n) | O(n) | Medium | backtracking, good concept, similar as, dfs, #90 Subsets II , uber, amazon, fb, google, apple, microsoft, bloomberg, neetcode150, top100liked |
AGAIN**************** (7) (MUST again!!!) |
| 0079 | Word Search | Python, Java | O(m * n * 4^l) | O(l) | Medium | backtracking, LC 212, good trick, dfs, bloomberg, microsoft, amazon, fb, google, apple, uber, linkedin, blind75, top100liked |
AGAIN*************** (10) (MUST) |
| 0090 | Subsets II | Python, Java | O(n * 2^n) | O(n) | Medium | backtracking, good basic, check # 078 Subsets, dfs, fb, google, amazon, apple, microsoft, uber, neetcode150 |
AGAIN********* (6) |
| 0093 | Restore IP Addresses | Python, Java | O(1) | O(1) | Medium | backtracking, good trick, recursive, IP address, amazon, google, fb, apple, microsoft |
AGAIN****** (4) |
| 0131 | Palindrome Partitioning | Python, Java | O(n * 2^n) | O(n^2) | Medium | backtracking, dfs, good trick, amazon, google, fb, apple, microsoft, uber,neetcode150, top100liked |
AGAIN************** (9) (MUST) |
| 0139 | Word Break | Python, Java | O(n^2 * l) | O(n) | Medium | backtracking, dfs, dp, good DP basic, uber, yahoo, amazon, google, fb, array, hash table, string, apple, microsoft, bloomberg, blind75, top100liked |
AGAIN********************** (9) (MUST) |
| 0140 | Word Break II | Python, Java | O(n * 2^n) | O(n * 2^n) | Hard | backtracking, good basic, LC 078, dfs, dp, trick, amazon, google, fb, apple, microsoft, uber, bloomberg, neetcode250 |
AGAIN******** (2) |
| 0212 | Word Search II | Python, Java | O(m * n * 4^l) | O(t) | Hard | backtracking, LC 208, LC 079, hashset, hashmap, trie, backtrack with trie, amazon, fb, apple, twitter, uber, google, indeed, microsoft, blind75 |
AGAIN********** (3) |
| 0216 | Combination Sum III | Python, Java | O(k * C(n, k)) | O(k) | Medium | backtracking, LC 39, LC 40, pick k distinct numbers from 1…9, google, amazon, microsoft |
AGAIN* |
| 0254 | Factor Combinations | Python, Java | O(sqrt(n) * f) | O(logn) | Medium | backtracking, 🔒, f = number of factor combinations, dfs from the smallest factor, google, uber, linkedin |
AGAIN (not start) |
| 0267 | Palindrome Permutation II | Python, Java | O(n * n!) | O(n) | Medium | backtracking, 🔒, LC 266, permute half then mirror, google, amazon, fb, uber |
AGAIN (not start*) |
| 0282 | Expression Add Operators | Python | O(4^n * n) | O(n) | Hard | backtracking, carry the last operand so * can be undone, leading-zero guard, complex, google, amazon, fb, apple, microsoft, uber, linkedin |
AGAIN(1) |
| 0294 | Flip Game II | Python, Java | O(n * 2^n) | O(2^n) | Medium | backtracking, 🔒, DP, Hash, google |
AGAIN* |
| 0301 | Remove Invalid Parentheses | Python | O(2^n * n) | O(2^n * n) | Hard | backtracking, BFS level by level = minimum removals, LC 20, LC 921, dedupe the frontier, good trick, google, amazon, fb, apple, uber, bloomberg |
AGAIN(1) |
| 0320 | Generalized Abbreviation | Python, Java | O(n * 2^n) | O(n) | Medium | backtracking, 🔒, abbreviate or keep each char, bit mask, dfs, google |
AGAIN (not start*) |
| 0425 | Word Squares | Python | O(m * 26^L * L) | O(m * L) | Hard | backtracking, prefix map, row k is forced by column k, LC 212, trie, good trick, google |
AGAIN(1) |
| 0489 | Robot Room Cleaner | Python, Java | O(m * n) | O(m * n) | Hard | backtracking, 🔒, google, amazon, fb, microsoft |
AGAIN (not start) |
| 0526 | Beautiful Arrangement | Python, Java | O(n!) | O(n) | Medium | backtracking, backtrack with divisibility pruning, bitmask dp, good trick, google, amazon |
AGAIN (not start*) |
| 0676 | Implement Magic Dictionary | Python, Java | build: O(t), search: O(26 * l) | O(t) | Medium | backtracking, Trie, DFS, hash table, string, google, amazon, fb, microsoft |
AGAIN (not start) |
| 0698 | Partition to K Equal Sum Subsets | Python, Java | O(n * 2^n) | O(2^n) | Medium | backtracking, DP, Memoization, similar as #416 Partition Equal Subset Sum, #473 Matchsticks to Square, google, amazon, fb, apple, microsoft, linkedin, neetcode250 |
AGAIN****** (2) (MUST) |
| 0718 | Maximum Length of Repeated Subarray | Python, Java | O(m * n) | O(min(m, n)) | Medium | backtracking, DP, Hash, Binary Search, array, google, amazon, apple |
AGAIN (not start*) |
| 0784 | Letter Case Permutation | Python, Java | O(n * 2^n) | O(n) | Medium | backtracking, dfs, recursion, good trick, fb, amazon, apple, microsoft |
AGAIN****** (3) |
| 0980 | Unique Paths III | Python, Java | O(3^(m * n)) | O(m * n) | Hard | backtracking, good trick, LC 62, 63, dfs, amazon, google, fb, apple, microsoft |
AGAIN********** (3) |
| 1219 | Path with Maximum Gold | Python, Java | O(3^(m * n)) | O(m * n) | Medium | backtracking, dfs, bfs, google, amazon, apple |
AGAIN**** (1) |
Dynamic Programming
| # | Title | Solution | Time | Space | Difficulty | Note | Status |
|---|---|---|---|---|---|---|---|
| 0044 | Wildcard Matching | Python | O(m * n) | O(m * n) | Hard | dp, 2D dp, wildcard, greedy two-pointer, amazon, facebook, google |
AGAIN (1) |
| 0053 | Maximum Subarray | Python, Java | O(n) | O(1) | Medium | dp, MUST, brute force, Kadane algo, pre-sum array, dp basic, amazon, fb, google, apple, microsoft, uber, linkedin, bloomberg, blind75, top100liked |
AGAIN**************** (8) |
| 0062 | Unique Paths | Python, Java | O(m * n) | O(n) | Medium | dp, 2D dp, basic, fb, google, apple, amazon, microsoft, uber, bloomberg, blind75, top100liked |
AGAIN********* (3)(MUST) |
| 0063 | Unique Paths II | Python, Java | O(m * n) | O(n) | Medium | dp, trick, LC 64, dfs + dp, amazon, google, fb, apple, microsoft, bloomberg, neetcode250 |
AGAIN* |
| 0064 | Minimum Path Sum | Python, Java | O(m * n) | O(n) | Medium | dp, Sum of grid values, Dijkstra, LC 1631, amazon, google, fb, apple, microsoft, uber, neetcode250, top100liked |
AGAIN******* (3)(MUST) |
| 0070 | Climbing Stairs | Python, Java | O(n) | O(1) | Easy | dp, Matrix Exponentiation, recursion, apple, google, amazon, fb, microsoft, uber, bloomberg, blind75, top100liked |
OK* (2) |
| 0072 | Edit Distance | Python, Java | O(m * n) | O(m * n) | Medium | dp, 2D DP, dp state, apple, google, amazon, fb, microsoft, uber, linkedin, bloomberg, neetcode150, top100liked |
AGAIN(5)************ (MUST) |
| 0091 | Decode Ways | Python, Java | O(n) | O(1) | Medium | dp, good basic, microsoft, uber, amazon, fb, google, apple, bloomberg, blind75 |
AGAIN*********************** (6) (MUST) |
| 0096 | Unique Binary Search Trees | Python, Java | O(n^2) | O(n) | Medium | dp, Math, fb, amazon, google, apple, microsoft, bloomberg |
AGAIN* (2) (not start) |
| 0097 | Interleaving String | Java, Python | O(m * n) | O(n) | Medium | dp, 1D, 2D DP, state machine, good trick, google, amazon, apple, microsoft, uber, bloomberg, neetcode150 |
again************ (4)(MUST) |
| 0115 | Distinct Subsequences | Java | O(m * n) | O(n) | Hard | dp, 2D dp, good trick, needcode 150, google, amazon, apple, neetcode150 |
AGAIN******** (1) |
| 0120 | Triangle | Python, Java | O(m * n) | O(n) | Medium | dp, amazon, google, apple, microsoft, bloomberg |
AGAIN* (not start) (2) |
| 0123 | Best Time to Buy and Sell Stock III | Python, Java | O(n) | O(1) | Hard | dp, amazon, uber, apple, google, fb, microsoft |
AGAIN* (not start) (1) |
| 0132 | Palindrome Partitioning II | Python | O(n^2) | O(n^2) | Hard | dp, LC 131, palindrome table + min-cut per prefix in one pass, 2D dp, good trick, google, amazon |
AGAIN(1) |
| 0152 | Maximum Product Subarray | Python, Java | O(n) | O(1) | Medium | dp, Kadane algo, brute force, google, amazon, linkedin, fb, apple, microsoft, uber, blind75, top100liked |
AGAIN***** (1) |
| 0198 | House Robber | Python, Java | O(n) | O(1) | Easy | dp, dp basic, amazon, google, fb, apple, microsoft, uber, linkedin, bloomberg, blind75, top100liked |
AGAIN*** (2) |
| 0213 | House Robber II | Python, Java | O(n) | O(1) | Medium | dp, good trick, LC 198, circular dp, google, amazon, apple, microsoft, blind75 |
AGAIN*************** (4)(MUST) |
| 0221 | Maximal Square | Python, Java | O(m * n) | O(n) | Medium | dp, EPI, amazon, fb, google, apple, microsoft, uber, bloomberg |
AGAIN** (3) (not start) |
| 0256 | Paint House | Python, Java | O(n) | O(1) | Medium | dp, google, 🔒, amazon, apple, linkedin |
AGAIN (2) |
| 0276 | Paint Fence | Python, Java | O(n) | O(1) | Easy | dp, good basic, 2 state DP, 🔒, google |
AGAIN*********(3) |
| 0279 | Perfect Squares | Python, Java | O(n * sqrt(n)) | O(n) | Medium | dp, bfs, 0/1 nbounded knapsack, GOOD trick, google, amazon, fb, apple, microsoft, uber, neetcode250, top100liked |
AGAIN************ (3)(MUST) |
| 0303 | Range Sum Query - Immutable | Python, Java | ctor: O(n), lookup: O(1) | O(n) | Easy | dp, prefix sum, LC 304, good basic, array, design, google, amazon, fb, bloomberg |
OK |
| 0304 | Range Sum Query 2D - Immutable | Python, Java | ctor: O(m * n), lookup: O(1) | O(m * n) | Medium | dp, prefix sum, NOTE: idx, trick, fb, array, design, matrix, google, amazon, apple, microsoft, neetcode250 |
AGAIN******** (6) |
| 0309 | Best Time to Buy and Sell Stock with Cooldown | Python, Java | O(n) | O(1) | Medium | dp, 2D dp, n x m array, good basic, google, amazon, fb, apple, neetcode150 |
AGAIN********* (1)(MUST) |
| 0312 | Burst Balloons | Java | O(n^3) | O(n^2) | Hard | dp, interval dp, think in reverse (which balloon bursts last), good trick, google, amazon, fb, apple, microsoft, uber, neetcode150 |
AGAIN (not start) |
| 0322 | Coin Change | Python, Java | O(n * k) | O(k) | Medium | dp, bfs, dfs, grab, google, fb, apple, amazon, microsoft, uber, linkedin, bloomberg, blind75, top100liked |
AGAIN****************** (7) (MUST) |
| 0329 | Longest Increasing Path in a Matrix | Java | O(m * n) | O(m * n) | Hard | dp, good trick, dfs+dp, 2D DP, topo sort, google, amazon, fb, apple, microsoft, uber, neetcode150 |
AGAIN************* (3)(MUST) |
| 0351 | Android Unlock Patterns | Python, Java | O(9^2 * 2^9) | O(9 * 2^9) | Medium | dp, 🔒 Backtracking, google, apple |
AGAIN (not start) |
| 0357 | Count Numbers with Unique Digits | Python, Java | O(n) | O(1) | Medium | dp, Backtracking, Math, google |
AGAIN (not start) |
| 0361 | Bomb Enemy | Python, Java | O(m * n) | O(m * n) | Medium | dp, 🔒, google, amazon, uber |
AGAIN* (2) |
| 0363 | Max Sum of Rectangle No Larger Than K | Java | O(m^2 * nlogn) | O(n) | Medium | dp, pre-sum. google, array, binary search, matrix, google, apple, microsoft |
AGAIN* (not start) |
| 0368 | Largest Divisible Subset | Python, Java | O(n^2) | O(n) | Medium | dp, sort then LIS-style dp, backtrack the chain, good trick, google, amazon, fb, apple, microsoft |
AGAIN (not start) |
| 0375 | Guess Number Higher or Lower II | Python, Java | O(n^3) | O(n^2) | Medium | dp, interval dp / minimax, pick the cost that minimizes the worst case, good trick, google |
AGAIN (not start) |
| 0377 | Combination Sum IV | Python, Java | O(n * t) | O(t) | Medium | dp, LC 518, dp basic, fb, google, amazon, apple, neetcode250 |
AGAIN******** (3) |
| 0403 | Frog Jump | Python, Java | O(n^2) | O(n^2) | Hard | dp, dfs, bfs, Memoization dfs, amazon, microsoft, google, fb, apple |
AGAIN (not start) |
| 0416 | Partition Equal Subset Sum | Python, Java | O(n * s) | O(s) | Medium | dp, good basic, 0/1 knapsack, backward, 1d, 2d dp, fb, google, apple, amazon, microsoft, uber, neetcode150, top100liked |
AGAIN******************* (6) (MUST) |
| 0418 | Sentence Screen Fitting | Python, Java | O(r + n * c) | O(n) | Medium | dp, 🔒, google, uber |
AGAIN (not start) |
| 0467 | Unique Substrings in Wraparound String | Python, Java | O(n) | O(1) | Medium | dp, longest consecutive substring ending at each letter, good trick, apple |
AGAIN (not start) |
| 0471 | Encode String with Shortest Length | Python, Java | O(n^3) on average | O(n^2) | Medium | dp, 🔒, google, amazon, microsoft |
AGAIN (not start) |
| 0472 | Concatenated Words | Python, Java | O(n * l^2) | O(n * l) | Hard | dp, good trick, trie+dfs, dfs, amazon, fb, apple, microsoft |
AGAIN******** (3) |
| 0474 | Ones and Zeroes | Python, Java | O(s * m * n) | O(m * n) | Medium | dp, good basic, 2D 0/1 knapsack, google, amazon |
AGAIN***** (2) (not start) |
| 0486 | Predict the Winner | Python, Java | O(n^2) | O(n) | Medium | dp, good trick, 1d, 2d DP, google, amazon, uber |
AGAIN********* (again)(MUST) |
| 0494 | Target Sum | Python, Java | O(n * s) | O(s) | Medium | dp, 2D dp, math, fb, google, amazon, apple, microsoft, uber, neetcode150 |
AGAIN****** (1) |
| 0509 | Fibonacci Number | Python, Java | O(logn) | O(1) | Easy | dp, variant of Climbing Stairs, Matrix Exponentiation, Spotify, google, amazon, fb, apple, microsoft |
OK** |
| 0516 | Longest Palindromic Subsequence | Python, Java | O(n^2) | O(n) | Medium | dp, good basic, 2D DP, backward+forward, forward+forward, uber, amazon, google, fb, apple, microsoft, linkedin |
AGAIN**************** (MUST) |
| 0518 | Coin Change 2 | Python, Java | O(n * amount) | O(amount) | Medium | dp, dp basic, good trick, LC 322, 377, google, fb, amazon, apple, microsoft, uber, neetcode150 |
AGAIN******** (4) |
| 0552 | Student Attendance Record II | Java | O(n) | O(1) | Medium | dp, 2d, 3d dp, good trick, google, uber |
AGAIN*********** (3) |
| 0562 | Longest Line of Consecutive One in Matrix | Python, Java | O(m * n) | O(n) | Medium | dp, 🔒, google |
AGAIN (not start) |
| 0576 | Out of Boundary Paths | Python, Java | O(N * m * n) | O(m * n) | Medium | dp, bfs, amazon |
AGAIN (not start) |
| 0583 | Delete Operation for Two Strings | Python, Java | O(m * n) | O(n) | Medium | dp, google |
AGAIN (not start) |
| 0639 | Decode Ways 2 | Java | O(n) | O(1) | Hard | dp, LC 91, state dp with the * wildcard, mod 1e9+7, google, amazon, fb, microsoft |
AGAIN (1) (not start) |
| 0650 | 2 Keys Keyboard | Python, Java | O(sqrt(n)) | O(1) | Medium | dp, dp basic, microsoft, google, amazon |
AGAIN* |
| 0673 | Number of Longest Increasing Subsequence | Python, Java | O(n^2) | O(n) | Medium | dp, good trick, fb, google, amazon |
AGAIN********** (3) |
| 0688 | Knight Probability in Chessboard | Python, Java | O(k * n^2) | O(n^2) | Medium | dp, dp basic, AGAIN, microsoft, goldman sachs, google, fb, amazon, apple |
AGAIN********* (5) |
| 0712 | Minimum ASCII Delete Sum for Two Strings | Python, Java | O(m * n) | O(n) | Medium | dp, LC 583, 2D dp on ASCII sums | AGAIN (not start) |
| 0714 | Best Time to Buy and Sell Stock with Transaction Fee | Python, Java | O(n) | O(1) | Medium | dp, AGAIN, good basic, greedy, fb, google, amazon, bloomberg |
AGAIN******** (3) |
| 0727 | Minimum Window Subsequence | Java | O(m * n) | O(m * n) | Hard | dp, google, amazon, fb, apple, bloomberg |
AGAIN (not start) |
| 0740 | Delete and Earn | Python, Java | O(n + k) | O(k) | Medium | dp, LC 198, google, amazon, fb, apple, microsoft, uber |
AGAIN********* (1)(MUST) |
| 0746 | Min Cost Climbing Stairs | Python, Java | O(n) | O(1) | Easy | dp, good dp basic, amazon, google, apple, microsoft, uber, neetcode150 |
AGAIN**** (2) |
| 0750 | Number Of Corner Rectangles | Python, Java | O(n * m^2) | O(n * m) | Medium | dp, fb, google |
AGAIN (3) (not start) |
| 0764 | Largest Plus Sign | Python, Java | O(n^2) | O(n^2) | Medium | dp, complex, fb, google, uber |
AGAIN (not start) (2) |
| 0788 | Rotated Digits | Python, Java | O(logn) | O(logn) | Easy | dp, Brute Force, Memoization, google, amazon, fb |
OK* |
| 0790 | Domino and Tromino Tiling | Python, Java | O(logn) | O(1) | Medium | dp, Matrix Exponentiation, google, amazon |
AGAIN (not start) |
| 0799 | Champagne Tower | Python, Java | O(n^2) | O(n) | Medium | dp, simulate the poured volume flowing down each row, 2D dp, google |
AGAIN |
| 0801 | Minimum Swaps To Make Sequences Increasing | Python, Java | O(n) | O(1) | Medium | dp, amazon, fb, google, apple |
AGAIN***** (not start) (2) |
| 0808 | Soup Servings | Python, Java | O(1) | O(1) | Medium | dp, memoized probability dp, converges to 1 for large n, trick, google |
AGAIN (not start) |
| 0813 | Largest Sum of Averages | Python, Java | O(k * n^2) | O(n) | Medium | dp, google, amazon, apple |
AGAIN (not start) |
| 0823 | Binary Trees With Factors | Python, Java | O(n^2) | O(n) | Medium | dp, sort + hashmap dp, count trees keyed by root value, amazon |
AGAIN (not start) |
| 0837 | New 21 Game | Python, Java | O(n) | O(n) | Medium | dp, trick, math, google, apple, uber |
AGAIN (2) (not start) |
| 0838 | Push Dominoes | Python, Java | O(n) | O(n) | Medium | dp, two pointers, google, amazon |
AGAIN (not start) |
| 0871 | Minimum Number of Refueling Stops | Java | O(nlogn) | O(n) | Hard | dp, PQ, good trick, google, amazon, apple, microsoft, uber |
AGAIN***** (1) |
| 0877 | Stone Game | Python, Java | O(n^2) | O(n) | Medium | dp, LC 486, math, game theory, variant of Predict the Winner, google, amazon, apple, neetcode250 |
AGAIN*** (1) |
| 0926 | Flip String to Monotone Increasing | Python, Java | O(n) | O(1) | Medium | dp, good trick, prefix idx VS str idx, prefix sum, google, amazon |
AGAIN*************** (6)(MUST) |
| 0931 | Minimum Falling Path Sum | Python, Java | O(n^2) | O(1) | Medium | dp, google, good basic, amazon, apple |
AGAIN******** (2)(MUST) |
| 0935 | Knight Dialer | Python, Java | O(logn) | O(1) | Medium | dp, Matrix Exponentiation, google, microsoft, fb, amazon, apple |
AGAIN (not start) |
| 0983 | Minimum Cost For Tickets | Java | O(n) | O(n) | Medium | dp, google, amazon, fb, apple, uber |
AGAIN (not start) |
| 1000 | Minimum Cost to Merge Stones | Python, Java | O(n^3 / k) | O(n^2) | Hard | dp, amazon, google |
AGAIN (not start) |
| 1025 | Divisor Game | Java | O(1) | O(1) | Easy | dp, n % 2 == 0 wins, math, good trick, google, amazon, uber |
AGAIN (not start) |
| 1048 | Longest String Chain | Java | O(n * l^2) | O(n) | Medium | dp, 1D dp, hashmap, string, good basic, google, amazon, fb, microsoft |
AGAIN******** (1)(MUST) |
| 1049 | Last Stone Weight II | Python, Java | O(n * s) | O(s) | Medium | dp, good trick !!!, 0/1 knapsack, minimize abs(S1 - S2), LC 416, 494, google, amazon, neetcode250 |
AGAIN****** (1) |
| 1137 | N-th Tribonacci Number | Python, Java | O(n) | O(1) | Easy | dp, good basic, amazon, fb, neetcode250 |
AGAIN** |
| 1140 | Stone Game II | Java | O(n^3) | O(n^2) | Medium | dp, need_code_250, google, neetcode250 |
AGAIN** |
| 1143 | Longest Common Subsequence | Python, Java | O(m * n) | O(n) | Medium | dp, Memoization, 2D dp, amazon, karat, google, fb, microsoft, uber, blind75, top100liked |
AGAIN******************** (6)(DP MUST) |
| 1277 | Count Square Submatrices with All Ones | Java | O(m * n) | O(1) | Medium | dp, google, amazon, fb, microsoft |
AGAIN(1) (not start) |
| 1312 | Minimum Insertion Steps to Make a String Palindrome | Python, Java | O(n^2) | O(n) | Hard | dp, amazon, google, apple, microsoft |
AGAIN (not start) |
| 1335 | Minimum Difficulty of a Job Schedule | Python, Java | O(d * n^2) | O(d * n) | Hard | dp, amazon, google, uber |
not start |
| 1406 | Stone Game III | Java | O(n) | O(n) | Medium | dp, amazon, google, neetcode250 |
AGAIN (not start) |
| 1617 | Count Subtrees With Max Distance Between Cities | Java | O(n^2 * 2^n) | O(n^2) | Hard | dp, enumerate subsets with a bitmask, tree diameter per subset, complex |
AGAIN (not start) |
| 1799 | Maximize Score After N Operations | Python, Java | O(n^2 * 2^n) | O(2^n) | Medium | dp, amazon |
not start |
| 2560 | House Robber IV | Java | O(nlog(max)) | O(1) | Medium | dp, binary search | AGAIN (not start) |
| 2646 | Minimize the Total Price of the Trips | Java | O(m * n) | O(n) | Hard | dp, dfs, LC weekly | not start AGAIN (1) |
| 2765 | Longest Alternating Subarray | Java | O(n) | O(1) | Easy | dp, 2 pointers, good trick, array |
AGAIN(1) ***** |
| 2767 | Partition String Into Minimum Beautiful Substrings | Java | O(n^2) | O(n) | Medium | dp, dp over prefixes, powers of 5 written in binary | AGAIN(1) |
| 3122 | Minimum Number of Operations to Satisfy Conditions | Java | O(m * n + n * 100) | O(n * 10) | Medium | dp, LC weekly, PQ | Again (1) |
| 3196 | Maximize Total Cost of Alternating Subarrays | Java | O(n) | O(1) | Medium | dp, LC weekly | Again |
Greedy
| # | Title | Solution | Time | Space | Difficulty | Note | Status |
|---|---|---|---|---|---|---|---|
| 0011 | Container With Most Water | Python, Java | O(n) | O(1) | Medium | greedy, good basics, two pointers, fb, amazon, google, apple, microsoft, uber, bloomberg, blind75, top100liked |
OK*** (3) (but again !!) |
| 0045 | Jump Game II | Python, Java | O(n) | O(1) | Medium | greedy, google, apple, fb, tesla, amazon, microsoft, uber, neetcode150, top100liked |
AGAIN******** (4) (MUST) |
| 0055 | Jump Game | Python, Java | O(n) | O(1) | Medium | greedy, good trick, backtrack, DP, amazon, google, fb, apple, microsoft, uber, blind75, top100liked |
AGAIN*********** (9)(MUST) |
| 0084 | Largest Rectangle in Histogram | Python, Java | O(n) | O(n) | Hard | greedy, brute force, good trick, mono stack, LC 085, amazon, fb, array, google, apple, microsoft, uber, bloomberg, neetcode150, top100liked |
AGAIN******** (3) |
| 0122 | Best Time to Buy and Sell Stock II | Python, Java | O(n) | O(1) | Easy | greedy, compare with #309 Best Time to Buy and Sell Stock with Cooldown , #714 Best Time to Buy and Sell Stock with Transaction Fee, amazon, google, fb, apple, microsoft, uber, linkedin, bloomberg, neetcode250 |
again* (2) |
| 0134 | Gas Station | Python, Java | O(n) | O(1) | Medium | greedy, trick, amazon, google, fb, apple, microsoft, uber, neetcode150 |
AGAIN****** (5) |
| 0135 | Candy | Python, Java | O(n) | O(n) | Hard | greedy, LC 123, boundary, array, amazon, google, apple, microsoft, neetcode250 |
AGAIN (2) |
| 0218 | The Skyline Problem | Python, Java | O(nlogn) | O(n) | Hard | greedy, brute force, swipe line, Priority Queue, Union Find, Divide-and-Conquer, apple, microsoft, array, binary indexed tree, google, amazon, fb, uber |
AGAIN (not start) |
| 0316 | Remove Duplicate Letters | Python, Java | O(n) | O(1) | Medium | greedy, good trick, MONO stack, char, visited, LC 1081, google, amazon, fb, apple, microsoft |
AGAIN********* (4)(MUST) |
| 0319 | Bulb Switcher | Python, Java | O(1) | O(1) | Medium | greedy, duplicate of the Math entry, answer is floor(sqrt(n)), good trick, fb, apple, microsoft |
not start |
| 0330 | Patching Array | Python, Java | O(n) | O(1) | Hard | greedy, array, amazon, google, uber |
AGAIN (not start) |
| 0358 | Rearrange String k Distance Apart | Python, Java | O(n) | O(k) | Hard | greedy, PQ, check LC 767, cooldown queue, good trick, google, amazon, fb |
AGAIN*** (1) |
| 0376 | Wiggle Subsequence | Python, Java | O(n) | O(1) | Medium | greedy, count direction changes, greedy or dp, good basic, amazon, apple, uber |
AGAIN* |
| 0392 | Is Subsequence | Python, Java | O(n) | O(1) | Easy | greedy, basics, 2 pointers, dp, string, google, amazon, fb, uber |
AGAIN********* (1)(MUST) |
| 0397 | Integer Replacement | Python, Java | O(logn) | O(1) | Medium | greedy, Recursion basics, Math, google, amazon, microsoft |
OK* |
| 0402 | Remove K Digits | Python, Java | O(n) | O(n) | Medium | greedy, LintCode, mono stack, str, good trick, google, amazon, fb, microsoft |
AGAIN************* (4)(MUST) |
| 0435 | Non-overlapping Intervals | Python, Java | O(nlogn) | O(1) | Medium | greedy, good trick, inverval, LC 452, Line Sweep, google, amazon, fb, apple, microsoft, blind75 |
AGAIN**************** (10)(must) |
| 0452 | Minimum Number of Arrows to Burst Balloons | Python, Java | O(nlogn) | O(1) | Medium | greedy, sort, compare i-1 element, overlap, good basic, google, amazon, fb, apple, microsoft, uber |
AGAIN***** (3) |
| 0455 | Assign Cookies | Python, Java | O(nlogn + mlogm) | O(1) | Easy | greedy, sort both arrays then two pointers, basic, amazon, apple |
OK* |
| 0621 | Task Scheduler | Python, Java | O(n) | O(1) | Medium | greedy, trick, PQ+queue, compare with 767, cool down, fb, amazon, google, apple, microsoft, uber, neetcode150 |
AGAIN********* (8)(MUST) |
| 0646 | Maximum Length of Pair Chain | Python, Java | O(nlogn) | O(1) | Medium | greedy, good trick, similar as #435 Non-overlapping Intervals, Line Sweep, amazon, fb, apple, uber, bloomberg |
OK********** (5) (but again) |
| 0649 | Dota2 Senate | Python, Java | O(n) | O(n) | Medium | greedy, complex question, neetcode250 |
AGAIN (not start*) |
| 0659 | Split Array into Consecutive Subsequences | Python, Java | O(n) | O(n) | Medium | greedy, map, pq, dp, google, uber |
AGAIN***** (1) |
| 0672 | Bulb Switcher II | Python, Java | O(1) | O(1) | Medium | greedy, duplicate of the Math entry, only 6 reachable states, trick, bit manipulation, dfs, microsoft |
not start |
| 0738 | Monotone Increasing Digits | Python, Java | O(logn) | O(logn) | Medium | greedy, good trick, string, trick, amazon |
AGAIN********* (4) |
| 0763 | Partition Labels | Python, Java | O(n) | O(1) | Medium | greedy, good trick, dict, sliding window, amazon, google, fb, apple, microsoft, uber, neetcode150, top100liked |
AGAIN******* (6) (AGAIN) |
| 0765 | Couples Holding Hands | Java | O(n) | O(n) | Hard | greedy, hashmap, union find, google, fb |
AGAIN (not start) |
| 0767 | Reorganize String | Python, Java | O(n) | O(1) | Medium | greedy, LC 1054, compare with 621, PQ, hashmap, good trick, amazon, fb, google, apple, microsoft, uber, neetcode250 |
AGAIN****************** (9) (MUST) |
| 0861 | Score After Flipping Matrix | Python, Java | O(r * c) | O(1) | Medium | greedy, greedy: make column 0 all ones, then maximize each column, good trick, amazon |
AGAIN (not start*) |
| 0870 | Advantage Shuffle | Python, Java | O(nlogn) | O(n) | Medium | greedy, sort both then greedily assign the smallest winning card (Tian Ji horse racing), good trick, fb, apple |
OK* |
| 0881 | Boats to Save People | Python, Java | O(nlogn) | O(n) | Medium | greedy, good trick, google, amazon, neetcode250 |
AGAIN* (2) |
| 0948 | Bag of Tokens | Python, Java | O(nlogn) | O(1) | Medium | greedy, Two Pointers, google |
AGAIN*** (1) (not start) |
| 0962 | Maximum Width Ramp | Python, Java | O(n) | O(n) | Medium | greedy, Descending Stack, array, two pointers, google, fb, apple |
AGAIN (not start) |
| 0978 | Longest Turbulent Subarray | Java | O(n) | O(1) | Medium | greedy, sliding window, array, dp, amazon, bloomberg, neetcode250 |
AGAIN (not start) |
| 0984 | String Without AAA or BBB | Java, Python | O(n) | O(n) | Medium | greedy, good basic, while, string builder, endsWith, PQ, microsoft |
AGAIN***** (2) |
| 1024 | Video Stitching | Python, Java | O(nlogn) | O(1) | Medium | greedy, Spotify, google, amazon |
AGAIN (not start) |
| 1102 | Path With Maximum Minimum Value | Python, Java | O(m * nlog(m * n)) | O(m * n) | Medium | greedy, dfs, dp, amazon, array, binary search, google, fb |
not start |
| 1375 | Bulb Switcher III | Python, Java | O(n) | O(1) | Medium | greedy, queue, array, gra*, amazon, microsoft |
AGAIN*** (1) |
| 1380 | Lucky Numbers in a Matrix | Java | O(m * n) | O(m + n) | Easy | greedy, intersect the row minimums with the column maximums, matrix, basic, array, apple |
AGAIN (1) |
| 1546 | Maximum Number of Non-Overlapping Subarrays With Sum Equals Target | Python, Java | O(n) | O(n) | Medium | greedy, prefix + greedy, good trick, google, microsoft |
AGAIN*** (1) |
| 1648 | Sell Diminishing-Valued Colored Balls | Python, Java | O(nlogn) | O(1) | Medium | greedy, trick, sorting, heapq, binary search, amazon |
AGAIN*** (2) (not start) |
| 1710 | Maximum Units on a Truck | Python, Java | O(nlogn) | O(1) | Easy | greedy, sort, amazon, apple |
AGAIN******** (3) (MUST) |
| 1791 | Find Center of Star Graph | Java | O(1) | O(1) | Easy | greedy, degree cnt, graph |
AGAIN (1) |
| 1851 | Minimum Interval to Include Each Query | Java | O(nlogn + qlogq) | O(n + q) | Hard | greedy, needcode 150, PQ, interval, sort, scan line, Segment Tree, google, array, binary search, neetcode150 |
AGAIN************** (1) |
| 1871 | Jump Game VII | Java | O(n) | O(n) | Medium | greedy, bfs, string, dp, sliding window, google, amazon, neetcode250 |
AGAIN (not start) |
| 1899 | Merge Triplets to Form Target Triplet | Java | O(n) | O(1) | Medium | greedy, sort, amazon, google, neetcode150 |
AGAIN(1) (not srart) |
| 2126 | Destroying Asteroids | Java | O(nlogn) | O(1) | Medium | greedy, sort, google |
AGAIN(1) (not srart) |
| 2279 | Maximum Bags With Full Capacity of Rocks | Java | O(nlogn) | O(n) | Medium | greedy, sort | AGAIN (1) |
| 2591 | Distribute Money to Maximum Children | Java | O(1) | O(1) | Easy | greedy, LC weekly | AGAIN (1) |
| 2643 | Row With Maximum Ones | Java | O(m * n) | O(1) | Easy | greedy, count ones per row, matrix, basic, array |
AGAIN(1) (not srart) |
| 2645 | Minimum Additions to Make Valid String | Java | O(n) | O(1) | Medium | greedy, string | AGAIN(1) (not srart) |
| 2656 | Maximum Sum With Exactly K Elements | Java | O(n) | O(1) | Easy | greedy, weekly_103 | AGAIN(1) (not srart) |
| 2960 | Count Tested Devices After Test Operations | Java | O(n) | O(1) | Easy | greedy, running count of tested devices acts as the decrement, good trick, array, simulation, counting |
AGAIN(1) (not srart) |
| 3120 | Count the Number of Special Characters I | Java | O(n) | O(1) | Easy | greedy, hashset of seen chars, require both cases, LC 3121, basic, string |
AGAIN(1) (not srart) |
| 3689 | Maximum Total Subarray Value I | Java | O(n) | O(1) | Medium | greedy, math, brute force | OK |
| 3690 | Split and Merge Array Transformation | Java | O(n! * n^4) | O(n! * n) | Medium | greedy, bfs dfs, array, hash table |
AGAIN (not start) |
| 3691 | Maximum Total Subarray Value II | Java | O((n + k) * logn) | O(nlogn) | Hard | greedy, brute force, tree | AGAIN |
| 3994 | Transform Binary String Using Subsequence Sort | Python, Java | O(n) | O(1) | Medium | greedy, brute force, LC weekly | AGAIN*****(1) |
| 3998 | Transform Binary String Using Subsequence Sort | Python, Java | O(n * m) | O(n) | Medium | greedy, brute force, prefix, LC weekly | AGAIN |
| 4040 | Minimum Operations to Form Subset Sum I | Python | O(n * sum * logx) | O(sum) | Medium | dp, group 0/1 knapsack, per-element (value, cost) options, x2 / x//2 chains, LC weekly | AGAIN(1) |
Graph
| # | Title | Solution | Time | Space | Difficulty | Note | Status |
|---|---|---|---|---|---|---|---|
| 0269 | Alien Dictionary | Python, Java | O(n * l) | O(1) | Hard | graph, good trick, dfs, bfs, Topologicals sort, fb, google, microsoft, airbnb, uber, amazon, apple, bloomberg, blind75 |
AGAIN*************** (7)(MUST) |
| 0305 | Number of Islands II | Java | O(k * a(m * n)) | O(m * n) | Hard | graph, union find, LC 200, google, amazon, fb, apple, uber |
AGAIN (1) |
| 0323 | Number of Connected Components in an Undirected Graph | Python , Java | O(n + e) | O(n) | Medium | graph, LC 547, 🔒, bfs, dfs, Union Find, linkedin, amazon, fb, google, microsoft, apple, blind75 |
AGAIN************** (6) (MUST) |
| 0778 | Swim in Rising Water | Java | O(n^2 * logn) | O(n^2) | Medium | graph, Dijkstra, google, amazon, fb, neetcode150 |
AGAIN1 (1) (not start) |
| 0959 | Regions Cut By Slashes | Python, Java | O(n^2 * a(n^2)) | O(n^2) | Medium | graph, Union Find, amazon, apple, uber |
again |
| 0997 | Find the Town Judge | Python, Java | O(n + e) | O(n) | Easy | graph, in-degree minus out-degree equals n - 1, good basic, google, amazon, apple, neetcode250 |
again |
| 1135 | Connecting Cities With Minimum Cost | Python, Java | O(e * loge) | O(n) | Medium | graph, union find, Kruskal, prime, amazon, google, uber |
AGAIN (not start) |
| 1462 | Course Schedule IV | Java | O(n^3) | O(n^2) | Medium | graph, Floyd-Warshall reachability, or topological sort with reach sets, LC 207, amazon, uber, neetcode250 |
AGAIN (not start) |
| 1489 | Find Critical and Pseudo-Critical Edges in Minimum Spanning Tree | Java | O(e^2 * a(n)) | O(n + e) | Hard | graph, dfs, bfs, Dijkstra, amazon, neetcode250 |
AGAIN (not start) |
| 1514 | Path with Maximum Probability | Python, Java | O(e * logn) | O(n + e) | Medium | graph, Dijkstra, google |
AGAIN (not start) |
| 1584 | Min Cost to Connect All Points | Java | O(n^2 * logn) | O(n^2) | Medium | graph, Kruskal algo, Prim algo, advanced graph, amazon, neetcode150 |
AGAIN (not start) |
| 1631 | Path With Minimum Effort | Python, Java | O(m * nlog(m * n)) | O(m * n) | Medium | graph, Max of step differences, dfs, bfs+PQ, LC 64, Dijkstra, google, amazon, neetcode250 |
AGAIN********** (2)(MUST) |
| 1761 | Minimum Degree of a Connected Trio in a Graph | Java | O(n^3) | O(n^2) | Hard | graph, DP, amazon |
AGAIN (not start) |
| 1971 | Find if Path Exists in Graph | Java | O(n + e) | O(n + e) | Easy | graph, bfs, dfs, union find, google, amazon, microsoft |
AGAIN (1) |
| 2290 | Minimum Obstacle Removal to Reach Corner | Java | O(m * nlog(m * n)) | O(m * n) | Hard | graph, bfs, PQ, Dijkstra classics | AGAIN****** (2)(MUST) |
| 2392 | Build a Matrix With Conditions | Java | O(k^2) | O(k^2) | Hard | graph, dfs, bfs, Dijkstra, neetcode250 |
AGAIN (not start) |
| 2508 | Add Edges to Make Degrees of All Nodes Even | Java | O(n + e) | O(n + e) | Hard | graph, LC weekly | AGAIN (not start) |
| 2617 | Minimum Number of Visited Cells in a Grid | Java | O(m * nlog(m * n)) | O(m * n) | Hard | graph, PQ, stack, LC weekly | AGAIN***** (1) (not start) |
| 2642 | Design Graph With Shortest Path Calculator | Java | ctor: O(n^3), addEdge: O(n^2), shortestPath: O(1) | O(n^2) | Medium | graph, Dijkstra, floyd warshall, LC weekly 102 | AGAIN******** (2) |
| 2709 | Greatest Common Divisor Traversal | Java | O(n * sqrt(maxV) * a(n)) | O(n + maxV) | Hard | graph, union find over shared prime factors, sieve, complex, neetcode250 |
AGAIN (not start) |
| 3123 | Find Edges in Shortest Paths | Java | O(e * logn) | O(n + e) | Hard | graph, Dijkstra from both ends, keep edges lying on some shortest path, good trick |
AGAIN (1) (not start) |
Geometry
| # | Title | Solution | Time | Space | Difficulty | Note | Status |
|---|---|---|---|---|---|---|---|
| 0587 | Erect the Fence | Python, Java | O(nlogn) | O(n) | Hard | geometry, complex, Convex Hull, Monotone Chain, amazon, google |
AGAIN (not start) |
| 0892 | Surface Area of 3D Shapes | Java | O(n^2) | O(1) | Easy | geometry, count 6 faces per cube then subtract hidden overlaps, matrix, math, amazon |
AGAIN |
Design
| # | Title | Solution | Time | Space | Difficulty | Note | Status |
|---|---|---|---|---|---|---|---|
| 0146 | LRU Cache | Python, Java | O(1) | O(k) | Medium | design, good basic, LRU, dequeue, Double Linkedlist, LinkedHashMap, OrderedDict, amazon, google, fb, apple, microsoft, uber, linkedin, bloomberg, neetcode150, top100liked, netflix |
AGAIN********** (5) |
| 0225 | Implement Stack using Queues | Python, Java | push: O(n), pop: O(1), top: O(1) | O(n) | Easy | design, two queues, or one queue rotated after each push, LC 232, basic, amazon, microsoft, neetcode250 |
AGAIN** (1)(MUST) |
| 0284 | Peeking Iterator | C++ Python, Java | O(1) | O(1) | Medium | design, good basic, google, apple, amazon, fb, microsoft |
not start*** (1) |
| 0348 | Design Tic-Tac-Toe | Python, Java | O(1) | O(n^2) | Medium | design, matrix, array, 🔒, google, fb, amazon, apple, microsoft, uber |
AGAIN****** (5) |
| 0353 | Design Snake Game | Python, Java | O(1) | O(s) | Medium | design, good trick, Deque, 🔒, amazon, google, square, microsoft, fb, apple, uber |
AGAIN*** (1) |
| 0355 | Design Twitter | Python, Java | O(klogu) | O(t + f) | Medium | design, good trick, data structure, heapq, defaultdict, amazon, apple, microsoft, neetcode150 |
OK******** (6) |
| 0362 | Design Hit Counter | Java | O(1), amortized | O(k) | Medium | design, 🔒, deque, sliding window count, google, amazon, apple, microsoft, uber, linkedin, bloomberg |
Again (1) |
| 0379 | Design Phone Directory | Java | O(1) | O(n) | Medium | design, 🔒, queue, free-slot pool, google, amazon |
AGAIN(1) |
| 0380 | Insert Delete GetRandom O(1) | Python, Java | O(1) | O(n) | Medium | design, set, list, dict, amazon, fb, google, apple, microsoft, uber, linkedin, bloomberg |
OK* (5) |
| 0381 | Insert Delete GetRandom O(1) - Duplicates allowed | C++ Python, Java | O(1) average | O(n) | Hard | design, LC 380, hashmap of value -> index set + swap-with-last, good trick, google, amazon, fb, apple, uber, linkedin |
|
| 0432 | All O`one Data Structure | Java | O(1) per op | O(n) | Hard | design, doubly linked list of count buckets + hashmap, LC 146, LC 460, complex, google, amazon, fb, uber, linkedin |
|
| 0460 | LFU Cache | Python, Java | O(1) | O(k) | Hard | design, Least Frequently Used (LFU) cache, complex, amazon, google, fb, apple, microsoft, uber, linkedin, bloomberg, neetcode250 |
AGAIN*** (3) |
| 0535 | Encode and Decode TinyURL | Python, Java | O(1) | O(n) | Medium | design, hash map, “duplicated”, “hash map collision”, uber, amazon, google, fb, microsoft |
OK**** (5) |
| 0588 | Design In-Memory File System | Python, Java | ls: O(l + klogk) mkdir: O(l) addContentToFile: O(l + c) readContentFromFile: O(l + c) |
O(n + s) | Hard | design, dict, a bit complex basic, 🔒, shoptify, amazon, google, microsoft, uber |
AGAIN******* (3) |
| 0604 | Design Compressed String Iterator | C++ Python, Java | ctor: O(n), next/hasNext: O(1) | O(n) | Easy | design, 🔒, decode (char, count) pairs lazily, iterator, google |
|
| 0631 | Design Excel Sum Formula | C++ Python, Java | set: O(1) get: O((r * c)^2) sum: O((r * c)^2) |
O(r * c) | Hard | design, 🔒, google, amazon, microsoft, uber |
|
| 0635 | Design Log Storage System | C++ Python, Java | put: O(1) retrieve: O(n + dlogd) |
O(n) | Medium | design, 🔒, google, amazon |
|
| 0641 | Design Circular Deque | Python, Java | O(1) per op | O(k) | Medium | design, 🔒, circular buffer or doubly linked list, LC 622, amazon, fb |
|
| 0642 | Design Search Autocomplete System | Python, Java | O(p^2) | O(p * t + s) | Hard | design, 🔒, amazon, google, fb, apple, microsoft, uber |
AGAIN**** (not start) (5) |
| 0705 | Design HashSet | Java | O(1) average | O(n) | Easy | design, bucket array + chaining, LC 706, good basic, google, microsoft, neetcode250 |
|
| 0706 | Design HashMap | Java | O(1) average | O(n) | Easy | design, bucket array + chaining, LC 705, good basic, google, amazon, fb, apple, microsoft, uber, linkedin, neetcode250 |
|
| 0715 | Range Module | C++ Python, Java | add: O(n) remove: O(n) query: O(logn) |
O(n) | Hard | design, sorted interval list with binary search, LC 352, TreeMap, segment tree, google, amazon, fb, linkedin |
|
| 0716 | Max Stack | Python, Java | push: O(logn) pop: O(logn) popMax: O(logn) top: O(1) peekMax: O(1) |
O(n) | Hard | design, basic, stack, amazon, google, fb, apple, microsoft, uber, linkedin, bloomberg |
again* |
| 0745 | Prefix and Suffix Search | Python, Java | ctor: O(w * l^2) search : O(p + s) |
O(t) | Hard | design, Trie, fb, google |
Not start* (1) (good basic) |
| 0900 | RLE Iterator | C++ Python, Java | O(n) | O(1) | Medium | design, google, treemap, array, amazon |
AGAIN (not start) (1) |
| 1146 | Snapshot Array | Java | set: O(1) get: O(logn) |
O(n) | Medium | design, treeMap, binary search, google, amazon, fb, apple, microsoft, uber |
AGAIN*** (1) |
| 1166 | Design File System | C++ Python, Java | create: O(n) get: O(n) |
O(n) | Medium | design, 🔒, google, airbnb, amazon, microsoft |
AGAIN***** (1) |
| 1172 | Dinner Plate Stacks | C++ Python, Java | push: O(logn) pop: O(1), amortized popAtStack: (logn) |
O(n * c) | Hard | design, PQ of indices of non-full stacks, good trick |
|
| 1188 | Design Bounded Blocking Queue | Java | O(1) per op | O(k) | Medium | design, google, Semaphore, concurrency, amazon, apple, microsoft, uber, linkedin |
AGAIN (not start) |
| 1206 | Design Skiplist | C++ Python, Java | O(logn), on average | O(n) | Hard | design, probabilistic multi-level linked list, complex, google, fb, microsoft |
|
| 1236 | Web Crawler | C++ Python | O(V + E) | O(V) | Medium | design, 🔒, BFS, DFS, string, google, amazon, fb, microsoft |
|
| 1244 | Design A Leaderboard | Python, Java | ctor: O(1) add: O(1) top: O(n) reset: O(1) |
O(n) | Medium | design, google, hashmap, amazon, fb, uber |
AGAIN (not start) |
| 1268 | Search Suggestions System | Python, Java | ctor: O(n * l) suggest: O(l^2) |
O(t) | Medium | design, good basic, array, heap, sort, Trie, amazon, string, binary search, google, apple, microsoft |
AGAIN******** (3) |
| 1286 | Iterator for Combination | Python | ctor: O(1), next: O(k) | O(k) | Medium | design, Stack, google, uber |
|
| 1381 | Design a Stack With Increment Operation | Java | O(1) per op | O(n) | Medium | design, array, stack, lazy increment (good trick), linked list, google, amazon |
AGAIN (1) |
| 1429 | First Unique Number | Python, Java | O(1) amortized per op | O(n) | Medium | design, good trick, heap, amazon, fb |
AGAIN*** (not start) |
| 1472 | Design Browser History | Python, Java | visit: O(1), back/forward: O(steps) | O(n) | Medium | design, two stacks, or a list with a cursor, good basic, google, amazon, microsoft |
AGAIN |
| 1500 | Design a File Sharing System | Python, Java | join/leave: O(logn), request: O(n) | O(n) | Medium | design, 🔒, min-heap of free ids + hashmap of owners, google |
AGAIN*** (not start) |
| 1603 | Design Parking System | Python, Java | O(1) | O(1) | Easy | design, amazon, paypal, google, microsoft |
OK |
| 1628 | Design an Expression Tree With Evaluate Function | Python, Java | build: O(n), evaluate: O(n) | O(n) | Medium | design, complex, amazon |
AGAIN*** (not start) |
| 1656 | Design an Ordered Stream | Python, Java | insert: O(1) amortized | O(n) | Easy | design, pointer + bucket array, return the contiguous chunk, basic |
|
| 1670 | Design Front Middle Back Queue | Python, Java | O(1) per op | O(n) | Medium | design, good basic, amazon |
AGAIN** (1) (not start) |
| 1756 | Design Recent Used Queue | Python, Java | fetch: O(k) | O(n) | Medium | design, 🔒, move-to-front list or BIT, LC 146, google |
AGAIN |
| 1797 | Design Authentication Manager | Python, Java | O(1) amortized | O(n) | Medium | design, hashmap | AGAIN |
| 1976 | Number of Ways to Arrive at Destination | Python, Java | O(e * logn) | O(n + e) | Medium | design, Dijkstra + count shortest paths, dp, mod 1e9+7, graph, topological sort, fb |
|
| 2034 | Stock Price Fluctuation | Python, Java | update: O(logn) current: O(1) maximum/minimum: O(logn) amortized |
O(n) | Medium | design, hashmap is the source of truth + two lazy heaps, pop stale tops instead of deleting, heap, good trick, LC weekly |
AGAIN(1) |
Prefix Sum
| # | Title | Solution | Time | Space | Difficulty | Note | Status |
|---|---|---|---|---|---|---|---|
| 1124 | Longest Well-Performing Interval | Python, Java | O(n) | O(n) | Medium | prefix sum, hashmap, first idx, Monotonic Stack, good basic, google |
AGAIN************* (3)(MUST) |
| 2012 | Sum of Beauty in the Array | Python | O(n) | O(n) | Medium | prefix sum, good basics, prefix, suffix sum, LC weekly | AGAIN****** (2) |
| 2017 | Grid Game | Python | O(n) | O(1) | Medium | prefix sum, 2 x n grid, path == turning column, prefix (bottom) + suffix (top) sum, minimax, greedy, LC weekly | AGAIN(1) |
Simulation
| # | Title | Solution | Time | Space | Difficulty | Note | Status |
|---|---|---|---|---|---|---|---|
| 0874 | Walking Robot Simulation | C++ Python | O(n + k) | O(k) | Easy | simulation, hashset of obstacles, direction array, LC 1041, good basic, amazon |
Concurrency
| # | Title | Solution | Time | Space | Difficulty | Note | Status |
|---|---|---|---|---|---|---|---|
| 1114 | Print in Order | C++ Python | O(n) | O(1) | Easy | concurrency, two semaphores (or CountDownLatch), enforce sequential ordering, google, amazon, apple, microsoft, bloomberg |
|
| 1115 | Print FooBar Alternately | C++ Python | O(n) | O(1) | Medium | concurrency, two semaphores alternating foo/bar | |
| 1116 | Print Zero Even Odd | C++ Python | O(n) | O(1) | Medium | concurrency, three semaphores: zero releases even or odd | |
| 1117 | Building H2O | C++ Python | O(n) | O(1) | Hard | concurrency, two semaphores sized 2 (H) and 1 (O), barrier per molecule, linkedin |
|
| 1188 | Design Bounded Blocking Queue | C++ Python | O(1) per op | O(k) | Medium | concurrency, 🔒, BlockingQueue with a Condition, or two counting semaphores, producer-consumer, google, amazon, apple, microsoft, uber, linkedin |
|
| 1195 | Fizz Buzz Multithreaded | C++ Python | O(n) | O(1) | Medium | concurrency, four semaphores, one per printer, LC 412, apple, microsoft |
|
| 1226 | The Dining Philosophers | C++ Python | O(n) | O(1) | Medium | concurrency, resource ordering, or allow at most 4 diners, deadlock avoidance, google, apple |
|
| 1242 | Web Crawler Multithreaded | C++ Python | O(|V| + |E|) | O(|V|) | Medium | concurrency, 🔒, BFS, DFS, thread pool, fb, microsoft |
|
| 1279 | Traffic Light Controlled Intersection | C++ Python | O(n) | O(1) | Easy | concurrency, 🔒, single lock guarding the shared green-light state |
SQL
| # | Title | Solution | Time | Space | Difficulty | Note | Status |
|---|---|---|---|---|---|---|---|
| 0175 | Combine Two Tables | MySQL | O(m + n) | O(m + n) | Easy | sql, left join on two tables, good basic, google, amazon, fb, apple |
OK (4) |
| 0176 | Second Highest Salary | MySQL | O(n) | O(1) | Easy | sql, amazon, fb, google, apple, microsoft |
OK (4) |
| 0177 | Nth Highest Salary | MySQL | O(n^2) | O(n) | Medium | sql, MySQL PROCEDURE, SQL FAQ, google, amazon, fb, apple, uber |
AGAIN*** (3) |
| 0178 | Rank Scores | MySQL | O(n^2) | O(n) | Medium | sql, trick, SQL var, ank, select same table, rank, amazon, fb, apple |
AGAIN****** (7) |
| 0180 | Consecutive Numbers | MySQL | O(n) | O(n) | Medium | sql, SQL var, join same table multi times, amazon |
OK* (3) |
| 0181 | Employees Earning More Than Their Managers | MySQL | O(n^2) | O(1) | Easy | sql, self join on manager id, good basic, google, amazon, fb, apple |
OK |
| 0182 | Duplicate Emails | MySQL | O(n^2) | O(n) | Easy | sql, group by + having count > 1, good basic |
OK |
| 0183 | Customers Who Never Order | MySQL | O(n^2) | O(1) | Easy | sql, left join, amazon |
OK** (3) (but again) |
| 0184 | Department Highest Salary | MySQL | O(n^2) | O(n) | Medium | sql, trick, where, good basic, amazon, fb, apple, microsoft |
OK***** (but again) (6) |
| 0185 | Department Top Three Salaries | MySQL | O(n^2) | O(n) | Hard | sql, similiar as # 0177 Nth Highest Salary, good trick, top N in group, google, amazon, uber, netflix |
AGAIN******** (5) |
| 0196 | Delete Duplicate Emails | MySQL | O(n^2) | O(n) | Easy | sql, DELETE with self join, good basic, SQL FAQ, amazon, fb |
AGAIN (2) |
| 0197 | Rising Temperature | MySQL | O(n^2) | O(n) | Easy | sql, self join on date - 1, or LAG window function, amazon |
OK |
| 0262 | Trips and Users | MySQL | O((t * u) + tlogt) | O(t) | Hard | sql, case condisions, amazon, fb, uber |
OK* (2) |
| 0511 | Game Play Analysis I | MySQL | O(n) | O(n) | Easy | sql, 🔒, amazon |
OK |
| 0512 | Game Play Analysis II | MySQL | O(n) | O(n) | Easy | sql, 🔒, 2 col where good trick |
AGAIN**(4) |
| 0534 | Game Play Analysis III | MySQL | O(nlogn) | O(n) | Medium | sql, 🔒, SQL var, tricky, window func |
AGAIN******** (6) |
| 0550 | Game Play Analysis IV | MySQL | O(n) | O(n) | Medium | sql, case, fraction, join, good basic, where min condition | OK*********** (7) (but again) |
| 0569 | Median Employee Salary | MySQL | O(n) | O(n) | Medium | sql, medium number, google |
AGAIN* (not start) |
| 0571 | Find Median Given Frequency of Numbers | MySQL | O(n) | O(n) | Medium | sql, medium number | AGAIN** (not start) (2) |
| 0577 | Employee Bonus | MySQL | O(n) | O(n) | Easy | sql, left join + where is null or condition, good basic |
OK |
| 0578 | Get Highest Answer Rate Question | MySQL | O(m + n) | O(n) | Medium | sql, fb, case condition |
OK* (3) |
| 0579 | Find Cumulative Salary of an Employee | MySQL | O(n^2) | O(n) | Hard | sql, window function, amazon, good trick |
OK***** (5)(but again) |
| 0580 | Count Student Number in Departments | MySQL | O(m + n) | O(n) | Medium | sql, 🔒, left join + group by, count students per department | OK*** (2) (but again) |
| 0595 | Big Countries | MySQL | O(n) | O(n) | Easy | sql, simple where with an OR condition, basic, google, bloomberg |
OK |
| 0597 | Friend Requests I: Overall Acceptance Rate | MySQL | O(n) | O(n) | Medium | sql, select distinct, ifnull, fb |
OK*** (7) |
| 0601 | Human Traffic of Stadium | MySQL | O(n) | O(n) | Hard | sql, consecutive nums, amazon |
OK* (1) |
| 0602 | Friend Requests II: Who Has Most Friend? | MySQL | O(n) | O(n) | Medium | sql, union all, fb, amazon |
OK*** (4) |
| 0603 | Consecutive Available Seats | MySQL | O(n^2) | O(n) | Medium | sql, consecutive nums, good basic, cross join, amazon |
OK***** (3)(but again) |
| 0618 | Students Report By Geography | MySQL | O(nlogn) | O(n) | Hard | sql, sql var, amazon |
AGAIN (not start) |
| 0620 | Not Boring Movies | MySQL | O(n) | O(n) | Easy | sql, simple where + order by, basic |
OK |
| 0626 | Exchange Seats | MySQL | O(n) | O(n) | Medium | sql, CASE on id parity, count total rows, good trick, amazon |
AGAIN (not start) |
| 0627 | Swap Salary | MySQL | O(n) | O(n) | Easy | sql, UPDATE with CASE, good basic, amazon |
OK* (1) (but again) |
| 1045 | Customers Who Bought All Products | MySQL | O(n + k) | O(n + k) | Medium | sql, 🔒, where with count, amazon |
OK*** (4) |
| 1050 | Actors and Directors Who Cooperated At Least Three Times | MySQL | O(n) | O(n) | Easy | sql, 🔒, amazon |
OK |
| 1068 | Product Sales Analysis I | MySQL | O(m + n) | O(m + n) | Easy | sql, 🔒, amazon |
OK |
| 1069 | Product Sales Analysis II | MySQL | O(n) | O(n) | Easy | sql, 🔒, amazon |
OK |
| 1070 | Product Sales Analysis III | MySQL | O(n) | O(n) | Medium | sql, 🔒, amazon |
OK |
| 1075 | Project Employees I | MySQL | O(m + n) | O(m + n) | Easy | sql, 🔒, fb |
OK |
| 1076 | Project Employees II | MySQL | O(n) | O(n) | Easy | sql, 🔒, fb |
OK (2) |
| 1077 | Project Employees III | MySQL | O((m + n)^2) | O(m + n) | Medium | sql, 🔒, tricky where, fb |
OK***** (2) (but again) |
| 1082 | Sales Analysis I | MySQL | O(n) | O(n) | Easy | sql, 🔒, group by only 1 col, good basic, amazon |
OK***** (5) (again) |
| 1083 | Sales Analysis II | MySQL | O(m + n) | O(m + n) | Easy | sql, 🔒, not in, amazon |
OK*** (3) (again) |
| 1084 | Sales Analysis III | MySQL | O(m + n) | O(m + n) | Easy | sql, 🔒, amazon |
OK** (2) |
| 1097 | Game Play Analysis V | MySQL | O(n^2) | O(n) | Hard | sql, 🔒, good basic, retention, case condition, data_add, left join |
AGAIN******* (8) |
| 1098 | Unpopular Books | MySQL | O(m + n) | O(n) | Medium | sql, 🔒, where not in, amazon |
OK* (2) |
| 1107 | New Users Daily Count | MySQL | O(n) | O(n) | Medium | sql, 🔒, amazon, linkedin |
OK* |
| 1112 | Highest Grade For Each Student | MySQL | O(nlogn) | O(n) | Medium | sql, 🔒, good basic | OK** (4) |
| 1113 | Reported Posts | MySQL | O(n) | O(n) | Easy | sql, 🔒, fb |
OK |
| 1126 | Active Businesses | MySQL | O(n) | O(n) | Medium | sql, 🔒, good basic |
AGAIN*** (3) |
| 1127 | User Purchase Platform | MySQL | O(n) | O(n) | Hard | sql, 🔒, complex, union all, case, linkedin |
OK**** (6) (but again) |
| 1132 | Reported Posts II | MySQL | O(m + n) | O(n) | Medium | sql, 🔒, fb |
OK*** (4) |
| 1141 | User Activity for the Past 30 Days I | MySQL | O(n) | O(n) | Easy | sql, 🔒, fb |
AGAIN* (2) |
| 1142 | User Activity for the Past 30 Days II | MySQL | O(n) | O(n) | Easy | sql, 🔒, fb |
AGAIN* (1) |
| 1148 | Article Views I | MySQL | O(nlogn) | O(n) | Easy | sql, 🔒, linkedin |
OK |
| 1149 | Article Views II | MySQL | O(nlogn) | O(n) | Medium | sql, 🔒, amazon, linkedin |
OK* |
| 1158 | Market Analysis I | MySQL | O(m + n) | O(m + n) | Medium | sql, 🔒, case when ... is not null |
AGAIN**** (5) |
| 1159 | Market Analysis II | MySQL | O(m + n) | O(m + n) | Hard | sql, 🔒, good trick | AGAIN** (3) |
| 1164 | Product Price at a Given Date | MySQL | O(mlogn) | O(m) | Medium | sql, 🔒, good trick, union, case, not in a period, amazon |
AGAIN******** (2) |
| 1173 | Immediate Food Delivery I | MySQL | O(n) | O(1) | Easy | sql, 🔒 | OK |
| 1174 | Immediate Food Delivery II | MySQL | O(n) | O(m) | Medium | sql, 🔒 | OK**** (3) |
| 1179 | Reformat Department Table | MySQL | O(n) | O(n) | Easy | sql, 🔒, amazon, apple |
OK |
| 1193 | Monthly Transactions I | MySQL | O(n) | O(n) | Medium | sql, 🔒 | OK (2) |
| 1194 | Tournament Winners | MySQL | O(m + n + nlogn) | O(m + n) | Hard | sql, 🔒 | AGAIN* |
| 1204 | Last Person to Fit in the Elevator | MySQL | O(nlogn) | O(n) | Medium | sql, 🔒, cumsum, window func, good basic | OK****** (3) |
| 1205 | Monthly Transactions II | MySQL | O(n) | O(n) | Medium | sql, 🔒, good trick, union all, case conditions | OK*** (3) (but again) |
| 1211 | Queries Quality and Percentage | MySQL | O(n) | O(n) | Easy | sql, avg with CASE, round, good basic, fb |
OK |
| 1212 | Team Scores in Football Tournament | MySQL | O(nlogn) | O(n) | Medium | sql, good trick | OK** (2) |
| 1225 | Report Contiguous Dates | MySQL | O(nlogn) | O(n) | Hard | sql, 🔒, amazon, fb |
AGAIN* (2) (not start) |
| 1241 | Number of Comments per Post | MySQL | O(n) | O(n) | Easy | sql, 🔒, good basic, fb |
OK**** (5) (but again) |
| 1251 | Average Selling Price | MySQL | O(n) | O(n) | Easy | sql, 🔒, good basic, amazon |
OK*** (but again) (3) |
| 1264 | Page Recommendations | MySQL | O(m + n) | O(m) | Medium | sql, 🔒, fb |
OK** (2) |
| 1270 | All People Report to the Given Manager | MySQL | O(n) | O(n) | Medium | sql, 🔒, good basic, google, amazon |
OK* (3) |
| 1280 | Students and Examinations | MySQL | O((m * n) * log(m * n)) | O(m * n) | Easy | sql, 🔒 | OK (1) |
| 1285 | Find the Start and End Number of Continuous Ranges | MySQL | O(n) | O(n) | Medium | sql, 🔒, variable, amazon |
AGAIN (not start) (1) |
| 1294 | Weather Type in Each Country | MySQL | O(m + n) | O(n) | Easy | sql, 🔒 | OK (1) |
| 1303 | Find the Team Size | MySQL | O(n) | O(n) | Easy | sql, 🔒, amazon |
ok (1) |
| 1308 | Running Total for Different Genders | MySQL | O(nlogn) | O(n) | Medium | sql, 🔒, good basic, union all, window func | OK**** (3) |
| 1321 | Restaurant Growth | MySQL | O(n^2) | O(n) | Medium | sql, 🔒, good basic, trick, amazon |
AGAIN***** (3) |
| 1322 | Ads Performance | MySQL | O(nlogn) | O(n) | Easy | sql, 🔒, good basic, fb |
OK******* (3) (but again) |
| 1327 | List the Products Ordered in a Period | MySQL | O(n) | O(n) | Easy | sql, 🔒, amazon |
OK |
| 1336 | Number of Transactions per Visit | MySQL | O(m + n) | O(m + n) | Medium | sql, 🔒, complex, variable | AGAIN (not start) |
| 1341 | Movie Rating | MySQL | O(nlogn) | O(n) | Medium | sql, 🔒 | AGAIN (not start) |
| 1350 | Students With Invalid Departments | MySQL | O(n) | O(n) | Easy | sql, 🔒, amazon |
OK |
| 1355 | Activity Participants | MySQL | O(n) | O(n) | Medium | sql, 🔒 | OK |
| 1364 | Number of Trusted Contacts of a Customer | MySQL | O(n + m + l + nlogn) | O(n + m + l) | Medium | sql, 🔒 | OK |
| 1369 | Get the Second Most Recent Activity | MySQL | O(nlogn) | O(n) | Hard | sql, 🔒, union, having | OK** (2) (but again) |
| 1378 | Replace Employee ID With The Unique Identifier | MySQL | O(n) | O(n) | Easy | sql, 🔒 | OK |
| 1384 | Total Sales Amount by Year | MySQL | O(nlogn) | O(n) | Hard | sql, 🔒, complex | OK* |
| 1393 | Capital Gain/Loss | MySQL | O(n) | O(n) | Medium | sql, 🔒 | OK |
| 1398 | Customers Who Bought Products A and B but Not C | MySQL | O(m + n) | O(m + n) | Medium | sql, 🔒, amazon, fb |
OK |
| 1407 | Top Travellers | MySQL | O(m + nlogn) | O(m + n) | Easy | sql, 🔒, ifnull | OK* |
| 1412 | Find the Quiet Students in All Exams | MySQL | O(m + nlogn) | O(m + n) | Hard | sql, 🔒, good trick, not in, inner join on multiple cols | OK**** (3) (but again) |
| 1421 | NPV Queries | MySQL | O(n) | O(n) | Medium | sql, 🔒, amazon |
OK |
| 1435 | Create a Session Bar Chart | MySQL | O(n) | O(1) | Easy | sql, 🔒 | OK |
| 1440 | Evaluate Boolean Expression | MySQL | O(n) | O(n) | Medium | sql, 🔒 | OK |
| 1445 | Apples & Oranges | MySQL | O(n) | O(n) | Medium | sql, 🔒, fb |
OK |
| 1454 | Active Users | MySQL | O(nlogn) | O(n) | Medium | sql, 🔒, good basic, window func, amazon |
AGAIN*** (2) |
| 1459 | Rectangles Area | MySQL | O(n^2) | O(n^2) | Medium | sql, 🔒 | OK* |
| 1468 | Calculate Salaries | MySQL | O(m + n) | O(m + n) | Easy | sql, 🔒 | OK* |
| 1479 | Sales by Day of the Week | MySQL | O(m + n) | O(n) | Hard | sql, 🔒, case, DAYOFWEEK, amazon |
OK |
| 1484 | Group Sold Products By The Date | MySQL | O(nlogn) | O(n) | Easy | sql, 🔒, GROUP_CONCAT |
OK* |
| 1495 | Friendly Movies Streamed Last Month | MySQL | O(n) | O(n) | Easy | sql, 🔒, amazon |
OK |
| 1501 | Countries You Can Safely Invest In | MySQL | O(n) | O(n) | Medium | sql, 🔒, good trick, group avg, global avg, SUBSTRING, inner join on or conditions |
OK****** (4) |
| 1511 | Customer Order Frequency | MySQL | O(n) | O(n) | Easy | sql, 🔒, having, like, amazon, fb |
OK* (1) |
| 1517 | Find Users With Valid E-Mails | MySQL | O(n) | O(n) | Easy | sql, 🔒, regular expression, apple |
AGAIN |
| 1527 | Patients With a Condition | MySQL | O(n) | O(n) | Easy | sql, 🔒 | OK |
| 1532 | The Most Recent Three Orders | MySQL | O(nlogn) | O(n) | Medium | sql, 🔒, window func, good basic | OK** (2) (but again) |
| 1543 | Fix Product Name Format | MySQL | O(nlogn) | O(n) | Easy | sql, 🔒, trim | OK |
| 1549 | The Most Recent Orders for Each Product | MySQL | O(nlogn) | O(n) | Medium | sql, 🔒, max day per id, good basic | OK* (again) |
| 1555 | Bank Account Summary | MySQL | O(m + n) | O(m + n) | Medium | sql, 🔒, union all, good trick | OK**** (2)(but again) |
| 1565 | Unique Orders and Customers Per Month | MySQL | O(n) | O(n) | Easy | sql, 🔒 | OK |
| 1571 | Warehouse Manager | MySQL | O(n) | O(n) | Medium | sql, 🔒, amazon |
OK* (1) |
| 1581 | Customer Who Visited but Did Not Make Any Transactions | MySQL | O(n) | O(n) | Easy | sql, 🔒, left join, good basic | OK** (2)(but again) |
| 1587 | Bank Account Summary II | MySQL | O(m + n) | O(m + n) | Easy | sql, 🔒 | OK |
| 1596 | The Most Frequently Ordered Products for Each Customer | MySQL | O(n) | O(n) | Medium | sql, 🔒, good trick, rank() ORDER BY count, get max in each group, amazon |
OK********* (3)(but again) |
| 1607 | Sellers With No Sales | MySQL | O(nlogm) | O(n + m) | Medium | sql, 🔒 | OK |
| 1613 | Find the Missing IDs | MySQL | O(n^2) | O(n) | Medium | sql, 🔒, RECURSIVE CTE, good trick, amazon |
AGAIN*** (2) |
| 1623 | All Valid Triplets That Can Represent a Country | MySQL | O(n^3) | O(n^3) | Easy | sql, 🔒, <>, amazon |
AGAIN* (not start) |
| 1633 | Percentage of Users Attended a Contest | MySQL | O(m + nlogn) | O(n) | Easy | sql, 🔒 | OK |
| 1635 | Hopper Company Queries I | MySQL | O(d + r + tlogt) | O(d + r + t) | Hard | sql, 🔒, complex, uber |
AGAIN (not start) |
| 1645 | Hopper Company Queries II | MySQL | O(d + r + tlogt) | O(d + r + t) | Hard | sql, 🔒, complex, uber |
AGAIN (not start) |
| 1651 | Hopper Company Queries III | MySQL | O(d + r + tlogt) | O(d + r + t) | Hard | sql, 🔒, complex, uber |
AGAIN (not start) |
| 1661 | Average Time of Process per Machine | MySQL | O(n) | O(n) | Easy | sql, 🔒, good basic, amazon, fb |
OK* (1) |
| 1667 | Fix Names in a Table | MySQL | O(nlogn) | O(n) | Easy | sql, 🔒, concat, sub-string | OK (1) |
| 1677 | Product’s Worth Over Invoices | MySQL | O(nlogn) | O(n) | Easy | sql, 🔒 | OK |
| 1683 | Invalid Tweets | MySQL | O(n) | O(n) | Easy | sql, 🔒 | OK |
| 1693 | Daily Leads and Partners | MySQL | O(n) | O(n) | Easy | sql, 🔒 | OK |
| 1699 | Number of Calls Between Two Persons | MySQL | O(n) | O(n) | Medium | sql, 🔒, cte, union all, amazon, fb |
OK* (1)(but again) |
| 1709 | Biggest Window Between Visits | MySQL | O(nlogn) | O(n) | Medium | sql, 🔒, window func, datediff, coalesce, good trick | AGAIN***** (2) |
| 1715 | Count Apples and Oranges | MySQL | O(n) | O(n) | Medium | sql, 🔒, ifnull | OK (2) |
| 1729 | Find Followers Count | MySQL | O(nlogn) | O(n) | Easy | sql, 🔒 | OK |
| 1731 | The Number of Employees Which Report to Each Employee | MySQL | O(nlogn) | O(n) | Easy | sql, 🔒 | OK |
| 1741 | Find Total Time Spent by Each Employee | MySQL | O(nlogn) | O(n) | Easy | sql, 🔒, amazon |
OK |
| 1747 | Leetflex Banned Accounts | MySQL | O(n^2) | O(n) | Medium | sql, 🔒 | OK (2) (but again) |
| 1757 | Recyclable and Low Fat Products | MySQL | O(n) | O(n) | Easy | sql, 🔒, fb |
OK |
| 1767 | Find the Subtasks That Did Not Execute | MySQL | O(n * c) | O(n * c) | Hard | sql, 🔒, RECURSIVE CTE, google |
AGAIN (not start) |
| 1777 | Product’s Price for Each Store | MySQL | O(n) | O(n) | Easy | sql, 🔒, amazon |
OK (2) |
| 1783 | Grand Slam Titles | MySQL | O(n) | O(n) | Medium | sql, 🔒, union all, good basic, amazon |
OK* (1) (but again) |
| 1789 | Primary Department for Each Employee | MySQL | O(n) | O(n) | Easy | sql, 🔒, where id in | OK (1) (but again) |
| 1795 | Rearrange Products Table | MySQL | O(n) | O(n) | Easy | sql, 🔒, union all, good basic, amazon |
OK****** (2) |
| 1809 | Ad-Free Sessions | MySQL | O(n) | O(n) | Easy | sql, 🔒, left join where col is null, amazon |
OK**** (3)(but again) |
| 1811 | Find Interview Candidates | MySQL | O(nlogn) | O(n) | Medium | sql, 🔒, union all, cte, where, good basic, amazon |
AGAIN* (2) |
| 1821 | Find Customers With Positive Revenue this Year | MySQL | O(n) | O(n) | Easy | sql, 🔒, google |
OK |
| 1831 | Maximum Transaction Each Day | MySQL | O(nlogn) | O(n) | Medium | sql, 🔒, rank(), where on 2 attr, good basic | AGAIN**** (2) |
| 1841 | League Statistics | MySQL | O(nlogn) | O(n) | Medium | sql, 🔒, case, complex | AGAIN* (2) |
| 1843 | Suspicious Bank Accounts | MySQL | O(nlogn) | O(n) | Medium | sql, 🔒, good trick, window func | OK** (2) (but AGAIN) |
| 1853 | Convert Date Format | MySQL | O(n) | O(n) | Easy | sql, 🔒 | OK |
| 1867 | Orders With Maximum Quantity Above Average | MySQL | O(n) | O(n) | Easy | sql, 🔒 | OK (1) |
| 1873 | Calculate Special Bonus | MySQL | O(n) | O(n) | Easy | sql, 🔒, left, odd num | OK (2) |
| 1875 | Group Employees of the Same Salary | MySQL | O(nlogn) | O(n) | Medium | sql, 🔒, complex, good basic | AGAIN* (1) |
| 1890 | The Latest Login in 2020 | MySQL | O(n) | O(n) | Easy | sql, 🔒 | OK |
| 1892 | Page Recommendations II | MySQL | O(n * m) | O(n * m) | Hard | sql, 🔒, join on friendship + page likes, not in, fb |
AGAIN*** (1) (not start) |
| 1907 | Count Salary Categories | MySQL | O(n) | O(n) | Medium | sql, 🔒, union all | OK* (1) |
| 1917 | Leetcodify Friends Recommendations | MySQL | O(n^2) | O(n^2) | Hard | sql, 🔒, NOT EXISTS |
AGAIN*** (2) |
| 1919 | Leetcodify Similar Friends | MySQL | O(n * l) | O(n * l) | Hard | sql, 🔒 | AGAIN* (not start) |
| 1934 | Confirmation Rate | MySQL | O(n + m) | O(n + m) | Medium | sql, 🔒, good basic | OK* (1) (but again) |
| 1939 | Users That Actively Request Confirmation Messages | MySQL | O(nlogn) | O(n) | Easy | sql, 🔒, TIMESTAMPDIFF, good basic | OK*** (2) (but again) |
| 1949 | Strong Friendship | MySQL | O(n^3) | O(n^2) | Medium | sql, 🔒, good basic, self join, where on 2 cols, fb |
OK* (2) (but again) |
| 1951 | All the Pairs With the Maximum Number of Common Followers | MySQL | O(n^3) | O(n^2) | Medium | sql, 🔒, good trick | AGAIN* (2) |
| 1965 | Employees With Missing Information | MySQL | O(nlogn) | O(n) | Easy | sql, 🔒, good basic | OK* (1) (but again) |
| 1972 | First and Last Call On the Same Day | MySQL | O(n) | O(n) | Hard | sql, 🔒, rank, union all, amazon |
AGAIN** (2) |
| 1978 | Employees Whose Manager Left the Company | MySQL | O(nlogn) | O(n) | Easy | sql, 🔒 | OK (1) |
| 1988 | Find Cutoff Score for Each School | MySQL | O(n * m) | O(n * m) | Medium | sql, 🔒, no ref | AGAIN (not start) |
| 1990 | Count the Number of Experiments | MySQL | O(n) | O(n) | Easy | sql, 🔒, cross join | AGAIN* (1) |
| 2004 | The Number of Seniors and Juniors to Join the Company | MySQL | O(nlogn) | O(n) | Hard | sql, 🔒, not ref | AGAIN (not start) |
Shell Script
| # | Title | Solution | Time | Space | Difficulty | Note | Status |
|---|---|---|---|---|---|---|---|
| 0192 | Word Frequency | Shell | O(n) | O(k) | Medium | shell, awk word count then sort by frequency, good basic, google, amazon, fb, apple |
|
| 0193 | Valid Phone Numbers | Shell | O(n) | O(1) | Easy | shell, grep with a regular expression, basic, amazon, apple, uber |
|
| 0194 | Transpose File | Shell | O(n^2) | O(n^2) | Medium | shell, awk transpose with a 2D array, good trick |
|
| 0195 | Tenth Line | Shell | O(n) | O(1) | Easy | shell, sed / awk NR == 10, basic, google, apple |
Newly Added (kamyu104 gap)
Problems imported from the coverage audit against kamyu104/LeetCode-Solutions.
These solutions were generated from the problem statements and have not been run against LeetCode’s judge. Treat them as drafts to review, not as verified-accepted answers.
Ranges covered so far: 0001-1000 (127 problems) and 1001-3687 (1855 problems) — 1982 in total.
Array
| # | Title | Solution | Time | Space | Difficulty | Note | Status |
|---|---|---|---|---|---|---|---|
| 0158 | Read N Characters Given read4 II - Call Multiple Times | Python, Java | O(n) per read | O(1) | Hard | array, 🔒, LC 157, carry the read4 buffer across calls, good trick, google, fb, new, amazon, apple, microsoft, uber, bloomberg |
|
| 0296 | Best Meeting Point | Python, Java | O(m * n) | O(m + n) | Hard | array, 🔒, median of the row and column coordinates, Manhattan distance, math, good trick, new, google, amazon, fb, linkedin |
|
| 0485 | Max Consecutive Ones | Python, Java | O(n) | O(1) | Easy | array, running count of consecutive 1s, LC 487, LC 1004, basic, new, google, amazon, fb, apple, microsoft |
|
| 0487 | Max Consecutive Ones II | Python, Java | O(n) | O(1) | Medium | array, 🔒, sliding window allowing one flip, LC 1004, good basic, new, google, amazon, fb, microsoft |
|
| 0495 | Teemo Attacking | Python, Java | O(n) | O(1) | Easy | array, sum of min(duration, gap), interval merge, basic, new |
|
| 0644 | Maximum Average Subarray II | Python, Java | O(n * log((max - min) / eps)) | O(1) | Hard | array, 🔒, binary search on the real-valued average + prefix sum, LC 643, good trick, new, google |
|
| 0732 | My Calendar III | Python, Java | O(nlogn) per book | O(n) | Hard | array, LC 729, LC 731, sweep line over a TreeMap of deltas, segment tree, good trick, new, binary search, design, google, amazon, fb, apple |
|
| 0803 | Bricks Falling When Hit | Python, Java | O((m * n + h) * a(m * n)) | O(m * n) | Hard | array, reverse thinking, union find with a virtual roof node, LC 200, complex, new, google |
|
| 0927 | Three Equal Parts | Python, Java | O(n) | O(1) | Hard | array, count the ones then match the suffix blocks, good trick, new |
|
| 0952 | Largest Component Size by Common Factor | Python, Java | O(n * sqrt(M) * a(M)) | O(M) | Hard | array, union find over prime factors, sieve, complex, new, google |
|
| 0985 | Sum of Even Numbers After Queries | Python, Java | O(n + m) | O(1) excluding output | Medium | array, maintain a running even-sum and apply deltas, good basic, new |
|
| 0999 | Available Captures for Rook | Python, Java | O(m * n) | O(1) | Easy | array, scan the 4 directions from the rook, matrix, basic, new |
|
| 1002 | Find Common Characters | Python | O(n * L), n = len(words), L = avg word length | O(1), at most 26 letters | Easy | array, COUNTER + take the MIN count of each char over all words, new, google, amazon, fb, apple, uber |
|
| 1013 | Partition Array Into Three Parts With Equal Sum | Python | O(n) | O(1) | Easy | array, PREFIX SUM + GREEDY, new, amazon, microsoft |
|
| 1018 | Binary Prefix Divisible By 5 | Python | O(n) | O(1), excluding the output | Easy | array, RUNNING REMAINDER (mod 5), new | |
| 1030 | Matrix Cells in Distance Order | Python | O(m * n * log(m * n)) | O(m * n) | Easy | array, SORT BY MANHATTAN DISTANCE, new | |
| 1051 | Height Checker | Python | O(n log n) | O(n) | Easy | array, SORT A COPY + COMPARE INDEX BY INDEX, new, amazon, apple |
|
| 1052 | Grumpy Bookstore Owner | Python | O(n) | O(1) | Medium | array, FIXED-SIZE SLIDING WINDOW, new, uber |
|
| 1072 | Flip Columns For Maximum Number of Equal Rows | Python | O(m * n) | O(m * n) | Medium | array, HASH MAP + row “normalization”, new | |
| 1085 | Sum of Digits in the Minimum Number | Python | O(n) | O(1) | Easy | array, 🔒, find min, sum its digits, return the INVERTED parity, new, amazon |
|
| 1093 | Statistics from a Large Sample | Python | O(256) | O(1) | Medium | array, COUNTING ARRAY (bucket) + prefix walk for the median, new, microsoft |
|
| 1144 | Decrease Elements To Make Array Zigzag | Python | O(n) | O(1) | Medium | array, GREEDY + ENUMERATE THE 2 PARITIES, new, google |
|
| 1184 | Distance Between Bus Stops | Python | O(n) | O(1) | Easy | array, PREFIX SUM on a circle (one arc + its complement), new, google |
|
| 1200 | Minimum Absolute Difference | Python | O(n log n) | O(n) | Easy | array, SORT + ADJACENT PAIRS, new, google, amazon, uber |
|
| 1222 | Queens That Can Attack the King | Python | O(8 * 8) | O(n) | Medium | array, SIMULATION / RAY CASTING FROM THE KING, new, amazon, microsoft |
|
| 1252 | Cells with Odd Values in a Matrix | Python | O(m + n + k), k = len(indices) | O(m + n) | Easy | array, COUNT ROWS / COLS ONLY + PARITY MATH, new, google |
|
| 1260 | Shift 2D Grid | Python | O(m * n) | O(m * n) | Easy | array, FLATTEN THE GRID + INDEX MATH, new, amazon |
|
| 1267 | Count Servers that Communicate | Python | O(m * n) | O(m + n) | Medium | array, COUNTING (row count + col count), new, google, microsoft |
|
| 1295 | Find Numbers with Even Number of Digits | Python | O(n log M), M = max(nums) | O(log M) | Easy | array, cast to STRING and check the length parity, new, amazon |
|
| 1304 | Find N Unique Integers Sum up to Zero | Python | O(n) | O(n) | Easy | array, MATH (emit symmetric +/- pairs, plus a lone 0 when n is odd), new, amazon, apple, microsoft |
|
| 1313 | Decompress Run-Length Encoded List | Python | O(n + k), k = total output length | O(1) extra, excluding the output list | Easy | array, simulation, walk the array 2 elements at a time, new, google, amazon, apple |
|
| 1333 | Filter Restaurants by Vegan-Friendly, Price and Distance | Python | O(n + k log k) | O(k) (k = number of survivors) | Medium | array, FILTER + SORT (by (-rating, -id)), new, amazon |
|
| 1337 | The K Weakest Rows in a Matrix | Python | O(m log n + m log m) | O(m) | Easy | array, BINARY SEARCH (count 1’s per row) + SORT by (count, idx), new, amazon |
|
| 1343 | Number of Sub-arrays of Size K and Average Greater than or Equal to Threshold | Python | O(n) | O(1) | Medium | array, SLIDING WINDOW (fixed size k), new | |
| 1346 | Check If N and Its Double Exist | Python | O(n) | O(n) | Easy | array, HASH SET (one pass), new, google, apple |
|
| 1351 | Count Negative Numbers in a Sorted Matrix | Python | O(m + n) | O(1) | Easy | array, STAIRCASE SEARCH from the bottom-left corner, new, amazon, fb, apple, microsoft |
|
| 1389 | Create Target Array in the Given Order | Python | O(n^2) | O(n) | Easy | array, DIRECT SIMULATION (list.insert already does the shifting), new, amazon, apple |
|
| 1394 | Find Lucky Integer in an Array | Python | O(n) | O(n) | Easy | array, COUNTING (a value is lucky when count == value), new | |
| 1399 | Count Largest Group | Python | O(n * log n) | O(log n) | Easy | array, COUNTING BY DIGIT SUM (bucket key = sum of digits), new | |
| 1404 | Number of Steps to Reduce a Number in Binary Representation to One | Python | O(n) | O(1) | Medium | array, BIT SIMULATION (carry), scan from the LSB, new, amazon |
|
| 1413 | Minimum Value to Get Positive Step by Step Sum | Python | O(n) | O(1) | Easy | array, PREFIX SUM, new | |
| 1426 | Counting Elements | Python | O(n) | O(n) | Easy | array, 🔒, HASH TABLE (counter), new | |
| 1427 | Perform String Shifts | Python | O(n + m) | O(n) | Easy | array, 🔒, MATH (collapse all shifts into ONE net left-shift), new | |
| 1428 | Leftmost Column with at Least a One | Python | O(m + n) | O(1) | Medium | array, 🔒, STAIRCASE SEARCH (start from TOP-RIGHT corner), new, fb, uber |
|
| 1437 | Check If All 1’s Are at Least Length K Places Away | Python | O(n) | O(1) | Easy | array, ONE PASS, TRACK PREVIOUS 1 INDEX, new | |
| 1450 | Number of Students Doing Homework at a Given Time | Python | O(n) | O(1) | Easy | array, LINEAR SCAN, count intervals covering queryTime, new | |
| 1460 | Make Two Arrays Equal by Reversing Sub-arrays | Python | O(n) | O(n) | Easy | array, MULTISET EQUALITY (reversals generate every permutation), new, fb |
|
| 1464 | Maximum Product of Two Elements in an Array | Python | O(n) | O(1) | Easy | array, TRACK THE TWO LARGEST VALUES (all values are positive), new, fb |
|
| 1465 | Maximum Area of a Piece of Cake After Horizontal and Vertical Cuts | Python | O(m log m + n log n) | O(m + n) | Medium | array, SORT + LARGEST GAP (height and width are independent), new, amazon |
|
| 1471 | The k Strongest Values in an Array | Python | O(n log n) | O(n) | Medium | array, SORT TWICE (find the centre, then rank by the custom “strength”), new, google |
|
| 1475 | Final Prices With a Special Discount in a Shop | Python | O(n) | O(n) | Easy | array, MONOTONIC STACK (“next smaller OR equal element to the right”), new, amazon, uber |
|
| 1480 | Running Sum of 1d Array | Python | O(n) | O(1) | Easy | array, PREFIX SUM IN PLACE, new, google, amazon, apple, microsoft, uber |
|
| 1491 | Average Salary Excluding the Minimum and Maximum Salary | Python | O(n) | O(1) | Easy | array, SUM MINUS THE EXTREMES (no sorting needed), new, amazon |
|
| 1502 | Can Make Arithmetic Progression From Sequence | Python | O(n log n) | O(n) | Easy | array, SORT + CHECK ADJACENT DIFF, new, amazon |
|
| 1503 | Last Moment Before All Ants Fall Out of a Plank | Python | O(n) | O(1) | Medium | array, BRAIN TEASER, new, google |
|
| 1534 | Count Good Triplets | Python | O(n^3) | O(1) | Easy | array, BRUTE FORCE ENUMERATION WITH EARLY PRUNING, new, google, amazon, apple |
|
| 1535 | Find the Winner of an Array Game | Python | O(n) | O(1) | Medium | array, ONE LINEAR SWEEP (no queue simulation needed), new | |
| 1538 | Guess the Majority in a Hidden Array | Python | O(n) calls | O(1) | Medium | array, 🔒, COMPARE EVERY INDEX AGAINST A FIXED REFERENCE INDEX, new, google |
|
| 1550 | Three Consecutive Odds | Python | O(n) | O(1) | Easy | array, RUNNING STREAK COUNTER, new | |
| 1559 | Detect Cycles in 2D Grid | Python | O(m * n * alpha) | O(m * n) | Medium | array, UNION FIND (an edge joining two already-connected cells closes a cycle), new, amazon, fb |
|
| 1560 | Most Visited Sector in a Circular Track | Python | O(n) | O(n) | Easy | array, MATH (only the first and the last sector matter), new | |
| 1562 | Find Latest Group of Size M | Python | O(n) | O(n) | Medium | array, INTERVAL MERGING (track the length stored at each group’s two ends), new, google |
|
| 1566 | Detect Pattern of Length M Repeated K or More Times | Python | O(n) | O(1) | Easy | array, RUN COUNTING (a period-m repeat means arr[i] == arr[i + m]), new | |
| 1572 | Matrix Diagonal Sum | Python | O(n) | O(1) | Easy | array, ARRAY (walk both diagonals at once, fix the double-counted centre), new, amazon |
|
| 1574 | Shortest Subarray to be Removed to Make Array Sorted | Python | O(n) | O(1) | Medium | array, TWO POINTERS (keep a non-decreasing prefix + a non-decreasing suffix), new, amazon |
|
| 1582 | Special Positions in a Binary Matrix | Python | O(m * n) | O(m + n) | Easy | array, ROW / COLUMN SUMS (a special 1 is alone in both its lines), new, google, uber |
|
| 1583 | Count Unhappy Friends | Python | O(n^2) | O(n^2) | Medium | array, RANK TABLE (O(1) “does a prefer b over c ?” lookups), new | |
| 1619 | Mean of Array After Removing Some Elements | Python | O(n log n) | O(n) for the sorted copy | Easy | array, SORT + TRIM THE TWO TAILS, new, google |
|
| 1629 | Slowest Key | Python | O(n) | O(1) | Easy | array, ONE PASS with a (duration, key) tie-break, new, amazon |
|
| 1646 | Get Maximum in Generated Array | Python | O(n) | O(n) | Easy | array, SIMULATION (build the array left to right, every rule looks back), new | |
| 1652 | Defuse the Bomb | Python | O(n) | O(n) for the output | Easy | array, SLIDING WINDOW over the circular array, new | |
| 1700 | Number of Students Unable to Eat Lunch | Python | O(n) | O(1) | Easy | array, COUNTING (the queue ORDER is irrelevant – only how many of each type), new | |
| 1701 | Average Waiting Time | Python | O(n) | O(1) | Medium | array, SINGLE-SERVER FIFO SIMULATION (track when the chef becomes free), new | |
| 1706 | Where Will the Ball Fall | Python | O(m * n) | O(1) excluding the output | Medium | array, SIMULATION (drop each ball row by row, check the neighbour board), new, google |
|
| 1714 | Sum Of Special Evenly-Spaced Elements In Array | Python | O((n + q) * sqrt(n)) | O(n * sqrt(n)) | Hard | array, 🔒, SQRT DECOMPOSITION (precompute small steps, brute force big steps), new | |
| 1732 | Find the Highest Altitude | Python | O(n) | O(1) | Easy | array, RUNNING PREFIX SUM (gain is a difference array), new, google, apple |
|
| 1738 | Find Kth Largest XOR Coordinate Value | Python | O(m * n * log(m * n)) | O(m * n) for the value list | Medium | array, 2D PREFIX XOR + SORT, new, google |
|
| 1742 | Maximum Number of Balls in a Box | Python | O(n * log10(highLimit)) | O(1) (a 55-slot array) | Easy | array, COUNTING BY DIGIT SUM (the box index space is tiny), new, microsoft |
|
| 1752 | Check if Array Is Sorted and Rotated | Python | O(n) | O(1) | Easy | array, COUNT THE “DROPS” ON THE CIRCULAR ARRAY (a rotation has at most one), new, amazon |
|
| 1755 | Closest Subsequence Sum | Python | O(2^(n/2) * n) | O(2^(n/2)) | Hard | array, MEET IN THE MIDDLE (n <= 40 -> two halves of at most 2^20 subset sums), new | |
| 1773 | Count Items Matching a Rule | Python | O(n) | O(1) | Easy | array, MAP THE RULE KEY TO A COLUMN INDEX, THEN COUNT, new, fb, apple |
|
| 1779 | Find Nearest Point That Has the Same X or Y Coordinate | Python | O(n) | O(1) | Easy | array, SINGLE PASS, KEEP THE BEST VALID POINT, new, amazon |
|
| 1800 | Maximum Ascending Subarray Sum | Python | O(n) | O(1) | Easy | array, RUNNING SUM OF THE CURRENT ASCENDING RUN, new | |
| 1826 | Faulty Sensor | Python | O(n) | O(1) | Easy | array, 🔒, FIRST MISMATCH + TEST BOTH SHIFT HYPOTHESES, new, fb |
|
| 1848 | Minimum Distance to the Target Element | Python | O(n) worst case | O(1) | Easy | array, EXPAND OUTWARD FROM start (first hit is the answer), new | |
| 1861 | Rotating the Box | Python | O(m * n) | O(m * n) for the output | Medium | array, SIMULATE GRAVITY FIRST (in the ORIGINAL frame), THEN ROTATE, new, microsoft, uber |
|
| 1869 | Longer Contiguous Segments of Ones than Zeros | Python | O(n) | O(1) | Easy | array, SINGLE PASS RUN LENGTH (track both runs at once), new, amazon |
|
| 1878 | Get Biggest Three Rhombus Sums in a Grid | Python | O(m * n * K^2), K = min(m, n) / 2 | O(m * n * K) for the set of sums | Medium | array, ENUMERATE (TOP CORNER, HALF-DIAGONAL) AND WALK THE BORDER, new, apple |
|
| 1886 | Determine Whether Matrix Can Be Obtained By Rotation | Python | O(n^2) | O(n^2) | Easy | array, BRUTE FORCE OVER THE 4 ROTATIONS (a 4th rotation is the identity), new, amazon |
|
| 1895 | Largest Magic Square | Python | O(m * n * min(m,n)^2) | O(m * n) | Medium | array, PREFIX SUMS PER ROW / PER COLUMN + SHRINKING BRUTE FORCE, new | |
| 1906 | Minimum Absolute Difference Queries | Python | O(n + q * (B + n / B)) | O(n / B) | Medium | array, EXPLOIT THE TINY VALUE RANGE (nums[i] <= 100), new, google |
|
| 1909 | Remove One Element to Make the Array Strictly Increasing | Python | O(n) | O(1) | Easy | array, GREEDY SCAN (only the FIRST bad pair matters), new, fb |
|
| 1940 | Longest Common Subsequence Between Sorted Arrays | Python | O(N + M), N = total elements, M = 101 | O(M) | Medium | array, 🔒, COUNTING (every row is STRICTLY increasing -> LCS == set intersection), new, google |
|
| 1958 | Check if Move is Legal | Python | O(8 * 8) = O(1) | O(1) | Medium | array, ENUMERATE 8 DIRECTIONS (walk out from the placed cell), new, amazon |
|
| 1966 | Binary Searchable Numbers in an Unsorted Array | Python | O(n) | O(n) | Medium | array, 🔒, PREFIX MAX + SUFFIX MIN, new, google |
|
| 1970 | Last Day Where You Can Still Cross | Python | O(mn * alpha(mn)) | O(m*n) | Hard | array, REVERSE TIME + UNION FIND (flooding is hard to undo, un-flooding is easy), new | |
| 1983 | Widest Pair of Indices With Equal Range Sum | Python | O(n) | O(n) | Medium | array, 🔒, PREFIX SUM OF THE DIFFERENCE + HASH TABLE (longest zero-sum subarray), new | |
| 1992 | Find All Groups of Farmland | Python | O(m * n) | O(1) besides the output | Medium | array, SCAN FOR TOP-LEFT CORNERS, THEN WALK THE RECTANGLE EDGES, new | |
| 1998 | GCD Sort of an Array | Python | O(M log log M + n log M * alpha), M = max(nums) | O(M) | Hard | array, SIEVE OF SMALLEST PRIME FACTOR + UNION FIND ON VALUES, new, amazon |
|
| 2007 | Find Original Array From Doubled Array | Python | O(n log n) | O(n) | Medium | array, GREEDY MATCHING ON A SORTED ARRAY + COUNTER, new, google |
|
| 2011 | Final Value of Variable After Performing Operations | Python | O(n) | O(1) | Easy | array, LOOK AT THE MIDDLE CHARACTER ONLY, new | |
| 2016 | Maximum Difference Between Increasing Elements | Python | O(n) | O(1) | Easy | array, RUNNING MIN (same shape as LC 121 “best time to buy and sell stock”), new | |
| 2018 | Check if Word Can Be Placed In Crossword | Python | O(m * n) | O(max(m, n)) | Medium | array, SPLIT EVERY ROW / COLUMN INTO ‘#’-FREE SLOTS, THEN MATCH, new, google, amazon |
|
| 2022 | Convert 1D Array Into 2D Array | Python | O(m * n) | O(1) beyond the output | Easy | array, SLICING (only feasible when len(original) == m * n), new, google |
|
| 2035 | Partition Array Into Two Arrays to Minimize Sum Difference | Python | O(2^n * n) | O(2^n) | Hard | array, MEET IN THE MIDDLE (2^30 is too big, 2 * 2^15 is not), new | |
| 2055 | Plates Between Candles | Python | O(n + q) | O(n) | Medium | array, PREFIX SUM OF PLATES + NEAREST-CANDLE ARRAYS (O(1) per query), new, amazon |
|
| 2057 | Smallest Index With Equal Value | Python | O(n) | O(1) | Easy | array, LINEAR SCAN (return on the first hit -> smallest index for free), new, google |
|
| 2075 | Decode the Slanted Ciphertext | Python | O(len(encodedText)) | O(len(encodedText)) | Medium | array, READ THE MATRIX BACK ALONG ITS DIAGONALS, new, amazon |
|
| 2078 | Two Furthest Houses With Different Colors | Python | O(n) | O(1) | Easy | array, THE OPTIMAL PAIR ALWAYS INVOLVES HOUSE 0 OR HOUSE n-1, new, amazon |
|
| 2098 | Subsequence of Size K With the Largest Even Sum | Python | O(n log n) | O(n) | Medium | array, 🔒, TAKE THE k LARGEST, THEN FIX THE PARITY WITH ONE SWAP, new | |
| 2099 | Find Subsequence of Length K With the Largest Sum | Python | O(n log n) | O(n) | Easy | array, PICK THE k LARGEST BY INDEX, THEN RESTORE THE ORIGINAL ORDER, new | |
| 2100 | Find Good Days to Rob the Bank | Python | O(n) | O(n) | Medium | array, TWO PREFIX ARRAYS — LENGTH OF THE NON-INCREASING RUN ENDING HERE, new, amazon |
|
| 2106 | Maximum Fruits Harvested After at Most K Steps | Python | O(n) | O(n) | Hard | array, SLIDING WINDOW OVER THE SORTED POSITIONS + PREFIX SUMS, new | |
| 2113 | Elements in Array After Removing and Replacing Elements | Python | O(n + q) | O(q) | Medium | array, 🔒, THE STATE IS PERIODIC WITH PERIOD 2n — ANSWER EACH QUERY IN O(1), new | |
| 2121 | Intervals Between Identical Elements | Python | O(n) | O(n) | Medium | array, GROUP THE INDICES BY VALUE, THEN ROLL THE SUM ALONG EACH GROUP, new | |
| 2122 | Recover the Original Array | Python | O(n^2) | O(n) | Hard | array, SORT, THEN TRY EVERY CANDIDATE PARTNER FOR THE SMALLEST ELEMENT, new, google |
|
| 2128 | Remove All Ones With Row and Column Flips | Python | O(m * n) | O(n) | Medium | array, 🔒, EVERY ROW MUST EQUAL ROW 0 OR ITS EXACT COMPLEMENT, new, google |
|
| 2132 | Stamping the Grid | Python | O(m * n) | O(m * n) | Hard | array, 2D PREFIX SUM (where can a stamp go?) + 2D DIFFERENCE ARRAY (what is covered?), new | |
| 2155 | All Divisions With the Highest Score of a Binary Array | Python | O(n) | O(n) for the output | Medium | array, ONE SWEEP, UPDATING THE SCORE INCREMENTALLY, new, google |
|
| 2194 | Cells in a Range on an Excel Sheet | Python | O(cols * rows) | O(1) beyond the output | Easy | array, NESTED LOOPS, COLUMN OUTER AND ROW INNER, new | |
| 2210 | Count Hills and Valleys in an Array | Python | O(n) | O(n) | Easy | array, COLLAPSE EQUAL RUNS FIRST, THEN COUNT LOCAL EXTREMA, new | |
| 2219 | Maximum Sum Score of Array | Python | O(n) | O(1) | Medium | array, 🔒, PREFIX / SUFFIX SUM IN ONE PASS, new | |
| 2237 | Count Positions on Street With Required Brightness | Python | O(n + len(lights)) | O(n) | Medium | array, 🔒, DIFFERENCE ARRAY — EACH LAMP IS ONE RANGE INCREMENT, new | |
| 2239 | Find Closest Number to Zero | Python | O(n) | O(1) | Easy | array, SORT KEY = (DISTANCE TO ZERO, NEGATED VALUE), new | |
| 2245 | Maximum Trailing Zeros in a Cornered Path | Python | O(m * n) | O(m * n) | Medium | array, TRAILING ZEROS = min(#2, #5) — SO ONLY THE 2/5 EXPONENTS MATTER, new | |
| 2256 | Minimum Average Difference | Python | O(n) | O(1) | Medium | array, RUNNING PREFIX SUM, THE SUFFIX FOLLOWS FROM THE TOTAL, new | |
| 2270 | Number of Ways to Split Array | Python | O(n) | O(1) | Medium | array, PREFIX SUM (one pass, total sum known up front), new | |
| 2271 | Maximum White Tiles Covered by a Carpet | Python | O(n log n) | O(1) beyond the sort | Medium | array, SORT + SLIDING WINDOW (an optimal carpet can start on some tile’s left end), new | |
| 2274 | Maximum Consecutive Floors Without Special Floors | Python | O(n log n) | O(n) | Medium | array, SORT THE SPECIAL FLOORS AND MEASURE THE GAPS BETWEEN THEM, new | |
| 2293 | Min Max Game | Python | O(n) | O(n) | Easy | array, DIRECT SIMULATION OF THE HALVING ROUNDS, new | |
| 2319 | Check if Matrix Is X-Matrix | Python | O(n^2) | O(1) | Easy | array, DIRECT SCAN (a cell is on the X iff i == j or i + j == n - 1), new | |
| 2326 | Spiral Matrix IV | Python | O(m * n) | O(m * n) for the output | Medium | array, WALK THE SPIRAL WITH FOUR SHRINKING BOUNDARIES, new | |
| 2373 | Largest Local Values in a Matrix | Python | O(n^2) | O(n^2) for the output | Easy | array, SLIDE A 3 x 3 WINDOW AND TAKE ITS MAXIMUM, new | |
| 2382 | Maximum Segment Sum After Removals | Python | O(n * alpha(n)) | O(n) | Hard | array, RUN THE QUERIES BACKWARDS SO REMOVALS BECOME INSERTIONS (union-find), new | |
| 2391 | Minimum Amount of Time to Collect Garbage | Python | O(n) | O(n) | Medium | array, PICKUP TIME IS FIXED; ONLY THE DRIVING DEPENDS ON THE LAST HOUSE, new | |
| 2407 | Longest Increasing Subsequence II | Python | O(n log V) | O(V) | Hard | array, DP INDEXED BY VALUE, WITH A SEGMENT TREE FOR RANGE MAXIMUM, new | |
| 2428 | Maximum Sum of an Hourglass | Python | O(m * n) | O(1) | Medium | array, SLIDE THE FIXED 7-CELL SHAPE OVER EVERY 3 x 3 WINDOW, new | |
| 2432 | The Employee That Worked on the Longest Task | Python | O(len(logs)) | O(1) | Easy | array, EACH TASK’S DURATION IS THE GAP TO THE PREVIOUS LEAVE TIME, new | |
| 2433 | Find The Original Array of Prefix Xor | Python | O(n) | O(n) for the output | Medium | array, XOR IS ITS OWN INVERSE — arr[i] = pref[i] ^ pref[i-1], new | |
| 2438 | Range Product Queries of Powers | Python | O(30 + q * log(sum e)) | O(30 + q) | Medium | array, BIT DECOMPOSITION + PREFIX SUM OF EXPONENTS, new | |
| 2446 | Determine if Two Events Have Conflict | Python | O(1) | O(1) | Easy | array, INTERVAL OVERLAP ON THE RAW STRINGS (HH:MM is zero-padded -> lexicographic order == chronological order), new | |
| 2460 | Apply Operations to an Array | Python | O(n) | O(n) | Easy | array, APPLY THE MERGES LEFT TO RIGHT, THEN A STABLE ZERO-SHIFT, new | |
| 2482 | Difference Between Ones and Zeros in Row and Column | Python | O(m * n) | O(m + n) besides the output | Medium | array, ROW / COLUMN ONE-COUNTS (zeros are derived, not counted separately), new | |
| 2500 | Delete Greatest Value in Each Row | Python | O(m * n * log n) | O(m * n) for the transposed columns | Easy | array, SORT EACH ROW + SUM OF COLUMN MAX, new | |
| 2515 | Shortest Distance to Target String in a Circular Array | Python | O(n * L) | O(1) | Easy | array, ONE PASS (circular distance = min(clockwise, counter-clockwise)), new | |
| 2535 | Difference Between Element Sum and Digit Sum of an Array | Python | O(n * log10(M)) | O(1) | Easy | array, SIMULATION (accumulate both sums in one pass), new | |
| 2536 | Increment Submatrices by One | Python | O(q + n^2) | O(1) beyond the output | Medium | array, 2D DIFFERENCE ARRAY (+ 2D PREFIX SUM TO RESTORE), new | |
| 2559 | Count Vowel Strings in Ranges | Python | O(n + m) | O(n) | Medium | array, PREFIX SUM, new | |
| 2569 | Handling Sum Queries After Update | Python | O(n + q * log(n)) | O(n) | Hard | array, LAZY SEGMENT TREE (range flip / range count of ones) + RUNNING TOTAL, new | |
| 2574 | Left and Right Sum Differences | Python | O(n) | O(1) beyond the output | Easy | array, RUNNING PREFIX / SUFFIX SUM IN ONE PASS, new | |
| 2580 | Count Ways to Group Overlapping Ranges | Python | O(n * log n) | O(n) for the sort | Medium | array, SORT + MERGE INTERVALS + POWER OF TWO, new | |
| 2655 | Find Maximal Uncovered Ranges | Python | O(m * log m) | O(m) for the sort (m = len(ranges)) | Medium | array, 🔒, SORT BY LEFT ENDPOINT + SWEEP THE “FURTHEST COVERED” WATERMARK, new | |
| 2660 | Determine the Winner of a Bowling Game | Python | O(n) | O(1) | Easy | array, SIMULATION (score each player independently, then compare), new | |
| 2672 | Number of Adjacent Elements With the Same Color | Python | O(n + q) | O(n) | Medium | array, INCREMENTAL COUNTER – ONLY THE 2 PAIRS TOUCHING index CHANGE, new |
|
| 2711 | Difference of Number of Distinct Values on Diagonals | Python | O(m * n) | O(m * n) | Medium | array, DIAGONAL SWEEP + PREFIX / SUFFIX DISTINCT COUNTS, new | |
| 2717 | Semi-Ordered Permutation | Python | O(n) | O(1) | Easy | array, MATH (only the positions of 1 and n matter), new | |
| 2733 | Neither Minimum nor Maximum | Python | O(n) | O(1) | Easy | array, MIN / MAX THEN FIRST SURVIVOR, new | |
| 2760 | Longest Even Odd Subarray With Threshold | Python | O(n) | O(1) | Easy | array, GREEDY SCAN WITHOUT BACKTRACKING (two pointers), new | |
| 2782 | Number of Unique Categories | Python | O(n^2) haveSameCategory calls | O(n) | Medium | array, 🔒, REPRESENTATIVE SCAN (INTERACTIVE), new | |
| 2798 | Number of Employees Who Met the Target | Python | O(n) | O(1) | Easy | array, LINEAR COUNT, new | |
| 2848 | Points That Intersect With Cars | Python | O(n + M) | O(M) (M = 102, the coordinate range) | Easy | array, DIFFERENCE ARRAY (line sweep over a tiny coordinate range), new | |
| 2855 | Minimum Right Shifts to Sort the Array | Python | O(n) | O(1) | Easy | array, COUNT THE “DROPS” (rotated sorted array detection), new | |
| 2873 | Maximum Value of an Ordered Triplet I | Python | O(n) | O(1) | Easy | array, ONE PASS, KEEP PREFIX MAX + BEST PREFIX DIFFERENCE, new | |
| 2903 | Find Indices With Index and Value Difference I | Python | O(n) | O(1) | Easy | array, SLIDING “GAP” + RUNNING MIN / MAX INDEX, new | |
| 2905 | Find Indices With Index and Value Difference II | Python | O(n) | O(1) | Medium | array, SLIDING “GAP” + RUNNING MIN / MAX INDEX, new | |
| 3000 | Maximum Area of Longest Diagonal Rectangle | Python | O(n) | O(1) | Easy | array, GREEDY ONE PASS ON (DIAGONAL^2, AREA), new | |
| 3009 | Maximum Number of Intersections on the Chart | Python | O(n log n) | O(n) | Hard | array, 🔒, EACH SEGMENT IS AN INTERVAL OF y-VALUES — SWEEP FOR THE MAX OVERLAP, new | |
| 3010 | Divide an Array Into Subarrays With Minimum Cost I | Python | O(n log n) | O(n) | Easy | array, THE FIRST COST IS FORCED — PICK THE TWO CHEAPEST STARTS FOR THE REST, new | |
| 3015 | Count the Number of Houses at a Certain Distance I | Python | O(n^2) | O(n) | Medium | array, n <= 100 — JUST BFS FROM EVERY HOUSE, new | |
| 3017 | Count the Number of Houses at a Certain Distance II | Python | O(n) | O(n) | Hard | array, THE GRAPH IS A CYCLE WITH TWO TAILS — EACH SOURCE ADDS O(1) RANGES, new | |
| 3026 | Maximum Good Subarray Sum | Python | O(n) | O(n) | Medium | array, PREFIX SUMS + “CHEAPEST START PER VALUE”, new | |
| 3028 | Ant on the Boundary | Python | O(n) | O(1) | Easy | array, RUNNING PREFIX SUM — COUNT HOW OFTEN IT HITS 0, new | |
| 3030 | Find the Grid of Region Average | Python | O(m * n) | O(m * n) | Medium | array, TEST EVERY 3x3 WINDOW, THEN AVERAGE THE PER-REGION AVERAGES, new | |
| 3033 | Modify the Matrix | Python | O(m * n) | O(m * n) | Easy | array, ONE PASS FOR THE COLUMN MAXIMA, ONE PASS TO SUBSTITUTE, new | |
| 3038 | Maximum Number of Operations With the Same Score I | Python | O(n) | O(1) | Easy | array, THE SCORE IS FIXED BY THE FIRST PAIR — THEN JUST WALK FORWARD, new | |
| 3065 | Minimum Operations to Exceed Threshold Value I | Python | O(n) | O(1) | Easy | array, THE OPERATION ALWAYS TAKES THE SMALLEST — SO IT JUST DELETES EVERY VALUE BELOW k, new | |
| 3069 | Distribute Elements Into Two Arrays I | Python | O(n) | O(n) | Easy | array, DIRECT SIMULATION — ONLY THE TWO TAIL VALUES DECIDE EACH STEP, new | |
| 3070 | Count Submatrices with Top-Left Element and Sum Less Than k | Python | O(m * n) | O(m * n) | Medium | array, A SUBMATRIX CONTAINING (0,0) IS A PREFIX RECTANGLE, new | |
| 3071 | Minimum Operations to Write the Letter Y on a Grid | Python | O(n^2) | O(1) | Medium | array, ONLY 6 TARGET COLOURINGS EXIST — COUNT ONCE, THEN SCORE EACH, new | |
| 3079 | Find the Sum of Encrypted Integers | Python | O(n * digits) | O(digits) | Easy | array, REPEAT THE LARGEST DIGIT AS MANY TIMES AS THERE ARE DIGITS, new | |
| 3096 | Minimum Levels to Gain More Points | Python | O(n) | O(1) | Medium | array, SCORES ARE PREFIX SUMS OF +1 / -1 — SCAN FOR THE FIRST SPLIT THAT WINS, new | |
| 3105 | Longest Strictly Increasing or Strictly Decreasing Subarray | Python | O(n) | O(1) | Easy | array, TWO RUNNING STREAK COUNTERS, ONE PER DIRECTION, new | |
| 3127 | Make a Square with the Same Color | Python | O(1) | O(1) | Easy | array, A 2x2 BLOCK IS FIXABLE IFF IT IS NOT ALREADY 2-2 SPLIT, new | |
| 3131 | Find the Integer Added to Array I | Python | O(n) | O(1) | Easy | array, A CONSTANT SHIFT MOVES THE MINIMUM BY EXACTLY THAT CONSTANT, new | |
| 3142 | Check if Grid Satisfies Conditions | Python | O(m * n) | O(1) | Easy | array, TWO LOCAL CHECKS PER CELL, GUARDED BY THE BOUNDS, new | |
| 3147 | Taking Maximum Energy From the Mystic Dungeon | Python | O(n) | O(1) beyond the copy | Medium | array, SUFFIX SUMS ALONG EACH JUMP CHAIN, BUILT FROM THE BACK, new | |
| 3151 | Special Array I | Python | O(n) | O(1) | Easy | array, NEIGHBOURS MUST DISAGREE IN THE LOWEST BIT, new | |
| 3152 | Special Array II | Python | O(n + q) | O(n) | Medium | array, PREFIX-COUNT THE BAD ADJACENT PAIRS, THEN EACH QUERY IS O(1), new | |
| 3153 | Sum of Digit Differences of All Pairs | Python | O(n * digits) | O(1) | Medium | array, HANDLE EACH DIGIT POSITION SEPARATELY AND COUNT THE AGREEING PAIRS, new | |
| 3159 | Find Occurrences of an Element in an Array | Python | O(n + q) | O(n) | Medium | array, COLLECT THE POSITIONS OF x ONCE, THEN EVERY QUERY IS A LOOKUP, new | |
| 3173 | Bitwise OR of Adjacent Elements | Python | O(n) | O(n) | Easy | array, 🔒, ZIP THE ARRAY WITH ITS OWN TAIL, new | |
| 3187 | Peaks in Array | Python | O((n + q) log n) | O(n) | Hard | array, A FENWICK TREE OVER “IS THIS INDEX A PEAK”, REPAIRED LOCALLY ON UPDATES, new | |
| 3224 | Minimum Array Changes to Make Differences Equal | Python | O(n + k) | O(k) | Medium | array, SCORE EVERY CANDIDATE X AT ONCE WITH A DIFFERENCE ARRAY, new | |
| 3285 | Find Indices of Stable Mountains | Python | O(n) | O(n) | Easy | array, A DIRECT READING — LOOK ONE STEP BACK, new | |
| 3300 | Minimum Element After Replacement With Digit Sum | Python | O(n * digits) | O(1) | Easy | array, DIGIT SUM VIA THE DECIMAL STRING, THEN TAKE THE MINIMUM, new | |
| 3330 | Find the Original Typed String I | Python | O(n) | O(1) | Easy | array, AT MOST ONE RUN MAY HAVE BEEN OVER-TYPED, AND ONLY BY SOME AMOUNT, new | |
| 3334 | Find the Maximum Factor Score of Array | Python | O(n log max) | O(n) | Medium | array, PREFIX AND SUFFIX GCD / LCM SO EACH REMOVAL IS AN O(1) COMBINE, new | |
| 3349 | Adjacent Increasing Subarrays Detection I | Python | O(n * k) | O(1) | Easy | array, TEST EVERY ANCHOR — THE SECOND BLOCK STARTS EXACTLY k LATER, new | |
| 3350 | Adjacent Increasing Subarrays Detection II | Python | O(n) | O(1) | Medium | array, SPLIT INTO MAXIMAL RISING RUNS — THE ANSWER LIVES INSIDE OR ACROSS ONE BOUNDARY, new | |
| 3354 | Make Array Elements Equal to Zero | Python | O(n * (n + sum(nums))) | O(n) | Easy | array, THE INPUT IS SMALL — REPLAY THE WHOLE PROCESS FOR EACH START, new | |
| 3355 | Zero Array Transformation I | Python | O(n + q) | O(n) | Medium | array, THE SUBSETS ARE FREE, SO ONLY THE PER-INDEX COVERAGE MATTERS, new | |
| 3379 | Transformed Array | Python | O(n) | O(n) | Easy | array, PYTHON’S MODULO ALREADY WRAPS IN BOTH DIRECTIONS, new | |
| 3380 | Maximum Area Rectangle With Point Constraints I | Python | O(n^5) worst case with n = 10 | O(n) | Medium | array, ONLY 10 POINTS — TRY EVERY (x1, x2) x (y1, y2) BOX, new | |
| 3382 | Maximum Area Rectangle With Point Constraints II | Python | O(n log n) | O(n) | Hard | array, SWEEP BY x, PAIRING VERTICALLY ADJACENT POINTS, COUNTING WITH A BIT, new | |
| 3386 | Button with Longest Push Time | Python | O(n) | O(1) | Easy | array, ONE PASS ON THE GAPS BETWEEN CONSECUTIVE PRESSES, new | |
| 3392 | Count Subarrays of Length Three With a Condition | Python | O(n) | O(1) | Easy | array, SLIDE A WINDOW OF 3 AND TEST THE CONDITION WITHOUT DIVIDING, new | |
| 3400 | Maximum Number of Matching Indices After Right Shifts | Python | O(n^2) | O(n) | Medium | array, 🔒, TRY EVERY ROTATION, COMPARE WITH A DOUBLED ARRAY, new | |
| 3417 | Zigzag Grid Traversal With Skip | Python | O(m * n) | O(m * n) | Easy | array, LINEARISE THE BOUSTROPHEDON ORDER, THEN TAKE EVERY OTHER CELL, new | |
| 3423 | Maximum Difference Between Adjacent Elements in a Circular Array | Python | O(n) | O(1) | Easy | array, SCAN THE PAIRS, WRAPPING THE INDEX WITH MODULO, new | |
| 3427 | Sum of Variable Length Subarrays | Python | O(n) | O(n) | Easy | array, PREFIX SUMS, ONE RANGE LOOKUP PER INDEX, new | |
| 3432 | Count Partitions with Even Sum Difference | Python | O(n) | O(1) | Easy | array, THE PARITY OF THE DIFFERENCE DOES NOT DEPEND ON WHERE YOU CUT, new | |
| 3440 | Reschedule Meetings for Maximum Free Time II | Python | O(n) | O(n) | Medium | array, ONE MEETING MAY TELEPORT — ASK WHETHER SOME OTHER GAP CAN HOST IT, new | |
| 3446 | Sort Matrix by Diagonals | Python | O(n^2 log n) | O(n^2) | Medium | array, GROUP CELLS BY i - j, SORT EACH DIAGONAL IN ITS OWN DIRECTION, new | |
| 3502 | Minimum Cost to Reach Every Position | Python | O(n) | O(1) extra | Easy | array, RUNNING PREFIX MINIMUM, new | |
| 3514 | Number of Unique XOR Triplets II | Python | O(n^2 + V^2) with V = 2048 | O(V) | Medium | array, PAIR XORS FIRST, THEN ONE MORE XOR PASS, new | |
| 3531 | Count Covered Buildings | Python | O(m) | O(m) | Medium | array, ONLY THE EXTREMES OF EACH ROW AND COLUMN CAN FAIL, new | |
| 3537 | Fill a Special Grid | Python | O(4^n) | O(4^n) | Medium | array, BUILD BY DOUBLING – THE FOUR QUADRANTS ARE THE SAME GRID, SHIFTED, new | |
| 3540 | Minimum Time to Visit All Houses | Python | O(n + q) | O(n) | Medium | array, 🔒, EACH HOP IS INDEPENDENT – TWO PREFIX SUMS AROUND THE CIRCLE, new | |
| 3546 | Equal Sum Grid Partition I | Python | O(m * n) | O(n) | Medium | array, A CUT IS JUST A PREFIX – CHECK EVERY PREFIX SUM AGAINST HALF THE TOTAL, new | |
| 3548 | Equal Sum Grid Partition II | Python | O(m * n) | O(m * n) | Hard | array, SWEEP EVERY CUT, THEN ASK WHETHER THE EXCESS SITS IN A REMOVABLE CELL, new | |
| 3549 | Multiply Two Polynomials | Python | O(N log N) via the big-int multiply | O(N) | Hard | array, 🔒, KRONECKER SUBSTITUTION – LET PYTHON’S BIG-INT MULTIPLY DO THE FFT, new | |
| 3550 | Smallest Index With Digit Sum Equal to Index | Python | O(n * d) | O(1) | Easy | array, SCAN LEFT TO RIGHT AND STOP AT THE FIRST HIT, new | |
| 3569 | Maximize Count of Distinct Primes After Split | Python | O((n + q) * log n + V log log V) | O(n + V) | Hard | array, REWRITE THE SPLIT VALUE AS “TOTAL PRIMES + INTERVAL COVERAGE”, new | |
| 3637 | Trionic Array I | Python | O(n) | O(1) | Easy | array, WALK THE THREE MONOTONE RUNS GREEDILY, new | |
| 3643 | Flip Square Submatrix Vertically | Python | O(k^2) | O(1) | Easy | array, SWAP MIRRORED ROW SLICES IN PLACE, new | |
| 3653 | XOR After Range Multiplication Queries I | Python | O(q * n) | O(1) | Medium | array, DIRECT SIMULATION — THE ARITHMETIC PROGRESSION IS SHORT ENOUGH, new | |
| 3655 | XOR After Range Multiplication Queries II | Python | O((q + n) * sqrt(n)) | O(n + q) | Hard | array, HEAVY/LIGHT SPLIT ON THE STRIDE, WITH A MULTIPLICATIVE DIFFERENCE, new | |
| 3674 | Minimum Operations to Equalize Array | Python | O(n) | O(1) | Easy | array, ONE WHOLE-ARRAY OPERATION ALWAYS SUFFICES, new | |
| 3683 | Earliest Time to Finish One Task | Python | O(n) | O(1) | Easy | array, EACH TASK’S FINISH TIME IS INDEPENDENT – TAKE THE MINIMUM, new | |
| 3687 | Library Late Fee Calculator | Python | O(n) | O(1) | Easy | array, 🔒, PER-BOOK PIECEWISE FEE, SUMMED, new |
Backtracking
| # | Title | Solution | Time | Space | Difficulty | Note | Status |
|---|---|---|---|---|---|---|---|
| 0291 | Word Pattern II | Python, Java | O(n^m) | O(m + n) | Medium | backtracking, 🔒, LC 290, backtracking with a bijection map, good trick, new, amazon, fb, uber |
|
| 0488 | Zuma Game | Python, Java | O(s * h * b^2) | O(s * (b + h)) | Hard | backtracking, backtracking + memo over (board, hand), complex, new, string, dp, stack |
|
| 0679 | 24 Game | Python, Java | O(1) | O(1) | Hard | backtracking, backtrack over every pair and operator, float epsilon compare, good trick, new, google, amazon, apple, microsoft, uber |
|
| 0996 | Number of Squareful Arrays | Python, Java | O(n!) | O(n) | Hard | backtracking, permutations with perfect-square adjacency pruning, dedupe same-layer, new, google, apple |
|
| 1096 | Brace Expansion II | Python | O(L * W) | O(W) | Hard | backtracking, STACK PARSER (union list + product set per nesting level), new, google, microsoft |
|
| 1240 | Tiling a Rectangle with the Fewest Squares | Python | exponential (pruned) ; n, m <= 13 | O(n * m), recursion depth | Hard | backtracking, BACKTRACKING + BITMASK (fill the first empty cell, scan row by row), new, google |
|
| 1255 | Maximum Score Words Formed by Letters | Python | O(2^n * L) | O(n + L) n = len(words), L = total word length | Hard | backtracking, BACKTRACKING (take / skip each word, undo the letter spend on return), new, google, amazon |
|
| 1258 | Synonymous Sentences | Python | O(m ^ w * w) | O(n + w), n = number of distinct synonym words | Medium | backtracking, UNION FIND + BACKTRACK (DFS), new, google, amazon |
|
| 1307 | Verbal Arithmetic Puzzle | Python | O(10!) worst case, heavily pruned in practice | O(1), at most 10 distinct letters | Hard | backtracking, coefficient backtracking, new | |
| 1379 | Find a Corresponding Node of a Binary Tree in a Clone of That Tree | Python | O(n) | O(h), h = tree height (recursion stack) | Easy | backtracking, walk BOTH trees in lock step (DFS), new, amazon, fb |
|
| 1593 | Split a String Into the Max Number of Unique Substrings | Python | O(2^n * n) | O(n^2) | Medium | backtracking, BACKTRACKING (n <= 16, try every cut with a “used pieces” set), new, google, microsoft |
|
| 1659 | Maximize Grid Happiness | Python | O(m*n * 3^n * I * E * 3) | O(m*n * 3^n * I * E) | Hard | backtracking, PROFILE (BROKEN-PROFILE) DP + MEMO, cell by cell, base-3 mask, new | |
| 1718 | Construct the Lexicographically Largest Valid Sequence | Python | O(n!) worst case (heavily pruned; n <= 20) | O(n) | Medium | backtracking, BACKTRACKING, TRY BIG VALUES FIRST (first success = the answer), new, fb |
|
| 1723 | Find Minimum Time to Finish All Jobs | Python | O(k^n) worst case, heavily pruned (n <= 12) | O(n + k) | Hard | backtracking, BACKTRACKING WITH BRANCH-AND-BOUND PRUNING, new, amazon |
|
| 1849 | Splitting a String Into Descending Consecutive Values | Python | O(n^2) | O(n) | Medium | backtracking, BACKTRACKING – only the FIRST piece really branches, new | |
| 1999 | Smallest Greater Multiple Made of Two Digits | Python | O(2^L) with L <= 10 digits before the 2^31 cutoff | O(2^L) | Medium | backtracking, 🔒, BFS OVER THE DIGIT TREE (generates candidates in increasing order), new | |
| 2014 | Longest Subsequence Repeated k Times | Python | O(26^L * n) with L <= 7 but the k-repetition prune keeps it tiny | O(number of surviving candidates) | Hard | backtracking, BFS OVER CANDIDATES (grow level by level, prune with a greedy check), new, fb |
|
| 2056 | Number of Valid Move Combinations On Chessboard | Python | O((8 * 8)^n) with n <= 4 | O(n * 81) | Hard | backtracking, BACKTRACKING PIECE BY PIECE, RECORDING EACH PIECE’S TIMELINE, new, fb |
|
| 2094 | Finding 3-Digit Even Numbers | Python | O(1) (bounded by 450 candidates) | O(1) | Easy | backtracking, ENUMERATE ALL 900 THREE-DIGIT EVEN NUMBERS, CHECK MULTISET SUPPLY, new | |
| 2443 | Sum of Number and Its Reverse | Python | O(num * d), d = number of digits | O(d) | Medium | backtracking, ENUMERATION (the candidate k is bounded, so just scan it), new | |
| 2664 | The Knight’s Tour | Python | O(8^(m*n)) worst case (tiny in practice) | O(m*n) | Medium | backtracking, 🔒, BACKTRACKING (DFS) OVER THE 8 KNIGHT MOVES, new | |
| 2698 | Find the Punishment Number of an Integer | Python | O(n * 2^d) with d = digits of n^2 (<= 7) | O(d) | Medium | backtracking, BACKTRACKING OVER THE SPLIT POINTS OF str(i * i), new | |
| 2741 | Special Permutations | Python | O(n^2 * 2^n) | O(n * 2^n) | Medium | backtracking, BACKTRACKING COMPRESSED INTO BITMASK DP (STATE COMPRESSION), new | |
| 3211 | Generate Binary Strings Without Adjacent Zeros | Python | O(n * number of valid strings) | O(n) recursion | Medium | backtracking, BACKTRACK, REFUSING TO PLACE A ‘0’ AFTER A ‘0’, new | |
| 3437 | Permutations III | Python | O(n * number of alternating permutations) | O(n) | Medium | backtracking, 🔒, BACKTRACKING THAT ONLY EVER OFFERS THE OPPOSITE PARITY, new | |
| 3565 | Sequential Grid Path Cover | Python | O(m * n * 3^(m * n)) worst case | O(m * n) | Medium | backtracking, 🔒, BACKTRACKING WITH THE “NEXT WANTED LABEL” AS PART OF THE STATE, new | |
| 3669 | Balanced K-Factor Decomposition | Python | O(d(n)^(k-1) * sqrt(n)) in the worst case, tiny in practice | O(k) | Medium | backtracking, DFS OVER DIVISORS IN NON-DECREASING ORDER, new |
Binary Heap
| # | Title | Solution | Time | Space | Difficulty | Note | Status |
|---|---|---|---|---|---|---|---|
| 0480 | Sliding Window Median | Python, Java | O(n * k) | O(k) | Hard | heap, two heaps with lazy deletion, or SortedList, LC 295, LC 239, good trick, new, google, amazon, fb, apple |
|
| 0632 | Smallest Range Covering Elements from K Lists | Python, Java | O(nlogk) | O(k) | Hard | heap, min-heap over k list pointers while tracking the current max, LC 23, good trick, new, google, amazon, fb, apple, microsoft |
|
| 0857 | Minimum Cost to Hire K Workers | Python, Java | O(nlogn) | O(n) | Hard | heap, sort by wage/quality ratio + max-heap of quality, greedy, good trick, new, google |
|
| 1439 | Find the Kth Smallest Sum of a Matrix With Sorted Rows | Python | O(m * k * n log(k * n)) | O(k * n) | Hard | heap, ROW BY ROW MERGE, KEEP ONLY THE k SMALLEST, new, fb |
|
| 1606 | Find Servers That Handled Most Number of Requests | Python | O((n + k) log k) | O(k) | Hard | heap, MIN-HEAP (busy servers by finish time) + BIT over free servers, new, apple |
|
| 1792 | Maximum Average Pass Ratio | Python | O((n + k) log n) | O(n) | Medium | heap, MAX HEAP ON THE MARGINAL GAIN (the gain is strictly decreasing per class), new, amazon |
|
| 1962 | Remove Stones to Minimize the Total | Python | O(n + k*log n) | O(n) | Medium | heap, GREEDY + MAX HEAP, new | |
| 2054 | Two Best Non-Overlapping Events | Python | O(n log n) | O(n) | Medium | heap, SORT BY START + SUFFIX MAX + BINARY SEARCH, new | |
| 2163 | Minimum Difference in Sums After Removal of Elements | Python | O(n log n) | O(n) | Hard | heap, SPLIT POINT + TWO HEAPS — MINIMISE THE LEFT SUM, MAXIMISE THE RIGHT, new | |
| 2208 | Minimum Operations to Halve Array Sum | Python | O(n log n) | O(n) | Medium | heap, ALWAYS HALVE THE CURRENT LARGEST — MAX-HEAP, new | |
| 2386 | Find the K-Sum of an Array | Python | O(n log n + k log k) | O(n + k) | Hard | heap, REDUCE TO “k SMALLEST SUBSET SUMS OF THE ABSOLUTE VALUES”, new | |
| 2462 | Total Cost to Hire K Workers | Python | O((k + candidates) log candidates) | O(candidates) | Medium | heap, TWO MIN-HEAPS, ONE PER END, REFILLED FROM THE SHRINKING MIDDLE, new | |
| 2519 | Count the Number of K-Big Indices | Python | O(n * log k) | O(n) | Hard | heap, 🔒, TWO SIZE-K MAX HEAPS (keep only the k smallest values on each side), new | |
| 2530 | Maximal Score After Applying K Operations | Python | O(n + k * log n) | O(n) | Medium | heap, GREEDY + MAX HEAP, new | |
| 2558 | Take Gifts From the Richest Pile | Python | O(n + k log n) | O(n) | Easy | heap, MAX HEAP (SIMULATION), new | |
| 2818 | Apply Operations to Maximize Score | Python | O(V log log V + n log n) | O(V + n) # V = max(nums) <= 10^5 | Hard | heap, PRIME SCORE (LINEAR SIEVE) + MONOTONIC STACK “DOMINANCE RANGE”, new | |
| 3066 | Minimum Operations to Exceed Threshold Value II | Python | O(n log n) | O(n) | Medium | heap, MIN-HEAP — THE OPERATION IS FORCED, SO JUST SIMULATE IT, new | |
| 3080 | Mark Elements on Array by Performing Queries | Python | O((n + sum of k) log n) | O(n) | Medium | heap, MIN-HEAP BY (VALUE, INDEX) + LAZY SKIPPING OF ALREADY-MARKED ENTRIES, new | |
| 3256 | Maximum Value Sum by Placing Three Rooks I | Python | O(m * n + m^3) | O(m) | Hard | heap, ONLY EACH ROW’S TOP THREE CELLS CAN EVER BE USED, new | |
| 3257 | Maximum Value Sum by Placing Three Rooks II | Python | O(m * n log n) | O(m) | Hard | heap, FIX THE MIDDLE ROW, THEN TAKE THE BEST ROW ABOVE AND BELOW, new | |
| 3275 | K-th Nearest Obstacle Queries | Python | O(q log k) | O(k) | Medium | heap, A BOUNDED MAX-HEAP HOLDING THE k CLOSEST DISTANCES, new | |
| 3684 | Maximize Sum of At Most K Distinct Elements | Python | O(n log n) | O(n) | Easy | heap, DEDUPE FIRST, THEN GREEDILY TAKE THE k LARGEST DISTINCT VALUES, new |
Binary Search
| # | Title | Solution | Time | Space | Difficulty | Note | Status |
|---|---|---|---|---|---|---|---|
| 0302 | Smallest Rectangle Enclosing Black Pixels | Python, Java | O(mlogn + nlogm) | O(1) | Hard | binary search, 🔒, binary search each border of the black region, LC 200, good trick, new, google |
|
| 0354 | Russian Doll Envelopes | Python, Java | O(nlogn) | O(n) | Hard | binary search, sort by width asc / height desc then LIS, LC 300, good trick, new, google, amazon, apple, microsoft, uber |
|
| 0363 | Max Sum of Rectangle No Larger Than K | Python, Java | O(m^2 * nlogn) | O(n) | Hard | binary search, prefix sum per row band + sorted set binary search, LC 304, new, google, apple, microsoft |
|
| 0668 | Kth Smallest Number in Multiplication Table | Python, Java | O(mlog(m * n)) | O(1) | Hard | binary search, binary search on the answer, count values <= x, good trick, new, google, amazon, uber |
|
| 0702 | Search in a Sorted Array of Unknown Size | Python, Java | O(logM) | O(1) | Medium | binary search, 🔒, exponential search then binary search, ArrayReader API, new, google, amazon, fb, microsoft |
|
| 0719 | Find K-th Smallest Pair Distance | Python, Java | O(nlogn + nlogW) | O(1) | Hard | binary search, binary search on the distance + two pointers to count pairs, good trick, new, google, amazon, fb |
|
| 0786 | K-th Smallest Prime Fraction | Python, Java | O(n + klogn) | O(n) | Medium | binary search, binary search on the fraction value, or a heap of k candidates, new, google |
|
| 0793 | Preimage Size of Factorial Zeroes Function | Python, Java | O((logk)^2) | O(1) | Hard | binary search, binary search on the trailing-zero count, LC 172, new, amazon |
|
| 0878 | Nth Magical Number | Python, Java | O(log(n * min(a, b))) | O(1) | Hard | binary search, binary search + inclusion-exclusion with lcm(a, b), math, new, amazon |
|
| 1044 | Longest Duplicate Substring | Python | O(n log n) | O(n) | Hard | binary search, BINARY SEARCH ON LENGTH + RABIN-KARP (rolling hash), new, google, amazon, fb, apple, microsoft, uber |
|
| 1062 | Longest Repeating Substring | Python | O(n^2 log n) | O(n^2) | Medium | binary search, 🔒, BINARY SEARCH on the answer + HASH SET, new, google, amazon, fb |
|
| 1064 | Fixed Point | Python | O(log n) | O(1) | Easy | binary search, 🔒, BINARY SEARCH (find first index with arr[i] - i >= 0), new, uber |
|
| 1201 | Ugly Number III | Python | O(log(2 * 10^9)) | O(1) | Medium | binary search, BINARY SEARCH on ANSWER + INCLUSION-EXCLUSION, new, google, amazon |
|
| 1228 | Missing Number In Arithmetic Progression | Python | O(log n) | O(1) | Easy | binary search, BINARY SEARCH ON THE “STILL IN PLACE” PREDICATE, new, fb |
|
| 1274 | Number of Ships in a Rectangle | Python | O(s * log(max(m, n))), s = number of ships (<= 10) | O(log(max(m, n))), recursion depth | Hard | binary search, DIVIDE AND CONQUER (quad tree style), new | |
| 1287 | Element Appearing More Than 25% In Sorted Array | Python | O(n) | O(1) | Easy | binary search, SORTED ARRAY property + fixed offset check, new, google, fb |
|
| 1385 | Find the Distance Value Between Two Arrays | Python | O((m + n) log n) | O(n), sorting | Easy | binary search, sort arr2 + binary search, new, uber |
|
| 1533 | Find the Index of the Large Integer | Python | O(log n) calls | O(1) | Medium | binary search, 🔒, BINARY SEARCH ON THE INTERACTIVE COMPARATOR, new, amazon |
|
| 1539 | Kth Missing Positive Number | Python | O(log n) | O(1) | Easy | binary search, BINARY SEARCH ON “HOW MANY ARE MISSING BEFORE INDEX i”, new, google, amazon, fb, apple, microsoft |
|
| 1618 | Maximum Font to Fit a Sentence in a Screen | Python | O(len(text) + 26 * log(len(fonts))) | O(26) | Medium | binary search, 🔒, BINARY SEARCH ON ANSWER (fit() is monotone over fonts), new, google |
|
| 1671 | Minimum Number of Removals to Make Mountain Array | Python | O(n log n) | O(n) | Hard | binary search, BIDIRECTIONAL LIS + BINARY SEARCH (keep the longest mountain, drop the rest), new | |
| 1713 | Minimum Operations to Make a Subsequence | Python | O(n * log m) | O(m + n) | Hard | binary search, LCS -> LIS (target is DISTINCT, so map values to indices) + BINARY SEARCH, new, google |
|
| 1802 | Maximum Value at a Given Index in a Bounded Array | Python | O(log(maxSum)) | O(1) | Medium | binary search, BINARY SEARCH ON THE ANSWER (feasibility is monotone), new | |
| 1818 | Minimum Absolute Sum Difference | Python | O(n log n) | O(n) | Medium | binary search, SORT + BINARY SEARCH FOR THE BEST SINGLE SWAP (maximise the saving), new, uber |
|
| 1870 | Minimum Speed to Arrive on Time | Python | O(n * log(10^7)) | O(1) | Medium | binary search, BINARY SEARCH ON THE ANSWER (total time is monotone in speed), new, google |
|
| 1901 | Find a Peak Element II | Python | O(n log m) | O(1) | Medium | binary search, BINARY SEARCH ON ROWS (the row max is a peak or points uphill), new, fb, microsoft |
|
| 1918 | Kth Smallest Subarray Sum | Python | O(n * log(S)), S = sum(nums) | O(1) | Medium | binary search, 🔒, BINARY SEARCH ON THE ANSWER + SLIDING WINDOW COUNT, new, google |
|
| 1964 | Find the Longest Valid Obstacle Course at Each Position | Python | O(n log n) | O(n) | Hard | binary search, LIS (non-decreasing) via PATIENCE / BINARY SEARCH ON TAILS, new | |
| 2064 | Minimized Maximum of Products Distributed to Any Store | Python | O(m log(max q)) | O(1) | Medium | binary search, BINARY SEARCH ON THE ANSWER (minimise the maximum), new | |
| 2111 | Minimum Operations to Make the Array K-Increasing | Python | O(n log n) | O(n) | Hard | binary search, SPLIT INTO k INDEPENDENT SUBSEQUENCES, KEEP THE LONGEST, new, amazon |
|
| 2137 | Pour Water Between Buckets to Make Water Levels Equal | Python | O(n * 100) | O(1) | Medium | binary search, 🔒, BINARY SEARCH ON THE FINAL WATER LEVEL (a real number), new | |
| 2187 | Minimum Time to Complete Trips | Python | O(n log(min(time) * totalTrips)) | O(1) | Medium | binary search, BINARY SEARCH ON THE ANSWER (a time, not an index), new | |
| 2226 | Maximum Candies Allocated to K Children | Python | O(n * log(max(candies))) | O(1) | Medium | binary search, BINARY SEARCH ON THE ANSWER (monotone feasibility), new | |
| 2250 | Count Number of Rectangles Containing Each Point | Python | O(R log R + P * 100 * log R) | O® | Medium | binary search, HEIGHTS ONLY GO UP TO 100 — BUCKET BY HEIGHT, BINARY SEARCH LENGTHS, new | |
| 2300 | Successful Pairs of Spells and Potions | Python | O((n + m) log m) | O(m) | Medium | binary search, SORT THE POTIONS ONCE, BINARY SEARCH THE THRESHOLD PER SPELL, new | |
| 2333 | Minimum Sum of Squared Difference | Python | O(n log(max diff)) | O(n) | Medium | binary search, ONLY abs(nums1[i] - nums2[i]) MATTERS — BINARY SEARCH THE CAP, new | |
| 2387 | Median of a Row Wise Sorted Matrix | Python | O(m log n log(max value)) | O(1) | Medium | binary search, 🔒, BINARY SEARCH ON THE VALUE, COUNTING WITH ONE BISECT PER ROW, new | |
| 2389 | Longest Subsequence With Limited Sum | Python | O(n log n + m log n) | O(n) | Easy | binary search, ORDER DOES NOT MATTER — SORT ASCENDING AND PREFIX-SUM, new | |
| 2448 | Minimum Cost to Make Array Equal | Python | O(n log n) | O(n) | Hard | binary search, WEIGHTED MEDIAN (f(x) = sum cost[i] * |nums[i] - x| is convex piecewise linear), new | |
| 2476 | Closest Nodes Queries in a Binary Search Tree | Python | O(n + q * log n) | O(n) | Medium | binary search, IN-ORDER TRAVERSAL -> SORTED ARRAY + BINARY SEARCH, new | |
| 2513 | Minimize the Maximum of Two Arrays | Python | O(log(MAX) + log(min(d1, d2))) | O(1) | Medium | binary search, BINARY SEARCH ON THE ANSWER (+ inclusion-exclusion via LCM), new | |
| 2517 | Maximum Tastiness of Candy Basket | Python | O(n * log n + n * log(maxPrice)) | O(1) beyond the sort | Medium | binary search, BINARY SEARCH ON THE ANSWER + GREEDY FEASIBILITY CHECK, new | |
| 2528 | Maximize the Minimum Powered City | Python | O(n * log(sum(stations) + k)) | O(n) | Hard | binary search, BINARY SEARCH ON ANSWER + DIFFERENCE ARRAY + GREEDY (sweep left->right), new | |
| 2529 | Maximum Count of Positive Integer and Negative Integer | Python | O(log n) | O(1) | Easy | binary search, BINARY SEARCH ON THE SORTED ARRAY (the follow-up’s O(log n)), new | |
| 2557 | Maximum Number of Integers to Choose From a Range II | Python | O(m log m + m log n) | O(m) (m = len(banned)) | Medium | binary search, 🔒, GREEDY (SMALLEST FIRST) + BINARY SEARCH ON EACH FREE GAP, new | |
| 2602 | Minimum Operations to Make All Array Elements Equal | Python | O((n + m) * log n) | O(n) | Medium | binary search, SORT + PREFIX SUM + BINARY SEARCH, new | |
| 2702 | Minimum Operations to Make Numbers Non-positive | Python | O(n * log(max(nums))) | O(1) | Hard | binary search, 🔒, BINARY SEARCH ON THE ANSWER, new | |
| 3048 | Earliest Second to Mark Indices I | Python | O(m log m) | O(n + m) | Medium | binary search, BINARY SEARCH THE DEADLINE, GREEDY CHECK WITH “MARK AT THE LAST CHANCE”, new | |
| 3049 | Earliest Second to Mark Indices II | Python | O(m log m log m) | O(n + m) | Hard | binary search, BINARY SEARCH THE DEADLINE + A HEAP GREEDY FOR “WHICH INDICES TO ZERO”, new | |
| 3104 | Find Longest Self-Contained Substring | Python | O(26 * n) | O(1) | Hard | binary search, 🔒, THE START MUST BE A FIRST OCCURRENCE — SO THERE ARE AT MOST 26 STARTS, new | |
| 3116 | Kth Smallest Amount With Single Denomination Combination | Python | O(2^n * log(min(coins) * k)) | O(2^n) | Hard | binary search, BINARY SEARCH THE AMOUNT, COUNT WITH INCLUSION-EXCLUSION, new | |
| 3134 | Find the Median of the Uniqueness Array | Python | O(n log n) | O(n) | Hard | binary search, BINARY SEARCH THE MEDIAN VALUE, COUNT WITH A SLIDING WINDOW, new | |
| 3135 | Equalize Strings by Adding or Removing Characters at Ends | Python | O(n * m) | O(m) | Medium | binary search, 🔒, ONLY A COMMON SUBSTRING CAN SURVIVE — SO MAXIMISE ITS LENGTH, new | |
| 3145 | Find Products of Elements of Big Array | Python | O(q * log^2(max index)) | O(1) | Hard | binary search, EVERY ENTRY IS A POWER OF TWO — SO WORK WITH EXPONENT SUMS, new | |
| 3231 | Minimum Number of Increasing Subsequence to Be Removed | Python | O(n log n) | O(n) | Hard | binary search, 🔒, DILWORTH — THE ANSWER IS THE LONGEST NON-INCREASING SUBSEQUENCE, new | |
| 3233 | Find the Count of Numbers Which Are Not Special | Python | O(sqrt® log log sqrt®) | O(sqrt®) | Medium | binary search, “EXACTLY TWO PROPER DIVISORS” MEANS x IS THE SQUARE OF A PRIME, new | |
| 3281 | Maximize Score of Numbers in Ranges | Python | O(n log n + n log(range)) | O(n) | Medium | binary search, BINARY SEARCH THE GAP, PLACE GREEDILY LEFT TO RIGHT, new | |
| 3288 | Length of the Longest Increasing Path | Python | O(n log n) | O(n) | Hard | binary search, TWO STRICT LIS RUNS — ONE BEFORE THE PIVOT, ONE AFTER, new | |
| 3296 | Minimum Number of Seconds to Make Mountain Height Zero | Python | O(n log(max T)) | O(1) | Medium | binary search, BINARY SEARCH THE FINISH TIME — THE WORKERS ARE INDEPENDENT, new | |
| 3356 | Zero Array Transformation II | Python | O((n + q) log q) | O(n) | Medium | binary search, BINARY SEARCH ON THE PREFIX LENGTH, DIFFERENCE ARRAY FOR THE CHECK, new | |
| 3357 | Minimize the Maximum Adjacent Element Difference | Python | O(n log(max value)) | O(n) | Hard | binary search, BINARY SEARCH THE ANSWER, GREEDY FEASIBILITY WITH TWO CANDIDATE VALUES, new | |
| 3398 | Smallest Substring With Identical Characters I | Python | O(n^2) worst case | O(1) | Hard | binary search, THE ANSWER IS MONOTONE — TEST EACH CANDIDATE LENGTH DIRECTLY, new | |
| 3399 | Smallest Substring With Identical Characters II | Python | O(n log n) | O(1) | Hard | binary search, BINARY SEARCH THE ANSWER, GREEDY FEASIBILITY CHECK, new | |
| 3520 | Minimum Threshold for Inversion Pairs Count | Python | O(n * log n * log(maxV)) | O(n) | Medium | binary search, 🔒, BINARY SEARCH ON THE THRESHOLD + FENWICK COUNT OF QUALIFYING PAIRS, new | |
| 3605 | Minimum Stability Factor of Array | Python | O(n * log(max(nums)) + n * log(n)) | O(n) | Hard | binary search, BINARY SEARCH THE ANSWER + GREEDY INTERVAL STABBING WITH GCD RUNS, new |
Binary Search Tree
| # | Title | Solution | Time | Space | Difficulty | Note | Status |
|---|---|---|---|---|---|---|---|
| 0352 | Data Stream as Disjoint Intervals | Python, Java | addNum: O(n), getIntervals: O(n) | O(n) | Hard | BST, sorted interval list with binary search insert, TreeMap, LC 228, LC 715, new, hash table, union find, google, amazon, microsoft, linkedin |
|
| 1373 | Maximum Sum BST in Binary Tree | Python | O(n) | O(h) h = tree height | Hard | binary search tree, POST-ORDER DFS returning (is_bst, subtree_min, subtree_max, subtree_sum), new, amazon, fb, apple |
|
| 1932 | Merge BSTs to Create Single BST | Python | O(n) | O(n) | Hard | binary search tree, FIND THE UNIQUE OVERALL ROOT, THEN SPLICE + VALIDATE IN ONE DFS, new, amazon |
|
| 2426 | Number of Pairs Satisfying Inequality | Python | O(n log V) | O(V) | Hard | binary search tree, REARRANGE INTO ONE ARRAY, THEN COUNT WITH A FENWICK TREE, new | |
| 2689 | Extract Kth Character From The Rope Tree | Python | O(h) where h is the tree height | O(1) | Easy | binary search tree, 🔒, BINARY-SEARCH STYLE DESCENT (never build the whole string), new | |
| 2817 | Minimum Absolute Difference Between Elements With Constraint | Python | O(n * log n) | O(n) | Medium | binary search tree, SLIDING “ORDERED SET” OF ELIGIBLE PARTNERS (BST-STYLE PREDECESSOR /, new | |
| 3072 | Distribute Elements Into Two Arrays II | Python | O(n log n) | O(n) | Hard | binary search tree, TWO FENWICK TREES OVER THE COMPRESSED VALUES, new | |
| 3073 | Maximum Increasing Triplet Value | Python | O(n log n) | O(n) | Medium | binary search tree, 🔒, FIX THE MIDDLE, THEN WANT THE BIGGEST VALID LEFT AND RIGHT, new | |
| 3161 | Block Placement Queries | Python | O((n + maxX) log maxX) | O(n + maxX) | Hard | binary search tree, RUN THE QUERIES BACKWARDS SO INSERTIONS BECOME DELETIONS, new | |
| 3165 | Maximum Sum of Subsequence With Non-adjacent Elements | Python | O((n + q) log n) | O(n) | Hard | binary search tree, SEGMENT TREE WHOSE NODES CARRY A 2x2 “BOUNDARY” TABLE, new | |
| 3526 | Range XOR Queries with Subarray Reversals | Python | O(n + q * log n) expected | O(n) | Hard | binary search tree, 🔒, IMPLICIT TREAP (BALANCED BST KEYED BY POSITION) WITH A LAZY REVERSE FLAG, new |
Bit Manipulation
| # | Title | Solution | Time | Space | Difficulty | Note | Status |
|---|---|---|---|---|---|---|---|
| 0411 | Minimum Unique Word Abbreviation | Python, Java | O(2^m * n) | O(n) | Hard | bit manipulation, 🔒, bit-mask each word then enumerate abbreviation masks, LC 320, LC 408, new, google |
|
| 0476 | Number Complement | Python, Java | O(1) | O(1) | Easy | bit manipulation, flip the bits below the highest set bit, LC 190, basic, new, apple |
|
| 1310 | XOR Queries of a Subarray | Python | O(n + m) | O(n) | Medium | bit manipulation, prefix XOR, new, amazon |
|
| 1318 | Minimum Flips to Make a OR b Equal to c | Python | O(32) | O(1) | Medium | bit manipulation, BIT MANIPULATION (bits are independent -> decide each one alone), new | |
| 1558 | Minimum Numbers of Function Calls to Make Target Array | Python | O(n * log(max)) | O(1) | Medium | bit manipulation, BIT MANIPULATION (work backwards : halve everything, decrement odds), new, amazon |
|
| 1707 | Maximum XOR With an Element From Array | Python | O(nlog n + qlog q + (n + q)*30) | O(n * 30) | Hard | bit manipulation, OFFLINE QUERIES + BINARY TRIE (sort by m, grow the trie monotonically), new, google |
|
| 1720 | Decode XORed Array | Python | O(n) | O(n) for the output | Easy | bit manipulation, BIT MANIPULATION (XOR is its own inverse), new | |
| 1734 | Decode XORed Permutation | Python | O(n) | O(n) for the output | Medium | bit manipulation, BIT MANIPULATION - recover ONE element first, then unroll the chain, new, amazon |
|
| 1829 | Maximum XOR for Each Query | Python | O(n) | O(1) extra (O(n) output) | Medium | bit manipulation, RUNNING PREFIX XOR + COMPLEMENT UNDER THE MASK, new, uber |
|
| 2151 | Maximum Good People Based on Statements | Python | O(2^n * n^2) | O(1) | Hard | bit manipulation, ENUMERATE EVERY GOOD/BAD ASSIGNMENT (n <= 15 -> 2^15 masks), new | |
| 2212 | Maximum Points in an Archery Competition | Python | O(2^12 * 12) | O(1) | Medium | bit manipulation, ONLY 12 SECTIONS -> ENUMERATE ALL 2^12 SUBSETS BOB COULD WIN, new | |
| 2220 | Minimum Bit Flips to Convert Number | Python | O(log n) | O(1) | Easy | bit manipulation, XOR + POPCOUNT (Hamming distance), new | |
| 2275 | Largest Combination With Bitwise AND Greater Than Zero | Python | O(n * 24) | O(24) | Medium | bit manipulation, THE AND IS NON-ZERO IFF SOME BIT SURVIVES — COUNT PER BIT COLUMN, new | |
| 2317 | Maximum XOR After Operations | Python | O(n) | O(1) | Medium | bit manipulation, BIT MANIPULATION (the operation can only CLEAR bits -> answer is OR), new | |
| 2397 | Maximum Rows Covered by Columns | Python | O(2^n * m) | O(m) | Medium | bit manipulation, BITMASK BRUTE FORCE (n <= 12 -> only 4096 column subsets), new | |
| 2411 | Smallest Subarrays With Maximum Bitwise OR | Python | O(n * 30) | O(30) | Medium | bit manipulation, PER BIT, REMEMBER THE NEAREST INDEX TO THE RIGHT THAT SETS IT, new | |
| 2419 | Longest Subarray With Maximum Bitwise AND | Python | O(n) | O(1) | Medium | bit manipulation, ANDing MORE ELEMENTS ONLY CLEARS BITS — SO THE BEST AND IS max(nums), new | |
| 2425 | Bitwise XOR of All Pairings | Python | O(n + m) | O(1) | Medium | bit manipulation, EACH ELEMENT APPEARS ONCE PER ELEMENT OF THE OTHER ARRAY — PARITY DECIDES, new | |
| 2429 | Minimize XOR | Python | O(30) | O(1) | Medium | bit manipulation, SPEND THE BIT BUDGET ON num1’s HIGHEST SET BITS, THEN THE LOWEST GAPS, new | |
| 2505 | Bitwise OR of All Subsequence Sums | Python | O(n * 32 + 64) | O(64) | Medium | bit manipulation, 🔒, BIT COUNTING + CARRY PROPAGATION, new | |
| 2527 | Find Xor-Beauty of Array | Python | O(n) | O(1) | Medium | bit manipulation, BIT MANIPULATION / CANCELLATION -> ANSWER IS JUST XOR OF ALL ELEMENTS, new | |
| 2595 | Number of Even and Odd Bits | Python | O(log n) | O(1) | Easy | bit manipulation, BIT SCAN (walk bits low -> high, flip the bucket each step), new | |
| 2859 | Sum of Values at Indices With K Set Bits | Python | O(n * log n) | O(1) | Easy | bit manipulation, POPCOUNT VIA n & (n - 1) BIT TRICK, new |
|
| 2935 | Maximum Strong Pair XOR II | Python | O(n * log n + n * 20) | O(n * 20) | Hard | bit manipulation, SORT + SLIDING WINDOW OVER A COUNTING BINARY TRIE, new | |
| 2980 | Check if Bitwise OR Has Trailing Zeros | Python | O(n) | O(1) | Easy | bit manipulation, BIT MANIPULATION (COUNT EVEN NUMBERS), new | |
| 3125 | Maximum Number That Makes Result of Bitwise AND Zero | Python | O(1) | O(1) | Medium | bit manipulation, 🔒, THE ANSWER IS ALWAYS 2^h - 1, WHERE h IS n’S HIGHEST SET BIT, new | |
| 3133 | Minimum Array End | Python | O(log n + log x) | O(1) | Medium | bit manipulation, EVERY ELEMENT MUST BE A SUPERSET OF x’S BITS — SO COUNT IN THE FREE BITS, new, neetcode250 |
|
| 3226 | Number of Bit Changes to Make Two Integers Equal | Python | O(1) | O(1) | Easy | bit manipulation, ONLY 1 -> 0 IS ALLOWED, SO k’S BITS MUST BE A SUBSET OF n’S, new | |
| 3289 | The Two Sneaky Numbers of Digitville | Python | O(n) | O(n) | Easy | bit manipulation, A SEEN-SET — THE SECOND SIGHTING IDENTIFIES A CULPRIT, new | |
| 3304 | Find the K-th Character in String Game I | Python | O(1) | O(1) | Easy | bit manipulation, EACH DOUBLING SHIFTS THE COPY BY ONE — SO COUNT THE SET BITS OF k-1, new | |
| 3307 | Find the K-th Character in String Game II | Python | O(len(operations)) | O(1) | Hard | bit manipulation, WALK THE OPERATIONS BACKWARDS, FOLDING k INTO THE FIRST HALF, new | |
| 3314 | Construct the Minimum Bitwise Array I | Python | O(n log max) | O(n) | Easy | bit manipulation, x OR (x+1) ONLY EVER SETS A RUN OF LOW BITS — SO CLEAR ONE OF THEM, new | |
| 3315 | Construct the Minimum Bitwise Array II | Python | O(n log max) | O(n) | Medium | bit manipulation, SAME BIT RULE AS LC 3314 — THE VALUES JUST GET BIGGER, new | |
| 3370 | Smallest Number With All Set Bits | Python | O(1) | O(1) | Easy | bit manipulation, THE ALL-ONES NUMBERS ARE 2^b - 1 — TAKE THE FIRST ONE THAT REACHES n, new | |
| 3566 | Partition Array into Two Equal Product Subsets | Python | O(2^n * n) | O(1) | Medium | bit manipulation, BITMASK ENUMERATION OVER EVERY SPLIT, new | |
| 3632 | Subarrays with XOR at Least K | Python | O(n log C) | O(n) | Hard | bit manipulation, 🔒, COUNT THE COMPLEMENT, ONE BIT OF K AT A TIME, new | |
| 3646 | Next Special Palindrome Number | Python | O(C log C) where C ~ 1e5 candidates | O© | Hard | bit manipulation, ENUMERATE EVERY SPECIAL NUMBER ONCE, THEN BINARY SEARCH, new |
Breadth-First Search
| # | Title | Solution | Time | Space | Difficulty | Note | Status |
|---|---|---|---|---|---|---|---|
| 0499 | The Maze III | Python, Java | O(m * n * max(m, n) * log(m * n)) | O(m * n) | Hard | bfs, duplicate of the BFS entry, Dijkstra with the lexicographically smallest path, new, google, microsoft |
|
| 0773 | Sliding Puzzle | Python, Java | O(1) | O(1) | Hard | bfs, BFS over board states encoded as strings, LC 752, good trick, new, google, amazon, fb, uber |
|
| 0854 | K-Similar Strings | Python, Java | O(n^2 * n!) | O(n!) | Hard | bfs, BFS over swap states with pruning, good trick, new, google, amazon |
|
| 0882 | Reachable Nodes In Subdivided Graph | Python, Java | O(eloge) | O(n + e) | Hard | bfs, Dijkstra on the original graph then count the subdivided nodes, good trick, new, heap |
|
| 0913 | Cat and Mouse | Python, Java | O(n^3) | O(n^2) | Hard | bfs, minimax BFS over (mouse, cat, turn) states, game theory, complex, new, math, dp, graph, google |
|
| 1034 | Coloring A Border | Python | O(m * n) | O(m * n) | Medium | bfs, BFS (collect whole component first, then repaint only its border), new, amazon, fb |
|
| 1036 | Escape a Large Maze | Python | O(m^2), m = len(blocked) | O(m^2) | Hard | bfs, BOUNDED BFS (the key trick), new, google, uber |
|
| 1129 | Shortest Path with Alternating Colors | Python | O(n + m) | O(n + m) | Medium | bfs, BFS on a “doubled” state graph, new, google, amazon |
|
| 1161 | Maximum Level Sum of a Binary Tree | Python | O(n) | O(n) | Medium | bfs, BFS (level order traversal), new, google, amazon, fb, microsoft |
|
| 1203 | Sort Items by Groups Respecting Dependencies | Python | O(n + m + E), E = total number of beforeItems edges | O(n + m + E) | Hard | bfs, TWO-LEVEL TOPOLOGICAL SORT (BFS / Kahn), new, google, apple |
|
| 1210 | Minimum Moves to Reach Target with Rotations | Python | O(n^2) | O(n^2) | Hard | bfs, BFS on state = (row, col, orientation), new | |
| 1215 | Stepping Numbers | Python | O(2^d), d = number of digits of high | O(2^d) | Medium | bfs, 🔒, BFS (build stepping numbers digit by digit), new | |
| 1245 | Tree Diameter | Python | O(n) | O(n) | Medium | bfs, DOUBLE BFS (two-sweep), new, google, amazon, fb |
|
| 1263 | Minimum Moves to Move a Box to Their Target Location | Python | O((m * n)^2) | O((m * n)^2) | Hard | bfs, 0-1 BFS on state (box position, player position), new, google, fb |
|
| 1284 | Minimum Number of Flips to Convert Binary Matrix to Zero Matrix | Python | O(2^(m*n) * m * n) | O(2^(m*n)) | Hard | bfs, BFS over BITMASK states, new, google |
|
| 1291 | Sequential Digits | Python | O(1), at most 36 candidates | O(1) | Medium | bfs, ENUMERATE all sequential numbers (there are only 36 of them), new, amazon, apple |
|
| 1293 | Shortest Path in a Grid with Obstacles Elimination | Python | O(m * n * k) | O(m * n * k) | Hard | bfs, BFS on the 3D STATE (row, col, remaining_k), new, google, amazon, fb, apple |
|
| 1298 | Maximum Candies You Can Get from Boxes | Python | O(n + total keys + total contained) | O(n) | Hard | bfs, BFS (a box becomes openable when it is BOTH owned and unlocked), new | |
| 1302 | Deepest Leaves Sum | Python | O(n) | O(w) w = max level width | Medium | bfs, BFS LEVEL ORDER (keep only the last level’s sum), new, google, amazon, apple, microsoft |
|
| 1306 | Jump Game III | Python | O(n) | O(n) | Medium | bfs, BFS + visited set, new, google, amazon, fb, apple |
|
| 1311 | Get Watched Videos by Your Friends | Python | O(n + m + v log v) | O(n + v) | Medium | bfs, BFS level by level + counting + custom sort, new, amazon |
|
| 1345 | Jump Game IV | Python | O(n) | O(n) | Hard | bfs, BFS (level by level = shortest number of steps), new, google, amazon |
|
| 1368 | Minimum Cost to Make at Least One Valid Path in a Grid | Python | O(m * n) | O(m * n) | Hard | bfs, 0-1 BFS (deque), new, google, uber |
|
| 1602 | Find Nearest Right Node in Binary Tree | Python | O(n) | O(width of the tree) | Medium | bfs, 🔒, LEVEL-ORDER BFS (the “next node right” is the next queue entry), new, google |
|
| 1625 | Lexicographically Smallest String After Applying Operations | Python | O(n^2 * 100) worst case | O(n) | Medium | bfs, ENUMERATE THE REACHABLE SET (rotations x independent digit shifts), new | |
| 1654 | Minimum Jumps to Reach Home | Python | O(LIMIT) | O(LIMIT) | Medium | bfs, BFS over state (position, came-here-by-backward-jump?), new, amazon, apple |
|
| 1660 | Correct a Binary Tree | Python | O(n) | O(n) | Medium | bfs, 🔒, DFS VISITING RIGHT-TO-LEFT (the bad edge points to an ALREADY seen node), new, google |
|
| 1728 | Cat and Mouse II | Python | O((mn)^2 * (m + n)) | O((mn)^2) | Hard | bfs, GAME THEORY, RETROGRADE ANALYSIS (BFS backwards from terminal states), new, google |
|
| 1926 | Nearest Exit from Entrance in Maze | Python | O(m * n) | O(m * n) | Medium | bfs, BFS LEVEL BY LEVEL (unweighted grid -> first border cell reached wins), new, amazon, fb, uber |
|
| 1928 | Minimum Cost to Reach Destination in Time | Python | O(maxTime * m) | O(maxTime * n) | Hard | bfs, DP OVER (TIME, CITY) - a “layered graph” shortest path relaxed by time, new, google, fb |
|
| 2039 | The Time When the Network Becomes Idle | Python | O(V + E) | O(V + E) | Medium | bfs, BFS SHORTEST PATH FROM NODE 0 + PER-NODE ARITHMETIC, new | |
| 2045 | Second Minimum Time to Reach Destination | Python | O(V + E) | O(V + E) | Hard | bfs, BFS TRACKING THE TWO SMALLEST EDGE COUNTS PER NODE, THEN SIMULATE, new | |
| 2050 | Parallel Courses III | Python | O(n + m) | O(n + m), m = len(relations) | Hard | bfs, TOPOLOGICAL SORT + DP (longest path in a DAG, node weight = time), new, google |
|
| 2059 | Minimum Operations to Convert Number | Python | O(1000 * n) | O(1000), n = len(nums) | Medium | bfs, BFS OVER THE 1001 REACHABLE STATES (shortest number of operations), new, google |
|
| 2146 | K Highest Ranked Items Within a Price Range | Python | O(m * n log(m * n)) | O(m * n) | Medium | bfs, BFS FROM THE START, THEN SORT THE COLLECTED ITEMS BY THE RANK TUPLE, new | |
| 2258 | Escape the Spreading Fire | Python | O(m * n * log(m * n)) | O(m * n) | Hard | bfs, BFS THE FIRE ONCE, THEN BINARY SEARCH THE WAITING TIME, new | |
| 2368 | Reachable Nodes With Restrictions | Python | O(n) | O(n) | Medium | bfs, BFS FROM NODE 0, TREATING RESTRICTED NODES AS WALLS, new | |
| 2471 | Minimum Number of Operations to Sort a Binary Tree by Level | Python | O(n log n) | O(n) | Medium | bfs, PER LEVEL, THE MINIMUM SWAPS TO SORT = size - (number of cycles), new | |
| 2492 | Minimum Score of a Path Between Two Cities | Python | O(V + E) | O(V + E) | Medium | bfs, ROADS MAY BE REUSED — SO EVERY EDGE IN 1’s COMPONENT IS REACHABLE, new | |
| 2493 | Divide Nodes Into the Maximum Number of Groups | Python | O(V * (V + E)) | O(V + E) | Hard | bfs, THE GROUPING IS A BFS LAYERING — TRY EVERY START, PER COMPONENT, new | |
| 2503 | Maximum Number of Points From Grid Queries | Python | O(mnlog(mn) + klog k) | O(m*n) | Hard | bfs, OFFLINE QUERIES (SORT) + BEST-FIRST BFS WITH A MIN HEAP, new | |
| 2577 | Minimum Time to Visit a Cell In a Grid | Python | O(m * n * log(m * n)) | O(m * n) | Hard | bfs, DIJKSTRA (BFS + MIN HEAP) + PARITY WAITING TRICK, new | |
| 2583 | Kth Largest Sum in a Binary Tree | Python | O(n * log n) | O(n) | Medium | bfs, BFS (level order traversal) + SORT, new | |
| 2603 | Collect Coins in a Tree | Python | O(n) | O(n) | Hard | bfs, TOPOLOGICAL (LEAF) PRUNING x 2 ROUNDS, new | |
| 2612 | Minimum Reverse Operations | Python | O((n + len(banned)) * alpha(n)) | O(n) | Hard | bfs, BFS over an INTERVAL of same-parity targets + UNION-FIND “next unvisited”, new | |
| 2812 | Find the Safest Path in a Grid | Python | O(n^2 * log n) | O(n^2) | Medium | bfs, MULTI-SOURCE BFS + MAX-MIN (WIDEST PATH) DIJKSTRA, new | |
| 2814 | Minimum Time Takes to Reach Destination Without Drowning | Python | O(n * m) | O(n * m) | Hard | bfs, 🔒, TWO BFS - FLOOD SPREAD FIRST, THEN THE WALKER, new | |
| 3157 | Find the Level of Tree with Minimum Sum | Python | O(n) | O(width) | Medium | bfs, 🔒, LEVEL-ORDER BFS, TRACKING THE BEST SUM AND ITS LEVEL, new | |
| 3286 | Find a Safe Walk Through a Grid | Python | O(m * n) | O(m * n) | Medium | bfs, 0-1 BFS — MINIMISE THE DAMAGE TAKEN, THEN COMPARE WITH health, new | |
| 3373 | Maximize the Number of Target Nodes After Connecting Trees II | Python | O(n + m) | O(n + m) | Hard | bfs, “EVEN DISTANCE” IS A 2-COLOURING — SO COUNTING COLLAPSES TO PARITIES, new | |
| 3528 | Unit Conversion I | Python | O(n) | O(n) | Medium | bfs, THE CONVERSIONS FORM A TREE ROOTED AT 0 – ONE DFS MULTIPLIES ALONG IT, new | |
| 3535 | Unit Conversion II | Python | O(n + q * log MOD) | O(n) | Medium | bfs, 🔒, ROOT THE CONVERSION TREE AT UNIT 0 AND STORE ONE RATIO PER NODE, new | |
| 3552 | Grid Teleportation Traversal | Python | O(m*n) | O(m*n) | Medium | bfs, 0-1 BFS — TELEPORTS ARE ZERO-COST EDGES, new | |
| 3568 | Minimum Moves to Clean the Classroom | Python | O(m * n * 2^L * energy) | O(m * n * 2^L) | Medium | bfs, BFS OVER (ROW, COL, COLLECTED-MASK) KEEPING THE BEST ENERGY, new | |
| 3619 | Count Islands With Total Value Divisible by K | Python | O(m * n) | O(m * n) | Medium | bfs, BFS FLOOD FILL, SUMMING EACH COMPONENT AS IT IS CONSUMED, new | |
| 3629 | Minimum Jumps to Reach End via Prime Teleportation | Python | O(max(nums) log log max(nums) + n log max(nums)) | O(max(nums) + n log max(nums)) | Medium | bfs, BFS + SMALLEST-PRIME-FACTOR SIEVE, EACH PRIME BUCKET USED ONCE, new |
Constructive Algorithms
| # | Title | Solution | Time | Space | Difficulty | Note | Status |
|---|---|---|---|---|---|---|---|
| 2202 | Maximize the Topmost Element After K Moves | Python | O(n) | O(1) | Medium | constructive, CASE ANALYSIS ON WHAT k MOVES CAN REACH, new | |
| 2335 | Minimum Amount of Time to Fill Cups | Python | O(1) | O(1) | Easy | constructive, TWO LOWER BOUNDS, AND THE LARGER ONE IS ALWAYS ACHIEVABLE, new | |
| 2350 | Shortest Impossible Sequence of Rolls | Python | O(n) | O(k) | Hard | constructive, GREEDY SEGMENT SPLIT (count complete “all k faces” blocks), new | |
| 2358 | Maximum Number of Groups Entering a Competition | Python | O(1) | O(1) | Medium | constructive, MATH / GREEDY (only the group SIZES matter), new | |
| 2546 | Apply Bitwise Operations to Make Strings Equal | Python | O(n) | O(1) | Medium | constructive, CONSTRUCTIVE / INVARIANT (“does the string contain any 1 at all?”), new | |
| 2610 | Convert an Array Into a 2D Array With Conditions | Python | O(n) | O(n) | Medium | constructive, COUNTING (bucket the c-th copy of a value into row c), new | |
| 2647 | Color the Triangle Red | Python | O(n^2) (that is the size of the output itself) | O(1) extra | Hard | constructive, 🔒, CONSTRUCTIVE / GREEDY PATTERN (walk the rows BOTTOM-UP in blocks of 4), new | |
| 2654 | Minimum Number of Operations to Make All Array Elements Equal to 1 | Python | O(n^2 * log(max(nums))) | O(1) | Medium | constructive, GCD + SHORTEST SUBARRAY WHOSE GCD IS 1, new | |
| 2728 | Count Houses in a Circular Street | Python | O(k) | O(1) | Easy | constructive, 🔒, INTERACTIVE - NORMALIZE THE STREET, THEN CLOSE-AND-COUNT ONE LAP, new | |
| 2732 | Find a Good Subset of the Matrix | Python | O(m * n + 4^n) | O(2^n) | Hard | constructive, BITMASK ROWS + PROOF THAT ONLY k = 1 OR k = 2 CAN EVER WIN, new | |
| 2745 | Construct the Longest New String | Python | O(1) | O(1) | Medium | constructive, GREEDY / CASE ANALYSIS ON THE “AA” vs “BB” ALTERNATION, new | |
| 2753 | Count Houses in a Circular Street II | Python | O(k) | O(1) | Hard | constructive, 🔒, INTERACTIVE / BRAIN TEASER – use one open door as an anchor, new | |
| 2811 | Check if it is Possible to Split Array | Python | O(n) | O(1) | Medium | constructive, GREEDY / OBSERVATION ON THE LAST SPLIT, new | |
| 2829 | Determine the Minimum Sum of a k-avoiding Array | Python | O(n + k) | O(n + k) | Medium | constructive, GREEDY (take the smallest still-legal integer each time), new | |
| 2834 | Find the Minimum Possible Sum of a Beautiful Array | Python | O(1) | O(1) | Medium | constructive, GREEDY + ARITHMETIC SERIES (closed form, no loop), new | |
| 2849 | Determine if a Cell Is Reachable at a Given Time | Python | O(1) | O(1) | Medium | constructive, MATH (Chebyshev distance + a single degenerate case), new | |
| 2856 | Minimum Array Length After Pair Removals | Python | O(n) | O(1) | Medium | constructive, MAJORITY-ELEMENT COUNTING (greedy pairing argument), new | |
| 3139 | Minimum Cost to Equalize Array | Python | O(n + max(nums)) | O(1) | Hard | constructive, FIX THE TARGET, THEN THE ONLY QUESTION IS HOW MANY INCREMENTS PAIR UP, new | |
| 3260 | Find the Largest Palindrome Divisible by K | Python | O(n * 10 * k) | O(n * k) | Hard | constructive, ONLY THE FIRST HALF IS FREE, AND EACH DIGIT HAS A FIXED WEIGHT MOD k, new | |
| 3375 | Minimum Operations to Make Array Values Equal to K | Python | O(n) | O(n) | Easy | constructive, EACH OPERATION ERASES EXACTLY ONE DISTINCT VALUE ABOVE k, new | |
| 3680 | Generate Schedule | Python | O(n^2) | O(1) besides the output | Medium | constructive, GROUP THE MATCHES BY CIRCULAR GAP, THEN WALK EACH GAP IN ORDER, new |
Depth-First Search
| # | Title | Solution | Time | Space | Difficulty | Note | Status |
|---|---|---|---|---|---|---|---|
| 0440 | K-th Smallest in Lexicographical Order | Python, Java | O((logn)^2) | O(1) | Hard | dfs, count nodes in each 10-ary prefix subtree, LC 386, good trick, new, trie, google |
|
| 0749 | Contain Virus | Python, Java | O((m * n)^2) | O(m * n) | Hard | dfs, simulate rounds, dfs each region, count walls, complex, new, bloomberg |
|
| 1059 | All Paths from Source Lead to Destination | Python | O(V + E) | O(V + E) | Medium | dfs, 🔒, DFS + 3 color (white / gray / black) cycle detection, new, google, amazon |
|
| 1202 | Smallest String With Swaps | Python | O(n log n + m), n = len(s), m = len(pairs) | O(n) | Medium | dfs, UNION FIND (connected components), new, google, fb, apple |
|
| 1273 | Delete Tree Nodes | Python | O(n) | O(n) | Medium | dfs, POST ORDER DFS (iterative, so a 10^4 deep chain is safe), new | |
| 1315 | Sum of Nodes with Even-Valued Grandparent | Python | O(n) | O(h), h = tree height (recursion depth) | Medium | dfs, DFS carrying (parent value, grandparent value), new, amazon |
|
| 1319 | Number of Operations to Make Network Connected | Python | O((n + m) * a(n)) | O(n) a = inverse Ackermann | Medium | dfs, UNION FIND (count components; every extra cable can join two of them), new, amazon, fb, apple, microsoft |
|
| 1367 | Linked List in Binary Tree | Python | O(n * m) | O(n) | Medium | dfs, DOUBLE RECURSION (try to “start the match” at every tree node), new, amazon, microsoft |
|
| 1377 | Frog Position After T Seconds | Python | O(n) | O(n) | Hard | dfs, DFS on the tree, carry the accumulated probability down, new, google, amazon |
|
| 1391 | Check if There is a Valid Path in a Grid | Python | O(m * n * alpha(m * n)) | O(m * n) | Medium | dfs, UNION FIND (a street type = a fixed pair of open sides), new, google, uber |
|
| 1485 | Clone Binary Tree With Random Pointer | Python | O(n) | O(n) | Medium | dfs, 🔒, DFS + OLD->NEW MAP (create the copy BEFORE recursing), new, amazon, fb |
|
| 1722 | Minimize Hamming Distance After Swap Operations | Python | O(n * alpha(n)) | O(n) | Medium | dfs, UNION FIND + PER-COMPONENT MULTISET, new, google, amazon |
|
| 1766 | Tree of Coprimes | Python | O(n * 50) | O(n) | Hard | dfs, DFS + PER-VALUE ANCESTOR STACKS (values are only 1…50), new, google |
|
| 1973 | Count Nodes Equal to Sum of Descendants | Python | O(n) | O(n) | Medium | dfs, 🔒, POST-ORDER DFS (bottom-up subtree sums), new, fb |
|
| 2065 | Maximum Path Quality of a Graph | Python | O(n + m + 4^(maxTime/min_time)) | O(n + m) | Hard | dfs, EXHAUSTIVE DFS (the time budget bounds the walk length), new, fb |
|
| 2192 | All Ancestors of a Node in a Directed Acyclic Graph | Python | O(n * (V + E)) | O(V + E) | Medium | dfs, ONE DFS PER SOURCE — MARK THAT SOURCE ON EVERYTHING IT REACHES, new | |
| 2246 | Longest Path With Different Adjacent Characters | Python | O(n) | O(n) | Hard | dfs, TREE DP — AT EACH NODE, JOIN ITS TWO BEST DOWNWARD CHAINS, new | |
| 2265 | Count Nodes Equal to Average of Subtree | Python | O(n) | O(n) | Medium | dfs, ITERATIVE POST-ORDER DFS (bubble up (sum, count) per subtree), new | |
| 2322 | Minimum Score After Removals on a Tree | Python | O(n^2) | O(n) | Hard | dfs, ROOT THE TREE, THEN AN EDGE IS JUST “THE SUBTREE BELOW IT”, new | |
| 2385 | Amount of Time for Binary Tree to Be Infected | Python | O(n) | O(n) | Medium | dfs, THE INFECTION IGNORES THE PARENT/CHILD DIRECTION — MAKE IT A GRAPH, new | |
| 2445 | Number of Nodes With Value One | Python | O(n + q) | O(n) | Medium | dfs, 🔒, LAZY FLIP TAG + TOP-DOWN PROPAGATION (heap-indexed tree, parent = i // 2), new | |
| 2458 | Height of Binary Tree After Subtree Removal Queries | Python | O(n + m) | O(n) | Hard | dfs, PRECOMPUTE, FOR EVERY NODE, THE TREE HEIGHT WITHOUT ITS SUBTREE, new | |
| 2467 | Most Profitable Path in a Tree | Python | O(n) | O(n) | Medium | dfs, BOB’S ROUTE IS FIXED — TIME-STAMP IT, THEN LET ALICE PICK A LEAF, new | |
| 2477 | Minimum Fuel Cost to Report to the Capital | Python | O(n) | O(n) | Medium | dfs, GREEDY ON SUBTREE SIZES (every edge is crossed ceil(sz / seats) times), new | |
| 2581 | Count Number of Possible Root Nodes | Python | O(n + m) | O(n + m) (m = len(guesses)) | Hard | dfs, REROOTING TREE DP (2 passes, iterative), new | |
| 2773 | Height of Special Binary Tree | Python | O(n) | O(n) | Medium | dfs, 🔒, DFS THAT FILTERS OUT THE FAKE LEAF-TO-LEAF LINKS, new | |
| 2791 | Count Paths That Can Form a Palindrome in a Tree | Python | O(26 * n) | O(n) | Hard | dfs, ROOT-TO-NODE XOR BITMASK + PAIR COUNTING, new | |
| 3004 | Maximum Subtree of the Same Color | Python | O(n) | O(n) | Medium | dfs, 🔒, POST-ORDER DFS — A SUBTREE IS UNIFORM IFF ALL ITS CHILDREN ARE, new | |
| 3067 | Count Pairs of Connectable Servers in a Weighted Tree Network | Python | O(n^2) | O(n) | Medium | dfs, ROOT AT EACH SERVER, COUNT PER BRANCH, MULTIPLY ACROSS BRANCHES, new | |
| 3203 | Find Minimum Diameter After Merging Two Trees | Python | O(n + m) | O(n + m) | Hard | dfs, JOIN THE TWO CENTRES — THE ANSWER IS A MAX OF THREE TERMS, new | |
| 3249 | Count the Number of Good Nodes | Python | O(n) | O(n) | Medium | dfs, POST-ORDER SUBTREE SIZES, THEN COMPARE EACH NODE’S CHILDREN, new | |
| 3327 | Check if DFS Strings Are Palindromes | Python | O(n) | O(n) | Hard | dfs, ONE GLOBAL DFS STRING — EVERY SUBTREE IS A CONTIGUOUS SLICE OF IT, new | |
| 3331 | Find Subtree Sizes After Changes | Python | O(n) | O(n) | Medium | dfs, ONE DFS CARRYING A STACK OF ANCESTORS PER LETTER, new | |
| 3367 | Maximize Sum of Weights after Edge Removals | Python | O(n log n) | O(n) | Hard | dfs, TREE DP ON “IS THE EDGE TO MY PARENT KEPT ?”, new | |
| 3590 | Kth Smallest Path XOR Sum | Python | O((n + q) * log(max_val)) | O(n * log(max_val)) | Hard | dfs, MERGEABLE BINARY TRIE OVER THE XOR VALUES, MERGED BOTTOM-UP, new | |
| 3593 | Minimum Increments to Equalize Leaf Paths | Python | O(n) | O(n) | Medium | dfs, BOTTOM-UP MAX, CHARGING ONE OPERATION PER SHORT CHILD, new | |
| 3607 | Power Grid Maintenance | Python | O((c + n + q) * log©) | O© | Medium | dfs, UNION-FIND + PER-GRID MIN-HEAP WITH LAZY DELETION, new |
Design
| # | Title | Solution | Time | Space | Difficulty | Note | Status |
|---|---|---|---|---|---|---|---|
| 0381 | Insert Delete GetRandom O(1) - Duplicates allowed | Python, Java | O(1) average | O(n) | Hard | design, LC 380, hashmap of value -> index set + swap-with-last, good trick, new, google, amazon, fb, apple, uber, linkedin |
|
| 0604 | Design Compressed String Iterator | Python, Java | ctor: O(n), next/hasNext: O(1) | O(n) | Easy | design, 🔒, decode (char, count) pairs lazily, iterator, LC 900, new, google |
|
| 0631 | Design Excel Sum Formula | Python, Java | set: O(1) get: O((r * c)^2) sum: O((r * c)^2) |
O(r * c) | Hard | design, 🔒, formula dependency graph, recompute on set, complex, new, google, amazon, microsoft, uber |
|
| 0641 | Design Circular Deque | Python, Java | O(1) per op | O(k) | Medium | design, circular buffer or doubly linked list, LC 622, good basic, new, amazon, fb |
|
| 0715 | Range Module | Python, Java | add: O(n) remove: O(n) query: O(logn) |
O(n) | Hard | design, sorted interval list, LC 352, TreeMap, segment tree, new, google, amazon, fb, linkedin |
|
| 1348 | Tweet Counts Per Frequency | Python | O(log n) per record, O(c * log n) per query (c = number of chunks) | O(n) | Medium | design, SORTED LIST PER TWEET + BINARY SEARCH per chunk, new, amazon |
|
| 1352 | Product of the Last K Numbers | Python | O(1) per add / getProduct | O(n) | Medium | design, PREFIX PRODUCTS, reset on every 0, new, google, amazon, apple, uber |
|
| 1357 | Apply Discount Every n Orders | Python | O(m) per getBill (m = #distinct products in that bill), O(k) init | O(k), k = len(products) | Medium | design, HASH TABLE (product id -> price) + CUSTOMER COUNTER MOD n, new, fb |
|
| 1476 | Subrectangle Queries | Python | O(rows * cols) per update, O(1) per getValue | O(rows * cols) | Medium | design, BRUTE FORCE UPDATE (just overwrite the cells), new | |
| 1483 | Kth Ancestor of a Tree Node | Python | O(n log n) build, O(log n) per query | O(n log n) | Hard | design, BINARY LIFTING (jump 2^j steps at a time), new, google, amazon |
|
| 1570 | Dot Product of Two Sparse Vectors | Python | O(n) to build, O(min(k1, k2)) per dot product | O(k), k = number of non-zero entries | Medium | design, 🔒, HASH TABLE (keep only the non-zero entries), new, google, amazon, fb, apple, microsoft |
|
| 1586 | Binary Search Tree Iterator II | Python | O(n) to build, O(1) per call | O(n) | Medium | design, 🔒, FLATTEN THE BST + CURSOR (in-order gives a sorted array), new, fb |
|
| 1600 | Throne Inheritance | Python | O(1) for birth / death, O(n) for getInheritanceOrder | O(n) | Medium | design, N-ARY TREE + PRE-ORDER DFS (the inheritance order IS a pre-order walk), new, google, amazon |
|
| 1622 | Fancy Sequence | Python | O(1) for append (amortised, O(log MOD) for the inverse), O(1) others | O(n) | Hard | design, LAZY AFFINE TRANSFORM + MODULAR INVERSE, new, google, apple |
|
| 1804 | Implement Trie II (Prefix Tree) | Python | O(L) per operation, L = len(word) | O(total inserted chars) | Medium | design, 🔒, TRIE WITH TWO COUNTERS PER NODE (word count + prefix count), new, apple |
|
| 1825 | Finding MK Average | Python | O(log M) per addElement / calculateMKAverage, M = 10^5 | O(M + m) | Hard | design, SLIDING WINDOW (deque) + FENWICK TREE INDEXED BY VALUE, new, google |
|
| 1865 | Finding Pairs With a Certain Sum | Python | O(1) per add, O(len(nums1)) per count | O(len(nums2)) | Medium | design, DESIGN - HASH COUNTER ON THE BIG ARRAY, LOOP OVER THE SMALL ONE, new | |
| 1912 | Design Movie Rental System | Python | O(m log m) init, O(log m) per rent/drop, O(1) per search/report | O(m), m = len(entries) | Hard | design, ORDERED SETS (one sorted list per movie + one global sorted list), new | |
| 1993 | Operations on Tree | Python | O(1) lock / unlock, O(n) upgrade | O(n) | Medium | design, DESIGN - parent array (walk up) + children lists (walk down), new, google |
|
| 2043 | Simple Bank System | Python | O(1) per operation | O(n) | Medium | design, PLAIN ARRAY + TWO VALIDATION HELPERS, new | |
| 2069 | Walking Robot Simulation II | Python | O(width + height) to build, O(1) per call | O(width + height) | Medium | design, THE ROBOT IS PERMANENTLY ON THE PERIMETER — WALK A CYCLIC RING, new | |
| 2080 | Range Frequency Queries | Python | O(n) build, O(log n) per query | O(n) | Medium | design, VALUE -> SORTED LIST OF ITS INDICES, THEN BINARY SEARCH THE RANGE, new | |
| 2102 | Sequentially Ordinal Rank Tracker | Python | O(log n) per call | O(n) | Hard | design, TWO HEAPS STRADDLING THE ANSWER POSITION, new, amazon |
|
| 2166 | Design Bitset | Python | O(1) per op except toString(), which is O(size) | O(size) | Medium | design, STORE THE BITS AND A LAZY “INVERTED” FLAG SO flip() IS O(1), new | |
| 2227 | Encrypt and Decrypt Strings | Python | init O(sum(len(dictionary[i]))), encrypt O(len(word1)), decrypt O(1) | O(len(keys) + total dictionary length) | Hard | design, REVERSE THE QUESTION - PRE-ENCRYPT THE DICTIONARY, new | |
| 2241 | Design an ATM Machine | Python | O(5) per call | O(1) | Medium | design, FIXED LARGEST-FIRST GREEDY, COMMITTED ONLY IF IT FULLY SUCCEEDS, new | |
| 2254 | Design Video Sharing Platform | Python | O(log n) for upload, O(1) for the rest (watch is O(slice length)) | O(total content) | Hard | design, 🔒, DICT OF LIVE VIDEOS + A MIN-HEAP OF RECYCLED IDs, new | |
| 2276 | Count Integers in Intervals | Python | O(log n) amortised per add, O(1) per count | O(n) | Hard | design, KEEP THE INTERVALS DISJOINT AND MERGE ON INSERT, new | |
| 2286 | Booking Concert Tickets in Groups | Python | O(log n) per gather, amortised O(log n) per scatter | O(n) | Hard | design, SEGMENT TREE HOLDING (MAX FREE SEATS, TOTAL FREE SEATS) PER ROW, new | |
| 2296 | Design a Text Editor | Python | O(k) per call | O(total text) | Hard | design, TWO STACKS STRADDLING THE CURSOR, new | |
| 2336 | Smallest Number in Infinite Set | Python | O(log n) per call | O(n) | Medium | design, A FRONTIER COUNTER FOR THE UNTOUCHED TAIL + A MIN-HEAP OF RETURNS, new | |
| 2349 | Design a Number Container System | Python | O(log n) amortized per change / find | O(n) | Medium | design, HASH MAP + MIN HEAP WITH LAZY DELETION (avoid an ordered set), new | |
| 2353 | Design a Food Rating System | Python | O(n log n) init, O(log n) amortized per call | O(n) | Medium | design, HASH MAP + MIN HEAP WITH LAZY DELETION (avoid an ordered set), new | |
| 2408 | Design SQL | Python | O(1) per operation | O(total rows stored) | Medium | design, 🔒, PER TABLE, A DICT rowId -> ROW PLUS A NEVER-DECREASING ID COUNTER, new | |
| 2424 | Longest Uploaded Prefix | Python | O(1) amortised per call | O(n) | Medium | design, A SET OF UPLOADS PLUS A POINTER THAT ONLY EVER MOVES FORWARD, new | |
| 2502 | Design Memory Allocator | Python | O(n) per call | O(n) | Medium | design, DIRECT SIMULATION ON A UNIT ARRAY, new | |
| 2526 | Find Consecutive Integers from a Data Stream | Python | O(1) per consec call | O(1) | Medium | design, RUNNING STREAK COUNTER (no queue needed), new | |
| 2590 | Design a Todo List | Python | O(1) addTask, O(n log n) per read, O(n) completeTask | O(n) | Medium | design, 🔒, HASH MAP (user -> task list) + SORT ON READ, new | |
| 2671 | Frequency Tracker | Python | O(1) per operation | O(n) with n = #distinct numbers added | Medium | design, TWO COUNTERS – “count of each number” + “count of each count”, new | |
| 3242 | Design Neighbor Sum Service | Python | O(n^2) to build, O(1) per query | O(n^2) | Easy | design, INDEX THE VALUES ONCE, THEN EACH QUERY IS FOUR BOUNDED LOOKUPS, new | |
| 3408 | Design Task Manager | Python | O(log n) amortised per operation | O(number of pushes) | Medium | design, MAX-HEAP WITH LAZY DELETION, DICT AS THE SOURCE OF TRUTH, new | |
| 3508 | Implement Router | Python | O(1) add / forward amortised, O(log n) getCount | O(n) | Medium | design, FIFO QUEUE + PER-DESTINATION TIMESTAMP LIST WITH A CONSUMED POINTER, new |
Dynamic Programming
| # | Title | Solution | Time | Space | Difficulty | Note | Status |
|---|---|---|---|---|---|---|---|
| 0087 | Scramble String | Python, Java | O(n^4) | O(n^3) | Hard | dp, 3D interval dp / memoized recursion on (i, j, len), new, google, amazon, apple |
|
| 0174 | Dungeon Game | Python, Java | O(m * n) | O(m * n) | Hard | dp, 2D dp filled from the bottom-right, track the min health needed, good trick, new, google, amazon, microsoft, uber |
|
| 0188 | Best Time to Buy and Sell Stock IV | Python, Java | O(n * k) | O(k) | Hard | dp, LC 122, LC 123, k-transaction stock dp, state machine, new, google, amazon, fb, apple, uber |
|
| 0446 | Arithmetic Slices II - Subsequence | Python, Java | O(n^2) | O(n^2) | Hard | dp, dp with a hashmap of (index, diff), LC 413, good trick, new, google, fb, uber |
|
| 0465 | Optimal Account Balancing | Python, Java | O(m!) | O(m) | Hard | dp, 🔒, net balances then backtracking over settlements, bitmask dp, new, google, amazon, uber |
|
| 0466 | Count The Repetitions | Python, Java | O(l1 * l2 + n1) | O(l2) | Hard | dp, find the repeating pattern of s2 matches inside s1, good trick, new, amazon |
|
| 0514 | Freedom Trail | Python, Java | O(m * n^2) | O(n) | Hard | dp, dp over (ring position, key index), precompute char positions, new, google |
|
| 0546 | Remove Boxes | Python, Java | O(n^4) | O(n^3) | Hard | dp, 3D interval dp on (l, r, k attached same-colour boxes), new, amazon, apple, uber |
|
| 0568 | Maximum Vacation Days | Python, Java | O(k * n^2) | O(n) | Hard | dp, 🔒, dp over (week, city) with a flight matrix, new, google, fb, microsoft |
|
| 0600 | Non-negative Integers without Consecutive Ones | Python, Java | O(1) | O(1) | Hard | dp, digit dp with Fibonacci counts, bit manipulation, good trick, new |
|
| 0629 | K Inverse Pairs Array | Python, Java | O(n * k) | O(k) | Hard | dp, dp on (n, k) with a sliding-window prefix sum, mod 1e9+7, new | |
| 0656 | Coin Path | Python, Java | O(n * maxJump) | O(n) | Hard | dp, 🔒, dp from the back, lexicographically smallest path, new, google |
|
| 0664 | Strange Printer | Python, Java | O(n^3) | O(n^2) | Hard | dp, interval dp, print the leftmost char across the whole range, new, google |
|
| 0689 | Maximum Sum of 3 Non-Overlapping Subarrays | Python, Java | O(n) | O(n) | Hard | dp, prefix sums + best-left / best-right arrays, LC 643, new, google, fb |
|
| 0691 | Stickers to Spell Word | Python, Java | O(2^l * n * l) | O(2^l) | Hard | dp, bitmask dp over target letters, BFS alternative, new, fb |
|
| 0730 | Count Different Palindromic Subsequences | Python, Java | O(n^2) | O(n^2) | Hard | dp, interval dp counting distinct palindromic subsequences, mod, new, google, amazon, fb, apple, linkedin |
|
| 0741 | Cherry Pickup | Python, Java | O(n^3) | O(n^2) | Hard | dp, two walkers moving simultaneously, 3D dp, LC 1463, new, google, amazon, fb, uber |
|
| 0805 | Split Array With Same Average | Python, Java | O(2^(n/2)) | O(2^(n/2)) | Hard | dp, meet in the middle over subset sums, good trick, new, google, amazon, apple, microsoft, uber |
|
| 0818 | Race Car | Python, Java | O(target * log(target)) | O(target) | Hard | dp, BFS over (position, speed) or dp, good trick, new, google, amazon, microsoft |
|
| 0847 | Shortest Path Visiting All Nodes | Python, Java | O(n^2 * 2^n) | O(n * 2^n) | Hard | dp, bitmask BFS/dp over visited sets, TSP-style, good trick, new, google, amazon, fb |
|
| 0879 | Profitable Schemes | Python, Java | O(m * n * minProfit) | O(n * minProfit) | Hard | dp, 3D knapsack dp on (members, profit), mod, new, google, linkedin |
|
| 0903 | Valid Permutations for DI Sequence | Python, Java | O(n^2) | O(n) | Hard | dp, dp on (index, number of smaller values used), prefix sums, new | |
| 0920 | Number of Music Playlists | Python, Java | O(goal * n) | O(goal * n) | Hard | dp, combinatorial dp on (songs used, distinct songs), mod, new, google, amazon, fb |
|
| 0940 | Distinct Subsequences II | Python, Java | O(26 * n) | O(1) | Hard | dp, dp with last-occurrence subtraction per letter, mod, new, google |
|
| 0943 | Find the Shortest Superstring | Python, Java | O(n^2 * 2^n + n^2 * l) | O(n * 2^n) | Hard | dp, bitmask dp (TSP) over pairwise overlap, reconstruct the path, new, google, amazon |
|
| 0956 | Tallest Billboard | Python, Java | O(n * s) | O(s) | Hard | dp, dp over the height difference between the two supports, new | |
| 0960 | Delete Columns to Make Sorted III | Python, Java | O(m^2 * n) | O(m) | Hard | dp, LIS over columns, LC 300, LC 944, LC 955, new, google |
|
| 0964 | Least Operators to Express Number | Python, Java | O((logt)^2) | O((logt)^2) | Hard | dp, memoized recursion over base-x digits, complex, new |
|
| 0975 | Odd Even Jump | Python, Java | O(nlogn) | O(n) | Hard | dp, monotonic stack / TreeMap for the next greater-or-equal, dp from the back, new, google |
|
| 1035 | Uncrossed Lines | Python | O(m * n) | O(m * n) | Medium | dp, 2D DP (this is exactly “Longest Common Subsequence”), new, amazon |
|
| 1039 | Minimum Score Triangulation of Polygon | Python | O(n^3) | O(n^2) | Medium | dp, INTERVAL DP, new, uber |
|
| 1043 | Partition Array for Maximum Sum | Python | O(n * k) | O(n) | Medium | dp, 1D DP, new, amazon, fb |
|
| 1092 | Shortest Common Supersequence | Python | O(m * n) | O(m * n) | Hard | dp, LCS (2D DP) + BACKTRACK the DP table, new, google, amazon, microsoft |
|
| 1105 | Filling Bookcase Shelves | Python | O(n^2) | O(n) | Medium | dp, 1D DP (partition the ordered list into consecutive shelves), new, google, amazon, bloomberg |
|
| 1125 | Smallest Sufficient Team | Python | O(2^m * n) | O(2^m) m = len(req_skills), n = len(people) | Hard | dp, BITMASK DP over skill sets (m <= 16 -> only 2^16 states), new, google |
|
| 1139 | Largest 1-Bordered Square | Python | O(m * n * min(m, n)) | O(m * n) | Medium | dp, DP (suffix counts) + ENUMERATION, new, amazon |
|
| 1155 | Number of Dice Rolls With Target Sum | Python | O(n * k * target) | O(target) | Medium | dp, 2D DP -> rolling 1D array, new, google, amazon, microsoft |
|
| 1182 | Shortest Distance to Target Color | Python | O(n + q) | O(n) | Medium | dp, 🔒, PREFIX / SUFFIX DP (nearest occurrence of each color on each side), new, google, uber |
|
| 1186 | Maximum Subarray Sum with One Deletion | Python | O(n) | O(1) | Medium | dp, KADANE with 2 STATES (DP), new | |
| 1187 | Make Array Strictly Increasing | Python | O(n * m log m) | O(m) | Hard | dp, DP over “last value kept” + BINARY SEARCH, new, google |
|
| 1191 | K-Concatenation Maximum Sum | Python | O(n) | O(1) | Medium | dp, PREFIX SUM + CASE DISCUSSION, new, google, amazon |
|
| 1216 | Valid Palindrome III | Python | O(n^2) | O(n^2) | Hard | dp, 🔒, 2D DP (Longest Palindromic Subsequence), new, amazon, fb |
|
| 1218 | Longest Arithmetic Subsequence of Given Difference | Python | O(n) | O(n) | Medium | dp, HASH MAP DP, new, google, fb, uber |
|
| 1220 | Count Vowels Permutation | Python | O(n) | O(1) | Hard | dp, 1D DP (count by last character), new, amazon |
|
| 1223 | Dice Roll Simulation | Python | O(n * 6 * M), M = max(rollMax) | O(6 * M) | Hard | dp, 2D DP (last face + current run length), new, google, bloomberg |
|
| 1230 | Toss Strange Coins | Python | O(n * target) | O(target) | Medium | dp, 1D DP (rolled from the 2D “first i coins, j heads” table), new, google |
|
| 1235 | Maximum Profit in Job Scheduling | Python | O(n log n) | O(n) | Hard | dp, DP + BINARY SEARCH (weighted interval scheduling), new, google, amazon, microsoft, uber |
|
| 1239 | Maximum Length of a Concatenated String with Unique Characters | Python | O(2^n + L), n = len(arr), L = total chars | O(2^n) | Medium | dp, BITMASK DP (build set of reachable “used letters” states), new, amazon, microsoft |
|
| 1246 | Palindrome Removal | Python | O(n^3) | O(n^2) | Hard | dp, INTERVAL DP, new, microsoft |
|
| 1262 | Greatest Sum Divisible by Three | Python | O(n) | O(1) | Medium | dp, DP ON REMAINDER, new, amazon, fb |
|
| 1269 | Number of Ways to Stay in the Same Place After Some Steps | Python | O(steps * min(arrLen, steps)) | O(min(arrLen, steps)) | Hard | dp, 1D DP (rolling array), new, google, fb, apple |
|
| 1278 | Palindrome Partitioning III | Python | O(n^2 * k) | O(n^2) | Hard | dp, 2 STAGE DP, new | |
| 1289 | Minimum Falling Path Sum II | Python | O(n^3) | O(n) | Hard | dp, 1D DP (rolling array), new, google |
|
| 1301 | Number of Paths with Max Score | Python | O(n^2) | O(n^2) | Hard | dp, 2D DP (max score + path count, filled bottom-right -> top-left), new | |
| 1320 | Minimum Distance to Type a Word Using Two Fingers | Python | O(26 * n) | O(26) | Hard | dp, DP over “where the OTHER finger rests” (the typing finger is implicit), new, google |
|
| 1340 | Jump Game V | Python | O(n log n + n * d) | O(n) | Hard | dp, SORT BY VALUE + DP, new | |
| 1387 | Sort Integers by The Power Value | Python | O(n log n * M), n = hi - lo + 1, M = max chain length | O(n + M) | Medium | dp, memoized Collatz “power” (top down DP) + sort by (power, value), new, google |
|
| 1388 | Pizza With 3n Slices | Python | O(n^2) | O(n^2) | Hard | dp, CIRCULAR HOUSE ROBBER, but taking EXACTLY n slices, new, google, uber |
|
| 1395 | Count Number of Teams | Python | O(n^2) | O(1) | Medium | dp, FIX THE MIDDLE SOLDIER (count smaller-left / larger-right), new, google, amazon, apple |
|
| 1397 | Find All Good Strings | Python | O(n * m * 26) | O(n * m * 4), m = len(evil) | Hard | dp, DIGIT DP + KMP AUTOMATON (build the string left to right), new, google |
|
| 1411 | Number of Ways to Paint N × 3 Grid | Python | O(n) | O(1) | Hard | dp, DP on ROW PATTERN TYPE (only 2 shapes matter), new, google, fb |
|
| 1416 | Restore The Array | Python | O(n * log10(k)) | O(n) | Hard | dp, DP OVER SUFFIXES (cut the first number, recurse on the rest), new, amazon |
|
| 1420 | Build Array Where You Can Find The Maximum Exactly K Comparisons | Python | O(n * m * k) | O(m * k) | Hard | dp, DP ON (length, prefix max, cost) + PREFIX SUM, new | |
| 1434 | Number of Ways to Wear Different Hats to Each Other | Python | O(40 * 2^n * n) | O(2^n) | Hard | dp, BITMASK DP (iterate over HATS, not people), new | |
| 1444 | Number of Ways of Cutting a Pizza | Python | O(m * n * k * (m + n)) | O(m * n * k) | Hard | dp, 2D PREFIX SUM + MEMOIZED SEARCH (state = remaining bottom-right block), new, google |
|
| 1449 | Form Largest Integer With Digits That Add up to Target | Python | O(target * 9) | O(target) | Hard | dp, UNBOUNDED KNAPSACK (maximize digit count) + GREEDY RECONSTRUCTION, new, google |
|
| 1458 | Max Dot Product of Two Subsequences | Python | O(m * n) | O(m * n) | Hard | dp, 2D DP (LCS-like), new | |
| 1463 | Cherry Pickup II | Python | O(rows * cols^2 * 9) | O(cols^2) | Hard | dp, DP ON BOTH ROBOTS AT ONCE (they always share the same row), new, google, apple |
|
| 1467 | Probability of a Two Boxes Having The Same Number of Distinct Balls | Python | O(k * n * k * maxBalls) | O(k * n * k) | Hard | dp, COMBINATORICS + DFS OVER COLORS (count splits, not shuffles), new | |
| 1473 | Paint House III | Python | O(m * n^2 * target) | O(n * target) | Hard | dp, DP ON (house, colour, neighborhoods so far), new, apple |
|
| 1477 | Find Two Non-overlapping Sub-arrays Each With Target Sum | Python | O(n) | O(n) | Medium | dp, PREFIX SUM HASH + BEST-SO-FAR DP, new, google |
|
| 1478 | Allocate Mailboxes | Python | O(n^2 * k) | O(n^2) | Hard | dp, INTERVAL COST + PARTITION DP, new, google, amazon |
|
| 1494 | Parallel Courses II | Python | O(3^n) worst case | O(2^n) | Hard | dp, BITMASK + BFS over subsets (n <= 15 -> state = set of taken courses), new, google |
|
| 1504 | Count Submatrices With All Ones | Python | O(m^2 * n) | O(m * n) | Medium | dp, ROW WIDTH DP + ENUMERATE BOTTOM RIGHT CORNER, new, google, microsoft |
|
| 1510 | Stone Game IV | Python | O(n * sqrt(n)) | O(n) | Hard | dp, GAME DP (win / lose states, bottom up), new, google, apple |
|
| 1524 | Number of Sub-arrays With Odd Sum | Python | O(n) | O(1) | Medium | dp, PREFIX-SUM PARITY COUNTING, new, google, apple |
|
| 1531 | String Compression II | Python | O(n^2 * k) | O(n * k) | Hard | dp, DP ON (index, deletions left), BUILDING ONE RUN AT A TIME, new, google, fb, microsoft, uber |
|
| 1547 | Minimum Cost to Cut a Stick | Python | O(m^3) | O(m^2) | Hard | dp, INTERVAL DP (same shape as matrix-chain / burst balloons), new, google, amazon, fb |
|
| 1548 | The Most Similar Path in a Graph | Python | O(L * (n + m)) with L = len(targetPath) | O(L * n) | Hard | dp, 🔒, DP OVER (step, city) + PARENT POINTERS TO REBUILD THE PATH, new, google |
|
| 1553 | Minimum Number of Days to Eat N Oranges | Python | O(log(n)^2) | O(log(n)^2) | Hard | dp, MEMOIZED DFS (only n//2 and n//3 states are ever reachable), new, google, amazon |
|
| 1563 | Stone Game V | Python | O(n^2) | O(n^2) | Hard | dp, INTERVAL DP + PREFIX MAX (O(n^2), the plain O(n^3) memo is too slow), new | |
| 1569 | Number of Ways to Reorder Array to Get Same BST | Python | O(n^2) | O(n^2) | Hard | dp, COMBINATORICS + DIVIDE & CONQUER (interleave the two subtrees), new, google, amazon |
|
| 1575 | Count All Possible Routes | Python | O(fuel * n^2) | O(fuel * n) | Hard | dp, DP over (fuel left, city) – bottom up so no deep recursion, new | |
| 1594 | Maximum Non Negative Product in a Matrix | Python | O(m * n) | O(m * n) | Medium | dp, DP KEEPING BOTH MAX AND MIN (a negative cell flips the two), new, google, amazon |
|
| 1595 | Minimum Cost to Connect Two Groups of Points | Python | O(m * 2^n * n) | O(m * 2^n) | Hard | dp, BITMASK DP over group 2 (size2 <= 12), new, google |
|
| 1626 | Best Team With No Conflicts | Python | O(n^2) | O(n) | Medium | dp, SORT + LONGEST-INCREASING-SUBSEQUENCE style DP (max sum variant), new, uber |
|
| 1639 | Number of Ways to Form a Target String Given a Dictionary | Python | O(n * (L + m)) | O(26 * n + m) with n = word len, m = len(target) | Hard | dp, DP over COLUMNS (which word we pick never matters, only the count), new, google, microsoft |
|
| 1655 | Distribute Repeating Integers | Python | O(k * 3^m) | O(2^m) | Hard | dp, BITMASK DP OVER SUBSETS (m <= 10 customers, <= 50 distinct values), new, google |
|
| 1664 | Ways to Make a Fair Array | Python | O(n) | O(1) | Medium | dp, PREFIX / SUFFIX PARITY SUMS (removing index i flips the parity of the tail), new | |
| 1681 | Minimum Incompatibility | Python | O(2^n * n) for the cost table + subset-sum DP | O(2^n) | Hard | dp, BITMASK DP OVER SUBSETS (n <= 16 -> partition into groups of size m = n/k), new | |
| 1682 | Longest Palindromic Subsequence II | Python | O(n^2 * 26) | O(n * 26) | Medium | dp, 🔒, INTERVAL DP WITH AN EXTRA “LAST PAIRED CHAR” DIMENSION, new | |
| 1690 | Stone Game VII | Python | O(n^2) | O(n) | Medium | dp, INTERVAL DP ON THE SCORE DIFFERENCE (zero-sum game -> one table, not two), new | |
| 1691 | Maximum Height by Stacking Cuboids | Python | O(n^2) | O(n) | Hard | dp, SORT EACH CUBOID + LIS-STYLE DP (rotation collapses to “sort the dims”), new, google |
|
| 1692 | Count Ways to Distribute Candies | Python | O(n * k) | O(k) | Hard | dp, 🔒, STIRLING NUMBERS OF THE SECOND KIND (bags are indistinguishable), new, google |
|
| 1745 | Palindrome Partitioning IV | Python | O(n^2) | O(n^2) | Hard | dp, INTERVAL DP PALINDROME TABLE + ENUMERATE THE TWO CUTS, new | |
| 1746 | Maximum Subarray Sum After One Operation | Python | O(n) | O(1) | Medium | dp, 🔒, KADANE WITH A STATE FLAG (0 = not squared yet, 1 = already squared), new | |
| 1751 | Maximum Number of Events That Can Be Attended II | Python | O(n log n + n * k) | O(n * k) | Hard | dp, DP + BINARY SEARCH (weighted interval scheduling, capped at k picks), new, amazon |
|
| 1770 | Maximum Score from Performing Multiplication Operations | Python | O(m^2) | O(m) | Hard | dp, DP ON (operation index, how many were taken from the LEFT), new, google, amazon |
|
| 1771 | Maximize Palindrome Length From Subsequences | Python | O((n1 + n2)^2) | O((n1 + n2)^2) | Hard | dp, LONGEST PALINDROMIC SUBSEQUENCE ON word1 + word2, WITH A CROSSING PAIR, new | |
| 1774 | Closest Dessert Cost | Python | O(3^m + n * 3^m) | O(3^m) | Medium | dp, ENUMERATE EVERY TOPPING COMBINATION (m <= 10 -> at most 3^10 sums), new, google |
|
| 1787 | Make the XOR of All Segments Equal to Zero | Python | O(n * 2^10 + k * 2^10) | O(n + 2^10) | Hard | dp, DP OVER RESIDUE CLASSES i % k, STATE = RUNNING XOR (values < 2^10), new | |
| 1803 | Count Pairs With XOR in a Range | Python | O(n * 15) | O(n * 15) | Hard | dp, BINARY TRIE + PREFIX COUNTING (count(< high+1) - count(< low)), new | |
| 1857 | Largest Color Value in a Directed Graph | Python | O((n + m) * 26) | O(n * 26) | Hard | dp, TOPOLOGICAL SORT (KAHN) + DP OVER 26 COLORS, new, google, apple |
|
| 1866 | Number of Ways to Rearrange Sticks With K Sticks Visible | Python | O(n * k) | O(k) | Hard | dp, DP (unsigned Stirling numbers of the FIRST kind), new, google |
|
| 1872 | Stone Game VIII | Python | O(n) | O(n) for the prefix sums | Hard | dp, PREFIX SUM + SUFFIX DP (a move is just “pick a prefix boundary”), new | |
| 1883 | Minimum Skips to Arrive at Meeting On Time | Python | O(n^2) | O(n) | Hard | dp, DP ON (road index, skips used), MEASURED IN “DISTANCE UNITS”, new, google |
|
| 1900 | The Earliest and Latest Rounds Where Players Compete | Python | O(n^4 * log n) states x transitions (n <= 28, trivial in practice) | O(n^3) memo entries | Hard | dp, MEMOISED SEARCH ON THE STATE (n, position of f, position of s), new, google |
|
| 1908 | Game of Nim | Python | O(n) | O(1) | Medium | dp, 🔒, GAME THEORY / SPRAGUE-GRUNDY (this is classic Nim -> XOR “nim-sum”), new | |
| 1931 | Painting a Grid With Three Different Colors | Python | O(3^(2m) + n * V^2) with V = number of valid columns | O(V^2) | Hard | dp, BITMASK / BASE-3 STATE COMPRESSION DP OVER COLUMNS, new, google |
|
| 1937 | Maximum Number of Points with Cost | Python | O(m * n) | O(n) | Medium | dp, ROW DP + PREFIX/SUFFIX MAX (split the abs() into two directions), new, google, amazon |
|
| 1955 | Count Number of Special Subsequences | Python | O(n) | O(1) | Hard | dp, DP ON “WHICH BLOCK ARE WE IN” (3 rolling counters, one pass), new, amazon |
|
| 1959 | Minimum Total Space Wasted With K Resizing Operations | Python | O(n^2 * k) | O(n^2 + n*k) | Medium | dp, PARTITION DP (k resizes == cut nums into k+1 segments), new | |
| 1960 | Maximum Product of the Length of Two Palindromic Substrings | Python | O(n) | O(n) | Hard | dp, MANACHER + PREFIX / SUFFIX BEST PALINDROME, new | |
| 1977 | Number of Ways to Separate Numbers | Python | O(n^2) | O(n^2) | Hard | dp, DP + PREFIX SUM OVER LAST-BLOCK LENGTH + LCP TABLE, new | |
| 1981 | Minimize the Difference Between Target and Chosen Elements | Python | O(m * n * S / 64) with S = max total sum | O(S) | Medium | dp, GROUPED KNAPSACK (reachable-sum bitset, one group per row), new, amazon |
|
| 1986 | Minimum Number of Work Sessions to Finish the Tasks | Python | O(3^n) | O(2^n) | Medium | dp, BITMASK DP + SUBSET ENUMERATION, new | |
| 1987 | Number of Unique Good Subsequences | Python | O(n) | O(1) | Hard | dp, DP ON THE LAST CHARACTER (count DISTINCT strings, not positions), new, google |
|
| 1994 | The Number of Good Subsets | Python | O(30 * 2^10) | O(2^10) | Hard | dp, BITMASK KNAPSACK OVER THE 10 PRIMES BELOW 30, new | |
| 1997 | First Day Where You Have Been in All the Rooms | Python | O(n) | O(n) | Medium | dp, DP ON “FIRST ARRIVAL DAY” (prefix invariant), new | |
| 2002 | Maximum Product of the Length of Two Palindromic Subsequences | Python | O(3^n + 2^n * n) | O(2^n) | Medium | dp, BITMASK ENUMERATION + SUBMASK ENUMERATION (n <= 12, so 2^n masks is tiny), new | |
| 2008 | Maximum Earnings From Taxi | Python | O(n + m), m = len(rides) | O(n + m) | Medium | dp, DP OVER THE ROAD POSITION (weighted interval scheduling on a line), new | |
| 2019 | The Score of Students Solving Math Expression | Python | O(n^3 * V^2) with V bounded by 1001 in practice | O(n^2 * V) | Hard | dp, INTERVAL DP (all possible parenthesizations) + CORRECT EVAL, new, fb |
|
| 2031 | Count Subarrays With More Ones Than Zeros | Python | O(n) | O(n) | Medium | dp, 🔒, MAP 0 -> -1, THEN COUNT PAIRS WITH prefix[j] > prefix[i] (i < j), new, google |
|
| 2044 | Count Number of Maximum Bitwise-OR Subsets | Python | O(n * |distinct ORs|) | O(|distinct ORs|) | Medium | dp, DP OVER REACHABLE OR VALUES (counts per OR value), new | |
| 2052 | Minimum Cost to Separate Sentence Into Rows | Python | O(n^2) | O(n), n = number of words | Medium | dp, 🔒, PREFIX SUM + BOTTOM-UP DP (word-break with squared slack cost), new | |
| 2060 | Check if an Original String Exists Given Two Encoded Strings | Python | O(n * m * D), D = O(1000) | O(n * m * D) | Hard | dp, MEMOISED DFS ON (i, j, diff) - “wildcard budget” matching, new, fb |
|
| 2088 | Count Fertile Pyramids in a Land | Python | O(m * n) | O(m * n) | Hard | dp, DP ON “TALLEST PYRAMID WITH APEX HERE”, RUN TWICE (flip the grid), new, google |
|
| 2140 | Solving Questions With Brainpower | Python | O(n) | O(n) | Medium | dp, SUFFIX DP — dp[i] = BEST SCORE ACHIEVABLE FROM QUESTION i ONWARDS, new | |
| 2143 | Choose Numbers From Two Arrays in Range | Python | O(n * S) with S the span of possible differences | O(S) | Hard | dp, 🔒, ROLLING DP OVER THE RUNNING DIFFERENCE, ALL STARTS AT ONCE, new | |
| 2167 | Minimum Time to Remove All Cars Containing Illegal Goods | Python | O(n) | O(n) | Hard | dp, PREFIX / SUFFIX DP AROUND A SPLIT POINT, new, google |
|
| 2174 | Remove All Ones With Row and Column Flips II | Python | O(2^(m*n) * m * n) | O(2^(m*n)) | Medium | dp, 🔒, THE WHOLE GRID FITS IN 15 BITS -> BFS / MEMOISED SEARCH OVER STATES, new, google |
|
| 2184 | Number of Ways to Build Sturdy Brick Wall | Python | O(height * 2^width * width) | O(2^width) | Medium | dp, 🔒, BITMASK DP OVER ROW “JOINT” PATTERNS + SUBSET-SUM TRANSFORM, new | |
| 2188 | Minimum Time to Finish the Race | Python | O(m * 18 + numLaps * 18) | O(numLaps) | Hard | dp, PRECOMPUTE “BEST STINT OF k LAPS”, THEN A 1D DP OVER THE LAPS, new | |
| 2189 | Number of Ways to Build House of Cards | Python | O(n * sqrt(n)) | O(n) | Medium | dp, 🔒, A ROW OF k TRIANGLES COSTS 3k - 1 CARDS, AND ROW SIZES ARE DISTINCT, new | |
| 2209 | Minimum White Tiles After Covering With Carpets | Python | O(n * numCarpets) | O(n * numCarpets) | Hard | dp, DP ON (PREFIX LENGTH, CARPETS USED), new | |
| 2218 | Maximum Value of K Coins From Piles | Python | O(k * L), L = total number of coins | O(k) | Hard | dp, GROUPED KNAPSACK DP (each pile is one “group”, pick a prefix of it), new | |
| 2222 | Number of Ways to Select Buildings | Python | O(n) | O(1) | Medium | dp, COUNTING BY THE MIDDLE BUILDING, new | |
| 2247 | Maximum Cost of Trip With K Highways | Python | O(2^n * n^2) | O(2^n * n) | Hard | dp, 🔒, BITMASK DP OVER (VISITED SET, CURRENT CITY) — A HAMILTONIAN-STYLE WALK, new | |
| 2266 | Count Number of Texts | Python | O(n) | O(n) | Medium | dp, DP ON EACH EQUAL-DIGIT RUN (tribonacci / tetranacci), multiply the runs, new | |
| 2267 | Check if There Is a Valid Parentheses String Path | Python | O(m * n * (m + n) / 64) big-int word ops | O(n * (m + n) / 64) | Hard | dp, DP OVER REACHABLE BALANCES, kept as a BITSET (one python int per cell), new | |
| 2291 | Maximum Profit From Trading Stocks | Python | O(n * budget) | O(budget) | Medium | dp, 🔒, 0/1 KNAPSACK — WEIGHT = present[i], VALUE = future[i] - present[i], new | |
| 2297 | Jump Game VIII | Python | O(n) | O(n) | Medium | dp, 🔒, EACH INDEX HAS AT MOST TWO OUTGOING JUMPS — FIND THEM WITH STACKS, new | |
| 2304 | Minimum Path Cost in a Grid | Python | O(m * n^2) | O(n) | Medium | dp, DP ROW BY ROW (dp[j] = cheapest path reaching row i, column j), new | |
| 2305 | Fair Distribution of Cookies | Python | O(k * 3^n) | O(2^n) | Medium | dp, BITMASK DP OVER SUBSETS (n <= 8, so 2^n masks are cheap), new | |
| 2312 | Selling Pieces of Wood | Python | O(m * n * (m + n)) | O(m * n) | Hard | dp, 2D INTERVAL DP (classic “cut a rod”, one dimension at a time), new | |
| 2313 | Minimum Flips in Binary Tree to Get Result | Python | O(n) | O(n) | Hard | dp, 🔒, TREE DP, 2 STATES PER NODE (cost to make it False / True), new | |
| 2318 | Number of Distinct Roll Sequences | Python | O(n * 6^3) | O(36) | Hard | dp, DP ON THE LAST TWO ROLLS (only a 6x6 state is needed), new | |
| 2320 | Count Number of Ways to Place Houses | Python | O(n) | O(1) | Medium | dp, FIBONACCI PER SIDE, THEN SQUARE (the two sides are independent), new | |
| 2327 | Number of People Aware of a Secret | Python | O(n) | O(n) | Medium | dp, DP ON “HOW MANY PEOPLE LEARN THE SECRET ON DAY i”, new | |
| 2328 | Number of Increasing Paths in a Grid | Python | O(m * n log(m * n)) | O(m * n) | Hard | dp, PROCESS THE CELLS IN ASCENDING VALUE ORDER — NO RECURSION NEEDED, new | |
| 2361 | Minimum Costs Using the Train Line | Python | O(n) | O(1) extra (O(n) for the answer) | Hard | dp, 🔒, DP WITH 2 STATES (which route we are standing on at each stop), new | |
| 2369 | Check if There is a Valid Partition For The Array | Python | O(n) | O(n) | Medium | dp, LINEAR DP ON PREFIX LENGTHS — ONLY BLOCKS OF SIZE 2 OR 3 EXIST, new | |
| 2370 | Longest Ideal Subsequence | Python | O(26 * n) | O(26) | Medium | dp, DP KEYED ON THE LAST LETTER, NOT ON THE INDEX, new | |
| 2378 | Choose Edges to Maximize Score in a Tree | Python | O(n) | O(n) | Medium | dp, 🔒, CLASSIC TREE MATCHING DP — TWO STATES PER NODE, new | |
| 2380 | Time Needed to Rearrange a Binary String | Python | O(n) | O(1) | Medium | dp, TRACK WHEN EACH ‘1’ FINISHES CROSSING THE ZEROS TO ITS LEFT, new | |
| 2403 | Minimum Time to Kill All Monsters | Python | O(2^n * n) | O(2^n) | Hard | dp, 🔒, BITMASK DP OVER WHICH MONSTERS ARE ALREADY DEAD, new | |
| 2420 | Find All Good Indices | Python | O(n) | O(n) | Medium | dp, TWO RUN-LENGTH ARRAYS, ONE FROM EACH DIRECTION, new | |
| 2430 | Maximum Deletions on a String | Python | O(n^2) | O(n) | Hard | dp, SUFFIX DP + ROLLING HASH FOR THE O(1) BLOCK COMPARISON, new | |
| 2431 | Maximize Total Tastiness of Purchased Fruits | Python | O(n * maxAmount * maxCoupons) | O(maxAmount * maxCoupons) | Medium | dp, 🔒, 0/1 KNAPSACK WITH A SECOND DIMENSION FOR THE COUPONS, new | |
| 2435 | Paths in Matrix Whose Sum Is Divisible by K | Python | O(m * n * k) | O(n * k) | Hard | dp, DP ON (cell, remainder) (carry the running sum modulo k as an extra state), new | |
| 2447 | Number of Subarrays With GCD Equal to K | Python | O(n * log(max(nums)) * log(max(nums))) | O(log(max(nums))) | Medium | dp, DP OVER “DISTINCT GCDs ENDING AT i” (a classic logarithmic-state trick), new | |
| 2463 | Minimum Total Distance Traveled | Python | O(n * m * limit) | O(n * m) | Hard | dp, SORT BOTH, THEN DP — AN OPTIMAL ASSIGNMENT NEVER CROSSES, new | |
| 2464 | Minimum Subarrays in a Valid Split | Python | O(n^2 log(max)) | O(n) | Medium | dp, 🔒, PREFIX DP OVER THE CUT POSITIONS, new | |
| 2466 | Count Ways To Build Good Strings | Python | O(high) | O(high) | Medium | dp, COUNT BY LENGTH — ONLY THE LENGTH MATTERS, NOT THE CONTENT, new | |
| 2470 | Number of Subarrays With LCM Equal to K | Python | O(n^2 log(max)) | O(1) | Medium | dp, EXTEND EACH START WHILE THE RUNNING LCM STILL DIVIDES k, new | |
| 2475 | Number of Unequal Triplets in Array | Python | O(n) | O(n) | Easy | dp, GROUP COUNTING (pick 3 DIFFERENT value-groups, order does not matter), new | |
| 2478 | Number of Beautiful Partitions | Python | O(n * k) | O(n * k) | Hard | dp, DP OVER CUT POSITIONS + PREFIX SUMS, new | |
| 2495 | Number of Subarrays Having Even Product | Python | O(n) | O(1) | Medium | dp, 🔒, DP (COUNT SUBARRAYS ENDING AT EACH INDEX) + LAST EVEN INDEX, new | |
| 2510 | Check if There is a Path With Equal Number of 0’s And 1’s | Python | O(m * n * (m + n) / 64) | O(n * (m + n) / 64) | Medium | dp, 🔒, DP + BITMASK (bitset of reachable “number of 1’s”), new | |
| 2518 | Number of Great Partitions | Python | O(n * k) | O(k) | Hard | dp, COMPLEMENTARY COUNTING + 0/1 KNAPSACK (count subsets with sum < k), new | |
| 2533 | Number of Good Binary Strings | Python | O(maxLength) | O(maxLength) | Medium | dp, 🔒, DP OVER “APPEND ONE WHOLE BLOCK”, new | |
| 2538 | Difference Between Maximum and Minimum Price Sum | Python | O(n) | O(n) | Hard | dp, TREE DP – BEST PATH WITH ONE ENDPOINT’S PRICE DROPPED, new | |
| 2547 | Minimum Cost to Split an Array | Python | O(n^2) | O(n) | Hard | dp, DP OVER SUFFIXES + INCREMENTAL “APPEARS ONCE” COUNTER, new | |
| 2552 | Count Increasing Quadruplets | Python | O(n^2) | O(n) | Hard | dp, DP OVER PAIRS (O(n^2) time, O(n) space), new | |
| 2565 | Subsequence With the Minimum Score | Python | O((m + n) + n log n) | O(n) | Hard | dp, PREFIX / SUFFIX GREEDY MATCH + BINARY SEARCH ON THE WINDOW LENGTH, new | |
| 2572 | Count the Number of Square-Free Subsets | Python | O(n + 30 * 2^10) | O(2^10) | Medium | dp, BITMASK DP OVER THE 10 PRIMES <= 30, new | |
| 2585 | Number of Ways to Earn Points | Python | O(n * target * count) | O(target) | Hard | dp, BOUNDED KNAPSACK DP (group / multiple knapsack), new | |
| 2597 | The Number of Beautiful Subsets | Python | O(n log n) | O(n) | Medium | dp, GROUP BY (value % k) -> HOUSE-ROBBER DP ON EACH CHAIN, new | |
| 2638 | Count the Number of K-Free Subsets | Python | O(n * log(n)) | O(n) | Medium | dp, 🔒, GROUP BY (value % k) -> CHAINS -> “HOUSE ROBBER” DP ON EACH CHAIN, new | |
| 2681 | Power of Heroes | Python | O(n * log(n)) (dominated by the sort) | O(1) extra | Hard | dp, SORT + RUNNING DP OVER “SUM OF WEIGHTED MAX^2”, new | |
| 2713 | Maximum Strictly Increasing Cells in a Matrix | Python | O(m * n * log(m * n)) | O(m * n) | Hard | dp, SORT BY VALUE + DP with PER-ROW / PER-COLUMN MAXIMA, new | |
| 2719 | Count of Integers | Python | O(10 * n * max_sum) | O(n * max_sum) (n = len(num2) <= 23) | Hard | dp, DIGIT DP (count [0, hi] then subtract via prefix difference), new | |
| 2742 | Painting the Walls | Python | O(n^2) | O(n) | Hard | dp, REPHRASE AS A 0/1 KNAPSACK (“BUY ENOUGH TIME TO COVER n WALLS”), new | |
| 2746 | Decremental String Concatenation | Python | O(n * 26^2) | O(26^2) | Medium | dp, DP OVER (FIRST CHAR, LAST CHAR) OF THE ACCUMULATED STRING, new | |
| 2770 | Maximum Number of Jumps to Reach the Last Index | Python | O(n^2) | O(n) | Medium | dp, LONGEST-PATH DP ON A DAG (jumps only go forward, so index order works), new | |
| 2771 | Longest Non-decreasing Subarray From Two Arrays | Python | O(n) | O(1) | Medium | dp, DP KEYED ON “WHICH ARRAY DID I TAKE AT i”, new | |
| 2786 | Visit Array Positions to Maximize Score | Python | O(n) | O(1) | Medium | dp, DP ON PARITY (2 ROLLING STATES), new | |
| 2787 | Ways to Express an Integer as Sum of Powers | Python | O(n * n^(1/x)) | O(n) | Medium | dp, 0/1 KNAPSACK (COUNT SUBSETS SUMMING TO n), new | |
| 2801 | Count Stepping Numbers in Range | Python | O(L * 10 * 10) | O(L * 10) L = len(high) <= 100 | Hard | dp, DIGIT DP (COUNT [1, high] - COUNT [1, low - 1]), new | |
| 2809 | Minimum Time to Make Array Sum At Most x | Python | O(n^2) | O(n) | Hard | dp, SORT BY nums2 + KNAPSACK-STYLE DP OVER “HOW MANY WE ZERO OUT”, new | |
| 2826 | Sorting Three Groups | Python | O(n) | O(1) | Medium | dp, DP (removals = n - longest non-decreasing subsequence), new | |
| 2827 | Number of Beautiful Integers in the Range | Python | O(log(x) * k * d * 10) per bound | O(log(x) * k * d) | Hard | dp, DIGIT DP + PREFIX SUBTRACTION, new | |
| 2830 | Maximize the Profit as the Salesman | Python | O(n + m) | O(n + m) | Medium | dp, DP OVER HOUSES (weighted interval scheduling, bucketed by end), new | |
| 2858 | Minimum Edge Reversals So Every Node Is Reachable | Python | O(n) | O(n) | Hard | dp, RE-ROOTING DP (TREE DP) ON THE UNDIRECTED TREE, new | |
| 2913 | Subarrays Distinct Element Sum of Squares I | Python | O(n^2) | O(n) | Easy | dp, BRUTE FORCE ENUMERATION + INCREMENTAL DISTINCT COUNT, new | |
| 3018 | Maximum Number of Removal Queries That Can Be Processed I | Python | O(n^2) | O(n^2) | Hard | dp, 🔒, DP OVER (TAKEN FROM THE LEFT, TAKEN FROM THE RIGHT), new | |
| 3020 | Find the Maximum Number of Elements in Subset | Python | O(n log log max) | O(n) | Medium | dp, WALK THE SQUARING CHAIN x, x^2, x^4, … AND SEE HOW FAR IT SURVIVES, new | |
| 3040 | Maximum Number of Operations With the Same Score II | Python | O(n^2) | O(n^2) | Medium | dp, ONLY 3 POSSIBLE SCORES — FIX ONE, THEN MEMOISED (l, r) SEARCH, new | |
| 3041 | Maximize Consecutive Elements in an Array After Modification | Python | O(n log n) | O(n) | Hard | dp, DP ON VALUES — EACH ELEMENT EXTENDS A RUN AS x OR AS x+1, new | |
| 3077 | Maximum Strength of K Disjoint Subarrays | Python | O(n * k) | O(n) | Hard | dp, DP OVER (SUBARRAYS USED, PREFIX LENGTH), WITH A “STILL OPEN” STATE, new | |
| 3082 | Find the Sum of the Power of All Subsequences | Python | O(n * k) | O(k) | Hard | dp, COUNT PAIRS (SUBSEQUENCE S, SUB-SUBSEQUENCE T OF S WITH SUM k), new | |
| 3098 | Find the Sum of Subsequence Powers | Python | O(n^2 * n * k) = O(n^3 * k) worst case | O(n * k) | Hard | dp, SUM THE MINIMUM BY LAYERS — count(power >= d) SUMMED OVER d, new | |
| 3101 | Count Alternating Subarrays | Python | O(n) | O(1) | Medium | dp, COUNT THE ALTERNATING SUBARRAYS ENDING AT EACH INDEX, new | |
| 3117 | Minimum Sum of Values by Dividing Array | Python | O(n * m * 17) | O(n) | Hard | dp, DP BY SEGMENT INDEX, CARRYING THE FEW DISTINCT SUFFIX-AND VALUES, new | |
| 3129 | Find All Possible Stable Binary Arrays I | Python | O(zero * one) | O(zero * one) | Medium | dp, “NO SUBARRAY LONGER THAN limit IS UNIFORM” == “NO RUN EXCEEDS limit”, new | |
| 3130 | Find All Possible Stable Binary Arrays II | Python | O(zero * one) | O(zero * one) | Hard | dp, SAME RECURRENCE AS LC 3129 — IT WAS ALREADY O(zero * one), new | |
| 3141 | Maximum Hamming Distances | Python | O(m * 2^m) | O(2^m) | Hard | dp, 🔒, FLIP THE QUESTION — FARTHEST FROM x IS NEAREST TO ~x, new | |
| 3144 | Minimum Substring Partition of Equal Character Frequency | Python | O(n^2) | O(n) | Medium | dp, DP OVER PREFIXES, EXTENDING THE LAST PIECE LEFTWARDS, new | |
| 3148 | Maximum Difference Score in a Grid | Python | O(m * n) | O(n) | Medium | dp, A MULTI-MOVE PATH TELESCOPES — ONLY THE ENDPOINTS MATTER, new | |
| 3149 | Find the Minimum Cost Array Permutation | Python | O(2^n * n^2) | O(2^n * n) | Hard | dp, HAMILTONIAN-CYCLE BITMASK DP, ANCHORED AT 0, new | |
| 3176 | Find the Maximum Length of a Good Subsequence I | Python | O(n^2 * k) | O(n * k) | Medium | dp, DP OVER (LAST INDEX TAKEN, CHANGES SPENT), new | |
| 3177 | Find the Maximum Length of a Good Subsequence II | Python | O(n * k) | O(n * k) | Hard | dp, DROP THE “WHICH EARLIER INDEX” LOOP — KEEP A BEST-PER-VALUE TABLE, new | |
| 3180 | Maximum Total Reward Using Operations I | Python | O(n * max value) | O(max value) | Medium | dp, REACHABLE-TOTALS DP, WITH THE VALUES TAKEN IN INCREASING ORDER, new | |
| 3181 | Maximum Total Reward Using Operations II | Python | O(n * max / word size) | O(max / word size) | Hard | dp, SAME REACHABILITY DP, BUT THE SET LIVES IN THE BITS OF ONE BIG INT, new | |
| 3186 | Maximum Total Damage With Spell Casting | Python | O(n log n) | O(n) | Medium | dp, GROUP EQUAL DAMAGES, THEN A “HOUSE ROBBER” DP OVER DISTINCT VALUES, new | |
| 3193 | Count the Number of Inversions | Python | O(n * maxCnt) | O(maxCnt) | Hard | dp, BUILD THE PERMUTATION LEFT TO RIGHT, COUNTING INVERSIONS AS THEY APPEAR, new | |
| 3197 | Find the Minimum Area to Cover All Ones II | Python | O(m * n * (m + n) * …) — small for 30x30 | O(m * n) | Hard | dp, THREE NON-OVERLAPPING RECTANGLES = TWO GUILLOTINE CUTS, SIX SHAPES, new | |
| 3201 | Find the Maximum Length of Valid Subsequence I | Python | O(n) | O(1) | Medium | dp, THE COMMON PARITY IS EITHER 0 OR 1 — SO THERE ARE ONLY TWO SHAPES, new | |
| 3202 | Find the Maximum Length of Valid Subsequence II | Python | O(n * k) | O(k) | Medium | dp, FIX THE COMMON SUM RESIDUE, THEN THE SEQUENCE OF RESIDUES IS FORCED, new | |
| 3209 | Number of Subarrays With AND Value of K | Python | O(30 * n) | O(30) | Hard | dp, THE ANDs OF ALL SUBARRAYS ENDING AT i FORM AT MOST ~30 DISTINCT VALUES, new | |
| 3212 | Count Submatrices With Equal Frequency of X and Y | Python | O(m * n) | O(m * n) | Medium | dp, “CONTAINS grid[0][0]” MEANS IT IS A PREFIX RECTANGLE, new | |
| 3213 | Construct String with Minimum Cost | Python | O(n * distinct lengths) | O(n + total word length) | Hard | dp, DP OVER PREFIXES, WITH A ROLLING HASH SO EACH WORD LENGTH IS O(1), new | |
| 3241 | Time Taken to Mark All Nodes | Python | O(n) | O(n) | Hard | dp, REROOTING — ONE DOWNWARD PASS, THEN PUSH THE ANSWER OUTWARDS, new | |
| 3253 | Construct String with Minimum Cost (Easy) | Python | O(n * m * L) | O(n) | Medium | dp, 🔒, DP OVER PREFIXES, TESTING EACH WORD AS THE LAST PIECE, new | |
| 3259 | Maximum Energy Boost From Two Drinks | Python | O(n) | O(1) | Medium | dp, TWO ROLLING DP CHAINS, ONE PER DRINK, new | |
| 3277 | Maximum XOR Score Subarray Queries | Python | O(n^2 + q) | O(n^2) | Hard | dp, THE XOR SCORE OBEYS A PASCAL-LIKE RECURRENCE, SO TABULATE IT, new | |
| 3283 | Maximum Number of Moves to Kill All Pawns | Python | O(16 * 50^2 + 2^n * n^2) | O(2^n * n) | Hard | dp, PRECOMPUTE KNIGHT DISTANCES, THEN A MINIMAX BITMASK DP, new | |
| 3287 | Find the Maximum Sequence Value of Array | Python | O(n * k * 7 + n * 128^2) | O(n * k) | Hard | dp, SPLIT AT EVERY CUT, TRACKING THE ACHIEVABLE ORs AS A 128-BIT SET, new | |
| 3290 | Maximum Multiplication Score | Python | O(n) | O(1) | Medium | dp, DP OVER “HOW MANY OF a HAVE BEEN MATCHED SO FAR”, new | |
| 3291 | Minimum Number of Valid Strings to Form Target I | Python | O(|target| * max word length + total word length) | O(total word length) | Medium | dp, LONGEST REACH PER START, THEN THE JUMP-GAME GREEDY, new | |
| 3292 | Minimum Number of Valid Strings to Form Target II | Python | O(sum of word lengths + |words| * |target|) | O(|target|) | Hard | dp, Z-FUNCTION PER WORD INSTEAD OF A TRIE WALK, new | |
| 3316 | Find Maximum Removals From Source String | Python | O(n * m) | O(m) | Medium | dp, DP OVER (SOURCE PREFIX, PATTERN PREFIX) MAXIMISING THE DELETIONS, new | |
| 3320 | Count The Number of Winning Sequences | Python | O(n^2) | O(n) | Hard | dp, DP OVER (ROUND, BOB’S LAST CREATURE, SCORE DIFFERENCE), new | |
| 3332 | Maximum Points Tourist Can Earn | Python | O(k * n^2) | O(n) | Medium | dp, DP OVER (DAY, CITY) — EVERY CITY IS A LEGAL START, new | |
| 3333 | Find the Original Typed String II | Python | O(m * k) | O(k) | Hard | dp, COUNT EVERYTHING, THEN SUBTRACT THE TOO-SHORT ONES WITH A DP, new | |
| 3335 | Total Characters in String After Transformations I | Python | O(n + 26 * t) | O(1) | Medium | dp, ONLY THE 26 LETTER COUNTS MATTER, NOT THE STRING ITSELF, new | |
| 3336 | Find the Number of Subsequences With Equal GCD | Python | O(n * reachable states) | O(reachable states) | Hard | dp, DP OVER THE PAIR OF RUNNING GCDs, WITH 0 STANDING FOR “STILL EMPTY”, new | |
| 3337 | Total Characters in String After Transformations II | Python | O(26^3 log t + n) | O(26^2) | Hard | dp, THE ROUND IS A LINEAR MAP ON THE 26 COUNTS — SO EXPONENTIATE IT, new | |
| 3343 | Count Number of Balanced Permutations | Python | O(10 * slots * sum * max count) | O(slots * sum) | Hard | dp, SPLIT THE MULTISET BETWEEN THE TWO POSITION CLASSES, THEN COUNT ARRANGEMENTS, new | |
| 3351 | Sum of Good Subsequences | Python | O(n) | O(n) | Hard | dp, PER-VALUE TALLIES OF “HOW MANY SUBSEQUENCES END HERE” AND “WHAT THEY SUM TO”, new | |
| 3352 | Count K-Reducible Numbers Less Than N | Python | O(len(s)^2) | O(len(s)^2) | Hard | dp, ONE STEP COLLAPSES x TO ITS POPCOUNT — SO GROUP BY POPCOUNT, new | |
| 3363 | Find the Maximum Number of Fruits Collected | Python | O(n^2) | O(n^2) | Hard | dp, THE DIAGONAL CHILD IS FORCED; THE OTHER TWO ARE MIRRORED DPs, new | |
| 3366 | Minimum Array Sum | Python | O(n * op1 * op2) | O(op1 * op2) | Medium | dp, DP OVER (INDEX, OPERATION-1 BUDGET LEFT, OPERATION-2 BUDGET LEFT), new | |
| 3372 | Maximize the Number of Target Nodes After Connecting Trees I | Python | O(n^2 + m^2) | O(n + m) | Medium | dp, COUNT WITHIN k IN TREE 1, WITHIN k-1 IN TREE 2, AND TAKE THE BEST BRIDGE, new | |
| 3381 | Maximum Subarray Sum With Length Divisible by K | Python | O(n) | O(k) | Medium | dp, PREFIX SUMS, KEEPING THE SMALLEST PREFIX PER INDEX RESIDUE, new | |
| 3393 | Count Paths With the Given XOR Value | Python | O(m * n * 16) | O(n * 16) | Medium | dp, GRID DP OVER THE 4-BIT XOR STATE, new | |
| 3409 | Longest Subsequence With Decreasing Adjacent Difference | Python | O(n * V) with V = 301 | O(V^2) | Medium | dp, DP KEYED ON (LAST VALUE, DIFFERENCE FLOOR) — VALUES ARE ONLY 1…300, new | |
| 3414 | Maximum Score of Non-overlapping Intervals | Python | O(n log n) with a 4-fold constant | O(n) | Hard | dp, SUFFIX DP OVER (INTERVAL, BUDGET), CARRYING THE WINNING INDEX SET, new | |
| 3418 | Maximum Amount of Money Robot Can Earn | Python | O(m * n * 3) | O(n * 3) | Medium | dp, GRID DP WITH THE NUMBER OF NEUTRALISATIONS USED AS A THIRD AXIS, new | |
| 3429 | Paint House IV | Python | O(n) | O(1) | Medium | dp, FOLD THE ROW IN HALF AND WALK BOTH ENDS INWARD TOGETHER, new | |
| 3434 | Maximum Frequency After Subarray Operation | Python | O(n) | O(max value) | Medium | dp, ONE KADANE PER CANDIDATE VALUE, ALL 50 RUN AT ONCE VIA AN OFFSET, new | |
| 3441 | Minimum Cost Good Caption | Python | O(26 n) | O(26 n) | Hard | dp, SUFFIX DP WITH TWO STATES, THEN A GREEDY LEX-SMALLEST REPLAY, new | |
| 3444 | Minimum Increments for Target Multiples in an Array | Python | O(n * 3^t) with t <= 4 | O(2^t) | Hard | dp, BITMASK DP OVER THE (AT MOST 4) TARGETS, new | |
| 3503 | Longest Palindrome After Substring Concatenation I | Python | O(n^2 * m^2 * (n+m)) | O(n+m) | Medium | dp, BRUTE FORCE OVER EVERY (SUBSTRING OF s, SUBSTRING OF t) PAIR, new | |
| 3504 | Longest Palindrome After Substring Concatenation II | Python | O(n^2 + m^2 + n*m) | O(n^2 + m^2) | Hard | dp, PEEL MATCHED OUTER PAIRS UNTIL ONE SIDE RUNS OUT, new | |
| 3505 | Minimum Operations to Make Elements Within K Subarrays Equal | Python | O(n * log n + n * k) | O(n) | Hard | dp, SLIDING WINDOW MEDIAN COST + DP OVER THE NUMBER OF PICKED WINDOWS, new | |
| 3509 | Maximum Product of Subsequences With an Alternating Sum Equal to K | Python | O(n * P) bigint ops with P the reachable products | O(P) | Hard | dp, DP KEYED ON (PARITY, PRODUCT), WITH THE SET OF SUMS AS A BITMASK, new | |
| 3524 | Find X Value of Array I | Python | O(n * k) | O(k) | Medium | dp, ROLLING RESIDUE HISTOGRAM OF ALL SUBARRAYS ENDING AT THE CURRENT INDEX, new | |
| 3525 | Find X Value of Array II | Python | O(n * k + q * k * log n) | O(n * k) | Hard | dp, SEGMENT TREE WHOSE NODE SUMMARISES ALL PREFIXES OF ITS SEGMENT, new | |
| 3530 | Maximum Profit from Valid Topological Order in DAG | Python | O(n * 2^n) | O(2^n) | Hard | dp, BITMASK DP OVER PROCESSED SETS, WITH A MEET-IN-THE-MIDDLE READY TABLE, new | |
| 3533 | Concatenated Divisibility | Python | O(2^n * n) | O(2^n) | Hard | dp, PRECOMPUTE THE REACHABLE REMAINDERS OF EVERY SUBSET, THEN PICK GREEDILY, new | |
| 3538 | Merge Operations for Minimum Travel Time | Python | O(n^3 * k) | O(n^2 * k) | Hard | dp, DP OVER (PREVIOUS KEPT SIGN, CURRENT KEPT SIGN, MERGES USED), new | |
| 3539 | Find Sum of Array Product of Magical Sequences | Python | O(n * m^2 * k) | O(m^2 * k) | Hard | dp, COUNT BY MULTIPLICITY PER INDEX, AND ADD 2^index WITH A RUNNING CARRY, new | |
| 3543 | Maximum Weighted K-Edge Path | Python | O(k * E * t / 64) | O(n * t / 64) | Medium | dp, LAYERED DP WHOSE STATE IS A BITSET OF THE ACHIEVABLE PATH SUMS, new | |
| 3544 | Subtree Inversion Sum | Python | O(n * k) | O(n * k) | Hard | dp, TREE DP ON THE DISTANCE SINCE THE LAST INVERTED ANCESTOR, new | |
| 3562 | Maximum Profit from Trading Stocks with Discounts | Python | O(n * budget^2) worst case | O(n * budget) | Hard | dp, TREE KNAPSACK WITH “DID MY BOSS BUY?” AS A SECOND STATE, new | |
| 3563 | Lexicographically Smallest String After Adjacent Removals | Python | O(n^3) | O(n^2) | Hard | dp, INTERVAL DP FOR “CAN VANISH” + SUFFIX DP FOR THE SMALLEST TAIL, new | |
| 3573 | Best Time to Buy and Sell Stock V | Python | O(n * k) | O(k) | Medium | dp, 3-STATE DP (IDLE / LONG OPEN / SHORT OPEN) INDEXED BY TRANSACTION COUNT, new | |
| 3574 | Maximize Subarray GCD Score | Python | O(n^2 * log(max)) | O(n) | Hard | dp, DOUBLING CAN ONLY LIFT THE GCD BY ONE FACTOR OF 2, new | |
| 3575 | Maximum Good Subtree Score | Python | O(n log n * 2^10) | O(n * 2^10) | Hard | dp, DIGIT-MASK KNAPSACK PER SUBTREE, REUSED VIA SMALL-TO-LARGE MERGING, new | |
| 3578 | Count Partitions With Max-Min Difference at Most K | Python | O(n) | O(n) | Medium | dp, DP OVER PREFIXES + SLIDING WINDOW OF FEASIBLE CUT POINTS, new | |
| 3579 | Minimum Steps to Convert String with Operations | Python | O(n^3 + n^2 * |S|) | O(n + |S|^2) | Hard | dp, PARTITION DP OVER SUBSTRINGS + GREEDY PAIRING OF MISMATCHES, new | |
| 3583 | Count Special Triplets | Python | O(n) | O(n) | Medium | dp, FIX THE MIDDLE INDEX AND MULTIPLY THE TWO SIDE COUNTS, new | |
| 3592 | Inverse Coin Change | Python | O(n^2) | O(n) | Medium | dp, REBUILD THE COIN-CHANGE DP LEFT TO RIGHT AND READ OFF MISSING COINS, new | |
| 3595 | Once Twice | Python | O(n) | O(1) | Medium | dp, 🔒, BIT-COUNT MOD 3, THEN SPLIT ON A BIT WHERE THE TWO ANSWERS DIFFER, new | |
| 3599 | Partition Array to Minimize XOR | Python | O(k * n^2) | O(n) | Medium | dp, DP OVER (NUMBER OF PARTS, PREFIX LENGTH), MINIMISING A RUNNING MAX, new | |
| 3603 | Minimum Cost Path with Alternating Directions II | Python | O(m * n) | O(n) | Medium | dp, GRID DP, WITH THE WAIT COST FOLDED ONTO THE CELL YOU LEAVE, new | |
| 3610 | Minimum Number of Primes to Sum to Target | Python | O(n * min(m, pi(n))) | O(n) | Medium | dp, 🔒, UNBOUNDED COIN CHANGE OVER THE FIRST M PRIMES, new | |
| 3615 | Longest Palindromic Path in Graph | Python | O(2^n * n^2) | O(2^n * n) | Hard | dp, BITMASK DP GROWING THE PALINDROME FROM BOTH ENDS INWARD, new | |
| 3628 | Maximum Number of Subsequences After One Inserting | Python | O(n) | O(1) | Medium | dp, COUNT “LCT” SUBSEQUENCES + TRY THE THREE USEFUL INSERTIONS, new | |
| 3647 | Maximum Weight in Two Bags | Python | O(n * w1 * w2 / 64) | O(w1 * w2 / 64) | Medium | dp, 🔒, TWO-DIMENSIONAL REACHABILITY (KNAPSACK OVER A PAIR OF LOADS), new | |
| 3651 | Minimum Cost Path with Teleportations | Python | O(k * m * n * log(m * n)) | O(m * n) | Hard | dp, ONE MONOTONE DP PER TELEPORT COUNT, LINKED BY A SUFFIX MINIMUM, new | |
| 3654 | Minimum Sum After Divisible Sum Deletions | Python | O(n) | O(k) | Medium | dp, PREFIX SUMS MOD k + “BEST dp SEEN AT THIS RESIDUE”, new | |
| 3661 | Maximum Walls Destroyed by Robots | Python | O(n log n + m log m) | O(n + m) | Hard | dp, SORT BY POSITION, DP OVER “WHICH WAY DID THE PREVIOUS ROBOT FIRE”, new | |
| 3665 | Twisted Mirror Path Count | Python | O(m * n) | O(n) | Medium | dp, DP ON FLOW THROUGH A CELL, SPLIT BY THE DIRECTION OF TRAVEL, new | |
| 3670 | Maximum Product of Two Integers With No Common Bits | Python | O(2^B * B + n) with B = 20 (nums[i] <= 10^6) | O(2^B) | Medium | dp, SUM-OVER-SUBSETS DP — BEST PARTNER FOR EVERY MASK, new | |
| 3685 | Subsequence Sum After Capping Elements | Python | O(n * k / 64 + k log n) | O(k / 64 + n) | Medium | dp, SPLIT AT THE CAP – UNTOUCHED ITEMS KEEP A DP, CAPPED ONES ARE COINS, new | |
| 3686 | Number of Stable Subsequences | Python | O(n) | O(1) | Hard | dp, DP ON (LAST PARITY, LENGTH OF THE CURRENT PARITY RUN), new |
Geometry
| # | Title | Solution | Time | Space | Difficulty | Note | Status |
|---|---|---|---|---|---|---|---|
| 1453 | Maximum Number of Darts Inside of a Circular Dartboard | Python | O(n^3) | O(1) | Hard | geometry, GEOMETRY - “the best circle can always be pushed onto 2 points”, new, fb |
|
| 1515 | Best Position for a Service Centre | Python | O(iters * n) | O(1) | Hard | geometry, GRADIENT DESCENT (geometric median / Weber point), new, uber |
|
| 1610 | Maximum Number of Visible Points | Python | O(n log n) | O(n) | Hard | geometry, POLAR ANGLES + SLIDING WINDOW ON A CIRCULAR SORTED ARRAY, new, google, amazon |
|
| 1924 | Erect the Fence II | Python | O(n) expected | O(n) | Hard | geometry, 🔒, WELZL / RANDOMIZED INCREMENTAL MINIMUM ENCLOSING CIRCLE, new, google |
|
| 1956 | Minimum Time For K Virus Variants to Spread | Python | O(100 * 100 * n log n) | O(n) | Hard | geometry, 🔒, ENUMERATE MEETING CELLS + k-TH SMALLEST MANHATTAN DISTANCE, new | |
| 2101 | Detonate the Maximum Bombs | Python | O(n^3) worst case (n DFS over n^2 edges) | O(n^2) | Medium | geometry, BUILD A DIRECTED REACHABILITY GRAPH, THEN DFS FROM EVERY BOMB, new, google |
Graph
| # | Title | Solution | Time | Space | Difficulty | Note | Status |
|---|---|---|---|---|---|---|---|
| 0924 | Minimize Malware Spread | Python, Java | O(n^2 * a(n)) | O(n) | Hard | graph, union find, pick the node in the largest single-infected component, new, google |
|
| 0928 | Minimize Malware Spread II | Python, Java | O(n^2 * a(n)) | O(n^2) | Hard | graph, union find over clean nodes, count each infected node’s exclusive reach, new | |
| 0959 | Regions Cut By Slashes | Python, Java | O(n^2 * a(n^2)) | O(n^2) | Medium | graph, split each cell into 4 triangles then union find, LC 200, new, amazon, apple, uber |
|
| 1042 | Flower Planting With No Adjacent | Python | O(n + e), e = len(paths) | O(n + e) | Medium | graph, GREEDY GRAPH COLORING, new, google, fb |
|
| 1101 | The Earliest Moment When Everyone Become Friends | Python | O(m log m) | O(n) | Medium | graph, 🔒, SORT by timestamp + UNION FIND (count components), new, google |
|
| 1168 | Optimize Water Distribution in a Village | Python | O((m + n) log (m + n)) | O(m + n) | Hard | graph, 🔒, MST (KRUSKAL) + VIRTUAL NODE 0, new, google, fb, microsoft |
|
| 1334 | Find the City With the Smallest Number of Neighbors at a Threshold Distance | Python | O(n^3) | O(n^2) | Medium | graph, FLOYD-WARSHALL (all pairs shortest path), new, apple, uber |
|
| 1349 | Maximum Students Taking Exam | Python | O(m * 4^n) | O(2^n) | Hard | graph, BITMASK DP row by row (n <= 8 -> a row is one byte), new | |
| 1557 | Minimum Number of Vertices to Reach All Nodes | Python | O(n + E) | O(n) | Medium | graph, IN-DEGREE (a node with an incoming edge is reachable from elsewhere), new, google, amazon |
|
| 1568 | Minimum Number of Days to Disconnect Island | Python | O((m * n)^2) | O(m * n) | Hard | graph, BRUTE FORCE + DFS (the answer is always 0, 1 or 2), new | |
| 1579 | Remove Max Number of Edges to Keep Graph Fully Traversable | Python | O(E * alpha) | O(n) | Hard | graph, UNION FIND x2 (add the shared type-3 edges first), new, uber |
|
| 1601 | Maximum Number of Achievable Transfer Requests | Python | O(2^m * m), m = len(requests) <= 16 | O(n) | Hard | graph, BITMASK ENUMERATION (requests.length <= 16 -> 2^16 subsets), new, amazon |
|
| 1615 | Maximal Network Rank | Python | O(n^2 + E) | O(n^2) | Medium | graph, DEGREE COUNT + INCLUSION-EXCLUSION over all pairs, new, amazon, microsoft |
|
| 1627 | Graph Connectivity With Threshold | Python | O(n log n * alpha(n) + q * alpha(n)) | O(n) | Hard | graph, UNION FIND over multiples (sieve-style edge generation), new | |
| 1697 | Checking Existence of Edge Length Limited Paths | Python | O((E + Q) log(E + Q)) dominated by the two sorts | O(n + Q) | Hard | graph, OFFLINE QUERIES + UNION-FIND (sort both sides by weight, add edges once), new, google |
|
| 1719 | Number Of Ways To Reconstruct A Tree | Python | O(V^2 + E) | O(V + E), V <= 500 | Hard | graph, DEGREE ORDERING + ADJACENCY SUBSET CHECK, new, uber |
|
| 1724 | Checking Existence of Edge Length Limited Paths II | Python | O(E log E) to build, O(log n) per query | O(n) | Hard | graph, 🔒, PERSISTENT (VERSIONED) UNION FIND - queries arrive online, so LC 1697’s, new, google |
|
| 1743 | Restore the Array From Adjacent Pairs | Python | O(n) | O(n) | Medium | graph, GRAPH IS A PATH - START AT A DEGREE-1 ENDPOINT AND WALK IT, new, uber |
|
| 1778 | Shortest Path in a Hidden Grid | Python | O(m * n) | O(m * n) | Medium | graph, 🔒, DFS TO MAP THE HIDDEN GRID, THEN BFS ON THE MAP, new, google, fb |
|
| 1782 | Count Pairs Of Nodes | Python | O(m + n log n + Q * (n + m)) | O(n + m) | Hard | graph, SORTED DEGREES + TWO POINTERS, THEN FIX UP THE SHARED EDGES, new, google, amazon |
|
| 1786 | Number of Restricted Paths From First to Last Node | Python | O((n + m) log n) | O(n + m) | Medium | graph, DIJKSTRA FROM NODE n, THEN DP IN ORDER OF INCREASING DISTANCE, new, google |
|
| 1810 | Minimum Path Cost in a Hidden Grid | Python | O(mn log(mn)) | O(m*n) | Medium | graph, 🔒, DFS TO EXPLORE (map the hidden grid) + DIJKSTRA ON THE MAP, new, google, fb |
|
| 1820 | Maximum Number of Accepted Invitations | Python | O(m * n * m) worst case (V * E) | O(m + n) | Medium | graph, 🔒, MAXIMUM BIPARTITE MATCHING (Hungarian / Kuhn’s augmenting path), new | |
| 1879 | Minimum XOR Sum of Two Arrays | Python | O(2^n * n) | O(2^n) | Hard | graph, BITMASK DP (min-cost perfect matching on a tiny bipartite graph), new | |
| 1947 | Maximum Compatibility Score Sum | Python | O(m^2 * n + 2^m * m) | O(2^m) | Medium | graph, BITMASK DP OVER THE SET OF USED MENTORS (assignment problem, m <= 8), new, fb |
|
| 2076 | Process Restricted Friend Requests | Python | O(R * K * alpha(n)) | O(n) | Hard | graph, UNION-FIND WITH A “DRY RUN” CHECK AGAINST EVERY RESTRICTION, new, google, fb |
|
| 2077 | Paths in Maze That Lead to Same Room | Python | O(E * n / 64) with set intersection | O(V + E) | Medium | graph, 🔒, COUNT TRIANGLES BY INTERSECTING THE NEIGHBOUR SETS OF EACH EDGE, new, google |
|
| 2092 | Find All People With Secret | Python | O(m log m * alpha(n)) | O(n) | Hard | graph, UNION-FIND PROCESSED IN TIME GROUPS, WITH A ROLLBACK PER GROUP, new, google, fb |
|
| 2093 | Minimum Cost to Reach City With Discounts | Python | O(E * D * log(V * D)) | O(V * D) | Medium | graph, 🔒, DIJKSTRA ON THE EXPANDED STATE (city, discounts already used), new | |
| 2097 | Valid Arrangement of Pairs | Python | O(V + E) | O(V + E) | Hard | graph, EULERIAN PATH (Hierholzer) — each pair is a DIRECTED EDGE, new | |
| 2123 | Minimum Operations to Remove Adjacent Ones in Matrix | Python | O(V * E) for Kuhn’s algorithm | O(V + E) | Hard | graph, 🔒, MINIMUM VERTEX COVER ON A BIPARTITE GRAPH = MAXIMUM MATCHING (König), new, amazon |
|
| 2127 | Maximum Employees to Be Invited to a Meeting | Python | O(n) | O(n) | Hard | graph, FUNCTIONAL GRAPH — EITHER ONE BIG CYCLE, OR ALL 2-CYCLES WITH TAILS, new | |
| 2172 | Maximum AND Sum of Array | Python | O(2^(2*numSlots) * numSlots) | O(2^(2*numSlots)) | Hard | graph, BITMASK DP OVER HALF-SLOTS (each slot split into two seats), new, google |
|
| 2203 | Minimum Weighted Subgraph With the Required Paths | Python | O((V + E) log V) | O(V + E) | Hard | graph, THE OPTIMAL SUBGRAPH IS A “Y” — THREE DIJKSTRAS, ONE MEETING POINT, new | |
| 2204 | Distance to a Cycle in Undirected Graph | Python | O(V + E) | O(V + E) | Hard | graph, 🔒, PEEL THE TREES OFF (Kahn on degree 1), THEN MULTI-SOURCE BFS, new | |
| 2242 | Maximum Score of a Node Sequence | Python | O(V + E log 3 + E * 9) | O(V + E) | Hard | graph, ANCHOR ON THE MIDDLE EDGE, AND ONLY THE TOP-3 NEIGHBOURS CAN MATTER, new | |
| 2307 | Check for Contradictions in Equations | Python | O(m * alpha(n)) | O(n) | Hard | graph, 🔒, WEIGHTED UNION FIND (w[x] = value(x) / value(root(x))), new | |
| 2359 | Find Closest Node to Given Two Nodes | Python | O(n) | O(n) | Medium | graph, FUNCTIONAL GRAPH WALK (out-degree <= 1 -> the reachable set is one chain), new | |
| 2360 | Longest Cycle in a Graph | Python | O(n) | O(n) | Hard | graph, FUNCTIONAL GRAPH + VISIT TIMESTAMPS (each node walked once overall), new | |
| 2473 | Minimum Cost to Buy Apples | Python | O(n * m * log m) | O(n + m) | Medium | graph, 🔒, DIJKSTRA FROM EVERY START CITY (a round trip costs dist * (k + 1)), new | |
| 2608 | Shortest Cycle in a Graph | Python | O(n * (n + m)) | O(n + m) | Hard | graph, BFS FROM EVERY VERTEX (girth of an unweighted graph), new | |
| 2662 | Minimum Cost of a Path With Special Roads | Python | O(n^2 * log n) | O(n^2) worst case heap (n = #specialRoads) | Medium | graph, DIJKSTRA ON A TINY GRAPH (start + the <=200 special-road EXITS), new | |
| 2699 | Modify Graph Edge Weights | Python | O(m * n^2) | O(n^2) | Hard | graph, DIJKSTRA, ACTIVATING THE -1 EDGES ONE BY ONE (greedy), new | |
| 2714 | Find Shortest Path with K Hops | Python | O(E * k * log(V * k)) | O(n * k) | Hard | graph, 🔒, DIJKSTRA on the LAYERED STATE GRAPH (node, #hops used so far), new | |
| 2737 | Find the Closest Marked Node | Python | O(E * log E) | O(V + E) | Medium | graph, 🔒, DIJKSTRA (SINGLE SOURCE) + MIN OVER THE MARKED SET, new | |
| 2836 | Maximize Value of Function in a Ball Passing Game | Python | O(n * log k) | O(n * log k) | Hard | graph, BINARY LIFTING (a.k.a. sparse table on the functional graph), new | |
| 3108 | Minimum Cost Walk in Weighted Graph | Python | O((n + E + Q) * alpha) | O(n) | Hard | graph, A WALK MAY REUSE EDGES — SO IT CAN AND EVERY EDGE OF ITS COMPONENT, new | |
| 3243 | Shortest Distance After Road Addition Queries I | Python | O(q * (n + q)) | O(n + q) | Medium | graph, ALL EDGES COST 1 — SO ONE BFS PER QUERY IS ENOUGH AT THIS SIZE, new | |
| 3244 | Shortest Distance After Road Addition Queries II | Python | O(n + q) | O(n) | Hard | graph, THE NON-CROSSING GUARANTEE MAKES THE SHORTCUTS NEST, SO JUST SPLICE, new | |
| 3265 | Count Almost Equal Pairs I | Python | O(n^2 * d^2) | O(d) | Medium | graph, PAD TO A COMMON WIDTH, THEN TEST EVERY SINGLE SWAP, new | |
| 3267 | Count Almost Equal Pairs II | Python | O(n * d^4) | O(n) | Hard | graph, ENUMERATE EVERY STRING REACHABLE FROM x IN AT MOST TWO SWAPS, new | |
| 3276 | Select Cells in Grid With Maximum Score | Python | O(distinct values * 2^m * m) | O(2^m) | Hard | graph, BITMASK OVER THE ROWS, ITERATING THE DISTINCT VALUES, new | |
| 3310 | Remove Methods From Project | Python | O(n + E) | O(n + E) | Medium | graph, MARK THE REACHABLE SET FROM k, THEN CHECK FOR ANY EDGE INTO IT, new | |
| 3341 | Find Minimum Time to Reach Last Room I | Python | O(n * m log(n * m)) | O(n * m) | Medium | graph, DIJKSTRA WHERE THE EDGE COST DEPENDS ON THE ARRIVAL TIME, new | |
| 3342 | Find Minimum Time to Reach Last Room II | Python | O(n * m log(n * m)) | O(n * m) | Medium | graph, SAME DIJKSTRA, BUT THE STEP COST FOLLOWS THE CHESSBOARD PARITY, new | |
| 3376 | Minimum Time to Break Locks I | Python | O(n! * n) | O(n) | Medium | graph, n <= 8, SO TRY EVERY ORDER — THE COST OF AN ORDER IS FORCED, new | |
| 3377 | Digit Operations to Make Two Integers Equal | Python | O(states * digits * 10 log states) | O(states) | Medium | graph, DIJKSTRA OVER THE NUMBERS, WHERE ENTERING A STATE COSTS ITS VALUE, new | |
| 3378 | Count Connected Components in LCM Graph | Python | O(threshold log threshold * alpha) | O(threshold + n) | Hard | graph, GROUP BY COMMON MULTIPLE — EVERY DIVISOR OF L IS CONNECTED THROUGH L, new | |
| 3419 | Minimize the Maximum Edge Weight of Graph | Python | O((V + E) log V) | O(V + E) | Medium | graph, REVERSE THE EDGES, THEN RUN A MINIMAX (BOTTLENECK) DIJKSTRA FROM 0, new | |
| 3435 | Frequencies of Shortest Supersequences | Python | O(2^V * V) with V <= 16 | O(2^V) | Hard | graph, THE SCS DUPLICATES EXACTLY A “FEEDBACK VERTEX SET” OF THE ORDER GRAPH, new | |
| 3532 | Path Existence Queries in a Graph I | Python | O(n + q) | O(n) | Medium | graph, SORTED VALUES MAKE COMPONENTS CONTIGUOUS RUNS, new | |
| 3534 | Path Existence Queries in a Graph II | Python | O((n + q) * log n) | O(n * log n) | Hard | graph, SORT BY VALUE -> INTERVAL GRAPH -> GREEDY JUMPS VIA BINARY LIFTING, new | |
| 3536 | Maximum Product of Two Digits | Python | O(d log d) with d <= 10 digits | O(d) | Easy | graph, TAKE THE TWO LARGEST DIGITS, new | |
| 3547 | Maximum Sum of Edge Values in a Graph | Python | O(n) | O(1) | Hard | graph, THE GRAPH IS ONE PATH OR ONE CYCLE – BUILD THE ZIGZAG AROUND n, new | |
| 3594 | Minimum Time to Transport All Individuals | Python | O(3^n * m * log(2^n * m)) | O(3^n) | Hard | graph, DIJKSTRA OVER (CAMP BITMASK, STAGE, BOAT SIDE), new | |
| 3600 | Maximize Spanning Tree Stability with Upgrades | Python | O(m * alpha(n) * log(M)) | O(n) | Hard | graph, BINARY SEARCH THE STABILITY + UNION-FIND FEASIBILITY CHECK, new | |
| 3604 | Minimum Time to Reach Destination in Directed Graph | Python | O((V + E) * log(V)) | O(V + E) | Medium | graph, DIJKSTRA ON EARLIEST ARRIVAL TIME, new | |
| 3620 | Network Recovery Pathways | Python | O((n + m) * log m) | O(n + m) | Hard | graph, BINARY SEARCH THE SCORE + CHEAPEST PATH ON THE DAG, new | |
| 3650 | Minimum Cost Path with Edge Reversals | Python | O((V + E) log V) | O(V + E) | Medium | graph, MODEL THE REVERSAL AS A SECOND, PRICIER EDGE + DIJKSTRA, new | |
| 3656 | Determine if a Simple Graph Exists | Python | O(n log n) | O(n) | Medium | graph, 🔒, ERDOS-GALLAI THEOREM, new | |
| 3660 | Jump Game IX | Python | O(n) | O(n) | Medium | graph, THE JUMP RELATION IS THE (SYMMETRIC) INVERSION GRAPH, new |
Greedy
| # | Title | Solution | Time | Space | Difficulty | Note | Status |
|---|---|---|---|---|---|---|---|
| 0484 | Find Permutation | Python, Java | O(n) | O(n) | Medium | greedy, 🔒, reverse the D runs of the identity permutation, good trick, new, google |
|
| 0630 | Course Schedule III | Python, Java | O(nlogn) | O(n) | Hard | greedy, sort by deadline + max-heap of durations, LC 1353, good trick, new, google, amazon, microsoft |
|
| 0757 | Set Intersection Size At Least Two | Python, Java | O(nlogn) | O(1) | Hard | greedy, sort by end then greedily add the last two points, new, uber |
|
| 0798 | Smallest Rotation with Highest Score | Python, Java | O(n) | O(n) | Hard | greedy, difference array over rotation scores, good trick, new, prefix sum |
|
| 0843 | Guess the Word | Python, Java | O(g * n^2 * l) | O(n) | Hard | greedy, minimax guess against the worst-case bucket, interactive, new, array, math, string, google, amazon, fb, microsoft |
|
| 0936 | Stamping The Sequence | Python, Java | O(n * (n - m + 1)) | O(n * (n - m + 1)) | Hard | greedy, reverse thinking, un-stamp back to ‘???’, good trick, new, google, fb |
|
| 0991 | Broken Calculator | Python, Java | O(log(target)) | O(1) | Medium | greedy, work backwards from the target, halve when even, good trick, new |
|
| 0995 | Minimum Number of K Consecutive Bit Flips | Python, Java | O(n) | O(n) | Hard | greedy, sliding window with a flip-difference array, good trick, new, bit manipulation, queue, google, amazon, fb, microsoft |
|
| 1005 | Maximize Sum Of Array After K Negations | Python | O(n log n) | O(1), ignoring the sort | Easy | greedy, GREEDY + SORT, new, amazon |
|
| 1029 | Two City Scheduling | Python | O(n log n) | O(1) | Medium | greedy, GREEDY + SORT ON (aCost - bCost), new, google, amazon, fb, apple, bloomberg |
|
| 1053 | Previous Permutation With One Swap | Python | O(n) | O(1) | Medium | greedy, GREEDY (mirror of “next permutation”), new, amazon, fb, microsoft |
|
| 1058 | Minimize Rounding Error to Meet Target | Python | O(n log n) | O(n) | Medium | greedy, 🔒, GREEDY + exact integer (thousandths) arithmetic, new | |
| 1090 | Largest Values From Labels | Python | O(n log n) | O(n) | Medium | greedy, GREEDY + SORT (big value first) + label counter, new, google |
|
| 1111 | Maximum Nesting Depth of Two Valid Parentheses Strings | Python | O(n) | O(n) | Medium | greedy, GREEDY (split by DEPTH PARITY), new, fb, apple |
|
| 1163 | Last Substring in Lexicographical Order | Python | O(n) | O(1) | Hard | greedy, TWO POINTERS, new | |
| 1183 | Maximum Number of Ones | Python | O(width * height + L^2 log L) | O(L^2) L = sideLength | Hard | greedy, 🔒, GREEDY over residue classes (the pattern must be periodic mod sideLength), new | |
| 1196 | How Many Apples Can You Put into the Basket | Python | O(n log n) | O(n) | Easy | greedy, 🔒, GREEDY (sort ascending, take the lightest apples first), new | |
| 1199 | Minimum Time to Build Blocks | Python | O(n log n) | O(n) | Hard | greedy, 🔒, GREEDY + MIN HEAP (reverse Huffman-style merging), new, google |
|
| 1221 | Split a String in Balanced Strings | Python | O(n) | O(1) | Easy | greedy, GREEDY + RUNNING BALANCE, new, google, apple |
|
| 1247 | Minimum Swaps to Make Strings Equal | Python | O(n) | O(1) | Medium | greedy, GREEDY / COUNTING, new, amazon, fb |
|
| 1249 | Minimum Remove to Make Valid Parentheses | Python | O(n) | O(n) | Medium | greedy, GREEDY, TWO PASSES, new, google, amazon, fb, apple, microsoft, uber |
|
| 1253 | Reconstruct a 2-Row Binary Matrix | Python | O(n) | O(1) | Medium | greedy, GREEDY (columns with sum 2 are forced ; sum 1 goes to the “richer” row), new | |
| 1282 | Group the People Given the Group Size They Belong To | Python | O(n) | O(n) | Medium | greedy, GREEDY + HASH MAP, new, apple |
|
| 1326 | Minimum Number of Taps to Open to Water a Garden | Python | O(n) | O(n) | Hard | greedy, GREEDY / JUMP GAME II (interval covering reduced to minimum jumps), new, google, amazon, fb, apple |
|
| 1338 | Reduce Array Size to The Half | Python | O(n log n) | O(n) | Medium | greedy, GREEDY + COUNTER, new, amazon |
|
| 1354 | Construct Target Array With Multiple Sums | Python | O(n log n log m) | O(n) | Hard | greedy, REVERSE SIMULATION + MAX HEAP, new | |
| 1386 | Cinema Seat Allocation | Python | O(m), m = len(reservedSeats) | O(m) | Medium | greedy, hash map (row -> bitmask of reserved seats) + greedy, new, amazon, microsoft |
|
| 1400 | Construct K Palindrome Strings | Python | O(n) | O(26) | Medium | greedy, GREEDY / PARITY COUNT (odd-count chars force separate palindromes), new, uber |
|
| 1402 | Reducing Dishes | Python | O(n log n) | O(n) | Hard | greedy, GREEDY + SORTING, new | |
| 1403 | Minimum Subsequence in Non-Increasing Order | Python | O(n log n) | O(n) | Easy | greedy, GREEDY + SORTING, new, amazon |
|
| 1414 | Find the Minimum Number of Fibonacci Numbers Whose Sum Is K | Python | O(log k) | O(log k) | Medium | greedy, GREEDY (Zeckendorf - always take the biggest Fibonacci <= k), new, google |
|
| 1419 | Minimum Number of Frogs Croaking | Python | O(n) | O(1) | Medium | greedy, GREEDY COUNTING OF FROGS IN EACH STAGE, new | |
| 1432 | Max Difference You Can Get From Changing an Integer | Python | O(d) | O(d) | Medium | greedy, GREEDY, new | |
| 1433 | Check If a String Can Break Another String | Python | O(n log n) | O(n) | Medium | greedy, GREEDY + SORT, new | |
| 1488 | Avoid Flood in The City | Python | O(n log n) | O(n) | Medium | greedy, GREEDY + MIN-HEAP KEYED ON THE NEXT RAIN (dry the most urgent lake), new, google |
|
| 1518 | Water Bottles | Python | O(numBottles / numExchange) | O(1) | Easy | greedy, SIMULATION (each trade consumes numExchange - 1 bottles net), new | |
| 1520 | Maximum Number of Non-Overlapping Substrings | Python | O(26 * n) | O(n) | Hard | greedy, SMALLEST VALID INTERVAL PER LETTER + GREEDY BY EARLIEST END, new, amazon |
|
| 1526 | Minimum Number of Increments on Subarrays to Form a Target Array | Python | O(n) | O(1) | Hard | greedy, GREEDY / SUM OF POSITIVE RISES, new, google |
|
| 1536 | Minimum Swaps to Arrange a Binary Grid | Python | O(n^2) | O(n) | Medium | greedy, REDUCE EACH ROW TO ITS TRAILING-ZERO COUNT, THEN GREEDY BUBBLING, new | |
| 1578 | Minimum Time to Make Rope Colorful | Python | O(n) | O(1) | Medium | greedy, GREEDY (inside a block of equal colours keep the most expensive one), new, apple, microsoft |
|
| 1580 | Put Boxes Into the Warehouse II | Python | O(n log n + b log b) | O(n) | Medium | greedy, 🔒, PREFIX/SUFFIX MIN + GREEDY (a room is reachable from the better side), new, google |
|
| 1585 | Check If String Is Transformable With Substring Sort Operations | Python | O(10 * n) | O(n) | Hard | greedy, GREEDY + QUEUE PER DIGIT (a sort = bubbling a digit left past bigger ones), new, google |
|
| 1589 | Maximum Sum Obtained of Any Permutation | Python | O(n log n + q) | O(n) | Medium | greedy, DIFFERENCE ARRAY + GREEDY (biggest number on the hottest index), new | |
| 1591 | Strange Printer II | Python | O(C * m * n) | O(m * n + C^2), C <= 60 colours | Hard | greedy, BOUNDING BOX + TOPOLOGICAL SORT (colour a must be printed before b), new, google |
|
| 1599 | Maximum Profit of Operating a Centennial Wheel | Python | O(n + total_customers / 4) | O(1) | Medium | greedy, SIMULATION (profit is only ever checked right after a rotation), new | |
| 1605 | Find Valid Matrix Given Row and Column Sums | Python | O(m * n) | O(1) extra (besides the output) | Medium | greedy, GREEDY (fill each cell with as much as it can possibly take), new, google |
|
| 1616 | Split Two Strings to Make Palindrome | Python | O(n) | O(n) for the slice comparisons | Medium | greedy, GREEDY TWO POINTERS (match the outside as far as possible, then, new, google |
|
| 1632 | Rank Transform of a Matrix | Python | O(m * n * log(m * n)) | O(m * n) | Hard | greedy, PROCESS VALUES IN INCREASING ORDER + UNION FIND on rows/cols, new, google |
|
| 1653 | Minimum Deletions to Make String Balanced | Python | O(n) | O(1) | Medium | greedy, RUNNING DP – keep the best cost for the prefix seen so far, new, microsoft |
|
| 1663 | Smallest String With A Given Numeric Value | Python | O(n) | O(n) | Medium | greedy, GREEDY FROM THE BACK (keep the prefix as small as possible), new | |
| 1665 | Minimum Initial Energy to Finish Tasks | Python | O(n log n) | O(n) for the sort | Hard | greedy, GREEDY + EXCHANGE-ARGUMENT SORT (do the biggest “slack” tasks LAST), new | |
| 1673 | Find the Most Competitive Subsequence | Python | O(n) | O(k) | Medium | greedy, MONOTONIC (INCREASING) STACK + FEASIBILITY GUARD, new, google, amazon |
|
| 1674 | Minimum Moves to Make Array Complementary | Python | O(n + limit) | O(limit) | Medium | greedy, DIFFERENCE ARRAY / LINE SWEEP over every candidate target sum T, new | |
| 1686 | Stone Game VI | Python | O(n log n) | O(n) | Medium | greedy, GREEDY, SORT BY a[i] + b[i] DESCENDING (exchange argument), new | |
| 1689 | Partitioning Into Minimum Number Of Deci-Binary Numbers | Python | O(len(n)) | O(1) | Medium | greedy, GREEDY / MAX DIGIT (each deci-binary number contributes at most 1 per column), new | |
| 1702 | Maximum Binary String After Change | Python | O(n) | O(n) | Medium | greedy, GREEDY / INVARIANT (op 2 gathers the zeros, op 1 then eats all but one), new | |
| 1705 | Maximum Number of Eaten Apples | Python | O((n + M) * log n), M = max(days) | O(n) | Medium | greedy, GREEDY + MIN HEAP (always eat the batch that rots soonest), new, uber |
|
| 1708 | Largest Subarray Length K | Python | O(n) | O(1) excluding the output | Easy | greedy, 🔒, GREEDY (all values are DISTINCT -> the first element decides everything), new, google |
|
| 1717 | Maximum Score From Removing Substrings | Python | O(n) | O(1) | Medium | greedy, GREEDY + STACK COUNTERS (strip the higher-paying pair first), new, google |
|
| 1725 | Number Of Rectangles That Can Form The Largest Square | Python | O(n) | O(1) | Easy | greedy, RUNNING MAX + COUNT (single pass, no sorting), new | |
| 1727 | Largest Submatrix With Rearrangements | Python | O(m * n * log n) | O(n) (heights kept one row at a time) | Medium | greedy, COLUMN HISTOGRAM + SORT EACH ROW (columns may be permuted freely), new, google |
|
| 1733 | Minimum Number of People to Teach | Python | O(k * L + |S| * L), k = len(friendships) | O(m * L) | Medium | greedy, GREEDY / COUNTING (only BROKEN friendships matter, then pick the best language), new | |
| 1736 | Latest Time by Replacing Hidden Digits | Python | O(1) | O(1) | Easy | greedy, GREEDY, DIGIT BY DIGIT (earlier digits dominate the value), new, google |
|
| 1737 | Change Minimum Characters to Satisfy One of Three Conditions | Python | O(m + n + 26) | O(26) | Medium | greedy, LETTER COUNTS + ENUMERATE THE 26 SPLIT POINTS, new, google |
|
| 1749 | Maximum Absolute Sum of Any Subarray | Python | O(n) | O(1) | Medium | greedy, KADANE TWICE (max subarray sum AND min subarray sum), new, amazon |
|
| 1754 | Largest Merge Of Two Strings | Python | O((m + n) * (m + n)) | O(m + n) | Medium | greedy, GREEDY WITH SUFFIX COMPARISON (take from the lexicographically bigger tail), new | |
| 1758 | Minimum Changes To Make Alternating Binary String | Python | O(n) | O(1) | Easy | greedy, COUNTING (there are only two possible alternating targets), new | |
| 1759 | Count Number of Homogenous Substrings | Python | O(n) | O(1) | Medium | greedy, GROUP CONSECUTIVE RUNS (a run of length L holds L * (L + 1) / 2 substrings), new | |
| 1762 | Buildings With an Ocean View | Python | O(n) | O(1) extra (output excluded) | Medium | greedy, 🔒, RIGHT TO LEFT SCAN (keep the tallest building seen so far on the right), new, google, amazon, fb, microsoft |
|
| 1764 | Form Array by Concatenating Subarrays of Another Array | Python | O(len(nums) * sum(len(groups[i]))) | O(1) | Medium | greedy, GREEDY TWO POINTERS (match each group at its earliest possible position), new, amazon |
|
| 1769 | Minimum Number of Operations to Move All Balls to Each Box | Python | O(n) | O(n) | Medium | greedy, PREFIX SUM IN BOTH DIRECTIONS (cost from the left + cost from the right), new, google, amazon |
|
| 1775 | Equal Sum Arrays With Minimum Number of Operations | Python | O(n + m) with counting sort over gains 0…5 | O(1) | Medium | greedy, GREEDY ON THE “GAIN” OF EACH SINGLE CHANGE, new | |
| 1785 | Minimum Elements to Add to Form a Given Sum | Python | O(n) | O(1) | Medium | greedy, GREEDY (every added element moves the sum by at most limit), new |
|
| 1788 | Maximize the Beauty of the Garden | Python | O(n) | O(n) | Hard | greedy, 🔒, FIRST OCCURRENCE + PREFIX SUM OF POSITIVE VALUES, new, amazon |
|
| 1793 | Maximum Score of a Good Subarray | Python | O(n) | O(1) | Hard | greedy, TWO POINTERS EXPANDING OUT OF k (greedily keep the larger side), new, google, uber |
|
| 1798 | Maximum Number of Consecutive Values You Can Make | Python | O(n log n) | O(1) | Medium | greedy, GREEDY ON SORTED COINS (keep the reachable prefix [0, res - 1]), new | |
| 1801 | Number of Orders in the Backlog | Python | O(n log n) | O(n) | Medium | greedy, TWO HEAPS SIMULATING AN ORDER BOOK, new, amazon |
|
| 1815 | Maximum Number of Groups Getting Fresh Donuts | Python | O(b * prod(cnt_i + 1) * b), b = batchSize | O(b * prod(cnt_i + 1)) | Hard | greedy, STATE-COMPRESSION DP OVER REMAINDER COUNTS (order matters only via, new, google |
|
| 1824 | Minimum Sideway Jumps | Python | O(n) | O(1) | Medium | greedy, ROLLING DP OVER 3 LANES (f[j] = min side jumps to stand on lane j+1, new | |
| 1827 | Minimum Operations to Make the Array Increasing | Python | O(n) | O(1) | Easy | greedy, GREEDY LEFT -> RIGHT (keep every element as small as legally possible), new, apple |
|
| 1833 | Maximum Ice Cream Bars | Python | O(n + M) | O(M) | Medium | greedy, GREEDY (buy cheapest first) IMPLEMENTED WITH COUNTING SORT, new | |
| 1840 | Maximum Building Height | Python | O(m log m), m = len(restrictions) | O(m) | Hard | greedy, TIGHTEN THE RESTRICTIONS BOTH WAYS, THEN PEAK BETWEEN NEIGHBOURS, new | |
| 1842 | Next Palindrome Using Same Digits | Python | O(n) | O(n) | Hard | greedy, 🔒, NEXT PERMUTATION OF THE FIRST HALF ONLY, THEN MIRROR, new, amazon |
|
| 1850 | Minimum Adjacent Swaps to Reach the Kth Smallest Number | Python | O(k*n + n^2) | O(n) | Medium | greedy, APPLY NEXT-PERMUTATION k TIMES, THEN GREEDY BUBBLE COUNT, new, google |
|
| 1864 | Minimum Number of Swaps to Make the Binary String Alternating | Python | O(n) | O(1) | Medium | greedy, GREEDY / COUNTING (only 2 target patterns exist), new, google |
|
| 1874 | Minimize Product Sum of Two Arrays | Python | O(n log n) | O(n) for the sorted copies | Medium | greedy, 🔒, GREEDY / REARRANGEMENT INEQUALITY (pair smallest with largest), new, google |
|
| 1881 | Maximum Value after Insertion | Python | O(len(n)) | O(len(n)) for the result string | Medium | greedy, GREEDY (insert at the FIRST position that improves the digit), new, microsoft |
|
| 1887 | Reduction Operations to Make the Array Elements Equal | Python | O(n log n) | O(n) for the sorted copy | Medium | greedy, SORT + COUNT DISTINCT LEVELS BELOW EACH ELEMENT, new | |
| 1893 | Check if All the Integers in a Range Are Covered | Python | O(n + M), M = 52 | O(M) | Easy | greedy, DIFFERENCE ARRAY (values are bounded by 50), new | |
| 1894 | Find the Student that Will Replace the Chalk | Python | O(n) | O(1) | Medium | greedy, MODULO THE FULL ROUND, THEN ONE LINEAR SCAN, new | |
| 1897 | Redistribute Characters to Make All Strings Equal | Python | O(L), L = total number of characters | O(1), at most 26 counters | Easy | greedy, COUNTING (characters are conserved, so each total must split evenly), new | |
| 1911 | Maximum Alternating Subsequence Sum | Python | O(n) | O(1) | Medium | greedy, DP ON PARITY OF THE PICKED LENGTH (2 rolling states, “stock trading” shape), new, amazon |
|
| 1913 | Maximum Product Difference Between Two Pairs | Python | O(n) | O(1) | Easy | greedy, GREEDY (all values are positive -> take the 2 largest & the 2 smallest), new | |
| 1921 | Eliminate Maximum Number of Monsters | Python | O(n log n) | O(n) | Medium | greedy, GREEDY + SORT BY DEADLINE (classic “shoot the most urgent first”), new, google |
|
| 1927 | Sum Game | Python | O(n) | O(1) | Medium | greedy, GAME THEORY / CASE ANALYSIS (closed form, no simulation), new | |
| 1936 | Add Minimum Number of Rungs | Python | O(n) | O(1) | Medium | greedy, GREEDY, GAP BY GAP (closed form per gap, no simulation), new | |
| 1946 | Largest Number After Mutating Substring | Python | O(n) | O(n) | Medium | greedy, GREEDY - START AT THE FIRST IMPROVABLE DIGIT, STOP AT THE FIRST LOSS, new | |
| 1953 | Maximum Number of Weeks for Which You Can Work | Python | O(n) | O(1) | Medium | greedy, GREEDY / “TASK REARRANGEMENT” BOUND (only the biggest project matters), new, amazon |
|
| 1975 | Maximum Matrix Sum | Python | O(n^2) | O(1) | Medium | greedy, GREEDY / PARITY INVARIANT, new | |
| 2027 | Minimum Moves to Convert String | Python | O(n) | O(1) | Easy | greedy, GREEDY LEFT-TO-RIGHT SCAN, new | |
| 2030 | Smallest K-Length Subsequence With Occurrences of a Letter | Python | O(n) | O(k) | Hard | greedy, MONOTONIC STACK (“remove k digits” greedy) + A QUOTA FOR letter, new, google |
|
| 2036 | Maximum Alternating Subarray Sum | Python | O(n) | O(1) | Medium | greedy, 🔒, KADANE WITH TWO STATES (the sign the NEXT element would carry), new, amazon |
|
| 2037 | Minimum Number of Moves to Seat Everyone | Python | O(n log n) | O(n) | Easy | greedy, SORT BOTH, MATCH IN ORDER (rearrangement / exchange argument), new | |
| 2071 | Maximum Number of Tasks You Can Assign | Python | O((n log n) + (m log m) + (n + m) log(min(n, m))) | O(m) | Hard | greedy, BINARY SEARCH ON THE ANSWER k + GREEDY FEASIBILITY WITH A DEQUE, new, fb |
|
| 2086 | Minimum Number of Food Buckets to Feed the Hamsters | Python | O(n) | O(n) | Medium | greedy, GREEDY — ALWAYS PREFER THE BUCKET ON THE RIGHT OF A HOUSE, new | |
| 2087 | Minimum Cost Homecoming of a Robot in a Grid | Python | O(m + n) | O(1) | Medium | greedy, THE COST IS PATH-INDEPENDENT — JUST WALK STRAIGHT THERE, new | |
| 2136 | Earliest Possible Day of Full Bloom | Python | O(n log n) | O(n) | Hard | greedy, PLANT THE SLOWEST-GROWING SEEDS FIRST (exchange argument), new | |
| 2139 | Minimum Moves to Reach Target Score | Python | O(log target) | O(1) | Medium | greedy, WORK BACKWARDS FROM target — HALVE WHENEVER YOU CAN, new | |
| 2141 | Maximum Running Time of N Computers | Python | O(m log(total / n)) | O(1) | Hard | greedy, BINARY SEARCH ON THE RUNTIME t + A CAPPED-SUM FEASIBILITY TEST, new | |
| 2144 | Minimum Cost of Buying Candies With Discount | Python | O(n log n) | O(n) | Easy | greedy, SORT DESCENDING, SKIP EVERY THIRD CANDY, new | |
| 2147 | Number of Ways to Divide a Long Corridor | Python | O(n) | O(n) | Hard | greedy, PAIR UP THE SEATS, MULTIPLY THE GAPS BETWEEN CONSECUTIVE PAIRS, new | |
| 2160 | Minimum Sum of Four Digit Number After Splitting Digits | Python | O(1) | O(1) | Easy | greedy, SORT THE DIGITS AND DEAL THEM ALTERNATELY INTO TWO 2-DIGIT NUMBERS, new, amazon |
|
| 2165 | Smallest Value of the Rearranged Number | Python | O(d log d) | O(d) | Medium | greedy, SIGN DECIDES THE SORT DIRECTION; ZEROS ONLY MATTER WHEN POSITIVE, new | |
| 2178 | Maximum Split of Positive Even Integers | Python | O(sqrt(finalSum)) | O(sqrt(finalSum)) for the output | Medium | greedy, GREEDY (take the smallest unused even number as long as we can), new, google |
|
| 2182 | Construct String With Repeat Limit | Python | O(n + 26^2) | O(n) | Medium | greedy, GREEDY + COUNTING (emit the largest letter, break runs with the next largest), new | |
| 2193 | Minimum Number of Moves to Make Palindrome | Python | O(n^2) | O(n) | Hard | greedy, GREEDY FROM THE OUTSIDE IN — MATCH s[i] WITH THE RIGHTMOST TWIN, new | |
| 2195 | Append K Integers With Minimal Sum | Python | O(n log n) | O(n) | Medium | greedy, WALK THE GAPS BETWEEN THE SORTED DISTINCT VALUES, SUMMING WITH GAUSS, new | |
| 2207 | Maximize Number of Subsequences in a String | Python | O(n) | O(1) | Medium | greedy, COUNT PAIRS IN ONE SWEEP, THEN CHOOSE THE BETTER SINGLE INSERTION, new | |
| 2214 | Minimum Health to Beat Game | Python | O(n) | O(1) | Medium | greedy, 🔒, SPEND THE SHIELD ON THE BIGGEST HIT — IT ONLY DEPENDS ON THE TOTAL, new | |
| 2216 | Minimum Deletions to Make Array Beautiful | Python | O(n) | O(1) | Medium | greedy, GREEDY LEFT-TO-RIGHT PAIRING, THEN FIX THE PARITY AT THE END, new | |
| 2224 | Minimum Number of Operations to Convert Time | Python | O(1) | O(1) | Easy | greedy, GREEDY (the coin system 1, 5, 15, 60 is canonical -> take the biggest first), new | |
| 2259 | Remove Digit From Number to Maximize Result | Python | O(n) | O(n) | Easy | greedy, GREEDY (all candidates have the same length -> compare left to right), new | |
| 2263 | Make Array Non-decreasing or Non-increasing | Python | O(n log n) | O(n) | Hard | greedy, 🔒, SLOPE TRICK / MAX-HEAP (isotonic L1 regression), new | |
| 2268 | Minimum Number of Keypresses | Python | O(n + 26 log 26) | O(26) | Medium | greedy, 🔒, GREEDY (exchange argument - cheapest slots go to the most frequent letters), new | |
| 2285 | Maximum Total Importance of Roads | Python | O(n log n + len(roads)) | O(n) | Medium | greedy, THE TOTAL IS sum(value[city] * degree[city]) — SO PAIR BIG WITH BIG, new | |
| 2294 | Partition Array Such That Maximum Difference Is K | Python | O(n log n) | O(n) | Medium | greedy, ORDER IS IRRELEVANT — SORT, THEN GREEDILY EXTEND EACH GROUP, new | |
| 2311 | Longest Binary Subsequence Less Than or Equal to K | Python | O(n) | O(1) | Medium | greedy, GREEDY FROM THE RIGHT (every ‘0’ is free, take cheap '1’s first), new | |
| 2321 | Maximum Score Of Spliced Array | Python | O(n) | O(1) | Hard | greedy, THE SWAP’S EFFECT IS A SUBARRAY SUM OF THE DIFFERENCE — KADANE, new | |
| 2323 | Find Minimum Time to Finish All Jobs II | Python | O(n log n) | O(n) | Medium | greedy, 🔒, SORT BOTH AND PAIR IN ORDER (rearrangement / exchange argument), new | |
| 2340 | Minimum Adjacent Swaps to Make a Valid Array | Python | O(n) | O(1) | Medium | greedy, 🔒, MOVE THE FIRST MINIMUM LEFT AND THE LAST MAXIMUM RIGHT — COUNT THE HOPS, new | |
| 2366 | Minimum Replacements to Sort the Array | Python | O(n) | O(1) | Hard | greedy, GREEDY RIGHT-TO-LEFT (split each value into as few parts as possible, new | |
| 2371 | Minimize Maximum Value in a Grid | Python | O(m * n log(m * n)) | O(m * n) | Hard | greedy, 🔒, ASSIGN VALUES IN INCREASING ORDER, EACH AS SMALL AS ITS ROW/COLUMN ALLOWS, new | |
| 2375 | Construct Smallest Number From DI String | Python | O(n) | O(n) | Medium | greedy, PUSH 1, 2, 3, … ON A STACK AND FLUSH IT AT EVERY ‘I’, new | |
| 2383 | Minimum Hours of Training to Win a Competition | Python | O(n) | O(1) | Easy | greedy, THE TWO RESOURCES ARE INDEPENDENT — COST THEM SEPARATELY, new | |
| 2384 | Largest Palindromic Number | Python | O(n) | O(n) | Medium | greedy, BUILD THE LEFT HALF GREEDILY FROM ‘9’ DOWN, THEN PICK A CENTRE, new | |
| 2405 | Optimal Partition of String | Python | O(n) | O(26) | Medium | greedy, EXTEND THE CURRENT PIECE AS FAR AS POSSIBLE, CUT ON THE FIRST REPEAT, new | |
| 2410 | Maximum Matching of Players With Trainers | Python | O(n log n + m log m) | O(n + m) | Medium | greedy, SORT BOTH, THEN A GREEDY TWO-POINTER SWEEP, new | |
| 2412 | Minimum Money Required Before Transactions | Python | O(n) | O(1) | Hard | greedy, WORST ORDER = ALL THE LOSSES FIRST, THEN THE HARDEST REMAINING ONE, new | |
| 2417 | Closest Fair Integer | Python | O(gap * digits) | O(digits) | Medium | greedy, 🔒, A FAIR NUMBER MUST HAVE AN EVEN DIGIT COUNT — JUMP OVER ODD LENGTHS, new | |
| 2422 | Merge Operations to Turn Array Into a Palindrome | Python | O(n) | O(n) | Medium | greedy, 🔒, TWO POINTERS, ALWAYS MERGE ON THE SMALLER SIDE, new | |
| 2434 | Using a Robot to Print the Lexicographically Smallest String | Python | O(n) | O(n) | Medium | greedy, STACK + SUFFIX MINIMUM — POP WHILE THE TOP CANNOT BE BEATEN, new | |
| 2436 | Minimum Split Into Subarrays With GCD Greater Than One | Python | O(n * log(max(nums))) | O(1) | Medium | greedy, 🔒, GREEDY + RUNNING GCD (extend the current piece as long as gcd stays > 1), new | |
| 2439 | Minimize Maximum of Array | Python | O(n) | O(1) | Medium | greedy, GREEDY / PREFIX AVERAGE (value can only ever move LEFT), new | |
| 2440 | Create Components With Same Value | Python | O(n * d(s)), d(s) = number of divisors of s | O(n) | Hard | greedy, ENUMERATE THE DIVISOR + GREEDY BOTTOM-UP PACKING, new | |
| 2449 | Minimum Number of Operations to Make Arrays Similar | Python | O(n log n) | O(n) | Hard | greedy, GREEDY MATCH WITHIN EACH PARITY CLASS, new | |
| 2457 | Minimum Addition to Make Integer Beautiful | Python | O(digits^2) | O(1) | Medium | greedy, CLEAR THE TRAILING DIGITS ONE PLACE AT A TIME, new | |
| 2459 | Sort Array by Moving Items to Empty Space | Python | O(n) | O(n) | Hard | greedy, 🔒, PERMUTATION CYCLES — THE HOLE RIDES ONE OF THEM FOR FREE, new | |
| 2472 | Maximum Number of Non-overlapping Palindrome Substrings | Python | O(n^2) | O(n) | Hard | greedy, INTERVAL SCHEDULING — TAKE THE PALINDROME THAT ENDS EARLIEST, new | |
| 2479 | Maximum XOR of Two Non-Overlapping Subtrees | Python | O(n * B) | O(n * B), B = 46 bits | Hard | greedy, 🔒, SUBTREE SUMS + BINARY TRIE, QUERY ON ENTRY / INSERT ON EXIT, new | |
| 2483 | Minimum Penalty for a Shop | Python | O(n) | O(1) | Medium | greedy, SWEEP THE CLOSING HOUR, UPDATING THE PENALTY INCREMENTALLY, new | |
| 2486 | Append Characters to String to Make Subsequence | Python | O(len(s) + len(t)) | O(1) | Medium | greedy, GREEDY TWO-POINTER MATCH — WHATEVER OF t IS LEFT MUST BE APPENDED, new | |
| 2498 | Frog Jump II | Python | O(n) | O(1) | Medium | greedy, GREEDY (SPLIT INTO 2 ALTERNATING PATHS), new | |
| 2499 | Minimum Total Cost to Make Arrays Unequal | Python | O(n) | O(n) | Hard | greedy, GREEDY (MANDATORY INDICES + DOMINANT VALUE) + COUNTER, new | |
| 2522 | Partition String Into Substrings With Values at Most K | Python | O(n) | O(1) | Medium | greedy, GREEDY (extend the current piece as far as it can legally go), new | |
| 2541 | Minimum Operations to Make Array Equal II | Python | O(n) | O(1) | Medium | greedy, GREEDY / COUNTING (every op moves exactly k from one slot to another), new | |
| 2548 | Maximum Price to Fill a Bag | Python | O(n * log n) | O(n) for the sorted copy | Medium | greedy, 🔒, GREEDY (fractional knapsack — take the best price-per-weight first), new | |
| 2551 | Put Marbles in Bags | Python | O(n log n) | O(n) | Hard | greedy, GREEDY (SPLIT POINTS) + SORTING, new | |
| 2561 | Rearranging Fruits | Python | O(n log n) | O(n) | Hard | greedy, GREEDY + COUNTING (with a “cheapest fruit as middleman” trick), new | |
| 2566 | Maximum Difference by Remapping a Digit | Python | O(log(num)) | O(log(num)) | Easy | greedy, GREEDY ON THE MOST SIGNIFICANT DIGIT, new | |
| 2567 | Minimum Score by Changing Two Elements | Python | O(n * log(n)) | O(n) for the sort | Medium | greedy, SORT + GREEDY (the low score is always free), new | |
| 2571 | Minimum Operations to Reduce an Integer to 0 | Python | O(log(n)) | O(1) | Medium | greedy, GREEDY ON THE LOWEST SET BIT (non-adjacent form / NAF), new | |
| 2573 | Find the String with LCP | Python | O(n^2) | O(n) | Hard | greedy, GREEDY CONSTRUCTION + FULL O(n^2) DP RE-VERIFICATION, new | |
| 2576 | Find the Maximum Number of Marked Indices | Python | O(n * log n) | O(1) beyond the sort | Medium | greedy, SORT + GREEDY TWO POINTERS, new | |
| 2578 | Split With Minimum Sum | Python | O(d * log d) | O(d) (d = number of digits, <= 10) | Easy | greedy, SORT DIGITS + GREEDY ALTERNATING DEAL, new | |
| 2587 | Rearrange Array to Maximize Prefix Score | Python | O(n log n) | O(n) for the sorted copy | Medium | greedy, GREEDY + SORT DESCENDING, new | |
| 2589 | Minimum Time to Complete All Tasks | Python | O(n log n + n * m) | O(m), with m = 2001 the time axis | Hard | greedy, GREEDY (SORT BY END TIME, THEN TURN ON THE LATEST SECONDS), new | |
| 2599 | Make the Prefix Sum Non-negative | Python | O(n log n) | O(n) | Medium | greedy, 🔒, GREEDY + MIN HEAP (undo the most damaging negative already taken), new | |
| 2600 | K Items With the Maximum Sum | Python | O(1) | O(1) | Easy | greedy, GREEDY (take the biggest labels first), new | |
| 2601 | Prime Subtraction Operation | Python | O(V log log V + n * pi(V)) | O(V) ; V = 1000 = max value | Medium | greedy, SIEVE + GREEDY (make every element as small as legally possible), new | |
| 2604 | Minimum Time to Eat All Grains | Python | O((n + m) * log U + n log n + m log m) | O(1) extra | Hard | greedy, 🔒, BINARY SEARCH ON THE ANSWER + GREEDY FEASIBILITY SWEEP, new | |
| 2606 | Find the Substring With Maximum Cost | Python | O(n) | O(26) | Medium | greedy, KADANE (MAXIMUM SUBARRAY SUM) ON THE MAPPED VALUES, new | |
| 2607 | Make K-Subarray Sums Equal | Python | O(n log n) | O(n) | Medium | greedy, GCD CYCLE GROUPING + MEDIAN, new | |
| 2611 | Mice and Cheese | Python | O(n * log(n)) | O(n) | Medium | greedy, GREEDY (start from “mouse 2 eats everything”, then buy back k swaps), new | |
| 2663 | Lexicographically Smallest Beautiful String | Python | O(n * k) | O(n) for the char list | Hard | greedy, GREEDY – “NEXT PERMUTATION” STYLE BUMP, THEN MINIMAL REFILL, new | |
| 2673 | Make Costs of Paths Equal in a Binary Tree | Python | O(n) | O(n) for the working copy | Medium | greedy, BOTTOM-UP GREEDY ON THE HEAP-INDEXED PERFECT TREE, new | |
| 2680 | Maximum OR | Python | O(n) | O(n) | Medium | greedy, GREEDY (spend all k doublings on ONE element) + PREFIX / SUFFIX OR, new | |
| 2697 | Lexicographically Smallest Palindrome | Python | O(n) | O(n) for the mutable char list | Easy | greedy, GREEDY + TWO POINTERS (each mirrored pair is independent), new | |
| 2708 | Maximum Strength of a Group | Python | O(n log n) | O(n) | Medium | greedy, GREEDY (take every positive, pair up the negatives), new | |
| 2712 | Minimum Cost to Make All Characters Equal | Python | O(n) | O(1) | Medium | greedy, GREEDY over the ADJACENT-PAIR BOUNDARIES, new | |
| 2734 | Lexicographically Smallest String After Substring Operation | Python | O(n) | O(n) | Medium | greedy, GREEDY - DECREMENT THE FIRST NON-‘a’ RUN, new | |
| 2769 | Find the Maximum Achievable Number | Python | O(1) | O(1) | Easy | greedy, GREEDY / MATH (each move closes a gap of 2), new | |
| 2772 | Apply Operations to Make All Array Elements Equal to Zero | Python | O(n) | O(n) | Medium | greedy, LEFT-TO-RIGHT GREEDY + DIFFERENCE ARRAY, new | |
| 2789 | Largest Element in an Array after Merge Operations | Python | O(n) | O(1) | Medium | greedy, GREEDY, SCAN FROM THE RIGHT, new | |
| 2790 | Maximum Number of Groups With Increasing Length | Python | O(n log n) | O(1) beyond the sort | Hard | greedy, SORT + GREEDY PREFIX BUDGET, new | |
| 2813 | Maximum Elegance of a K-Length Subsequence | Python | O(n * log n) | O(n) | Hard | greedy, GREEDY (SORT BY PROFIT DESC) + STACK OF “SACRIFICEABLE” DUPLICATES, new | |
| 2819 | Minimum Relative Loss After Buying Chocolates | Python | O((n + q) * log n) | O(n) | Hard | greedy, 🔒, SORT + PREFIX SUMS + GREEDY SHAPE (“CHEAP PREFIX + EXPENSIVE SUFFIX”), new | |
| 2825 | Make String a Subsequence Using Cyclic Increments | Python | O(m + n) | O(1) | Medium | greedy, GREEDY TWO POINTERS (relaxed subsequence match), new | |
| 2835 | Minimum Operations to Form Subsequence With Target Sum | Python | O(n + 32 * 32) | O(32) | Hard | greedy, GREEDY + BIT MANIPULATION (low bit -> high bit, split only on demand), new | |
| 2842 | Count K-Subsequences of a String With Maximum Beauty | Python | O(n + 26 log 26) | O(26) | Hard | greedy, GREEDY (pick the k biggest frequencies) + COMBINATORICS, new | |
| 2844 | Minimum Operations to Make a Special Number | Python | O(4 * n) | O(1) | Medium | greedy, GREEDY - only the LAST TWO digits decide divisibility by 25, new | |
| 2860 | Happy Students | Python | O(n * log n) | O(1) beyond the sort | Medium | greedy, SORT + ENUMERATE THE GROUP SIZE, new | |
| 2868 | The Wording Game | Python | O(m + n) | O(1) | Hard | greedy, 🔒, GREEDY SIMULATION + TWO POINTERS, new | |
| 2914 | Minimum Number of Changes to Make Binary String Beautiful | Python | O(n) | O(1) | Medium | greedy, GREEDY / PAIRING (fixed blocks of 2), new | |
| 3002 | Maximum Size of a Set After Removals | Python | O(n) | O(n) | Medium | greedy, GREEDY — SPEND EACH ARRAY’S HALF ON ITS EXCLUSIVE VALUES FIRST, new | |
| 3003 | Maximize the Number of Partitions After Operations | Python | O(reachable states * 26) | O(reachable states) | Hard | greedy, MEMOIZED DFS OVER (POSITION, CURRENT SEGMENT MASK, EDIT USED), new | |
| 3012 | Minimize Length of Array Using Operations | Python | O(n) | O(1) | Medium | greedy, EVERYTHING TURNS ON THE MINIMUM — CAN ANY VALUE BEAT IT MODULO ?, new | |
| 3014 | Minimum Number of Pushes to Type Word I | Python | O(n) | O(1) | Easy | greedy, FILL ALL 8 KEYS’ FIRST SLOTS BEFORE USING ANY SECOND SLOT, new | |
| 3016 | Minimum Number of Pushes to Type Word II | Python | O(n) | O(1) (26 counters) | Medium | greedy, EXCHANGE ARGUMENT — THE MOST FREQUENT LETTERS GET THE CHEAPEST SLOTS, new | |
| 3022 | Minimize OR of Remaining Elements Using Operations | Python | O(30 * n) | O(1) | Hard | greedy, DECIDE THE ANSWER BIT BY BIT, HIGH TO LOW, WITH A GREEDY FEASIBILITY TEST, new | |
| 3035 | Maximum Palindromes After Operations | Python | O(total characters + n log n) | O(n) | Medium | greedy, SWAPS ARE UNRESTRICTED — ONLY THE GLOBAL LETTER PAIRS MATTER, new | |
| 3068 | Find the Maximum Sum of Node Values | Python | O(n) | O(1) | Hard | greedy, THE TREE IS A RED HERRING — ANY EVEN-SIZED SUBSET CAN BE FLIPPED, new | |
| 3074 | Apple Redistribution into Boxes | Python | O(m log m) | O(m) | Easy | greedy, PACKS CAN BE SPLIT, SO ONLY THE TOTALS MATTER — TAKE THE BIGGEST BOXES, new | |
| 3075 | Maximize Happiness of Selected Children | Python | O(n log n) | O(n) | Medium | greedy, PICK THE HAPPIEST FIRST — THE i-TH PICK HAS ALREADY LOST i POINTS, new | |
| 3086 | Minimum Moves to Pick K Ones | Python | O(n) | O(n) | Hard | greedy, PRICE EVERY ONE, THEN NOTICE ONLY ~4 SPLITS BETWEEN REAL/CREATED MATTER, new | |
| 3088 | Make String Anti-palindrome | Python | O(n log n) | O(n) | Hard | greedy, 🔒, SORT, THEN REPAIR THE MIRROR CLASHES BY TOUCHING THE RIGHT HALF ONLY, new | |
| 3106 | Lexicographically Smallest String After Operations With Constraint | Python | O(26 * n) | O(n) | Medium | greedy, GREEDY LEFT TO RIGHT — SPEND THE BUDGET ON THE EARLIEST POSITIONS, new | |
| 3107 | Minimum Operations to Make Median of Array Equal to K | Python | O(n log n) | O(n) | Medium | greedy, SORT, THEN ONLY THE WRONG SIDE OF THE MEDIAN SLOT NEEDS FIXING, new | |
| 3111 | Minimum Rectangles to Cover Points | Python | O(n log n) | O(n) | Medium | greedy, y IS IRRELEVANT — IT IS A 1-D INTERVAL COVER ON THE x AXIS, new | |
| 3114 | Latest Time You Can Obtain After Replacing Characters | Python | O(1) (720 candidates x 5 characters) | O(1) | Easy | greedy, ONLY 720 VALID TIMES EXIST — TRY THEM FROM THE LATEST DOWN, new | |
| 3119 | Maximum Number of Potholes That Can Be Fixed | Python | O(n log n) | O(n) | Medium | greedy, 🔒, EACH REPAIR PAYS A FLAT +1 OVERHEAD — SO FIX THE LONGEST RUNS FIRST, new | |
| 3170 | Lexicographically Minimum String After Removing Stars | Python | O(26 * n) worst case | O(n) | Medium | greedy, ONE STACK OF POSITIONS PER LETTER — DELETE THE LATEST SMALLEST, new | |
| 3189 | Minimum Moves to Get a Peaceful Board | Python | O(n log n) | O(n) | Medium | greedy, 🔒, ROWS AND COLUMNS ARE INDEPENDENT — SORT EACH AND MATCH IN ORDER, new | |
| 3205 | Maximum Array Hopping Score I | Python | O(n^2) | O(n) | Medium | greedy, 🔒, PLAIN O(n^2) DP OVER THE LANDING INDEX, new | |
| 3207 | Maximum Points After Enemy Battles | Python | O(n) | O(1) | Medium | greedy, SPEND EVERYTHING ON THE CHEAPEST ENEMY, HARVEST ALL THE OTHERS ONCE, new | |
| 3216 | Lexicographically Smallest String After a Swap | Python | O(n) | O(n) | Easy | greedy, ONE SWAP, SO TAKE THE EARLIEST ONE THAT ACTUALLY HELPS, new | |
| 3218 | Minimum Cost for Cutting Cake I | Python | O(m log m + n log n) | O(m + n) | Medium | greedy, EXPENSIVE LINES FIRST — A LINE IS PAID ONCE PER PIECE IT CROSSES, new | |
| 3219 | Minimum Cost for Cutting Cake II | Python | O(m log m + n log n) | O(m + n) | Hard | greedy, IDENTICAL GREEDY TO LC 3218 — IT WAS ALREADY O(n log n), new | |
| 3221 | Maximum Array Hopping Score II | Python | O(n) | O(n) | Medium | greedy, 🔒, ALWAYS HOP TO THE LARGEST VALUE STILL AHEAD — THE SUFFIX MAXIMA, new | |
| 3228 | Maximum Number of Operations to Move Ones to the End | Python | O(n) | O(1) | Medium | greedy, EVERY 1 CAN CROSS EACH ZERO-BLOCK TO ITS RIGHT EXACTLY ONCE, new | |
| 3229 | Minimum Operations to Make Array Equal to Target | Python | O(n) | O(1) | Hard | greedy, WORK ON THE DIFFERENCE ARRAY — ONLY THE NEW DEMAND COSTS ANYTHING, new | |
| 3239 | Minimum Number of Flips to Make Binary Grid Palindromic I | Python | O(m * n) | O(1) | Medium | greedy, COUNT THE MISMATCHED MIRROR PAIRS, ONCE PER ORIENTATION, new | |
| 3240 | Minimum Number of Flips to Make Binary Grid Palindromic II | Python | O(m * n) | O(1) | Medium | greedy, GROUPS OF FOUR ARE FREE OF THE MOD-4 RULE — ONLY THE MIDDLES MATTER, new | |
| 3273 | Minimum Amount of Damage Dealt to Bob | Python | O(n log n) | O(n) | Hard | greedy, EXCHANGE ARGUMENT — ORDER THE KILLS BY damage / time, new | |
| 3282 | Reach End of Array With Max Score | Python | O(n) | O(1) | Medium | greedy, EVERY UNIT OF DISTANCE IS PAID AT THE BEST RATE SEEN SO FAR, new | |
| 3301 | Maximize the Total Height of Unique Towers | Python | O(n log n) | O(n) | Medium | greedy, SORT DESCENDING AND KEEP EACH TOWER AS TALL AS THE RULES ALLOW, new | |
| 3302 | Find the Lexicographically Smallest Valid Sequence | Python | O(n + m) | O(n) | Medium | greedy, PRECOMPUTE HOW MUCH OF word2 EACH SUFFIX CAN STILL MATCH, THEN BE GREEDY, new | |
| 3362 | Zero Array Transformation III | Python | O((n + q) log q) | O(n + q) | Medium | greedy, SWEEP LEFT TO RIGHT, ALWAYS SPENDING THE QUERY THAT REACHES FURTHEST, new | |
| 3397 | Maximum Number of Distinct Elements After Operations | Python | O(n log n) | O(1) beyond the sort | Medium | greedy, SORT, THEN GREEDILY PUSH EACH VALUE AS FAR LEFT AS ALLOWED, new | |
| 3402 | Minimum Operations to Make Columns Strictly Increasing | Python | O(m * n) | O(1) | Easy | greedy, PER-COLUMN GREEDY, RAISE EACH CELL TO THE MINIMUM LEGAL VALUE, new | |
| 3403 | Find the Lexicographically Largest String From the Box I | Python | O(n^2) | O(n) | Medium | greedy, EVERY SUBSTRING OF THE CAPPED LENGTH IS REACHABLE, new | |
| 3406 | Find the Lexicographically Largest String From the Box II | Python | O(n) | O(n) for the returned slice | Hard | greedy, 🔒, MAXIMUM SUFFIX (DUVAL-STYLE TWO POINTER), THEN TRUNCATE, new | |
| 3410 | Maximize Subarray Sum After Removing All Occurrences of One Element | Python | O(n log n) | O(n) | Hard | greedy, ZERO OUT ONE VALUE AT A TIME IN A MAX-SUBARRAY SEGMENT TREE, new | |
| 3424 | Minimum Cost to Make Arrays Identical | Python | O(n log n) | O(n) | Medium | greedy, ONLY TWO SCENARIOS EXIST — NEVER REARRANGE, OR REARRANGE ONCE, new | |
| 3443 | Maximum Manhattan Distance After K Changes | Python | O(n) | O(1) | Medium | greedy, AT EVERY PREFIX, EACH EDIT IS WORTH EXACTLY +2 — UNTIL THE PREFIX RUNS OUT, new | |
| 3506 | Find Time Required to Eliminate Bacterial Strains | Python | O(n * log n) | O(n) | Hard | greedy, 🔒, REVERSE THE SPLITS INTO MERGES, THEN GREEDY WITH A MIN-HEAP, new | |
| 3511 | Make a Positive Array | Python | O(n) | O(n) | Medium | greedy, 🔒, TURN IT INTO INTERVAL STABBING, THEN SWEEP WITH A MONOTONIC DEQUE, new | |
| 3517 | Smallest Palindromic Rearrangement I | Python | O(n + 26 log 26) | O(n) | Medium | greedy, A PALINDROME IS DETERMINED BY ITS FIRST HALF, new | |
| 3518 | Smallest Palindromic Rearrangement II | Python | O(26 * n) | O(n) | Hard | greedy, ONLY A SHORT SUFFIX OF THE HALF CAN VARY – FREEZE THE REST, THEN, new | |
| 3523 | Make Array Non-decreasing | Python | O(n) | O(1) | Medium | greedy, GREEDY — MERGE A DIP INTO THE BLOCK ON ITS LEFT, new | |
| 3542 | Minimum Operations to Convert All Elements to Zero | Python | O(n) | O(n) | Medium | greedy, MONOTONIC STACK OVER “NESTED” VALUE LEVELS, new | |
| 3545 | Minimum Deletions for At Most K Distinct Characters | Python | O(n + 26 log 26) | O(26) | Easy | greedy, DROP THE RAREST LETTERS FIRST, new | |
| 3557 | Find Maximum Number of Non Intersecting Substrings | Python | O(n) | O(1) | Medium | greedy, GREEDY — CLOSE EVERY CANDIDATE AT THE EARLIEST POSSIBLE END, new | |
| 3576 | Transform Array to All Equal Elements | Python | O(n) | O(1) | Medium | greedy, LEFT-TO-RIGHT FORCED SWEEP, ONE TARGET SIGN AT A TIME, new | |
| 3587 | Minimum Adjacent Swaps to Alternate Parity | Python | O(n) | O(n) | Medium | greedy, ADJACENT SWAPS = SUM OF |CURRENT INDEX - TARGET INDEX| PER PARITY CLASS, new | |
| 3627 | Maximum Median Sum of Subsequences of Size 3 | Python | O(n log n) | O(1) beyond the sort | Medium | greedy, SORT + PAIR EACH SMALL ELEMENT WITH THE TOP OF THE ARRAY, new | |
| 3630 | Partition Array for Maximum XOR and AND | Python | O(2^n * n^2) | O(2^n) | Hard | greedy, ENUMERATE B, THEN SOLVE THE A/C SPLIT IN CLOSED FORM WITH A XOR BASIS, new | |
| 3633 | Earliest Finish Time for Land and Water Rides I | Python | O(n * m) | O(1) | Easy | greedy, BRUTE FORCE OVER BOTH ORDERS, new | |
| 3635 | Earliest Finish Time for Land and Water Rides II | Python | O(n log n + m log m) | O(n + m) | Medium | greedy, SORT THE SECOND RIDE BY START TIME + PREFIX/SUFFIX MINIMA, new | |
| 3638 | Maximum Balanced Shipments | Python | O(n) | O(1) | Medium | greedy, GREEDY — CLOSE A SHIPMENT AT THE FIRST MOMENT IT BECOMES BALANCED, new | |
| 3645 | Maximum Total from Optimal Activation Order | Python | O(n log n) | O(n) | Medium | greedy, AT MOST L ELEMENTS OF limit == L CAN EVER BE ACTIVATED, new | |
| 3675 | Minimum Operations to Transform String | Python | O(n) | O(1) | Medium | greedy, THE ANSWER IS THE LONGEST DISTANCE TO ‘a’ AROUND THE CYCLE, new | |
| 3681 | Maximum XOR of Subsequences | Python | O(n log C) | O(log C) | Hard | greedy, TWO OVERLAPPING SUBSEQUENCES COLLAPSE TO ONE SUBSET – LINEAR BASIS, new |
Hash Table
| # | Title | Solution | Time | Space | Difficulty | Note | Status |
|---|---|---|---|---|---|---|---|
| 0159 | Longest Substring with At Most Two Distinct Characters | Python, Java | O(n) | O(1) | Medium | hash table, 🔒, sliding window with at most 2 distinct chars, LC 340, good basic, new, google, amazon, fb, microsoft |
|
| 0982 | Triples with Bitwise AND Equal To Zero | Python, Java | O(n^2 + n * 2^16) | O(2^16) | Hard | hash table, precompute pairwise ANDs into a counter over 2^16 masks, new, google |
|
| 1001 | Grid Illumination | Python | O(m + q), m = len(lamps), q = len(queries) | O(m) | Hard | hash table, HASH TABLE (count lamps per row / col / 2 diagonals), new | |
| 1133 | Largest Unique Number | Python | O(n) | O(n) | Easy | hash table, 🔒, HASH TABLE (counting), new, amazon |
|
| 1153 | String Transforms Into Another String | Python | O(n) | O(1) | Hard | hash table, 🔒, HASH TABLE (functional mapping) + “spare character” argument, new, google, amazon |
|
| 1160 | Find Words That Can Be Formed by Characters | Python | O(L), L = total length of chars + all words | O(1) | Easy | hash table, HASH TABLE (counting), new, amazon, fb |
|
| 1165 | Single-Row Keyboard | Python | O(n) | O(1), 26 entries | Easy | hash table, 🔒, HASH TABLE (char -> index on keyboard), new, google |
|
| 1198 | Find Smallest Common Element in All Rows | Python | O(m * n) | O(m * n), size of the counter | Medium | hash table, 🔒, HASH TABLE (counting), new, microsoft |
|
| 1207 | Unique Number of Occurrences | Python | O(n) | O(n) | Easy | hash table, HASH TABLE (count) + SET (dedupe the counts), new, google, amazon, fb, apple |
|
| 1224 | Maximum Equal Frequency | Python | O(n) | O(n) | Hard | hash table, HASH TABLE (count of values) + HASH TABLE (count of counts), new | |
| 1331 | Rank Transform of an Array | Python | O(nlogn) | O(n) | Easy | hash table, SORT + RANK DICT (rank = index in the sorted distinct values), new, google, amazon, fb |
|
| 1418 | Display Table of Food Orders in a Restaurant | Python | O(n + t * log t + m * log m + t * m) | O(n) | Medium | hash table, HASH TABLE + SORTING (count (table, item) pairs, then lay out a grid), new | |
| 1452 | People Whose List of Favorite Companies Is Not a Subset of Another List | Python | O(n^2 * m) | O(n * m) | Medium | hash table, HASH TABLE (intern company name -> int id) + pairwise set subset check, new, google |
|
| 1487 | Making File Names Unique | Python | O(L) amortised | O(L), L = total length of all names | Medium | hash table, HASH TABLE OF “NEXT SUFFIX TO TRY” (never restart k from 1), new, amazon, apple, microsoft |
|
| 1577 | Number of Ways Where Square of Number Is Equal to Product of Two Numbers | Python | O((n1 + n2) * D) | O(D), D = #distinct values | Medium | hash table, HASH TABLE (count value pairs whose product equals x*x), new | |
| 1590 | Make Sum Divisible by P | Python | O(n) | O(n) | Medium | hash table, PREFIX SUM MOD + HASH TABLE (shortest subarray with a given remainder), new, amazon |
|
| 1640 | Check Array Formation Through Concatenation | Python | O(n) | O(n) | Easy | hash table, HASH TABLE keyed on each piece’s HEAD value, new, fb, uber |
|
| 1657 | Determine if Two Strings Are Close | Python | O(n + m) | O(1) (at most 26 letters) | Medium | hash table, HASH TABLE / COUNTING (two invariants under the allowed operations), new | |
| 1679 | Max Number of K-Sum Pairs | Python | O(n) | O(n) | Medium | hash table, HASH TABLE, ONE PASS (greedily close a pair the moment its partner exists), new, amazon |
|
| 1711 | Count Good Meals | Python | O(n * 22) | O(n) | Medium | hash table, HASH TABLE + ENUMERATE THE 22 POSSIBLE POWERS OF TWO (“two sum” style), new, amazon |
|
| 1748 | Sum of Unique Elements | Python | O(n) | O(n) | Easy | hash table, HASH TABLE COUNT, THEN SUM THE COUNT-ONE KEYS, new, fb |
|
| 1781 | Sum of Beauty of All Substrings | Python | O(n^2 * 26) | O(26) | Medium | hash table, GROW EVERY SUBSTRING FROM A FIXED LEFT END, KEEPING A 26-SLOT COUNTER, new, google |
|
| 1807 | Evaluate the Bracket Pairs of a String | Python | O(n + m), n = len(s), m = len(knowledge) | O(n + m) | Medium | hash table, HASH TABLE + ONE LINEAR SCAN (build the output in a list, join once), new, google |
|
| 1814 | Count Nice Pairs in an Array | Python | O(n * d), d = number of digits (<= 10) | O(n) | Medium | hash table, REARRANGE THE EQUATION INTO AN INVARIANT, THEN GROUP-COUNT, new | |
| 1817 | Finding the Users Active Minutes | Python | O(n + k) | O(n) | Medium | hash table, HASH MAP OF SETS (id -> set of distinct minutes), then bucket the sizes, new | |
| 1925 | Count Square Sum Triples | Python | O(n^2) | O(n) | Easy | hash table, HASH SET OF SQUARES + ENUMERATE (a, b), new, amazon |
|
| 1930 | Unique Length-3 Palindromic Subsequences | Python | O(26 * n) | O(26) | Medium | hash table, FIX THE OUTER CHARACTER (26 passes) + COUNT DISTINCT MIDDLES, new | |
| 1941 | Check if All Characters Have Equal Number of Occurrences | Python | O(n) | O(26) | Easy | hash table, HASH TABLE COUNT, THEN COLLAPSE THE COUNTS INTO A SET, new, microsoft |
|
| 1995 | Count Special Quadruplets | Python | O(n^2) | O(n^2) worst case for the counter keys | Easy | hash table, HASH TABLE ON (nums[d] - nums[c]) -> O(n^2) instead of O(n^4), new | |
| 2006 | Count Number of Pairs With Absolute Difference K | Python | O(n) | O(n) | Easy | hash table, HASH TABLE (one pass, count partners already seen), new, amazon |
|
| 2023 | Number of Pairs of Strings With Concatenation Equal to Target | Python | O(n * L) | O(n * L) | Medium | hash table, COUNT PREFIXES SEEN SO FAR, THEN THE MATCHING SUFFIXES, new, fb, apple |
|
| 2025 | Maximum Number of Ways to Partition an Array | Python | O(n) | O(n) | Hard | hash table, PREFIX SUMS + TWO COUNTERS OF THE “DIFFERENCE” 2*prefix - total, new, google, fb |
|
| 2032 | Two Out of Three | Python | O(n1 + n2 + n3) | O(number of distinct values) | Easy | hash table, DEDUPE EACH ARRAY FIRST, THEN COUNT HOW MANY ARRAYS HOLD EACH VALUE, new | |
| 2053 | Kth Distinct String in an Array | Python | O(L) | O(L), L = total length of all strings | Easy | hash table, HASH TABLE COUNTING (one pass to count, one pass to keep order), new, amazon |
|
| 2068 | Check Whether Two Strings are Almost Equivalent | Python | O(n + 26) | O(26) | Easy | hash table, COUNT BOTH WORDS, COMPARE EVERY LETTER ‘a’…‘z’, new | |
| 2085 | Count Common Words With One Occurrence | Python | O(n1 + n2) | O(n1 + n2) | Easy | hash table, TWO COUNTERS, KEEP THE WORDS WITH COUNT == 1 IN BOTH, new | |
| 2120 | Execution of All Suffix Instructions Staying in a Grid | Python | O(m^2) | O(m) | Medium | hash table, DIRECT SIMULATION PER STARTING INDEX (m, n <= 500 so O(m^2) is fine), new | |
| 2150 | Find All Lonely Numbers in the Array | Python | O(n) | O(n) | Medium | hash table, ONE COUNTER ANSWERS BOTH HALVES OF THE CONDITION, new, google |
|
| 2154 | Keep Multiplying Found Values by Two | Python | O(n) | O(n) | Easy | hash table, HASH SET + DOUBLING LOOP, new | |
| 2170 | Minimum Operations to Make the Array Alternating | Python | O(n) | O(n) | Medium | hash table, PICK ONE VALUE FOR THE EVEN SLOTS AND ANOTHER FOR THE ODD SLOTS, new | |
| 2190 | Most Frequent Number Following Key In an Array | Python | O(n) | O(n) | Easy | hash table, COUNT THE SUCCESSOR OF EVERY key OCCURRENCE, new |
|
| 2201 | Count Artifacts That Can Be Extracted | Python | O(len(dig) + len(artifacts)) | O(len(dig)) | Medium | hash table, HASH THE EXCAVATED CELLS, THEN CHECK EACH ARTIFACT’S FOOTPRINT, new | |
| 2206 | Divide Array Into Equal Pairs | Python | O(n) | O(n) | Easy | hash table, EVERY VALUE MUST OCCUR AN EVEN NUMBER OF TIMES, new | |
| 2215 | Find the Difference of Two Arrays | Python | O(n1 + n2) | O(n1 + n2) | Easy | hash table, SET DIFFERENCE IN BOTH DIRECTIONS, new | |
| 2225 | Find Players With Zero or One Losses | Python | O(n log n) | O(n) | Medium | hash table, HASH TABLE (count losses; a player only “exists” if they played), new | |
| 2229 | Check if an Array Is Consecutive | Python | O(n) | O(n) | Easy | hash table, 🔒, HASH SET (three numbers must agree), new | |
| 2260 | Minimum Consecutive Cards to Pick Up | Python | O(n) | O(n) | Medium | hash table, HASH TABLE (closest previous index of the same value), new | |
| 2261 | K Divisible Elements Subarrays | Python | O(n^3) worst case for the hashing of the tuples, O(n^2) windows | O(n^2) | Medium | hash table, BRUTE FORCE ENUMERATION + HASH SET (n <= 200 so O(n^2) windows is fine), new | |
| 2283 | Check if Number Has Equal Digit Count and Digit Value | Python | O(n) | O(n) | Easy | hash table, COUNT THE DIGITS ONCE, THEN CHECK EVERY INDEX, new | |
| 2287 | Rearrange Characters to Make Target String | Python | O(len(s) + len(target)) | O(26) | Easy | hash table, THE BOTTLENECK LETTER DECIDES — TAKE THE MIN RATIO, new | |
| 2295 | Replace Elements in an Array | Python | O(n + m) | O(n) | Medium | hash table, TRACK WHERE EACH VALUE LIVES — POSITION MAP, NOT VALUE SCANNING, new | |
| 2306 | Naming a Company | Python | O(26 * L + 26^2 * L) with L = total length | O(L) | Hard | hash table, GROUP BY FIRST LETTER + COUNT SUFFIX OVERLAP (26 x 26 buckets), new | |
| 2309 | Greatest English Letter in Upper and Lower Case | Python | O(n) | O(1) | Easy | hash table, BITMASK OF SEEN LETTERS (26 bits for lower, 26 for upper), new | |
| 2325 | Decode the Message | Python | O(len(key) + len(message)) | O(26) | Easy | hash table, BUILD THE SUBSTITUTION TABLE FROM THE FIRST APPEARANCES IN key, new |
|
| 2341 | Maximum Number of Pairs in Array | Python | O(n) | O(n) | Easy | hash table, EACH VALUE CONTRIBUTES count // 2 PAIRS AND count % 2 LEFTOVERS, new | |
| 2342 | Max Sum of a Pair With Equal Sum of Digits | Python | O(n * d) | O(number of distinct digit sums) | Medium | hash table, BUCKET BY DIGIT SUM, KEEP ONLY THE LARGEST SEEN PER BUCKET, new | |
| 2347 | Best Poker Hand | Python | O(1) | O(1) | Easy | hash table, TEST THE FOUR HANDS IN DESCENDING QUALITY AND RETURN THE FIRST HIT, new | |
| 2351 | First Letter to Appear Twice | Python | O(n) | O(26) | Easy | hash table, HASH SET (first char whose 2nd occurrence comes earliest = first repeat while scanning), new | |
| 2352 | Equal Row and Column Pairs | Python | O(n^2) | O(n^2) | Medium | hash table, HASH TABLE ON TUPLES (count rows, then look each column up), new | |
| 2354 | Number of Excellent Pairs | Python | O(n + 31) | O(n) | Hard | hash table, BIT COUNTING IDENTITY + SUFFIX COUNTS, new | |
| 2363 | Merge Similar Items | Python | O((n + m) log(n + m)) | O(n + m) | Easy | hash table, HASH TABLE (bucket weights by value, then sort the keys), new | |
| 2364 | Count Number of Bad Pairs | Python | O(n) | O(n) | Medium | hash table, COMPLEMENT COUNTING + HASH TABLE (rearrange the equation), new | |
| 2365 | Task Scheduler II | Python | O(n) | O(n) | Medium | hash table, GREEDY SIMULATION + HASH TABLE (earliest legal day per task type), new | |
| 2367 | Number of Arithmetic Triplets | Python | O(n) | O(n) | Easy | hash table, HASH SET (values are distinct + increasing, so a value fixes its index), new | |
| 2374 | Node With Highest Edge Score | Python | O(n) | O(n) | Medium | hash table, ACCUMULATE THE SOURCE LABELS INTO A SCORE ARRAY, THEN ARGMAX, new | |
| 2395 | Find Subarrays With Equal Sum | Python | O(n) | O(n) | Easy | hash table, HASH TABLE (remember every adjacent-pair sum we have already seen), new | |
| 2399 | Check Distances Between Same Letters | Python | O(n) | O(1) (26 slots) | Easy | hash table, HASH TABLE (record the first index of each letter, check on the 2nd), new | |
| 2404 | Most Frequent Even Element | Python | O(n) | O(n) | Easy | hash table, COUNT ONLY THE EVEN VALUES, THEN ARGMAX WITH A SMALLEST-VALUE TIE-BREAK, new | |
| 2423 | Remove Letter To Equalize Frequency | Python | O(26 * 26) | O(26) | Easy | hash table, TRY REMOVING ONE COPY OF EACH DISTINCT LETTER AND RE-CHECK, new | |
| 2441 | Largest Positive Integer That Exists With Its Negative | Python | O(n) | O(n) | Easy | hash table, HASH SET (membership test for the mirrored value), new | |
| 2442 | Count Number of Distinct Integers After Reverse Operations | Python | O(n * d), d = number of digits (<= 7 here) | O(n) | Medium | hash table, HASH SET (just collect every value and every reversed value), new | |
| 2451 | Odd String Difference | Python | O(len(words) * n) | O(len(words) * n) | Easy | hash table, GROUP THE WORDS BY THEIR DIFFERENCE SIGNATURE — THE ODD ONE IS ALONE, new | |
| 2452 | Words Within Two Edits of Dictionary | Python | O(len(queries) * len(dictionary) * n) | O(1) beyond the output | Medium | hash table, ALL WORDS SHARE A LENGTH, SO AN “EDIT” IS JUST A POSITION MISMATCH, new | |
| 2453 | Destroy Sequential Targets | Python | O(n) | O(n) | Medium | hash table, A SEED DESTROYS EXACTLY ITS OWN RESIDUE CLASS MOD space (from itself up), new |
|
| 2456 | Most Popular Video Creator | Python | O(n) | O(n) | Medium | hash table, TWO PASSES OF BOOKKEEPING PER CREATOR, new | |
| 2484 | Count Palindromic Subsequences | Python | O(100 * n) | O(100) | Hard | hash table, FIX THE MIDDLE CHARACTER AND COUNT THE “ab” PAIRS ON EACH SIDE, new | |
| 2488 | Count Subarrays With Median K | Python | O(n) | O(n) | Hard | hash table, ONLY THE BALANCE OF “BIGGER THAN k” vs “SMALLER THAN k” MATTERS, new | |
| 2489 | Number of Substrings With Fixed Ratio | Python | O(n) | O(n) | Medium | hash table, 🔒, TURN THE RATIO INTO A SINGLE PREFIX QUANTITY THAT MUST REPEAT, new | |
| 2491 | Divide Players Into Teams of Equal Skill | Python | O(n log n) | O(n) | Medium | hash table, SORT AND PAIR THE ENDS — THE TARGET SUM IS FORCED, new | |
| 2501 | Longest Square Streak in an Array | Python | O(n * log log M) | O(n) | Medium | hash table, HASH SET + FOLLOW THE SQUARING CHAIN, new | |
| 2531 | Make Number of Distinct Characters Equal | Python | O(m + n + 26^2) | O(26) | Medium | hash table, COUNTING + ENUMERATE THE 26 x 26 CHARACTER PAIRS, new | |
| 2564 | Substring XOR Queries | Python | O(n * 32 + m) | O(n * 32) | Medium | hash table, HASH TABLE PRE-COMPUTATION OVER SHORT WINDOWS + XOR IDENTITY, new | |
| 2588 | Count the Number of Beautiful Subarrays | Python | O(n) | O(n) | Medium | hash table, PREFIX XOR + HASH MAP (same trick as “subarray sum equals K”), new | |
| 2598 | Smallest Missing Non-negative Integer After Operations | Python | O(n) | O(min(n, value)) | Medium | hash table, COUNT REMAINDERS mod value, THEN GREEDILY FILL 0, 1, 2, …, new | |
| 2605 | Form Smallest Number From Two Digit Arrays | Python | O(m + n) | O(m + n) | Easy | hash table, HASH SET INTERSECTION + 2-DIGIT FALLBACK, new | |
| 2661 | First Completely Painted Row or Column | Python | O(m * n) | O(m * n) | Medium | hash table, HASH TABLE (value -> cell) + PER ROW / PER COLUMN PAINT COUNTERS, new | |
| 2670 | Find the Distinct Difference Array | Python | O(n) | O(n) | Easy | hash table, PRECOMPUTE SUFFIX DISTINCT COUNTS, THEN SWEEP THE PREFIX, new | |
| 2716 | Minimize String Length | Python | O(n) | O(|charset|) = O(26) | Easy | hash table, HASH SET (count of DISTINCT characters), new | |
| 2718 | Sum of Matrix After Queries | Python | O(m) | O(n) (m = len(queries)) | Medium | hash table, HASH SET + REVERSE SCAN, new | |
| 2744 | Find Maximum Number of String Pairs | Python | O(n * L) | O(n * L) | Easy | hash table, HASH SET OF ALREADY-SEEN WORDS (ONE PASS), new | |
| 2748 | Number of Beautiful Pairs | Python | O(n * 10 * log(10)) | O(10) = O(1) | Easy | hash table, HASH TABLE (bucket counting on the 9 possible leading digits), new | |
| 2784 | Check if Array is Good | Python | O(n) | O(n) | Easy | hash table, COUNTING, new | |
| 2808 | Minimum Seconds to Equalize a Circular Array | Python | O(n) | O(n) | Medium | hash table, GROUP INDICES BY VALUE + LARGEST CIRCULAR GAP, new | |
| 2815 | Max Pair Sum in an Array | Python | O(n * log10(max(nums))) | O(1) # 10 buckets only | Easy | hash table, BUCKET BY LARGEST DIGIT + KEEP THE RUNNING BEST PER BUCKET, new | |
| 2839 | Check if Strings Can be Made Equal With Operations I | Python | O(1) (length is fixed at 4) | O(1) | Easy | hash table, PARITY CLASSES + COUNTING, new | |
| 2840 | Check if Strings Can be Made Equal With Operations II | Python | O(n + 26) | O(26) | Medium | hash table, PARITY CLASSES + COUNTING (hash table over 2 x 26 counters), new | |
| 2845 | Count of Interesting Subarrays | Python | O(n) | O(n) | Medium | hash table, PREFIX SUM (mod) + HASH TABLE – the “subarray sum equals target” trick, new | |
| 3005 | Count Elements With Maximum Frequency | Python | O(n) | O(n) | Easy | hash table, COUNT, TAKE THE MAX, THEN SUM THE COUNTS THAT MATCH IT, new | |
| 3039 | Apply Operations to Make String Empty | Python | O(n) | O(1) (26 counters) | Medium | hash table, THE SURVIVORS ARE THE MOST FREQUENT LETTERS, IN LAST-OCCURRENCE ORDER, new | |
| 3044 | Most Frequent Prime | Python | O(m * n * max(m,n) * sqrt(max value)) | O(number of primes seen) | Medium | hash table, THE GRID IS TINY — ENUMERATE EVERY RAY AND TEST PRIMALITY, new | |
| 3046 | Split the Array | Python | O(n) | O(n) | Easy | hash table, A VALUE CAN APPEAR AT MOST ONCE PER HALF, SO AT MOST TWICE OVERALL, new | |
| 3078 | Match Alphanumerical Pattern in Matrix I | Python | O(m * n * pm * pn) | O(1) (at most 10 letters can map) | Medium | hash table, 🔒, TRY EVERY ANCHOR, VERIFY WITH A BIJECTIVE LETTER -> DIGIT MAP, new | |
| 3083 | Existence of a Substring in a String and Its Reverse | Python | O(n) | O(n) | Easy | hash table, A LENGTH-2 SUBSTRING IS IN reverse(s) IFF ITS REVERSE IS IN s, new | |
| 3137 | Minimum Number of Operations to Make Word K-Periodic | Python | O(n) | O(n) | Medium | hash table, THE BLOCKS ARE INTERCHANGEABLE — KEEP THE MOST COMMON ONE, new | |
| 3138 | Minimum Length of Anagram Concatenation | Python | O(d(g) * n log n) worst case | O(n) | Medium | hash table, THE BLOCK COUNT MUST DIVIDE EVERY LETTER’S TOTAL — THEN VERIFY, new | |
| 3143 | Maximum Points Inside the Square | Python | O(n) | O(1) (26 tags) | Medium | hash table, A SQUARE IS JUST A CHEBYSHEV RADIUS — FIND WHERE THE FIRST TAG REPEATS, new | |
| 3146 | Permutation Difference between Two Strings | Python | O(n) | O(n) | Easy | hash table, INDEX EACH CHARACTER ONCE, THEN SUM THE SHIFTS, new | |
| 3158 | Find the XOR of Numbers Which Appear Twice | Python | O(n) | O(n) | Easy | hash table, A SET REMEMBERS WHAT HAS BEEN SEEN — XOR ON THE SECOND SIGHTING, new | |
| 3160 | Find the Number of Distinct Colors Among the Balls | Python | O(n) | O(n) | Medium | hash table, TWO MAPS — BALL -> ITS COLOR, AND COLOR -> HOW MANY BALLS WEAR IT, new | |
| 3167 | Better Compression of String | Python | O(n) | O(1) (26 counters) | Medium | hash table, 🔒, PARSE LETTER-THEN-NUMBER, ACCUMULATE, THEN EMIT IN ALPHABETICAL ORDER, new | |
| 3184 | Count Pairs That Form a Complete Day I | Python | O(n^2) | O(1) | Easy | hash table, n <= 100 — TEST EVERY PAIR, new | |
| 3185 | Count Pairs That Form a Complete Day II | Python | O(n) | O(1) (24 counters) | Medium | hash table, ONLY THE RESIDUE MOD 24 MATTERS — COUNT THE COMPLEMENT ON THE FLY, new | |
| 3223 | Minimum Length of String After Operations | Python | O(n) | O(1) (26 counters) | Medium | hash table, EACH OPERATION REMOVES TWO COPIES OF ONE LETTER — SO ONLY PARITY MATTERS, new | |
| 3238 | Find the Number of Winning Players | Python | O(len(pick) + n * colors) | O(n * colors) | Easy | hash table, TALLY (PLAYER, COLOR) PAIRS, THEN COMPARE EACH PLAYER’S BEST COLOR, new | |
| 3295 | Report Spam Message | Python | O(n + m) | O(m) | Medium | hash table, HASH THE BANNED LIST, THEN COUNT HITS AND STOP AT TWO, new | |
| 3365 | Rearrange K Substrings to Form Target String | Python | O(n) | O(n) | Medium | hash table, THE BLOCKS ARE ATOMIC — SO COMPARE THE TWO MULTISETS OF BLOCKS, new | |
| 3371 | Identify the Largest Outlier in an Array | Python | O(n) | O(n) | Medium | hash table, PICK THE SUM ELEMENT, AND THE OUTLIER FALLS OUT OF THE TOTAL, new | |
| 3396 | Minimum Number of Operations to Make Elements in Array Distinct | Python | O(n) | O(n) | Easy | hash table, FIND THE LONGEST DISTINCT SUFFIX, THEN CEIL-DIVIDE BY 3, new | |
| 3404 | Count Special Subsequences | Python | O(n^2 log(max)) | O(n^2) worst case for the fraction counter | Medium | hash table, REWRITE THE PRODUCT EQUATION AS A RATIO, THEN COUNT PAIRS BY RATIO, new | |
| 3438 | Find Valid Pair of Adjacent Digits in String | Python | O(n) | O(1) | Easy | hash table, COUNT ONCE UP FRONT, THEN THE SCAN IS A LOCAL TEST, new | |
| 3442 | Maximum Difference Between Even and Odd Frequency I | Python | O(n) | O(1) | Easy | hash table, THE TWO SIDES OF THE DIFFERENCE ARE INDEPENDENT, new | |
| 3527 | Find the Most Common Response | Python | O(total tokens) | O(distinct tokens) | Medium | hash table, DEDUPLICATE PER DAY, THEN ARGMAX WITH A LEXICOGRAPHIC TIE-BREAK, new | |
| 3541 | Find Most Frequent Vowel and Consonant | Python | O(n) | O(1) | Easy | hash table, TWO INDEPENDENT MAXIMA OVER A SINGLE FREQUENCY TABLE, new | |
| 3572 | Maximize Y‑Sum by Picking a Triplet of Distinct X‑Values | Python | O(n) | O(n) | Medium | hash table, KEEP ONLY THE BEST Y PER DISTINCT X, THEN TAKE THE TOP THREE, new | |
| 3581 | Count Odd Letters from Number | Python | O(log n) | O(1) | Easy | hash table, 🔒, XOR PARITY MASK OVER THE 26 LETTERS, new | |
| 3591 | Check if Any Element Has Prime Frequency | Python | O(n * sqrt(n)) | O(n) | Easy | hash table, COUNT, THEN TRIAL-DIVIDE THE COUNTS, new | |
| 3636 | Threshold Majority Queries | Python | O(n^2 / B + q * B log n) | O(n^2 / B^2 + n) | Hard | hash table, RANGE MODE BY BLOCK PRECOMPUTATION + A CANDIDATE SCAN OF THE EDGES, new | |
| 3662 | Filter Characters by Frequency | Python | O(n) | O(1) – the counter holds at most 26 keys | Easy | hash table, 🔒, COUNT THEN FILTER (TWO PASSES), new | |
| 3663 | Find The Least Frequent Digit | Python | O(log n) | O(1) | Easy | hash table, COUNT DIGITS, THEN PICK BY (FREQUENCY, DIGIT) — SKIPPING ABSENT ONES, new | |
| 3668 | Restore Finishing Order | Python | O(n) | O(n) | Easy | hash table, ONE PASS OVER order, FILTERING BY A MEMBERSHIP SET, new | |
| 3678 | Smallest Absent Positive Greater Than Average | Python | O(n) | O(n) | Easy | hash table, FLOOR OF THE AVERAGE + 1, THEN WALK PAST PRESENT VALUES, new | |
| 3682 | Minimum Index Sum of Common Elements | Python | O(n) | O(n) | Medium | hash table, 🔒, PER-VALUE EARLIEST INDEX, THEN ONE PASS, new |
Linked list
| # | Title | Solution | Time | Space | Difficulty | Note | Status |
|---|---|---|---|---|---|---|---|
| 1171 | Remove Zero Sum Consecutive Nodes from Linked List | Python | O(n) | O(n) | Medium | linked list, PREFIX SUM + HASH TABLE (2 passes), new, amazon, apple, uber |
|
| 1180 | Count Substrings with Only One Distinct Letter | Python | O(n) | O(1) | Easy | linked list, 🔒, TWO POINTERS (group equal-letter runs), new, amazon |
|
| 1181 | Before and After Puzzle | Python | O(n^2 * L) worst case | O(n * L) | Medium | linked list, 🔒, HASH TABLE (index the first word) + SET dedup, new | |
| 1265 | Print Immutable Linked List in Reverse | Python | O(n) | O(n), recursion stack | Medium | linked list, 🔒, RECURSION, new, google, fb |
|
| 1290 | Convert Binary Number in a Linked List to Integer | Python | O(n) | O(1) | Easy | linked list, LINKED LIST traversal + BIT SHIFT, new, google, amazon, uber |
|
| 1474 | Delete N Nodes After M Nodes of a Linked List | Python | O(N) | O(1) | Easy | linked list, 🔒, SIMULATION (in-place pointer surgery), new | |
| 1634 | Add Two Polynomials Represented as Linked Lists | Python | O(m + n) | O(1) extra (besides the output list) | Medium | linked list, 🔒, MERGE TWO SORTED LISTS (both are strictly descending by power), new, amazon |
|
| 1669 | Merge In Between Linked Lists | Python | O(n + m) | O(1) | Medium | linked list, POINTER SURGERY (find the two splice points, then relink), new, amazon |
|
| 1721 | Swapping Nodes in a Linked List | Python | O(n) | O(1) | Medium | linked list, TWO POINTERS, FIXED GAP (one pass, no length precomputation), new, amazon, fb, microsoft |
|
| 2058 | Find the Minimum and Maximum Number of Nodes Between Critical Points | Python | O(n) | O(1) | Medium | linked list, SINGLE PASS, KEEP FIRST / PREVIOUS CRITICAL INDEX, new | |
| 2074 | Reverse Nodes in Even Length Groups | Python | O(n) | O(1) | Medium | linked list, WALK GROUP BY GROUP, REVERSE IN PLACE WHEN THE ACTUAL LENGTH IS EVEN, new | |
| 2095 | Delete the Middle Node of a Linked List | Python | O(n) | O(1) | Medium | linked list, SLOW / FAST POINTERS, WITH slow LAGGING ONE NODE BEHIND, new | |
| 2130 | Maximum Twin Sum of a Linked List | Python | O(n) | O(1) | Medium | linked list, SLOW/FAST TO THE MIDDLE, REVERSE THE SECOND HALF, WALK IN LOCKSTEP, new, amazon |
|
| 2181 | Merge Nodes in Between Zeros | Python | O(n) | O(1) extra (output nodes aside) | Medium | linked list, ONE PASS ON THE LINKED LIST (accumulate until the next 0), new | |
| 2487 | Remove Nodes From Linked List | Python | O(n) | O(1) | Medium | linked list, REVERSE, KEEP A RUNNING MAXIMUM, REVERSE BACK, new | |
| 2674 | Split a Circular Linked List | Python | O(n) | O(1) | Medium | linked list, 🔒, FAST / SLOW POINTERS ON A CIRCULAR LIST, new | |
| 2816 | Double a Number Represented as a Linked List | Python | O(n) | O(1) | Medium | linked list, SINGLE FORWARD PASS - LOOK-AHEAD CARRY (NO REVERSING NEEDED), new | |
| 3062 | Winner of the Linked List Game | Python | O(n) | O(1) | Easy | linked list, 🔒, WALK TWO NODES AT A TIME AND KEEP A RUNNING SCORE DIFFERENCE, new | |
| 3063 | Linked List Frequency | Python | O(n) | O(k) | Easy | linked list, 🔒, COUNT INTO A HASH MAP, THEN REBUILD A LIST FROM THE COUNTS, new | |
| 3217 | Delete Nodes From Linked List Present in Array | Python | O(n + m) | O(m) | Medium | linked list, HASH THE VALUES, THEN ONE UNLINKING PASS BEHIND A DUMMY HEAD, new | |
| 3263 | Convert Doubly Linked List to Array I | Python | O(n) | O(n) for the output | Easy | linked list, 🔒, WALK FORWARD FROM THE HEAD — THE prev POINTERS ARE NOT NEEDED, new | |
| 3294 | Convert Doubly Linked List to Array II | Python | O(n) | O(n) for the output | Medium | linked list, 🔒, WALK BACK TO THE HEAD FIRST — THAT IS WHAT prev IS FOR, new |
Math
| # | Title | Solution | Time | Space | Difficulty | Note | Status |
|---|---|---|---|---|---|---|---|
| 0065 | Valid Number | Python, Java | O(n) | O(n) | Hard | math, finite state machine, or careful manual parsing, complex, new, string, google, amazon, fb, microsoft, linkedin |
|
| 0233 | Number of Digit One | Python, Java | O(logn) | O(1) | Hard | math, count the 1s per digit position, digit dp, good trick, new, google, amazon, apple, microsoft, uber |
|
| 0248 | Strobogrammatic Number III | Python, Java | O(5^(l/2) * l) | O(5^(l/2) * l) | Hard | math, 🔒, LC 246, LC 247, build strobogrammatic numbers per length and compare bounds, new, array, string, recursion, google, fb |
|
| 0391 | Perfect Rectangle | Python, Java | O(n) | O(n) | Hard | math, corner-count parity + total area check, hashset, good trick, new, google, apple |
|
| 0479 | Largest Palindrome Product | Python, Java | O(10^(2n)) | O(1) | Hard | math, build palindromes downward and test their factors, new | |
| 0483 | Smallest Good Base | Python, Java | O((logn)^3) | O(1) | Hard | math, enumerate the digit count then binary search the base, new, google, microsoft |
|
| 0492 | Construct the Rectangle | Python, Java | O(sqrt(area)) | O(1) | Easy | math, walk down from sqrt(area) to the first divisor, basic, new |
|
| 0660 | Remove 9 | Python, Java | O(logn) | O(logn) | Hard | math, 🔒, treat n as a base-9 number, good trick, new, google |
|
| 0780 | Reaching Points | Python, Java | O(log(max(x, y))) | O(1) | Hard | math, work backwards with modulo instead of subtraction, good trick, new, google, amazon, uber |
|
| 0782 | Transform to Chessboard | Python, Java | O(n^2) | O(1) | Hard | math, check the row patterns then count the minimum swaps, bit manipulation, new, google |
|
| 0810 | Chalkboard XOR Game | Python, Java | O(n) | O(1) | Hard | math, game theory: the first player wins if xor != 0 or n is even, new | |
| 0887 | Super Egg Drop | Python, Java | O(k * n) | O(k) | Hard | math, dp on (eggs, moves) -> max floors, binary search, good trick, new, google, amazon, fb |
|
| 0899 | Orderly Queue | Python, Java | O(n^2) | O(n) | Hard | math, k == 1 means try every rotation, otherwise just sort, trick, new, amazon |
|
| 0902 | Numbers At Most N Given Digit Set | Python, Java | O(m * d) | O(1) | Hard | math, digit dp counting numbers <= n built from a digit set, new, amazon |
|
| 0906 | Super Palindromes | Python, Java | O(M^(1/4) * logM) | O(1) | Hard | math, enumerate palindrome roots and test their squares, new, google |
|
| 0972 | Equal Rational Numbers | Python, Java | O(l) | O(1) | Hard | math, parse the repeating decimal into an exact fraction, new, microsoft |
|
| 1006 | Clumsy Factorial | Python | O(n) | O(1) | Medium | math, SIMULATION, group the terms 4 at a time, new, microsoft |
|
| 1009 | Complement of Base 10 Integer | Python | O(log n) | O(1) | Easy | math, BIT MANIPULATION, build an all-1 mask of the SAME bit length as n, new | |
| 1012 | Numbers With Repeated Digits | Python | O(L^2), L = number of digits ~ 10 | O(L) | Hard | math, COMBINATORICS (count the COMPLEMENT), new, google |
|
| 1017 | Convert to Base -2 | Python | O(log n) | O(log n) | Medium | math, REPEATED DIVISION BY -2, new | |
| 1037 | Valid Boomerang | Python | O(1) | O(1) | Easy | math, CROSS PRODUCT (avoid slope division / zero-division), new, google |
|
| 1067 | Digit Count in Range | Python | O(len(n) * len(n) * 10) | O(len(n) * len(n)) | Hard | math, 🔒, DIGIT DP + prefix trick count(high) - count(low - 1), new, amazon |
|
| 1073 | Adding Two Negabinary Numbers | Python | O(n), n = max(len(arr1), len(arr2)) | O(n) | Medium | math, SCHOOL BOOK ADDITION with a base -2 carry, new | |
| 1079 | Letter Tile Possibilities | Python | O(n!) worst case (n <= 7) | O(n) | Medium | math, BACKTRACK on a letter COUNTER (dedupe by letter, not by position), new, google |
|
| 1088 | Confusing Number II | Python | O(5^len(n)) | O(len(n)) | Hard | math, 🔒, DIGIT DFS (only generate numbers made of 0,1,6,8,9) + check rotation, new, google |
|
| 1103 | Distribute Candies to People | Python | O(sqrt(candies)) | O(num_people) | Easy | math, SIMULATION, new | |
| 1118 | Number of Days in a Month | Python | O(1) | O(1) | Easy | math, 🔒, MATH (leap year rule + month length lookup table), new, amazon |
|
| 1128 | Number of Equivalent Domino Pairs | Python | O(n) | O(1) | Easy | math, HASH TABLE (counting) + normalize each domino to a 2 digit key, new, amazon |
|
| 1134 | Armstrong Number | Python | O(log n) | O(1) | Easy | math, 🔒, MATH (simulation), new, amazon |
|
| 1154 | Day of the Year | Python | O(1) | O(1) | Easy | math, MATH (sum days of all previous months + day), new | |
| 1175 | Prime Arrangements | Python | O(n log log n) | O(n) | Easy | math, MATH (SIEVE + FACTORIAL), new, amazon |
|
| 1185 | Day of the Week | Python | O(year) | O(1) | Easy | math, ZELLER-STYLE DAY COUNTING (days elapsed since a known anchor), new, apple, microsoft |
|
| 1217 | Minimum Cost to Move Chips to The Same Position | Python | O(n) | O(1) | Easy | math, MATH / PARITY (greedy), new, amazon, apple |
|
| 1227 | Airplane Seat Assignment Probability | Python | O(1) | O(1) | Medium | math, MATH / BRAINTEASER, new, google |
|
| 1232 | Check If It Is a Straight Line | Python | O(n) | O(1) | Easy | math, MATH / CROSS PRODUCT, new | |
| 1237 | Find Positive Integer Solution for a Given Equation | Python | O(n) | O(1) | Medium | math, TWO POINTERS (start at top-left corner of the “sorted matrix”), new, google |
|
| 1238 | Circular Permutation in Binary Representation | Python | O(2^n) | O(1) | Medium | math, GRAY CODE + XOR SHIFT, new | |
| 1250 | Check If It Is a Good Array | Python | O(n log m), m = max(nums) | O(1) | Hard | math, MATH - BEZOUT’S IDENTITY, new | |
| 1256 | Encode Number | Python | O(log num) | O(log num) | Medium | math, MATH / BIT TRICK (the table is just binary of num + 1 with the leading 1 dropped), new | |
| 1259 | Handshakes That Don’t Cross | Python | O(n^2) | O(n) | Hard | math, DP (Catalan number recurrence), new, amazon |
|
| 1266 | Minimum Time Visiting All Points | Python | O(n) | O(1) | Easy | math, MATH (Chebyshev distance), new, google, amazon, fb, apple |
|
| 1276 | Number of Burgers with No Waste of Ingredients | Python | O(1) | O(1) | Medium | math, MATH (solve the 2 x 2 linear system), new | |
| 1281 | Subtract the Product and Sum of Digits of an Integer | Python | O(log n) | O(1) | Easy | math, DIGIT EXTRACTION, new, uber |
|
| 1300 | Sum of Mutated Array Closest to Target | Python | O(n log n) | O(n) | Medium | math, BINARY SEARCH on the answer (the mutated sum is monotonic in value), new, google, apple |
|
| 1317 | Convert Integer to the Sum of Two No-Zero Integers | Python | O(n log n) | O(log n) | Easy | math, brute force enumeration of a, then b = n - a, new | |
| 1323 | Maximum 69 Number | Python | O(d) | O(d) d = number of digits | Easy | math, GREEDY (flip the LEFTMOST 6 into a 9), new | |
| 1330 | Reverse Subarray To Maximize Array Value | Python | O(n) | O(1) | Hard | math, MATH (a reversal only rewires 2 boundaries -> maximise the delta), new | |
| 1344 | Angle Between Hands of a Clock | Python | O(1) | O(1) | Medium | math, MATH, new, google, amazon, fb, apple, microsoft, uber |
|
| 1359 | Count All Valid Pickup and Delivery Options | Python | O(n) | O(1) | Hard | math, COMBINATORICS / 1D DP, new, microsoft |
|
| 1360 | Number of Days Between Two Dates | Python | O(y + m) | O(1) | Easy | math, MATH - convert each date to a “days since 1971-01-01” ordinal, new, amazon, fb, microsoft |
|
| 1362 | Closest Divisors | Python | O(sqrt(num)) | O(1) | Medium | math, ENUMERATE DIVISORS DOWN FROM sqrt(x), new, amazon |
|
| 1363 | Largest Multiple of Three | Python | O(n log n) | O(n) | Hard | math, DP (max count per remainder) + BACKTRACK THE CHOICES, new, google, amazon |
|
| 1390 | Four Divisors | Python | O(n * sqrt(m)) | O(1) m = max(nums) | Medium | math, TRIAL DIVISION up to sqrt(x), stop as soon as the 4th divisor appears, new | |
| 1401 | Circle and Rectangle Overlapping | Python | O(1) | O(1) | Medium | math, MATH (clamp the centre into the rectangle, then measure), new, google |
|
| 1415 | The k-th Lexicographical String of All Happy Strings of Length n | Python | O(n) | O(n) | Medium | math, COUNTING / DIGIT SELECTION (no need to enumerate every string), new | |
| 1442 | Count Triplets That Can Form Two Arrays of Equal XOR | Python | O(n^2) | O(1) | Medium | math, XOR PREFIX TRICK, new | |
| 1447 | Simplified Fractions | Python | O(n^2 * log n) | O(1) besides the output | Medium | math, ENUMERATE PAIRS + GCD (a fraction is simplified iff gcd == 1), new, google |
|
| 1486 | XOR Operation in an Array | Python | O(n) | O(1) | Easy | math, DIRECT SIMULATION (n <= 1000, just fold the XOR), new, apple |
|
| 1497 | Check If Array Pairs Are Divisible by k | Python | O(n + k) | O(k) | Medium | math, COUNT REMAINDERS, new, amazon, uber |
|
| 1512 | Number of Good Pairs | Python | O(n) | O©, C = number of distinct values | Easy | math, RUNNING COUNTER, new, google, amazon, apple, microsoft |
|
| 1513 | Number of Substrings With Only 1s | Python | O(n) | O(1) | Medium | math, COUNT RUNS INCREMENTALLY, new, google |
|
| 1525 | Number of Good Ways to Split a String | Python | O(n) | O(26) | Medium | math, SWEEP THE CUT, MAINTAIN DISTINCT COUNTS ON BOTH SIDES, new, google, apple |
|
| 1537 | Get the Maximum Score | Python | O(m + n) | O(1) | Hard | math, MERGE THE TWO SORTED ARRAYS, SETTLE THE CHOICE AT EACH CROSSING, new, amazon, microsoft |
|
| 1551 | Minimum Operations to Make Array Equal | Python | O(1) | O(1) | Medium | math, MATH (pair up the smallest with the largest), new, microsoft |
|
| 1611 | Minimum One Bit Operations to Make Integers Zero | Python | O(log n) | O(1) | Hard | math, GRAY CODE (n is a Gray code; the answer is its rank), new | |
| 1641 | Count Sorted Vowel Strings | Python | O(1) | O(1) | Medium | math, STARS AND BARS (a sorted string is just a multiset of 5 vowels), new, google, amazon |
|
| 1643 | Kth Smallest Instructions | Python | O((row + col)^2) | O(row + col) | Hard | math, COMBINATORIAL COUNTING, build the answer greedily left to right, new | |
| 1735 | Count Ways to Make Array With Product | Python | O(K log log K + q * log K) | O(K), K = 10^4 | Hard | math, PRIME FACTORISATION + STARS AND BARS, new, amazon |
|
| 1739 | Building Boxes | Python | O(sqrt(n)) | O(1) | Hard | math, GREEDY STAIRCASE + MATH (build a corner pyramid, then extend it), new | |
| 1744 | Can You Eat Your Favorite Candy on Your Favorite Day? | Python | O(n + q) | O(n) | Medium | math, PREFIX SUM + INTERVAL OVERLAP (two ranges must intersect), new | |
| 1753 | Maximum Score From Removing Stones | Python | O(1) | O(1) | Medium | math, MATH / GREEDY (always draw from the two currently largest piles), new, google |
|
| 1776 | Car Fleet II | Python | O(n) amortised | O(n) | Hard | math, MONOTONIC STACK SCANNED RIGHT TO LEFT, new, google |
|
| 1780 | Check if Number is a Sum of Powers of Three | Python | O(log n) | O(1) | Medium | math, BASE-3 REPRESENTATION (distinct powers of 3 <=> every trit is 0 or 1), new, microsoft |
|
| 1808 | Maximize Number of Nice Divisors | Python | O(log primeFactors) | O(1) | Hard | math, INTEGER BREAK (maximize a product of parts summing to primeFactors), new | |
| 1812 | Determine Color of a Chessboard Square | Python | O(1) | O(1) | Easy | math, PARITY (a chessboard colours by (file + rank) % 2), new | |
| 1819 | Number of Different Subsequences GCDs | Python | O(M log M + n), M = max(nums) | O(M) | Hard | math, ENUMERATE THE CANDIDATE GCD, NOT THE SUBSEQUENCE (harmonic sieve), new | |
| 1822 | Sign of the Product of an Array | Python | O(n) | O(1) | Easy | math, TRACK THE SIGN ONLY (never build the product), new, microsoft |
|
| 1823 | Find the Winner of the Circular Game | Python | O(n) | O(1) | Medium | math, JOSEPHUS RECURRENCE, BOTTOM-UP (linear time, constant space), new, apple |
|
| 1828 | Queries on Number of Points Inside a Circle | Python | O(n * q) | O(1) extra | Medium | math, BRUTE FORCE WITH SQUARED DISTANCES (500 x 500 is tiny), new, google |
|
| 1830 | Minimum Number of Operations to Make String Sorted | Python | O(n * 26) | O(n) | Hard | math, THE OPERATION IS “PREVIOUS PERMUTATION” -> ANSWER = RANK OF s, new | |
| 1835 | Find XOR Sum of All Pairs Bitwise AND | Python | O(n + m) | O(1) | Hard | math, AND DISTRIBUTES OVER XOR -> (XOR arr1) AND (XOR arr2), new | |
| 1837 | Sum of Digits in Base K | Python | O(log_k n) | O(1) | Easy | math, REPEATED DIVMOD (peel off base-k digits from the least significant end), new | |
| 1860 | Incremental Memory Leak | Python | O(sqrt(memory1 + memory2)) | O(1) | Medium | math, DIRECT SIMULATION (it terminates in O(sqrt(total)) steps), new | |
| 1862 | Sum of Floored Pairs | Python | O(n + M log M), M = max(nums) <= 10^5 | O(M) | Hard | math, COUNTING + PREFIX SUM OVER MULTIPLES (harmonic series), new | |
| 1863 | Sum of All Subset XOR Totals | Python | O(n) | O(1) | Easy | math, BIT CONTRIBUTION (answer = OR(nums) * 2^(n-1)), new, amazon, neetcode250 |
|
| 1884 | Egg Drop With 2 Eggs and N Floors | Python | O(sqrt(n)) | O(1) | Medium | math, MATH (with a budget of k drops, 2 eggs can cover k*(k+1)/2 floors), new, google, fb, microsoft |
|
| 1904 | The Number of Full Rounds You Have Played | Python | O(1) | O(1) | Medium | math, CONVERT TO MINUTES, THEN COUNT WHOLE 15-MINUTE SLOTS, new | |
| 1916 | Count Ways to Build Rooms in an Ant Colony | Python | O(n log MOD) | O(n) | Hard | math, HOOK LENGTH FORMULA FOR TREES (count linear extensions of a rooted tree), new | |
| 1922 | Count Good Numbers | Python | O(log n) | O(1) | Medium | math, COMBINATORICS + FAST POWER (each position is independent), new, google, amazon |
|
| 1945 | Sum of Digits of String After Convert | Python | O(n + k) | O(n) | Easy | math, STRAIGHT SIMULATION (the number shrinks to <= 2 digits almost at once), new | |
| 1952 | Three Divisors | Python | O(sqrt(n)) | O(1) | Easy | math, NUMBER THEORY (exactly 3 divisors <=> n is the SQUARE OF A PRIME), new | |
| 1954 | Minimum Garden Perimeter to Collect Enough Apples | Python | O(log X) | O(1) | Medium | math, CLOSED-FORM APPLE COUNT + BINARY SEARCH ON THE HALF-SIDE, new, amazon |
|
| 1969 | Minimum Non-Zero Product of the Array Elements | Python | O(p) (fast power over a p-bit exponent) | O(1) | Medium | math, GREEDY / MATH (pair x with 2^p-1-x, then FAST POWER), new | |
| 1980 | Find Unique Binary String | Python | O(n) | O(n) for the answer | Medium | math, CANTOR DIAGONAL (flip the i-th bit of the i-th string), new, amazon |
|
| 1982 | Find Array Given Subset Sums | Python | O(2^n * n) | O(2^n) | Hard | math, DIVIDE AND CONQUER ON THE SORTED MULTISET (peel one element at a time), new | |
| 2005 | Subtree Removal Game with Fibonacci Tree | Python | O(n) | O(n) | Hard | math, 🔒, SPRAGUE-GRUNDY / COLON PRINCIPLE ON A ROOTED TREE, new | |
| 2063 | Vowels of All Substrings | Python | O(n) | O(1) | Medium | math, COUNT EACH VOWEL’S CONTRIBUTION (combinatorics, no substring loop), new | |
| 2073 | Time Needed to Buy Tickets | Python | O(n) | O(1) | Easy | math, COUNT EACH PERSON’S CONTRIBUTION DIRECTLY (no simulation needed), new | |
| 2083 | Substrings That Begin and End With the Same Letter | Python | O(n) | O(26) | Medium | math, 🔒, COMBINATORICS PER LETTER — CHOOSE 2 POSITIONS (plus the singletons), new, google |
|
| 2091 | Removing Minimum and Maximum From Array | Python | O(n) | O(1) | Medium | math, ONLY THREE STRATEGIES EXIST — TRY ALL THREE, new | |
| 2110 | Number of Smooth Descent Periods of a Stock | Python | O(n) | O(1) | Medium | math, COUNT THE RUN LENGTH ENDING AT EACH DAY, new, amazon |
|
| 2117 | Abbreviating the Product of a Range | Python | O(right - left) big-int multiplications | O(1) | Hard | math, HANDLE THE THREE PIECES SEPARATELY — ZEROS, SUFFIX, PREFIX, new | |
| 2119 | A Number After a Double Reversal | Python | O(1) | O(1) | Easy | math, THE DOUBLE REVERSAL ONLY LOSES TRAILING ZEROS, new | |
| 2133 | Check if Every Row and Column Contains All Numbers | Python | O(n^2) | O(n) | Easy | math, EVERY ROW AND EVERY COLUMN MUST BE A SET OF SIZE n, new | |
| 2145 | Count the Hidden Sequences | Python | O(n) | O(1) | Medium | math, THE WHOLE SEQUENCE IS PINNED BY ITS FIRST ELEMENT, new, amazon |
|
| 2148 | Count Elements With Strictly Smaller and Greater Elements | Python | O(n) | O(1) | Easy | math, ANYTHING STRICTLY BETWEEN THE GLOBAL MIN AND MAX QUALIFIES, new | |
| 2152 | Minimum Number of Lines to Cover Points | Python | O(2^n * n) | O(2^n) | Medium | math, 🔒, BITMASK DP OVER UNCOVERED POINTS (n <= 10), new | |
| 2169 | Count Operations to Obtain Zero | Python | O(log(min(num1, num2))) | O(1) | Easy | math, THIS IS THE SUBTRACTIVE EUCLIDEAN ALGORITHM — BATCH THE SUBTRACTIONS, new | |
| 2171 | Removing Minimum Number of Magic Beans | Python | O(n log n) | O(n) | Medium | math, SORT, THEN TRY EVERY SURVIVING VALUE (it must be one of the beans[i]), new | |
| 2176 | Count Equal and Divisible Pairs in an Array | Python | O(n^2) | O(1) | Easy | math, DIRECT DOUBLE LOOP (n <= 100 -> at most ~5000 pairs), new | |
| 2177 | Find Three Consecutive Integers That Sum to a Given Number | Python | O(1) | O(1) | Medium | math, THE MIDDLE TERM IS num / 3, new | |
| 2180 | Count Integers With Even Digit Sum | Python | O(log num) | O(1) | Easy | math, MATH / COUNTING (every block of 10 holds exactly 5 even digit sums), new | |
| 2183 | Count Array Pairs Divisible by K | Python | O(n log k + d(k)^2) | O(d(k)) | Hard | math, GCD BUCKETS (only gcd(nums[i], k) matters for divisibility), new | |
| 2198 | Number of Single Divisor Triplets | Python | O(n + 100^3) | O(100) | Medium | math, 🔒, VALUES ARE <= 100 — ENUMERATE VALUE TRIPLES, NOT INDEX TRIPLES, new | |
| 2217 | Find Palindrome With Fixed Length | Python | O(q * L), q = len(queries), L = intLength | O(q) | Medium | math, MATH / CONSTRUCTION (a palindrome is fully decided by its left half), new | |
| 2221 | Find Triangular Sum of an Array | Python | O(n^2) | O(1) | Medium | math, IN-PLACE SIMULATION (Pascal-triangle folding), new | |
| 2235 | Add Two Integers | Python | O(1) | O(1) | Easy | math, DIRECT ARITHMETIC, new | |
| 2240 | Number of Ways to Buy Pens and Pencils | Python | O(total / cost1) | O(1) | Medium | math, FIX THE NUMBER OF PENS, COUNT THE PENCILS ARITHMETICALLY, new | |
| 2244 | Minimum Rounds to Complete All Tasks | Python | O(n) | O(n) | Medium | math, PER DIFFICULTY, GREEDILY USE AS MANY 3s AS POSSIBLE, new | |
| 2249 | Count Lattice Points Inside a Circle | Python | O(circles * r^2) | O(number of covered points) | Medium | math, THE COORDINATE SPACE IS TINY — COLLECT THE COVERED POINTS IN A SET, new | |
| 2262 | Total Appeal of A String | Python | O(n) | O(26) | Hard | math, CONTRIBUTION / RUNNING DP (sum over substrings ending at i), new | |
| 2280 | Minimum Lines to Represent a Line Chart | Python | O(n log n) | O(n) | Medium | math, SORT BY DAY, THEN COUNT SLOPE CHANGES USING CROSS PRODUCTS, new | |
| 2310 | Sum of Numbers With Units Digit K | Python | O(1) | O(1) | Medium | math, MATH / ENUMERATE THE SET SIZE (only the last digit constrains us), new | |
| 2338 | Count the Number of Ideal Arrays | Python | O(log(maxValue) * maxValue * log(maxValue)) | O(log(maxValue) * maxValue) | Hard | math, SPLIT THE ARRAY INTO ITS DISTINCT VALUES AND WHERE THEY CHANGE, new | |
| 2344 | Minimum Deletions to Make Array Divisible | Python | O(n log n + m) | O(n) | Hard | math, “DIVIDES EVERY numsDivide” IS THE SAME AS “DIVIDES THEIR GCD”, new | |
| 2376 | Count Special Integers | Python | O(digits^2) | O(digits) | Hard | math, COUNT BY DIGIT LENGTH, THEN WALK n’s DIGITS FIXING A COMMON PREFIX, new | |
| 2396 | Strictly Palindromic Number | Python | O(1) | O(1) | Medium | math, MATH (base n-2 is always a counter-example, so the answer is always false), new | |
| 2400 | Number of Ways to Reach a Position After Exactly k Steps | Python | O(k) | O(1) | Medium | math, PURE COMBINATORICS — CHOOSE WHICH STEPS GO RIGHT, new | |
| 2409 | Count Days Spent Together | Python | O(1) | O(1) | Easy | math, CONVERT EACH “MM-DD” TO A DAY-OF-YEAR, THEN INTERSECT TWO INTERVALS, new | |
| 2413 | Smallest Even Multiple | Python | O(1) | O(1) | Easy | math, lcm(2, n) — WHICH IS n IF n IS EVEN, ELSE 2n, new | |
| 2427 | Number of Common Factors | Python | O(sqrt(min(a, b))) | O(1) | Easy | math, THE COMMON FACTORS OF a AND b ARE EXACTLY THE DIVISORS OF gcd(a, b), new | |
| 2437 | Number of Valid Clock Times | Python | O(24 + 60) = O(1) | O(1) | Easy | math, ENUMERATION (hours and minutes are independent -> multiply the counts), new | |
| 2450 | Number of Distinct Binary Strings After Applying Operations | Python | O(log n) for the modular power | O(1) | Medium | math, 🔒, LINEAR ALGEBRA OVER GF(2) (the n - k + 1 flip windows are independent), new | |
| 2455 | Average Value of Even Numbers That Are Divisible by Three | Python | O(n) | O(n) | Easy | math, “EVEN AND DIVISIBLE BY 3” IS EXACTLY “DIVISIBLE BY 6”, new | |
| 2468 | Split Message Based on Limit | Python | O(n log n) | O(n) | Hard | math, TRY EACH PART COUNT k IN ORDER AND CHECK THE TOTAL CAPACITY, new | |
| 2469 | Convert the Temperature | Python | O(1) | O(1) | Easy | math, APPLY THE TWO CONVERSION FORMULAS, new | |
| 2481 | Minimum Cuts to Divide a Circle | Python | O(1) | O(1) | Easy | math, MATH / CASE SPLIT, new | |
| 2485 | Find the Pivot Integer | Python | O(1) | O(1) | Easy | math, SOLVE IT ALGEBRAICALLY — x^2 = n(n+1)/2, new | |
| 2514 | Count Anagrams | Python | O(n) | O(1) (alphabet is fixed at 26) | Hard | math, COMBINATORICS (multinomial coefficient per word) + MODULAR INVERSE, new | |
| 2520 | Count the Digits That Divide a Number | Python | O(log num) | O(1) | Easy | math, DIGIT ENUMERATION (peel digits off with divmod), new | |
| 2521 | Distinct Prime Factors of Product of Array | Python | O(n * sqrt(m)) | O(number of distinct primes <= m) (m = max(nums)) | Medium | math, TRIAL DIVISION + SET, new | |
| 2523 | Closest Prime Numbers in Range | Python | O(right * log log right) | O(right) | Medium | math, SIEVE OF ERATOSTHENES + ADJACENT PAIR SCAN, new | |
| 2525 | Categorize Box According to Criteria | Python | O(1) | O(1) | Easy | math, SIMULATION -> 2 INDEPENDENT FLAGS -> LOOKUP TABLE, new | |
| 2539 | Count the Number of Good Subsequences | Python | O(n * 26) | O(n) | Medium | math, 🔒, COMBINATORICS – FIX THE COMMON FREQUENCY, MULTIPLY OVER LETTERS, new | |
| 2543 | Check if Point Is Reachable | Python | O(log(min(targetX, targetY))) | O(1) | Hard | math, MATH / NUMBER THEORY (gcd is invariant up to powers of 2), new | |
| 2544 | Alternating Digit Sum | Python | O(log n) | O(log n) | Easy | math, SIMULATION (walk digits left -> right, flip the sign each step), new | |
| 2549 | Count Distinct Numbers on Board | Python | O(1) | O(1) | Easy | math, MATH (every x > 2 immediately spawns x - 1, so the board fills up), new | |
| 2550 | Count Collisions of Monkeys on a Polygon | Python | O(log n) | O(1) | Medium | math, MATH / COMPLEMENT COUNTING + FAST MODULAR POWER, new | |
| 2562 | Find the Array Concatenation Value | Python | O(n log M) | O(1) (M = max value in nums) | Easy | math, TWO POINTERS + MATH (digit shift), new | |
| 2568 | Minimum Impossible OR | Python | O(n + log(max(nums))) | O(n) | Medium | math, BRAINTEASER - THE ANSWER IS ALWAYS A POWER OF 2, new | |
| 2579 | Count Total Number of Colored Cells | Python | O(1) | O(1) | Medium | math, MATH (closed form for the diamond / Aztec shape), new | |
| 2582 | Pass the Pillow | Python | O(1) | O(1) | Easy | math, MATH (divmod on the half-period), new | |
| 2584 | Split the Array to Make Coprime Products | Python | O(n * P + n) with P = 168 primes below 1000 | O(n + distinct primes) | Hard | math, PRIME FACTORIZATION -> INTERVAL MERGING (sweep the furthest reach), new | |
| 2651 | Calculate Delayed Arrival Time | Python | O(1) | O(1) | Easy | math, MATH (modular clock arithmetic), new | |
| 2652 | Sum Multiples | Python | O(n) | O(1) | Easy | math, DIRECT SCAN, new | |
| 2731 | Movement of Robots | Python | O(n log n) | O(n) | Medium | math, COLLISIONS ARE A RELABELLING (pass-through) + SORT + PREFIX SUM, new | |
| 2739 | Total Distance Traveled | Python | O(mainTank + additionalTank) | O(1) | Easy | math, SIMULATION (BURN 5 LITERS AT A TIME), new | |
| 2749 | Minimum Operations to Make the Integer Zero | Python | O(log(max(num1, num2))) | O(1) | Medium | math, ENUMERATE THE OPERATION COUNT k (bit manipulation / brainteaser), new | |
| 2750 | Ways to Split Array Into Good Subarrays | Python | O(n) | O(1) | Medium | math, MULTIPLICATION PRINCIPLE (count the cut positions between consecutive 1s), new | |
| 2761 | Prime Pairs With Target Sum | Python | O(n * log log n) | O(n) | Medium | math, SIEVE OF ERATOSTHENES + ENUMERATE THE SMALLER PRIME, new | |
| 2778 | Sum of Squares of Special Elements | Python | O(n) | O(1) | Easy | math, DIRECT SCAN OVER THE DIVISORS OF n, new | |
| 2780 | Minimum Index of a Valid Split | Python | O(n) | O(1) | Medium | math, BOYER-MOORE MAJORITY VOTE + PREFIX COUNT SWEEP, new | |
| 2802 | Find The K-th Lucky Number | Python | O(log k) | O(log k) | Medium | math, 🔒, MATH / BINARY ENCODING (4 -> bit 0, 7 -> bit 1), new | |
| 2806 | Account Balance After Rounded Purchase | Python | O(1) | O(1) | Easy | math, MATH (ROUND-HALF-UP TO THE NEAREST MULTIPLE OF 10), new | |
| 2833 | Furthest Point From Origin | Python | O(n) | O(1) | Easy | math, MATH / COUNTING (fixed displacement + free moves), new | |
| 2861 | Maximum Number of Alloys | Python | O(k * n * log(max_stock + budget)) | O(1) | Medium | math, BINARY SEARCH ON THE ANSWER, PER MACHINE, new | |
| 3001 | Minimum Moves to Capture The Queen | Python | O(1) | O(1) | Medium | math, THE ANSWER IS ONLY EVER 1 OR 2 — SO JUST TEST FOR 1, new | |
| 3007 | Maximum Number That Sum of the Prices Is Less Than or Equal to K | Python | O(log(hi) * log(hi)/x) | O(1) | Medium | math, BINARY SEARCH ON num, WITH A CLOSED FORM FOR “SET BITS UP TO num”, new | |
| 3021 | Alice and Bob Playing Flower Game | Python | O(1) | O(1) | Medium | math, EVERY TURN REMOVES EXACTLY ONE FLOWER — SO ONLY THE PARITY MATTERS, new | |
| 3024 | Type of Triangle | Python | O(1) | O(1) | Easy | math, SORT FIRST — THEN ONE INEQUALITY DECIDES EXISTENCE, new | |
| 3032 | Count Numbers With Unique Digits II | Python | O((b - a) * digits) | O(1) | Easy | math, 🔒, b <= 1000, SO JUST TEST EVERY NUMBER, new | |
| 3047 | Find the Largest Area of Square Inside Two Rectangles | Python | O(n^2) | O(1) | Medium | math, THE BEST SQUARE ALWAYS LIVES IN SOME PAIRWISE INTERSECTION, new | |
| 3084 | Count Substrings Starting and Ending with Given Character | Python | O(n) | O(1) | Medium | math, PICK AN ORDERED PAIR OF c-POSITIONS (THE SAME ONE TWICE IS ALLOWED), new | |
| 3102 | Minimize Manhattan Distances | Python | O(n log n) | O(n) | Hard | math, ROTATE TO CHEBYSHEV — MANHATTAN MAX BECOMES TWO INDEPENDENT SPREADS, new | |
| 3115 | Maximum Prime Difference | Python | O(n) | O(1) | Medium | math, ONLY THE FIRST AND LAST PRIME POSITIONS MATTER, new | |
| 3128 | Right Triangles | Python | O(m * n) | O(m + n) | Medium | math, COUNT BY THE CORNER — THE CELL THAT SUPPLIES BOTH LEGS, new | |
| 3154 | Find Number of Ways to Reach the K-th Stair | Python | O(log k * …) — about 60 binomials | O(1) | Hard | math, THE UP-MOVES ARE FORCED — SO ONLY WHERE THE DOWN-MOVES GO IS FREE, new | |
| 3155 | Maximum Number of Upgradable Servers | Python | O(n) | O(n) | Medium | math, 🔒, SOLVE THE INEQUALITY FOR k INSTEAD OF SEARCHING FOR IT, new | |
| 3162 | Find the Number of Good Pairs I | Python | O(n * m) | O(1) | Easy | math, 50 x 50 PAIRS — TEST THE DIVISIBILITY DIRECTLY, new | |
| 3164 | Find the Number of Good Pairs II | Python | O(n + max value * H(distinct)) | O(max value) | Medium | math, DIVIDE OUT k, THEN SWEEP THE MULTIPLES OF EACH DISTINCT nums2 VALUE, new | |
| 3178 | Find the Child Who Has the Ball After K Seconds | Python | O(1) | O(1) | Easy | math, THE MOTION IS PERIODIC WITH PERIOD 2*(n-1) — FOLD, THEN REFLECT, new | |
| 3179 | Find the N-th Value After K Seconds | Python | O(n * k) | O(n) | Medium | math, EACH SECOND IS ONE IN-PLACE PREFIX-SUM SWEEP, new | |
| 3183 | The Number of Ways to Make the Sum | Python | O(n) | O(n) | Medium | math, 🔒, UNBOUNDED COIN COUNT FOR {1, 2, 6}, THEN ADD 0, 1 OR 2 FOURS BY HAND, new | |
| 3200 | Maximum Height of a Triangle | Python | O(sqrt(red + blue)) | O(1) | Easy | math, ONLY TWO ARRANGEMENTS EXIST — TRY BOTH AND SIMULATE, new | |
| 3222 | Find the Winning Player in Coin Game | Python | O(1) | O(1) | Easy | math, 115 HAS EXACTLY ONE DECOMPOSITION — 75 + 4 x 10, new | |
| 3227 | Vowels Game in a String | Python | O(n) | O(1) | Medium | math, ALICE WINS IFF THE STRING HOLDS AT LEAST ONE VOWEL, new | |
| 3232 | Find if Digit Game Can Be Won | Python | O(n) | O(1) | Easy | math, THE TWO CHOICES ARE COMPLEMENTARY — SO ALICE LOSES ONLY ON A TIE, new | |
| 3247 | Number of Subsequences with Odd Sum | Python | O(n) | O(1) | Medium | math, 🔒, THE SUM’S PARITY DEPENDS ONLY ON HOW MANY ODD ELEMENTS ARE TAKEN, new | |
| 3250 | Find the Count of Monotonic Pairs I | Python | O(n * max value) | O(max value) | Hard | math, arr2 IS DETERMINED BY arr1 — SO COUNT THE VALID arr1 SEQUENCES, new | |
| 3251 | Find the Count of Monotonic Pairs II | Python | O(n * max value) | O(max value) | Hard | math, SAME PREFIX-SUM DP AS LC 3250 — IT WAS ALREADY O(n * max), new | |
| 3270 | Find the Key of the Numbers | Python | O(1) | O(1) | Easy | math, PAD TO FOUR DIGITS, TAKE THE COLUMN-WISE MINIMUM, READ IT BACK, new | |
| 3272 | Find the Count of Good Integers | Python | O(10^ceil(n/2) * n) | O(number of multisets) | Hard | math, ENUMERATE THE PALINDROMES, THEN COUNT PERMUTATIONS PER DIGIT MULTISET, new | |
| 3274 | Check if Two Chessboard Squares Have the Same Color | Python | O(1) | O(1) | Easy | math, A SQUARE’S COLOUR IS THE PARITY OF (COLUMN + ROW), new | |
| 3312 | Sorted GCD Pair Queries | Python | O(max log max + q log max) | O(max) | Hard | math, COUNT PAIRS BY GCD WITH A DIVISOR SIEVE, THEN BINARY SEARCH THE PREFIX, new | |
| 3326 | Minimum Division Operations to Make Array Non Decreasing | Python | O(max value log log max + n) | O(max value) | Medium | math, DIVIDING BY THE GREATEST PROPER DIVISOR LEAVES THE SMALLEST PRIME FACTOR, new | |
| 3345 | Smallest Divisible Digit Product I | Python | O(1) in practice | O(1) | Easy | math, n AND t ARE TINY — WALK UPWARDS UNTIL THE PRODUCT DIVIDES, new | |
| 3360 | Stone Removal Game | Python | O(1) | O(1) | Easy | math, THE MOVE SIZES ARE FIXED — 10, 9, 8, … — SO JUST PLAY IT OUT, new | |
| 3395 | Subsequences with a Unique Middle Mode I | Python | O(n * D) with D distinct values | O(D) | Hard | math, FIX THE MIDDLE, COUNT BY HOW MANY COPIES OF IT WE TAKE, new | |
| 3405 | Count the Number of Arrays with K Matching Adjacent Elements | Python | O(n + log n) | O(1) | Hard | math, CLOSED-FORM COUNT — CHOOSE THE MATCHING POSITIONS, THEN FILL FREELY, new | |
| 3411 | Maximum Subarray With Equal Products | Python | O(n^2 log(max)) | O(1) | Easy | math, BRUTE FORCE EVERY SUBARRAY, GROWING PROD / GCD / LCM INCREMENTALLY, new | |
| 3416 | Subsequences with a Unique Middle Mode II | Python | O(n) | O(n) | Hard | math, 🔒, SAME COUNTING AS PART I, BUT THE SUM OVER y IS KEPT INCREMENTALLY, new | |
| 3426 | Manhattan Distances of All Arrangements of Pieces | Python | O(mn) for the factorial table | O(mn) | Hard | math, SWAP THE SUMMATION ORDER — EVERY CELL PAIR IS SEEN THE SAME NUMBER OF TIMES, new | |
| 3428 | Maximum and Minimum Sums of at Most Size K Subsequences | Python | O(n log n) | O(n) | Medium | math, SORT, THEN COUNT HOW OFTEN EACH ELEMENT IS THE MAX / THE MIN, new | |
| 3512 | Minimum Operations to Make Array Sum Divisible by K | Python | O(n) | O(1) | Easy | math, EACH OPERATION LOWERS THE SUM BY EXACTLY ONE, new | |
| 3513 | Number of Unique XOR Triplets I | Python | O(1) after reading n | O(1) | Medium | math, CLOSURE OF {1…n} UNDER XOR IS THE FULL POWER-OF-TWO BLOCK, new | |
| 3516 | Find Closest Person | Python | O(1) | O(1) | Easy | math, EQUAL SPEED MEANS TIME IS JUST DISTANCE, new | |
| 3519 | Count Numbers with Non-Decreasing Digits | Python | O(L^2 + L * b) with L the base-b length | O(L) | Hard | math, DIGIT DP IN BASE b, COUNTED WITH STARS-AND-BARS INSTEAD OF A STATE, new | |
| 3556 | Sum of Largest Prime Substrings | Python | O(n^2 * sqrt(10^n)) with n <= 10 | O(n^2) | Medium | math, ENUMERATE ALL SUBSTRINGS, DEDUPLICATE, TAKE THE TOP THREE, new | |
| 3560 | Find Minimum Log Transportation Cost | Python | O(1) | O(1) | Easy | math, AT MOST ONE CUT, AND THE CUT IS FORCED, new | |
| 3577 | Count the Number of Computer Unlocking Permutations | Python | O(n) | O(1) | Medium | math, EITHER COMPUTER 0 UNLOCKS EVERYTHING, OR NOTHING WORKS, new | |
| 3588 | Find Maximum Area of a Triangle | Python | O(n) | O(n) | Medium | math, THE AXIS-PARALLEL SIDE IS THE BASE; THE APEX IS A GLOBAL EXTREME, new | |
| 3596 | Minimum Cost Path with Alternating Directions I | Python | O(1) | O(1) | Medium | math, 🔒, PARITY INVARIANT ON (row + col) — ONLY THREE GRIDS ARE SOLVABLE, new | |
| 3602 | Hexadecimal and Hexatrigesimal Conversion | Python | O(log n) | O(log n) | Easy | math, ONE GENERIC BASE-CONVERSION HELPER, CALLED TWICE, new | |
| 3618 | Split Array by Prime Indices | Python | O(n log log n) | O(n) | Medium | math, SIEVE OF ERATOSTHENES + SIGNED SUM IN ONE PASS, new | |
| 3621 | Number of Integers With Popcount-Depth Equal to K I | Python | O((log n)^2) | O((log n)^2) | Hard | math, COLLAPSE THE DEPTH ONTO THE POPCOUNT, THEN COUNT BY POPCOUNT, new | |
| 3622 | Check Divisibility by Digit Sum and Product | Python | O(log n) | O(1) | Easy | math, DIGIT SCAN, new | |
| 3623 | Count Number of Trapezoids I | Python | O(n) | O(n) | Medium | math, COUNT HORIZONTAL SEGMENTS PER ROW, THEN PAIR ACROSS ROWS, new | |
| 3624 | Number of Integers With Popcount-Depth Equal to K II | Python | O((n + q) * log n) | O(n) | Hard | math, DEPTH IS TINY, SO KEEP ONE FENWICK TREE PER DEPTH, new | |
| 3625 | Count Number of Trapezoids II | Python | O(n^2) | O(n^2) | Hard | math, PAIR UP PARALLEL SEGMENTS, THEN UNDO THE PARALLELOGRAM DOUBLE COUNT, new | |
| 3648 | Minimum Sensors to Cover Grid | Python | O(1) | O(1) | Medium | math, THE CHEBYSHEV BALL IS A SQUARE, SO ROWS AND COLUMNS DECOUPLE, new | |
| 3658 | GCD of Odd and Even Sums | Python | O(1) | O(1) | Easy | math, CLOSED FORMS COLLAPSE THE GCD TO n, new | |
| 3659 | Partition Array Into K-Distinct Groups | Python | O(n) | O(n) | Medium | math, COUNTING ARGUMENT — n % k == 0 AND maxFreq <= n / k, new | |
| 3664 | Two-Letter Card Game | Python | O(n + z) | O(1) | Medium | math, MAXIMUM MATCHING IN TWO COMPLETE MULTIPARTITE GRAPHS SHARING “xx”, new | |
| 3666 | Minimum Operations to Equalize Binary String | Python | O(n * alpha(n)) | O(n) | Hard | math, COLLAPSE THE STATE TO “HOW MANY ZEROS” AND BFS OVER INTERVALS, new | |
| 3671 | Sum of Beautiful Subsequences | Python | O(V log V + sum_x d(x) * log n) | O(V + sum_x d(x)) | Hard | math, DIVISOR SUM + EULER’S PHI COLLAPSES THE “EXACTLY g” CONDITION, new | |
| 3677 | Count Binary Palindromic Numbers | Python | O(log^2 n) | O(log n) | Hard | math, A PALINDROME IS DETERMINED BY ITS FIRST HALF – COUNT HALVES, new |
Pandas
| # | Title | Solution | Time | Space | Difficulty | Note | Status |
|---|---|---|---|---|---|---|---|
| 2882 | Drop Duplicate Rows | Python | O(n) | O(n) | Easy | pandas, PANDAS drop_duplicates ON A SUBSET OF COLUMNS, new | |
| 2883 | Drop Missing Data | Python | O(n) | O(n) | Easy | pandas, PANDAS dropna RESTRICTED TO THE name COLUMN, new |
|
| 2884 | Modify Columns | Python | O(n) | O(n) | Easy | pandas, VECTORISED COLUMN ARITHMETIC (in-place column assignment), new | |
| 2885 | Rename Columns | Python | O(m) for m columns | O(m) | Easy | pandas, PANDAS rename WITH AN OLD -> NEW COLUMN MAPPING, new | |
| 2886 | Change Data Type | Python | O(n) | O(n) | Easy | pandas, PANDAS astype ON A SINGLE COLUMN, new |
Queue
| # | Title | Solution | Time | Space | Difficulty | Note | Status |
|---|---|---|---|---|---|---|---|
| 1424 | Diagonal Traverse II | Python | O(n) | O(n) | Medium | queue, BUCKET BY (i + j) DIAGONAL KEY, new, google, fb |
|
| 1499 | Max Value of Equation | Python | O(n) | O(n) | Hard | queue, MONOTONIC DEQUE (sliding window maximum), new, google |
|
| 1696 | Jump Game VI | Python | O(n) | O(n) | Medium | queue, DP + MONOTONIC DEQUE (sliding-window MAXIMUM over the last k states), new, amazon, apple, uber |
|
| 2398 | Maximum Number of Robots Within Budget | Python | O(n) | O(n) | Hard | queue, SLIDING WINDOW + MONOTONIC (DECREASING) DEQUE, new |
Recursion
| # | Title | Solution | Time | Space | Difficulty | Note | Status |
|---|---|---|---|---|---|---|---|
| 0761 | Special Binary String | Python, Java | O(n^2logn) | O(n^2) | Hard | recursion, recursively sort the balanced special substrings, good trick, new |
|
| 1106 | Parsing A Boolean Expression | Python | O(n) | O(n) | Hard | recursion, STACK (evaluate the inner-most group on every ‘)’), new, amazon |
|
| 2613 | Beautiful Pairs | Python | O(n * log(n)^2) | O(n) | Hard | recursion, 🔒, CLOSEST PAIR OF POINTS (DIVIDE & CONQUER) under the MANHATTAN metric, new |
Simulation
| # | Title | Solution | Time | Space | Difficulty | Note | Status |
|---|---|---|---|---|---|---|---|
| 0874 | Walking Robot Simulation | Python, Java | O(n + k) | O(k) | Medium | simulation, duplicate of the Simulation entry, hashset of obstacles, direction array, new, amazon |
|
| 1138 | Alphabet Board Path | Python | O(n * (rows + cols)), n = len(target) | O(n * (rows + cols)), for the output string | Medium | simulation, SIMULATION + move ORDER trick (handle the lonely ‘z’), new, google, amazon |
|
| 1243 | Array Transformation | Python | O(n * m), n = len(arr), m = max value | O(n) | Easy | simulation, SIMULATION, new | |
| 2061 | Number of Spaces Cleaning Robot Cleaned | Python | O(m * n) | O(m * n) | Medium | simulation, 🔒, SIMULATION UNTIL A (cell, direction) STATE REPEATS, new, microsoft |
|
| 2162 | Minimum Cost to Set Cooking Time | Python | O(1) | O(1) | Medium | simulation, ONLY TWO (minutes, seconds) ENCODINGS EXIST — COST THEM BOTH, new, google |
|
| 2257 | Count Unguarded Cells in the Grid | Python | O(m * n + guards * (m + n)) | O(m * n) | Medium | simulation, RAY-CAST FROM EACH GUARD, STOPPING AT ANY OCCUPIED CELL, new | |
| 2303 | Calculate Amount Paid in Taxes | Python | O(n) | O(1) | Easy | simulation, SIMULATION (walk the brackets, clip each slice by the income), new | |
| 2532 | Time to Cross a Bridge | Python | O((n + k) * log k) | O(k) | Hard | simulation, EVENT SIMULATION WITH 4 HEAPS, new | |
| 2534 | Time Taken to Cross the Door | Python | O(n + max(arrival)) | O(n) | Hard | simulation, 🔒, TWO FIFO QUEUES + SECOND-BY-SECOND SIMULATION, new | |
| 2596 | Check Knight Tour Configuration | Python | O(n^2) | O(n^2) | Medium | simulation, INVERT THE GRID INTO A VISIT ORDER, THEN CHECK EACH STEP, new | |
| 2751 | Robot Collisions | Python | O(n * log n) | O(n) | Hard | simulation, SORT BY POSITION + MONOTONIC STACK SIMULATION (“asteroid collision”), new | |
| 2934 | Minimum Operations to Maximize Last Elements in Arrays | Python | O(n) | O(1) | Medium | simulation, CASE SPLIT ON THE LAST INDEX + GREEDY SCAN, new | |
| 3100 | Water Bottles II | Python | O(sqrt(numBottles)) | O(1) | Medium | simulation, DRINK EVERYTHING, THEN EXCHANGE WHILE THE EMPTIES STILL COVER THE PRICE, new | |
| 3168 | Minimum Number of Chairs in a Waiting Room | Python | O(n) | O(1) | Easy | simulation, THE ANSWER IS THE PEAK OCCUPANCY, new | |
| 3175 | Find The First Player to win K Games in a Row | Python | O(n) | O(1) | Medium | simulation, ONE SWEEP IS ENOUGH — AFTER IT, THE STRONGEST PLAYER NEVER LOSES, new | |
| 3248 | Snake in Matrix | Python | O(len(commands)) | O(1) | Easy | simulation, TRACK (row, col) AND ENCODE AT THE END, new | |
| 3412 | Find Mirror Score of a String | Python | O(n) | O(n) | Medium | simulation, ONE STACK OF UNMARKED INDICES PER LETTER, new | |
| 3433 | Count Mentions Per User | Python | O(n log n + total tokens) | O(numberOfUsers + n) | Medium | simulation, SORT THE EVENTS, KEEP AN “OFFLINE UNTIL” CLOCK PER USER, new | |
| 3507 | Minimum Pair Removal to Sort Array I | Python | O(n^2) | O(n) | Easy | simulation, DIRECT SIMULATION, new | |
| 3510 | Minimum Pair Removal to Sort Array II | Python | O(n * log n) | O(n) | Hard | simulation, DOUBLY LINKED LIST + LAZY MIN-HEAP + A COUNTER OF DESCENTS, new | |
| 3522 | Calculate Score After Performing Instructions | Python | O(n) | O(n) | Medium | simulation, SIMULATION WITH A VISITED SET, new | |
| 3561 | Resulting String After Adjacent Removals | Python | O(n) | O(n) | Medium | simulation, STACK — REPLAY THE REQUIRED LEFTMOST REMOVALS IN ONE PASS, new | |
| 3597 | Partition String | Python | O(n * sqrt(n)) worst case | O(n) | Medium | simulation, GREEDY SCAN WITH A SET OF ALREADY-EMITTED SEGMENTS, new | |
| 3608 | Minimum Time for K Connected Components | Python | O(m * log(m) + (n + m) * alpha(n)) | O(n) | Medium | simulation, REVERSE KRUSKAL — ADD EDGES BACK FROM THE LATEST TIME DOWN, new | |
| 3609 | Minimum Moves to Reach Target in Grid | Python | O(log(tx) + log(ty)) | O(1) | Hard | simulation, BACKWARD WALK — THE PREDECESSOR IS FORCED, new | |
| 3612 | Process String with Special Operations I | Python | O(2^n) | O(2^n) | Medium | simulation, DIRECT SIMULATION ON A CHARACTER LIST, new | |
| 3613 | Minimize Maximum Component Cost | Python | O(m * log(m) + (n + m) * alpha(n)) | O(n) | Medium | simulation, KRUSKAL — GROW FROM THE CHEAPEST EDGE UNTIL K COMPONENTS REMAIN, new | |
| 3614 | Process String with Special Operations II | Python | O(n) | O(1) | Hard | simulation, LENGTH SWEEP FORWARD, THEN WALK THE INDEX BACKWARDS, new | |
| 3616 | Number of Student Replacements | Python | O(n) | O(1) | Medium | simulation, 🔒, COUNT STRICT PREFIX MINIMA, new | |
| 3639 | Minimum Time to Activate String | Python | O(n log n) | O(n) | Medium | simulation, BINARY SEARCH ON TIME + COMPLEMENT COUNT OF STARRED SUBSTRINGS, new |
Sort
| # | Title | Solution | Time | Space | Difficulty | Note | Status |
|---|---|---|---|---|---|---|---|
| 0937 | Reorder Data in Log Files | Python, Java | O(nlogn * l) | O(n * l) | Medium | sort, duplicate of the Sort entry, custom comparator, letter-logs before digit-logs, new, google, amazon, apple |
|
| 1086 | High Five | Python | O(n log n) | O(n) | Easy | sort, 🔒, GROUP BY id (hash map) + keep the 5 biggest scores per student, new, amazon |
|
| 1122 | Relative Sort Array | Python | O(n log n) | O(n) n = len(arr1) | Easy | sort, CUSTOM SORT KEY (rank from arr2, then value), new, google, amazon, fb, apple, microsoft |
|
| 1356 | Sort Integers by The Number of 1 Bits | Python | O(n log n) | O(n) | Easy | sort, CUSTOM SORT KEY (popcount, value), new | |
| 1365 | How Many Numbers Are Smaller Than the Current Number | Python | O(n log n) | O(n) | Easy | sort, SORT + BINARY SEARCH (bisect_left), new, google, amazon, apple |
|
| 1366 | Rank Teams by Votes | Python | O(n*m + m^2 log m) | O(m^2) | Medium | sort, COUNTING + CUSTOM SORT KEY, new, google, fb |
|
| 1451 | Rearrange Words in a Sentence | Python | O(n log n) | O(n) | Medium | sort, STABLE SORT by word length, new, amazon |
|
| 1509 | Minimum Difference Between Largest and Smallest Value in Three Moves | Python | O(n log n) | O(1) beyond the sort | Medium | sort, SORT + ENUMERATE THE 4 SPLITS, new, google, microsoft |
|
| 1523 | Count Odd Numbers in an Interval Range | Python | O(1) | O(1) | Easy | sort, MATH / PREFIX COUNT (no loop needed), new | |
| 1561 | Maximum Number of Coins You Can Get | Python | O(n log n) | O(1) (in-place sort) | Medium | sort, GREEDY + SORT (always sacrifice the 3 smallest piles to Bob), new | |
| 1588 | Sum of All Odd Length Subarrays | Python | O(n) | O(1) | Easy | sort, CONTRIBUTION COUNTING (how many odd subarrays cover index i ?), new, google, amazon, apple |
|
| 1608 | Special Array With X Elements Greater Than or Equal X | Python | O(n log n) | O(n) | Easy | sort, SORT + BINARY SEARCH the count of elements >= x, new, google |
|
| 1620 | Coordinate With Maximum Network Quality | Python | O(51 * 51 * m), m = len(towers) | O(1) | Medium | sort, BRUTE FORCE over the bounded 51 x 51 integral grid, new | |
| 1621 | Number of Sets of K Non-Overlapping Line Segments | Python | O(k) | O(1) | Medium | sort, COMBINATORICS – the answer is C(n + k - 1, 2k), new, amazon |
|
| 1630 | Arithmetic Subarrays | Python | O(m * n) | O(n) | Medium | sort, MIN / MAX / SET check per query (no sorting needed), new, google |
|
| 1636 | Sort Array by Increasing Frequency | Python | O(n log n) | O(n) | Easy | sort, COUNTER + CUSTOM SORT KEY, new, google, amazon, fb |
|
| 1637 | Widest Vertical Area Between Two Points Containing No Points | Python | O(n log n) | O(n) | Easy | sort, SORT BY X, take the largest gap between consecutive x values, new | |
| 1680 | Concatenation of Consecutive Binary Numbers | Python | O(n) | O(1) | Medium | sort, BIT MANIPULATION, INCREMENTAL SHIFT (never build the giant string), new, google, amazon |
|
| 1685 | Sum of Absolute Differences in a Sorted Array | Python | O(n) | O(1) extra (excluding the output) | Medium | sort, PREFIX SUMS (sorted input kills the absolute value), new | |
| 1688 | Count of Matches in Tournament | Python | O(1) | O(1) | Easy | sort, COUNTING ARGUMENT (every match eliminates exactly one team), new | |
| 1716 | Calculate Money in Leetcode Bank | Python | O(1) | O(1) | Easy | sort, MATH (arithmetic series over whole weeks + the leftover days), new | |
| 1772 | Sort Features by Popularity | Python | O(L + n log n), L = total length of responses, n = len(features) | O(L) | Medium | sort, 🔒, COUNT WITH A HASH TABLE + STABLE SORT, new, amazon |
|
| 1847 | Closest Room | Python | O((n + k) log n) | O(n) | Hard | sort, OFFLINE SORT BY SIZE (descending) + FENWICK OVER SORTED ROOM IDS, new, amazon |
|
| 1859 | Sorting the Sentence | Python | O(n) | O(n) | Easy | sort, BUCKET PLACEMENT (the trailing digit IS the target index), new, google, amazon |
|
| 1942 | The Number of the Smallest Unoccupied Chair | Python | O(n log n) | O(n) | Medium | sort, SORT BY ARRIVAL + TWO HEAPS (free chairs / occupied chairs by leave time), new, amazon |
|
| 1996 | The Number of Weak Characters in the Game | Python | O(n log n) | O(n) for the sort | Medium | sort, SORT BY (attack DESC, defense ASC) + RUNNING MAX DEFENSE, new, google |
|
| 2015 | Average Height of Buildings in Each Segment | Python | O(m log m), m = len(buildings) | O(m) | Medium | sort, 🔒, SWEEP LINE / DIFFERENCE ARRAY ON EVENT POINTS + MERGE EQUAL SEGMENTS, new | |
| 2070 | Most Beautiful Item for Each Query | Python | O((n + m) log n) | O(n) | Medium | sort, SORT BY PRICE + PREFIX MAX OF BEAUTY, THEN BINARY SEARCH PER QUERY, new | |
| 2089 | Find Target Indices After Sorting Array | Python | O(n) | O(1) beyond the output | Easy | sort, COUNT, DON’T SORT — THE POSITIONS FOLLOW FROM TWO TALLIES, new, google, fb |
|
| 2158 | Amount of New Area Painted Each Day | Python | O((n + RANGE) * alpha) | O(RANGE) | Hard | sort, 🔒, UNION-FIND AS A “JUMP TO THE NEXT UNPAINTED UNIT” POINTER, new, google |
|
| 2164 | Sort Even and Odd Indices Independently | Python | O(n log n) | O(n) | Easy | sort, SPLIT BY INDEX PARITY, SORT EACH SLICE, WRITE THEM BACK, new | |
| 2191 | Sort the Jumbled Numbers | Python | O(n log n * d) | O(n) | Medium | sort, SORT BY THE MAPPED VALUE, RELYING ON PYTHON’S STABLE SORT, new | |
| 2231 | Largest Number After Digit Swaps by Parity | Python | O(d log d), d = number of digits | O(d) | Easy | sort, SORT EACH PARITY CLASS DESCENDING, THEN REFILL IN PLACE, new | |
| 2233 | Maximum Product After K Increments | Python | O((n + k) log n) | O(n) | Medium | sort, GREEDY + MIN-HEAP (always feed the currently smallest element), new | |
| 2248 | Intersection of Multiple Arrays | Python | O(total elements + k log k) | O(n) | Easy | sort, SET INTERSECTION ACROSS EVERY ROW, THEN SORT, new | |
| 2251 | Number of Flowers in Full Bloom | Python | O((F + P) log F) | O(F) | Hard | sort, INCLUSION-EXCLUSION ON TWO SORTED ARRAYS OF ENDPOINTS, new | |
| 2343 | Query Kth Smallest Trimmed Number | Python | O(q * n log n * L) | O(n * L) | Medium | sort, SORT THE (TRIMMED STRING, INDEX) PAIRS PER QUERY, new | |
| 2418 | Sort the People | Python | O(n log n) | O(n) | Easy | sort, ZIP THE TWO ARRAYS AND SORT BY HEIGHT, DESCENDING, new | |
| 2497 | Maximum Star Sum of a Graph | Python | O(V + E log E) | O(V + E) | Medium | sort, SORT NEIGHBOR VALUES DESC + GREEDY TAKE TOP k, new | |
| 2512 | Reward Top K Students | Python | O(n * L + n * log n) | O(P + N + n) | Medium | sort, HASH SET SCORING + CUSTOM SORT, new | |
| 2545 | Sort the Students by Their Kth Score | Python | O(m * log(m) * n) (row moves cost O(n)) | O(m * n) for the output | Medium | sort, SORTING BY A KEY COLUMN, new | |
| 2679 | Sum in a Matrix | Python | O(m * n * log(n)) | O(1) extra (rows sorted in place) | Medium | sort, SORT EACH ROW DESCENDING, THEN TAKE THE COLUMN MAX, new | |
| 2740 | Find the Value of the Partition | Python | O(n * log n) | O(n) for the sort | Medium | sort, SORT + MIN ADJACENT DIFFERENCE, new | |
| 2785 | Sort Vowels in a String | Python | O(n log n) | O(n) | Medium | sort, EXTRACT -> SORT -> RE-INSERT, new | |
| 2792 | Count Nodes That Are Great Enough | Python | O(n * k * log k) | O(n * k) | Hard | sort, 🔒, POST-ORDER + BOUNDED MAX-HEAP OF THE k SMALLEST SUBTREE VALUES, new | |
| 3011 | Find if Array Can Be Sorted | Python | O(n) | O(1) | Medium | sort, EQUAL-POPCOUNT RUNS CAN BE SHUFFLED FREELY, BUT NEVER CROSS EACH OTHER, new | |
| 3025 | Find the Number of Ways to Place People I | Python | O(n^2) | O(n) | Medium | sort, SORT BY (x ASC, y DESC), THEN SWEEP KEEPING THE HIGHEST y SEEN, new | |
| 3027 | Find the Number of Ways to Place People II | Python | O(n^2) | O(n) | Hard | sort, SAME SWEEP AS LC 3025 — IT WAS ALREADY O(n^2), new | |
| 3081 | Replace Question Marks in String to Minimize Its Value | Python | O(n log 26) | O(n) | Medium | sort, THE VALUE ONLY DEPENDS ON THE MULTISET; THE ORDER ONLY ON TIE-BREAKING, new | |
| 3132 | Find the Integer Added to Array II | Python | O(n log n) | O(n) | Medium | sort, ONLY THREE CANDIDATE SHIFTS — THE SMALLEST SURVIVOR IS AMONG THE FIRST 3, new | |
| 3169 | Count Days Without Meetings | Python | O(n log n) | O(n) | Medium | sort, SORT BY START AND SWEEP, TRACKING THE FURTHEST DAY ALREADY BOOKED, new | |
| 3309 | Maximum Possible Number by Binary Concatenation | Python | O(1) | O(1) | Medium | sort, ONLY SIX ORDERINGS EXIST — BUILD THEM ALL, new | |
| 3394 | Check if Grid can be Cut into Sections | Python | O(n log n) | O(n) | Medium | sort, INTERVAL MERGING ON EACH AXIS INDEPENDENTLY, new | |
| 3431 | Minimum Unlocked Indices to Sort Nums | Python | O(n) | O(1) | Medium | sort, A BOUNDARY NEEDS UNLOCKING EXACTLY WHEN ITS PREFIX IS WRONG, new | |
| 3551 | Minimum Swaps to Sort by Digit Sum | Python | O(n log n) | O(n) | Medium | sort, PERMUTATION CYCLE DECOMPOSITION, new | |
| 3631 | Sort Threats by Severity and Exploitability | Python | O(n log n) | O(n) | Medium | sort, 🔒, SORT ON A COMPOSITE KEY (-score, id), new | |
| 3644 | Maximum K to Sort a Permutation | Python | O(n) | O(1) | Medium | sort, k MUST BE A SUBMASK OF EVERY MISPLACED VALUE — SO TAKE THEIR AND, new | |
| 3667 | Sort Array By Absolute Value | Python | O(n log n) | O(n) | Easy | sort, 🔒, SORT ON A DERIVED KEY, new |
Stack
| # | Title | Solution | Time | Space | Difficulty | Note | Status |
|---|---|---|---|---|---|---|---|
| 0726 | Number of Atoms | Python, Java | O(n^2) | O(n) | Hard | stack, stack of counters, parse nested parentheses, sort the atoms, new, google, amazon, fb, microsoft |
|
| 0736 | Parse Lisp Expression | Python, Java | O(n^2) | O(n) | Hard | stack, recursive evaluation with a scope stack, complex, new, google |
|
| 0770 | Basic Calculator IV | Python, Java | O(n * t^2) | O(n + t) | Hard | stack, parse the expression into polynomial terms, complex, new, google, amazon |
|
| 1003 | Check If Word Is Valid After Substitutions | Python | O(n) | O(n) | Medium | stack, STACK, new | |
| 1019 | Next Greater Node In Linked List | Python | O(n) | O(n) | Medium | stack, MONOTONIC (DECREASING) STACK, new, google, amazon, fb, apple, microsoft, uber |
|
| 1021 | Remove Outermost Parentheses | Python | O(n) | O(n), for the output | Easy | stack, DEPTH COUNTER (a stack of size 1), new, google, fb, apple |
|
| 1063 | Number of Valid Subarrays | Python | O(n) | O(n) | Hard | stack, 🔒, MONOTONIC STACK (next strictly smaller element to the right), new | |
| 1190 | Reverse Substrings Between Each Pair of Parentheses | Python | O(n^2) | O(n) | Medium | stack, STACK of BUFFERS (simulation), new, amazon, fb, microsoft |
|
| 1441 | Build an Array With Stack Operations | Python | O(n) | O(1) | Medium | stack, SIMULATION, new, google |
|
| 1541 | Minimum Insertions to Balance a Parentheses String | Python | O(n) | O(1) | Medium | stack, GREEDY COUNTER (a “close” is the 2-char token ‘))’), new, fb, apple, microsoft |
|
| 1856 | Maximum Subarray Min-Product | Python | O(n) | O(n) | Medium | stack, MONOTONIC STACK + PREFIX SUM (largest window where nums[i] is the min), new, uber |
|
| 1944 | Number of Visible People in a Queue | Python | O(n) | O(n) | Hard | stack, MONOTONIC (DECREASING) STACK, SCANNING RIGHT -> LEFT, new, google, amazon, fb |
|
| 1950 | Maximum of Minimum Values in All Subarrays | Python | O(n) | O(n) | Medium | stack, 🔒, MONOTONIC STACK (widest window where nums[i] is the minimum) + SUFFIX MAX, new, amazon |
|
| 2197 | Replace Non-Coprime Numbers in Array | Python | O(n log(max value)) amortised | O(n) | Hard | stack, MONOTONIC-STYLE STACK — MERGE BACKWARDS UNTIL COPRIME, new | |
| 2281 | Sum of Total Strength of Wizards | Python | O(n) | O(n) | Hard | stack, MONOTONIC STACK FOR THE “I AM THE MINIMUM” RANGE + DOUBLE PREFIX SUMS, new | |
| 2282 | Number of People That Can Be Seen in a Grid | Python | O(m * n) | O(max(m, n)) | Medium | stack, 🔒, MONOTONIC DECREASING STACK, ONCE PER ROW AND ONCE PER COLUMN, new | |
| 2334 | Subarray With Elements Greater Than Varying Threshold | Python | O(n) | O(n) | Hard | stack, “EVERY ELEMENT > threshold / k” IS REALLY “THE MINIMUM > threshold / k”, new | |
| 2355 | Maximum Number of Books You Can Take | Python | O(n) | O(n) | Hard | stack, 🔒, MONOTONIC STACK + DP (optimal section ending at i is a 1-step staircase), new | |
| 2454 | Next Greater Element IV | Python | O(n) | O(n) | Hard | stack, TWO MONOTONIC STACKS — “WAITING FOR THE FIRST” AND “WAITING FOR THE SECOND”, new | |
| 2696 | Minimum String Length After Removing Substrings | Python | O(n) | O(n) | Easy | stack, STACK (adjacent-pair cancellation, same shape as “valid parentheses”), new | |
| 2735 | Collecting Chocolates | Python | O(n^2) | O(n) (n <= 1000 -> ~10^6 steps) | Medium | stack, ENUMERATE THE TOTAL NUMBER OF ROTATIONS + RUNNING PREFIX MIN, new | |
| 2736 | Maximum Sum Queries | Python | O((n + m) * log n + m * log m) | O(n + m) | Hard | stack, OFFLINE QUERIES (SORT BY x) + BINARY INDEXED TREE (MAX) OVER nums2, new | |
| 2764 | is Array a Preorder of Some Binary Tree | Python | O(n) | O(n) | Medium | stack, 🔒, MONOTONIC “ANCESTOR PATH” STACK, new | |
| 2832 | Maximal Range That Each Element Is Maximum in It | Python | O(n) | O(n) | Medium | stack, 🔒, MONOTONIC STACK (previous greater / next greater element), new | |
| 3113 | Find the Number of Subarrays Where Boundary Elements Are Maximum | Python | O(n) | O(n) | Hard | stack, MONOTONIC STACK OF (VALUE, HOW MANY COPIES ARE STILL “VISIBLE”), new | |
| 3174 | Clear Digits | Python | O(n) | O(n) | Easy | stack, A STACK — A DIGIT ALWAYS CANCELS WHATEVER IS ON TOP, new | |
| 3676 | Count Bowl Subarrays | Python | O(n) | O(n) | Medium | stack, MONOTONIC STACK — COUNT “MUTUALLY VISIBLE” INDEX PAIRS, new |
String
| # | Title | Solution | Time | Space | Difficulty | Note | Status |
|---|---|---|---|---|---|---|---|
| 0068 | Text Justification | Python, Java | O(n * w) | O(w) excluding output | Hard | string, greedy line packing then distribute spaces, complex, google, new, amazon, fb, apple, microsoft, uber, linkedin |
|
| 0420 | Strong Password Checker | Python, Java | O(n) | O(n) | Hard | string, case analysis on length, greedy replace/insert/delete, complex, new, google, amazon, fb, apple, microsoft, uber |
|
| 0481 | Magical String | Python, Java | O(n) | O(n) | Medium | string, generate the magical string with two pointers, good trick, new, google |
|
| 0500 | Keyboard Row | Python, Java | O(l) | O(1) | Easy | string, map each letter to its keyboard row, hashset, basic, new |
|
| 0527 | Word Abbreviation | Python, Java | O(nlogn * l) | O(n * l) | Hard | string, 🔒, group by (length, first, last) and resolve collisions with a longer prefix, Trie, new, google, uber |
|
| 0555 | Split Concatenated Strings | Python, Java | O(l * (l + n)) | O(l) | Medium | string, try each string reversed or not, then cut at the best position, good trick, new |
|
| 0709 | To Lower Case | Python, Java | O(n) | O(n) | Easy | string, shift by 32 or use a lookup table, bit manipulation, basic, new, google, amazon, apple |
|
| 0839 | Similar String Groups | Python, Java | O(n^2 * m) | O(n) | Hard | string, union find over similar pairs, LC 200, good trick, new, google, amazon, fb |
|
| 1016 | Binary String With Substrings Representing 1 To N | Python | O(L * 30), L = len(s) | O(L * 30) | Medium | string, ENUMERATE the SUBSTRINGS, not the numbers, new, google |
|
| 1056 | Confusing Number | Python | O(d), d = number of digits | O(1) | Easy | string, 🔒, DIGIT MAP + BUILD THE ROTATED NUMBER, new, google |
|
| 1061 | Lexicographically Smallest Equivalent String | Python | O((n + m) * a(26)), n = len(s1), m = len(baseStr) | O(26) | Medium | string, 🔒, UNION FIND (26 letters), root of a group is always its SMALLEST letter, new | |
| 1078 | Occurrences After Bigram | Python | O(n) | O(n) | Easy | string, SPLIT + sliding window of size 3, new, google |
|
| 1100 | Find K-Length Substrings With No Repeated Characters | Python | O(n) | O(1) | Medium | string, 🔒, SLIDING WINDOW (fixed size k) + counter, new, amazon |
|
| 1108 | Defanging an IP Address | Python | O(n) | O(n) | Easy | string, STRING REPLACE, new, google, amazon, fb, apple |
|
| 1177 | Can Make Palindrome from Substring | Python | O(n + m) | O(n) | Medium | string, PREFIX XOR BITMASK (parity of each letter count), new | |
| 1178 | Number of Valid Words for Each Puzzle | Python | O(L + m * 2^7), L = total length of words, m = len(puzzles) | O(n) | Hard | string, BITMASK + HASH TABLE + SUBSET ENUMERATION, new | |
| 1233 | Remove Sub-Folders from the Filesystem | Python | O(n * L log n), L = max path length | O(n) | Medium | string, SORT + PREFIX CHECK, new, google, amazon, fb, apple |
|
| 1271 | Hexspeak | Python | O(log n) | O(log n) | Easy | string, STRING + BASE CONVERSION, new | |
| 1309 | Decrypt String from Alphabet to Integer Mapping | Python | O(n) | O(n) | Easy | string, simulation, scan left -> right and look ahead for ‘#’, new, amazon |
|
| 1324 | Print Words Vertically | Python | O(n * m) | O(n * m) n = #words, m = longest word length | Medium | string, MATRIX TRANSPOSE with padding, then right-strip, new | |
| 1328 | Break a Palindrome | Python | O(n) | O(n) | Medium | string, GREEDY (first non-‘a’ in the left half -> ‘a’, else last char -> ‘b’), new, amazon, fb |
|
| 1332 | Remove Palindromic Subsequences | Python | O(n) | O(n) | Easy | string, STRING + MATH, new, amazon |
|
| 1347 | Minimum Number of Steps to Make Two Strings Anagram | Python | O(n) | O(1), at most 26 keys | Medium | string, COUNTER (count the surplus characters in t), new, amazon, microsoft |
|
| 1370 | Increasing Decreasing String | Python | O(26 * n) | O(n) | Easy | string, COUNTING (simulate one full up-then-down sweep at a time), new, google, amazon |
|
| 1371 | Find the Longest Substring Containing Vowels in Even Counts | Python | O(n) | O(1) (at most 32 mask entries) | Medium | string, PREFIX XOR MASK + FIRST-SEEN HASH TABLE, new | |
| 1374 | Generate a String With Characters That Have Odd Counts | Python | O(n) | O(n) | Easy | string, CONSTRUCTION by parity of n, new | |
| 1392 | Longest Happy Prefix | Python | O(n) | O(n) | Hard | string, KMP FAILURE FUNCTION (longest proper prefix that is also a suffix), new, google, amazon, microsoft |
|
| 1408 | String Matching in an Array | Python | O(n^2 * L^2), L = max word length | O(n) | Easy | string, BRUTE FORCE (n is tiny : n <= 100, len <= 30), new, amazon |
|
| 1410 | HTML Entity Parser | Python | O(n * L), L = 7 (longest entity) | O(n) | Medium | string, HASH TABLE + LEFT-TO-RIGHT SCAN, new, amazon |
|
| 1417 | Reformat The String | Python | O(n) | O(n) | Easy | string, SPLIT BY TYPE + INTERLEAVE (the longer group must start), new, google |
|
| 1422 | Maximum Score After Splitting a String | Python | O(n) | O(1) | Easy | string, RUNNING COUNTS (one sweep of the cut point), new, google |
|
| 1446 | Consecutive Characters | Python | O(n) | O(1) | Easy | string, ONE PASS RUN LENGTH (track the current run, keep the best), new, google, apple |
|
| 1455 | Check If a Word Occurs As a Prefix of Any Word in a Sentence | Python | O(m * n) | O(m) | Easy | string, SPLIT + str.startswith, return the FIRST (1-indexed) hit, new, amazon |
|
| 1496 | Path Crossing | Python | O(n) | O(n) | Easy | string, HASH SET (record every visited coordinate), new, google, amazon |
|
| 1507 | Reformat Date | Python | O(1) | O(1) | Easy | string, STRING PARSING (split into 3 tokens, normalise each), new | |
| 1528 | Shuffle String | Python | O(n) | O(n) | Easy | string, SCATTER INTO A RESULT BUFFER, new, google, fb, apple |
|
| 1529 | Minimum Suffix Flips | Python | O(n) | O(1) | Medium | string, GREEDY LEFT-TO-RIGHT (count boundaries between blocks), new | |
| 1540 | Can Convert String in K Moves | Python | O(n) | O(26) | Medium | string, BUCKET BY REQUIRED SHIFT AMOUNT (mod 26), new | |
| 1542 | Find Longest Awesome Substring | Python | O(10 * n) | O(2^10) | Hard | string, PREFIX PARITY BITMASK + FIRST-OCCURRENCE TABLE, new | |
| 1545 | Find Kth Bit in Nth Binary String | Python | O(n) | O(1) | Medium | string, FOLD k BACK INTO THE PREVIOUS STRING (no string is ever built), new | |
| 1554 | Strings Differ by One Character | Python | O(n * m) | O(n * m), n = #words, m = word length | Medium | string, ROLLING HASH (hash of a word with one position “blanked out”), new, google, fb |
|
| 1556 | Thousand Separator | Python | O(d) | O(d), d = number of digits | Easy | string, STRING (chop the decimal form into 3-digit groups from the right), new, uber |
|
| 1576 | Replace All ?'s to Avoid Consecutive Repeating Characters | Python | O(n) | O(n) | Easy | string, GREEDY (three letters are always enough), new, google, microsoft |
|
| 1592 | Rearrange Spaces Between Words | Python | O(n) | O(n) | Easy | string, STRING (count the spaces, then spread them evenly), new, google |
|
| 1598 | Crawler Log Folder | Python | O(n) | O(1) | Easy | string, COUNTER (only the depth matters, never the folder names), new | |
| 1624 | Largest Substring Between Two Equal Characters | Python | O(n) | O(26) | Easy | string, HASH TABLE (remember the FIRST index of every character), new, google |
|
| 1638 | Count Substrings That Differ by One Character | Python | O(m * n * min(m, n)) | O(1) ; m, n <= 100 | Medium | string, PIVOT ON THE MISMATCH, then expand both ways, new | |
| 1662 | Check If Two String Arrays are Equivalent | Python | O(n + m) on total characters | O(n + m) | Easy | string, STRING CONCAT (the array is just a chunked representation of one string), new, fb, apple |
|
| 1668 | Maximum Repeating Substring | Python | O(n^2 / m * m) = O(n^2) with n = len(sequence) | O(n) | Easy | string, BRUTE FORCE SEARCH DOWNWARD (n <= 100 so k is at most 100), new, uber |
|
| 1678 | Goal Parser Interpretation | Python | O(n) | O(n) | Easy | string, SINGLE PASS PARSE (the token is decided by the char after ‘(’), new, google, apple |
|
| 1684 | Count the Number of Consistent Strings | Python | O(A + sum(len(words[i]))) | O(A) | Easy | string, SET CONTAINMENT (a word is consistent iff its char set is a subset), new, google, apple |
|
| 1694 | Reformat Phone Number | Python | O(n) | O(n) | Easy | string, STRING SIMULATION DRIVEN BY len(digits) % 3, new | |
| 1698 | Number of Distinct Substrings in a String | Python | O(n * A) with A = alphabet size | O(n * A) | Medium | string, 🔒, SUFFIX AUTOMATON (answers the O(n) follow-up, not the O(n^2) set dump), new | |
| 1704 | Determine if String Halves Are Alike | Python | O(n) | O(1) (the vowel set is a fixed 10 chars) | Easy | string, COUNTING (single pass, one running balance instead of two counters), new | |
| 1763 | Longest Nice Substring | Python | O(n^2) worst case | O(n) | Easy | string, DIVIDE AND CONQUER ON A “BAD” CHARACTER, new, microsoft |
|
| 1784 | Check if Binary String Has at Most One Segment of Ones | Python | O(n) | O(1) | Easy | string, LOOK FOR THE PATTERN “01”, new | |
| 1790 | Check if One String Swap Can Make Strings Equal | Python | O(n) | O(1) | Easy | string, COLLECT THE MISMATCHING POSITIONS (there must be exactly 0 or 2), new, fb |
|
| 1796 | Second Largest Digit in a String | Python | O(n) | O(1) | Easy | string, TRACK THE TWO LARGEST DISTINCT DIGITS IN ONE PASS, new | |
| 1805 | Number of Different Integers in a String | Python | O(n) | O(n) | Easy | string, SCAN + STRIP LEADING ZEROS, STORE AS STRING IN A SET, new | |
| 1813 | Sentence Similarity III | Python | O(n) | O(n) | Medium | string, TWO POINTERS ON WORD LISTS (common prefix + common suffix must cover, new, google |
|
| 1816 | Truncate Sentence | Python | O(n) | O(1) extra (O(n) for the returned slice) | Easy | string, SCAN AND CUT AT THE k-TH SPACE (no split / join needed), new | |
| 1832 | Check if the Sentence Is Pangram | Python | O(n) | O(1) | Easy | string, BITMASK OF SEEN LETTERS (26 bits, one per letter), new, amazon, fb, apple |
|
| 1844 | Replace All Digits with Characters | Python | O(n) | O(n) | Easy | string, IN-PLACE CHARACTER ARITHMETIC ON THE ODD INDICES, new, google |
|
| 1854 | Maximum Population Year | Python | O(n + Y), Y = 101 year slots | O(Y) | Easy | string, DIFFERENCE ARRAY / SWEEP LINE (years are bounded to 1950…2050), new, fb, microsoft |
|
| 1858 | Longest Word With All Prefixes | Python | O(L + n log n), L = total length of all words | O(L) | Medium | string, 🔒, SORT BY LENGTH + INCREMENTAL DP (“good” set), new, google |
|
| 1876 | Substrings of Size Three with Distinct Characters | Python | O(n) | O(1) | Easy | string, FIXED-SIZE SLIDING WINDOW (the window is only 3 chars wide), new | |
| 1880 | Check if Word Equals Summation of Two Words | Python | O(L) | O(1) | Easy | string, HORNER’S RULE (build the decimal value digit by digit), new | |
| 1903 | Largest Odd Number in String | Python | O(n) | O(1) extra (the slice is the returned answer) | Easy | string, GREEDY (keep the whole prefix up to the LAST odd digit), new | |
| 1910 | Remove All Occurrences of a Substring | Python | O(n * m) | O(n) | Medium | string, STACK (one pass, pop the tail whenever it just became part), new, google, amazon, microsoft |
|
| 1933 | Check if String Is Decomposable Into Value-Equal Substrings | Python | O(n) | O(1) | Easy | string, 🔒, GROUP EQUAL RUNS, THEN LOOK AT EACH RUN LENGTH MOD 3, new | |
| 1935 | Maximum Number of Words You Can Type | Python | O(n) | O(26) | Easy | string, HASH SET OF BROKEN KEYS + SET DISJOINTNESS PER WORD, new | |
| 1957 | Delete Characters to Make Fancy String | Python | O(n) | O(n) for the output (O(1) extra) | Easy | string, GREEDY / SIMULATION (keep at most 2 of every run), new | |
| 1961 | Check If String Is a Prefix of Array | Python | O(n), n = len(s) | O(1) | Easy | string, LINEAR SCAN (match words against s with a moving cursor), new, uber |
|
| 1967 | Number of Strings That Appear as Substrings in Word | Python | O(n * m), n = len(patterns), m = len(word) | O(1) | Easy | string, DIRECT SUBSTRING CHECK, new, uber |
|
| 1974 | Minimum Time to Type Word Using Special Typewriter | Python | O(n) | O(1) | Easy | string, GREEDY (each hop is independent -> take the shorter arc), new | |
| 2000 | Reverse Prefix of Word | Python | O(n) | O(n) | Easy | string, FIND THE FIRST OCCURRENCE, THEN SLICE-REVERSE, new | |
| 2042 | Check if Numbers Are Ascending in a Sentence | Python | O(n) | O(n) | Easy | string, SPLIT ON SPACE, KEEP THE PREVIOUS NUMBER, new, apple |
|
| 2047 | Number of Valid Words in a Sentence | Python | O(n) | O(n) | Easy | string, TOKENIZE, THEN CHECK THE THREE RULES DIRECTLY, new | |
| 2048 | Next Greater Numerically Balanced Number | Python | O(A * log A) with A the answer | O(1) | Medium | string, BRUTE-FORCE SCAN UPWARD (the search space is provably tiny), new | |
| 2081 | Sum of k-Mirror Numbers | Python | O(#candidates * digits) | O(digits) | Hard | string, GENERATE BASE-10 PALINDROMES IN ORDER, THEN TEST BASE-k, new, fb |
|
| 2103 | Rings and Rods | Python | O(n) | O(1) — at most 10 rods, 3 colours | Easy | string, A SET OF COLOURS PER ROD, new, google |
|
| 2108 | Find First Palindromic String in the Array | Python | O(n * L) | O(L) | Easy | string, LINEAR SCAN, RETURN ON THE FIRST MATCH, new | |
| 2109 | Adding Spaces to a String | Python | O(n) | O(n) | Medium | string, CUT THE STRING AT THE GIVEN INDICES AND JOIN WITH SPACES, new, amazon |
|
| 2114 | Maximum Number of Words Found in Sentences | Python | O(total characters) | O(1) | Easy | string, WORD COUNT = SPACE COUNT + 1, new, google |
|
| 2116 | Check if a Parentheses String Can Be Valid | Python | O(n) | O(1) | Medium | string, TWO GREEDY SWEEPS — BEST CASE FROM EACH SIDE, new, amazon |
|
| 2124 | Check if All A’s Appears Before All B’s | Python | O(n) | O(1) | Easy | string, THE FORBIDDEN PATTERN IS THE SUBSTRING “ba”, new | |
| 2129 | Capitalize the Title | Python | O(n) | O(n) | Easy | string, SPLIT, APPLY THE LENGTH RULE PER WORD, JOIN BACK, new | |
| 2131 | Longest Palindrome by Concatenating Two Letter Words | Python | O(n) | O(n) | Medium | string, PAIR EACH WORD WITH ITS REVERSE; ONE DOUBLE LETTER MAY SIT IN THE MIDDLE, new, google |
|
| 2135 | Count Words Obtained After Adding a Letter | Python | O((S + T) * 26) | O(S) | Medium | string, LETTERS ARE DISTINCT -> EACH WORD IS JUST A 26-BIT SET, new, google |
|
| 2138 | Divide a String Into Groups of Size k | Python | O(n) | O(n) | Easy | string, SLICE IN STEPS OF k, PAD THE LAST CHUNK, new | |
| 2156 | Find Substring With Given Hash Value | Python | O(n) | O(1) | Hard | string, ROLLING HASH — SLIDE RIGHT-TO-LEFT TO AVOID A MODULAR INVERSE, new | |
| 2157 | Groups of Strings | Python | O(n * 26^2 * alpha) | O(n) | Hard | string, EACH WORD IS A 26-BIT SET -> UNION-FIND OVER THE MASKS, new | |
| 2168 | Unique Substrings With Equal Digit Frequency | Python | O(n^2) | O(n^2) worst case for the set of hashes | Medium | string, 🔒, EXPAND EVERY START, TRACK THE COUNTS INCREMENTALLY, DEDUPE BY HASH, new | |
| 2185 | Counting Words With a Given Prefix | Python | O(n * len(pref)) | O(1) | Easy | string, COUNT THE WORDS WHOSE startswith() IS TRUE, new | |
| 2186 | Minimum Number of Steps to Make Two Strings Anagram II | Python | O(len(s) + len(t)) | O(26) | Medium | string, SYMMETRIC DIFFERENCE OF THE TWO LETTER COUNTS, new | |
| 2211 | Count Collisions on a Road | Python | O(n) | O(n) | Medium | string, ONLY THE CARS THAT ESCAPE NEVER COLLIDE — STRIP THEM AND COUNT, new | |
| 2213 | Longest Substring of One Repeating Character | Python | O((n + k) log n) | O(n) | Hard | string, SEGMENT TREE WHERE EACH NODE KEEPS PREFIX / SUFFIX / BEST RUNS, new | |
| 2223 | Sum of Scores of Built Strings | Python | O(n) | O(n) | Hard | string, Z-ALGORITHM (every si is a SUFFIX of s, so score(si) = z[n - i]), new | |
| 2232 | Minimize Result by Adding Parentheses to Expression | Python | O(m * n * L), m,n = lengths of the two numbers (<= 10 total) | O(L) | Medium | string, BRUTE FORCE ENUMERATION (the string is at most 10 chars), new | |
| 2243 | Calculate Digit Sum of a String | Python | O(n log n) rounds-wise | O(n) | Easy | string, DIRECT SIMULATION OF THE ROUNDS, new | |
| 2255 | Count Prefixes of a Given String | Python | O(n * len(s)) | O(1) | Easy | string, COUNT THE WORDS THAT s STARTS WITH, new | |
| 2264 | Largest 3-Same-Digit Number in String | Python | O(10 * n) | O(1) | Easy | string, ENUMERATE THE 10 CANDIDATES FROM BIG TO SMALL, new | |
| 2269 | Find the K-Beauty of a Number | Python | O(d * k), d = number of digits (<= 10) | O(d) | Easy | string, SLIDING WINDOW OVER THE DECIMAL STRING, new | |
| 2272 | Substring With Largest Variance | Python | O(26 * 26 * n) | O(1) | Hard | string, KADANE PER ORDERED LETTER PAIR (a = +1, b = -1, b must appear), new | |
| 2273 | Find Resultant Array After Removing Anagrams | Python | O(n * L log L) | O(n) | Easy | string, KEEP ONLY THE FIRST OF EACH RUN OF MUTUALLY-ANAGRAM NEIGHBOURS, new | |
| 2278 | Percentage of Letter in String | Python | O(n) | O(1) | Easy | string, INTEGER ARITHMETIC — MULTIPLY BEFORE DIVIDING, new | |
| 2288 | Apply Discount to Prices | Python | O(n) | O(n) | Medium | string, TOKENIZE ON SPACES AND REWRITE ONLY THE WORDS THAT ARE PRICES, new | |
| 2299 | Strong Password Checker II | Python | O(n) | O(1) | Easy | string, CHECK THE SIX RULES DIRECTLY, new | |
| 2301 | Match Substring After Replacement | Python | O(len(s) * len(sub)) | O(len(mappings)) | Hard | string, PRECOMPUTE “WHAT CAN EACH sub CHARACTER BECOME”, THEN SLIDE, new | |
| 2315 | Count Asterisks | Python | O(n) | O(1) | Easy | string, PARITY TOGGLE (one scan, a single “am I inside a pair?” flag), new | |
| 2381 | Shifting Letters II | Python | O(n + len(shifts)) | O(n) | Medium | string, DIFFERENCE ARRAY — EACH SHIFT IS A RANGE +1 OR -1, new | |
| 2414 | Length of the Longest Alphabetical Continuous Substring | Python | O(n) | O(1) | Medium | string, RUN LENGTH OF “EACH CHARACTER IS THE PREVIOUS ONE PLUS 1”, new | |
| 2416 | Sum of Prefix Scores of Strings | Python | O(total characters) | O(total characters) | Hard | string, TRIE WHERE EACH NODE COUNTS HOW MANY WORDS PASS THROUGH IT, new | |
| 2490 | Circular Sentence | Python | O(n) | O(n) | Easy | string, CHECK EVERY WORD AGAINST THE NEXT ONE, WRAPPING AT THE END, new | |
| 2496 | Maximum Value of a String in an Array | Python | O(n * L) | O(1) | Easy | string, STRING SCAN + MAX, new | |
| 2575 | Find the Divisibility Array of a String | Python | O(n) | O(1) beyond the output | Medium | string, ROLLING REMAINDER (Horner’s rule under a modulus), new | |
| 2586 | Count the Number of Vowel Strings in Range | Python | O(right - left + 1) | O(1) | Easy | string, SIMULATION (scan the inclusive window and test both ends), new | |
| 2678 | Number of Senior Citizens | Python | O(n) | O(1) | Easy | string, FIXED FIELD SLICING, new | |
| 2710 | Remove Trailing Zeros From a String | Python | O(n) | O(1) beyond the output | Easy | string, SCAN FROM THE RIGHT, new | |
| 2729 | Check if The Number is Fascinating | Python | O(1) | O(1) (the string is at most ~12 chars) | Easy | string, STRING CONCAT + SORT, new | |
| 2788 | Split Strings by Separator | Python | O(n * m) | O(n * m) for the output | Easy | string, SPLIT + FILTER EMPTIES, new | |
| 2800 | Shortest String That Contains Three Strings | Python | O(n^2) | O(n) n = max length of the three strings | Medium | string, ENUMERATE THE 6 PERMUTATIONS + GREEDY PAIRWISE MERGE, new | |
| 2810 | Faulty Keyboard | Python | O(n) | O(n) | Easy | string, DEQUE + ORIENTATION FLAG (LAZY REVERSAL), new | |
| 2828 | Check if a String Is an Acronym of Words | Python | O(n) | O(1) | Easy | string, SIMULATION (length check + pairwise first-letter compare), new | |
| 2843 | Count Symmetric Integers | Python | O((high - low) * log(high)) | O(log(high)) | Easy | string, BRUTE FORCE ENUMERATION over [low, high], new | |
| 3019 | Number of Changing Keys | Python | O(n) | O(n) | Easy | string, CASE-FOLD FIRST, THEN COUNT ADJACENT MISMATCHES, new | |
| 3023 | Find Pattern in Infinite Stream I | Python | O(N * m) over N read bits | O(m) | Medium | string, 🔒, ROLLING WINDOW OF THE LAST len(pattern) BITS, new | |
| 3029 | Minimum Time to Revert Word to Initial State I | Python | O(n^2 / k) | O(n) | Medium | string, THE ADDED CHARACTERS ARE FREE — ONLY THE SURVIVING SUFFIX MATTERS, new | |
| 3031 | Minimum Time to Revert Word to Initial State II | Python | O(n) | O(n) | Hard | string, SAME CONDITION AS LC 3029, BUT ANSWERED WITH THE Z-FUNCTION, new | |
| 3034 | Number of Subarrays That Match a Pattern I | Python | O(n * m) | O(n) | Medium | string, TURN nums INTO ITS SIGN SEQUENCE, THEN LOOK FOR THE PATTERN IN IT, new | |
| 3036 | Number of Subarrays That Match a Pattern II | Python | O(n + m) | O(n + m) | Hard | string, SIGN SEQUENCE + KMP, new | |
| 3037 | Find Pattern in Infinite Stream II | Python | O(N + m) over N read bits | O(m) | Hard | string, 🔒, KMP AS A STREAMING AUTOMATON — NO NEED TO STORE THE STREAM, new | |
| 3042 | Count Prefix and Suffix Pairs I | Python | O(n^2 * L) | O(1) | Easy | string, 50 WORDS OF LENGTH 10 — CHECK EVERY ORDERED PAIR DIRECTLY, new | |
| 3043 | Find the Length of the Longest Common Prefix | Python | O((n + m) * digits) | O(n * digits) | Medium | string, PUT EVERY PREFIX OF arr1 IN A SET, THEN WALK arr2’S PREFIXES, new | |
| 3045 | Count Prefix and Suffix Pairs II | Python | O(sum of word lengths) | O(sum of word lengths) | Hard | string, TRIE KEYED ON PAIRS (k-th FROM THE FRONT, k-th FROM THE BACK), new | |
| 3076 | Shortest Uncommon Substring in an Array | Python | O(n^2 * L^3) | O(L^2) | Medium | string, THE INPUT IS TINY — ENUMERATE SUBSTRINGS SHORTEST-FIRST, new | |
| 3110 | Score of a String | Python | O(n) | O(1) | Easy | string, SUM |ord(s[i]) - ord(s[i-1])| OVER THE ADJACENT PAIRS, new | |
| 3136 | Valid Word | Python | O(n) | O(1) | Easy | string, FOUR INDEPENDENT CHECKS IN ONE PASS, new | |
| 3163 | String Compression III | Python | O(n) | O(n) | Medium | string, WALK THE RUNS, EMITTING THEM IN CHUNKS OF AT MOST 9, new | |
| 3210 | Find the Encrypted String | Python | O(n) | O(n) | Easy | string, A CYCLIC SHIFT OF THE POSITIONS, NOT OF THE ALPHABET, new | |
| 3271 | Hash Divided String | Python | O(n) | O(n / k) | Medium | string, SUM EACH BLOCK’S LETTER INDICES, TAKE IT MOD 26, MAP BACK, new | |
| 3280 | Convert Date to Binary | Python | O(1) | O(1) | Easy | string, SPLIT ON ‘-’, CONVERT EACH FIELD, RE-JOIN, new | |
| 3303 | Find the Occurrence of First Almost Equal Substring | Python | O(n + m) | O(n + m) | Hard | string, MATCH THE PATTERN FROM BOTH ENDS — ONE MISMATCH MAY SIT IN THE MIDDLE, new | |
| 3324 | Find the Sequence of Strings Appeared on the Screen | Python | O(n^2) for the strings produced | O(n^2) | Medium | string, BUILD LEFT TO RIGHT — EACH CHARACTER COSTS ONE APPEND PLUS SOME BUMPS, new | |
| 3340 | Check Balanced String | Python | O(n) | O(1) | Easy | string, ONE RUNNING DIFFERENCE, ALTERNATING THE SIGN, new | |
| 3407 | Substring Matching Pattern | Python | O(n^3) worst case on tiny inputs (n <= 50) | O(n) | Easy | string, SPLIT AT THE STAR, ANCHOR THE PREFIX, THEN LOOK RIGHT, new | |
| 3529 | Count Cells in Overlapping Horizontal and Vertical Substrings | Python | O(m * n) | O(m * n) | Medium | string, FLATTEN THE GRID BOTH WAYS AND RUN KMP ON THE TWO STRINGS, new | |
| 3571 | Find the Shortest Superstring II | Python | O(n^2) | O(n) | Easy | string, 🔒, MAXIMUM PREFIX / SUFFIX OVERLAP, new | |
| 3582 | Generate Tag for Video Caption | Python | O(n) | O(n) | Easy | string, SPLIT ON WHITESPACE, THEN RE-CASE EACH WORD BY ITS POSITION, new | |
| 3598 | Longest Common Prefix Between Adjacent Strings After Removals | Python | O(total length) | O(n) | Medium | string, PREFIX / SUFFIX MAXIMA OVER THE ORIGINAL ADJACENT PAIRS, new | |
| 3606 | Coupon Code Validator | Python | O(n * L + n * log(n)) | O(n) | Easy | string, FILTER + SORT ON THE (CATEGORY, CODE) KEY, new |
Tree
| # | Title | Solution | Time | Space | Difficulty | Note | Status |
|---|---|---|---|---|---|---|---|
| 0428 | Serialize and Deserialize N-ary Tree | Python, Java | O(n) | O(n) | Hard | tree, 🔒, LC 297, serialize with child counts or sentinels, dfs / bfs, new, google, amazon, fb, apple, microsoft, uber, linkedin |
|
| 0431 | Encode N-ary Tree to Binary Tree | Python, Java | O(n) | O(n) | Hard | tree, 🔒, first-child / next-sibling encoding, good trick, new, microsoft |
|
| 0558 | Logical OR of Two Binary Grids Represented as Quad-Trees | Python, Java | O(n1 + n2) | O(logn) | Medium | tree, recursive quad-tree merge, LC 427, new, google, apple |
|
| 0559 | Maximum Depth of N-ary Tree | Python, Java | O(n) | O(h) | Easy | tree, LC 104 for n-ary trees, dfs, bfs, good basic, new, google, amazon, microsoft |
|
| 0589 | N-ary Tree Preorder Traversal | Python, Java | O(n) | O(h) | Easy | tree, LC 144 for n-ary trees, iterative with a stack, new, apple, microsoft |
|
| 0590 | N-ary Tree Postorder Traversal | Python, Java | O(n) | O(h) | Medium | tree, LC 145 for n-ary trees, reverse-preorder trick, new, amazon |
|
| 0685 | Redundant Connection II | Python, Java | O(n * a(n)) | O(n) | Hard | tree, LC 684, union find with the two-parent case, good trick, new, dfs, bfs, google, amazon |
|
| 0699 | Falling Squares | Python, Java | O(n^2) | O(n) | Hard | tree, coordinate compression + segment tree, or an O(n^2) interval scan, new, array, ordered set, fb, uber |
|
| 0850 | Rectangle Area II | Python, Java | O(n^2) | O(n) | Hard | tree, sweep line + coordinate compression, segment tree, LC 218, new, array, scan line, google |
|
| 0993 | Cousins in Binary Tree | Python, Java | O(n) | O(h) | Easy | tree, LC 2641, dfs / bfs tracking depth and parent, good basic, new, google, amazon, fb, microsoft, bloomberg |
|
| 0998 | Maximum Binary Tree II | Python, Java | O(h) | O(h) | Medium | tree, LC 654, insert along the right spine, good trick, new, fb |
|
| 1008 | Construct Binary Search Tree from Preorder Traversal | Python | O(n) | O(n), recursion depth (skewed tree) | Medium | tree, RECURSION + UPPER BOUND (single pass), new, amazon, fb, apple, microsoft |
|
| 1026 | Maximum Difference Between Node and Ancestor | Python | O(n) | O(h), recursion depth | Medium | tree, DFS, carry the MIN and MAX seen on the path from the root, new, google, amazon, fb |
|
| 1065 | Index Pairs of a String | Python | O(sum(len(w)) + n * L), n = len(text), L = max word length | O(sum(len(w))) | Easy | tree, 🔒, TRIE, new, amazon |
|
| 1080 | Insufficient Nodes in Root to Leaf Paths | Python | O(n) | O(h), h = tree height | Medium | tree, DFS (post order) + pass the REMAINING limit down, new, amazon, apple |
|
| 1104 | Path In Zigzag Labelled Binary Tree | Python | O(log label) | O(log label) | Medium | tree, MATH (mirror the label back to the “normal” numbering), new, amazon, fb |
|
| 1120 | Maximum Average Subtree | Python | O(n) | O(h) h = tree height (recursion stack) | Medium | tree, 🔒, POST-ORDER DFS (each node returns (subtree sum, subtree size)), new, amazon, fb |
|
| 1261 | Find Elements in a Contaminated Binary Tree | Python | O(n) for init, O(1) for find | O(n) | Medium | tree, DFS RECOVER + HASH SET, new, google |
|
| 1409 | Queries on a Permutation With Key | Python | O(m * q), q = len(queries) | O(m) | Medium | tree, SIMULATION (m <= 1000, so a plain list is fast enough), new, amazon |
|
| 1430 | Check If a String Is a Valid Sequence from Root to Leaves Path in a Binary Tree | Python | O(n) | O(h) | Medium | tree, 🔒, DFS, new, google, amazon |
|
| 1469 | Find All The Lonely Nodes | Python | O(n) | O(h) recursion, h = tree height | Easy | tree, 🔒, DFS (a node reports its own single child, never itself), new | |
| 1490 | Clone N-ary Tree | Python | O(n) | O(h) recursion, h = depth | Medium | tree, 🔒, POST-ORDER DFS (clone the children first, then build the parent), new, google, amazon |
|
| 1505 | Minimum Possible Integer After at Most K Adjacent Swaps On Digits | Python | O(n * 10 * log n) | O(n) | Hard | tree, GREEDY + BINARY INDEXED TREE (Fenwick tree), new, amazon |
|
| 1506 | Find Root of N-Ary Tree | Python | O(n) | O(1) | Medium | tree, 🔒, XOR TRICK (O(1) extra space), new, google |
|
| 1516 | Move Sub-Tree of N-Ary Tree | Python | O(n) | O(n) | Hard | tree, 🔒, PARENT MAP + 3-CASE SURGERY, new, google |
|
| 1519 | Number of Nodes in the Sub-Tree With the Same Label | Python | O(26 * n) | O(26 * n) | Medium | tree, POST-ORDER DFS, MERGING 26-SLOT LABEL COUNTERS UPWARDS, new, uber |
|
| 1612 | Check If Two Expression Trees are Equivalent | Python | O(n1 + n2) | O(26) counters + O(h) stack | Medium | tree, 🔒, COUNT LEAVES (addition is commutative + associative -> only the, new, google |
|
| 1649 | Create Sorted Array through Instructions | Python | O(n log M), M = max value | O(M) | Hard | tree, BINARY INDEXED TREE (Fenwick) as a live frequency histogram, new | |
| 1938 | Maximum Genetic Difference Query | Python | O((n + q) * 18) | O(n * 18) | Hard | tree, OFFLINE DFS + BINARY TRIE THAT HOLDS EXACTLY THE CURRENT ROOT PATH, new | |
| 1948 | Delete Duplicate Folders in System | Python | O(total signature length) | O(same) | Hard | tree, TRIE + SUBTREE SERIALIZATION (canonical string per folder = its identity), new, google, amazon |
|
| 2003 | Smallest Missing Genetic Value in Each Subtree | Python | O(n) | O(n) | Hard | tree, WALK UP THE PATH FROM THE NODE HOLDING VALUE 1 (incremental DFS), new | |
| 2096 | Step-By-Step Directions From a Binary Tree Node to Another | Python | O(n) | O(n) | Medium | tree, ROOT-TO-NODE PATHS + STRIP THE COMMON PREFIX (the LCA), new, google, amazon |
|
| 2179 | Count Good Triplets in an Array | Python | O(n log n) | O(n) | Hard | tree, BIT (FENWICK) over positions in nums2, count “middle” elements, new | |
| 2196 | Create Binary Tree From Descriptions | Python | O(n) | O(n) | Medium | tree, NODE POOL KEYED BY VALUE + A SET OF EVERY VALUE THAT HAS A PARENT, new | |
| 2236 | Root Equals Sum of Children | Python | O(1) | O(1) | Easy | tree, DIRECT NODE ACCESS (the tree is guaranteed to have exactly 3 nodes), new | |
| 2277 | Closest Node to Path in Tree | Python | O(n^2 + m * n) | O(n^2) | Hard | tree, 🔒, n <= 1000 -> PRECOMPUTE ALL-PAIRS DISTANCES WITH n BFS RUNS, new | |
| 2421 | Number of Good Paths | Python | O(n log n) | O(n) | Hard | tree, ADD EDGES IN INCREASING “MAX ENDPOINT VALUE” ORDER (union-find), new | |
| 3109 | Find the Index of Permutation | Python | O(n log n) | O(n) | Medium | tree, 🔒, FACTORIAL NUMBER SYSTEM — COUNT THE PERMUTATIONS SKIPPED AT EACH SLOT, new | |
| 3515 | Shortest Path in a Weighted Tree | Python | O((n + q) * log n) | O(n) | Hard | tree, EULER TOUR TURNS “EDGE UPDATE” INTO A RANGE ADD ON A FENWICK TREE, new | |
| 3553 | Minimum Weighted Subgraph With the Required Paths II | Python | O(n * log n + q) | O(n * log n) | Hard | tree, THE STEINER TREE OF THREE NODES IS HALF THE SUM OF THEIR PAIRWISE PATHS, new | |
| 3558 | Number of Ways to Assign Edge Weights I | Python | O(n) | O(n) | Medium | tree, ONLY THE PARITY MATTERS, SO EXACTLY HALF THE ASSIGNMENTS WORK, new | |
| 3559 | Number of Ways to Assign Edge Weights II | Python | O(n * log n + q) | O(n * log n) | Hard | tree, PATH LENGTH VIA LCA, THEN THE PARITY COUNT IS 2^(L-1), new | |
| 3585 | Find Weighted Median Node in Tree | Python | O((n + q) * log n) | O(n * log n) | Hard | tree, ROOT DISTANCES + LCA, THEN ONE BINARY-LIFTING JUMP PER QUERY, new |
Two Pointers
| # | Title | Solution | Time | Space | Difficulty | Note | Status |
|---|---|---|---|---|---|---|---|
| 0862 | Shortest Subarray with Sum at Least K | Python, Java | O(n) | O(n) | Hard | two pointers, prefix sum + monotonic deque, LC 209, good trick, new, array, binary search, queue, google, amazon, fb, apple, microsoft |
|
| 1033 | Moving Stones Until Consecutive | Python | O(1) | O(1) | Medium | two pointers, MATH / CASE ANALYSIS, new, fb |
|
| 1040 | Moving Stones Until Consecutive II | Python | O(n log n) | O(1) | Medium | two pointers, SORT + SLIDING WINDOW (min) + MATH (max), new, fb |
|
| 1156 | Swap For Longest Repeated Character Substring | Python | O(n) | O(1) | Medium | two pointers, TWO POINTERS + counting, new, amazon |
|
| 1169 | Invalid Transactions | Python | O(n^2) | O(n) | Medium | two pointers, HASH TABLE (group by name) + PAIRWISE CHECK, new, amazon, apple, bloomberg |
|
| 1176 | Diet Plan Performance | Python | O(n) | O(1) | Easy | two pointers, FIXED SIZE SLIDING WINDOW, new, amazon |
|
| 1208 | Get Equal Substrings Within Budget | Python | O(n) | O(1) | Medium | two pointers, SLIDING WINDOW (2 pointers), new | |
| 1213 | Intersection of Three Sorted Arrays | Python | O(n1 + n2 + n3) | O(1), excluding the output | Easy | two pointers, 🔒, 3 POINTERS (k-way merge on sorted arrays), new, fb |
|
| 1214 | Two Sum BSTs | Python | O(m + n) | O(m + n) | Medium | two pointers, 🔒, IN-ORDER TRAVERSAL (-> sorted array) + TWO POINTERS, new, amazon |
|
| 1234 | Replace the Substring for Balanced String | Python | O(n) | O(1) | Medium | two pointers, SLIDING WINDOW / TWO POINTERS (shrinkable window), new, apple |
|
| 1297 | Maximum Number of Occurrences of a Substring | Python | O(n * minSize) | O(n * minSize) | Medium | two pointers, SLIDING WINDOW of FIXED size minSize + HASH MAP, new, amazon, fb |
|
| 1305 | All Elements in Two Binary Search Trees | Python | O(m + n) | O(m + n) | Medium | two pointers, INORDER + TWO POINTERS MERGE (never re-sort), new, google, amazon, fb, apple |
|
| 1358 | Number of Substrings Containing All Three Characters | Python | O(n) | O(1) | Medium | two pointers, LAST-SEEN INDEX (one pass), new | |
| 1425 | Constrained Subsequence Sum | Python | O(n) | O(n) | Hard | two pointers, DP + MONOTONIC DEQUE (sliding window maximum), new, google |
|
| 1456 | Maximum Number of Vowels in a Substring of Given Length | Python | O(n) | O(1) | Medium | two pointers, FIXED SIZE SLIDING WINDOW, new, amazon |
|
| 1493 | Longest Subarray of 1’s After Deleting One Element | Python | O(n) | O(1) | Medium | two pointers, SLIDING WINDOW (longest window holding at most one 0), new | |
| 1508 | Range Sum of Sorted Subarray Sums | Python | O(n^2 log n) | O(n^2) | Medium | two pointers, BUILD ALL SUBARRAY SUMS + SORT, new, google |
|
| 1521 | Find a Value of a Mysterious Function Closest to Target | Python | O(n * log M) | O(log M) | Hard | two pointers, SET OF DISTINCT AND-VALUES ENDING AT EACH INDEX, new | |
| 1604 | Alert Using Same Key-Card Three or More Times in a One Hour Period | Python | O(n log n) | O(n) | Medium | two pointers, GROUP BY NAME + SORT + FIXED-WIDTH WINDOW OF 3, new | |
| 1687 | Delivering Boxes from Storage to Ports | Python | O(n) | O(n) | Hard | two pointers, DP + SLIDING-WINDOW MINIMUM (monotonic deque) – O(n), not O(n * maxBoxes), new, google |
|
| 1695 | Maximum Erasure Value | Python | O(n) | O(n) | Medium | two pointers, SLIDING WINDOW / TWO POINTERS (longest-unique-window, but scored by sum), new | |
| 1712 | Ways to Split Array Into Three Subarrays | Python | O(n * log n) | O(n) | Medium | two pointers, PREFIX SUM + BINARY SEARCH (nums are non-negative -> prefix is monotone), new, amazon |
|
| 1750 | Minimum Length of String After Deleting Similar Ends | Python | O(n) | O(1) | Medium | two pointers, TWO POINTERS SHRINKING INWARD (greedy - always strip the full block), new, amazon |
|
| 1852 | Distinct Numbers in Each Subarray | Python | O(n) | O(k) | Medium | two pointers, 🔒, FIXED-SIZE SLIDING WINDOW + COUNTER (distinct == number of live keys), new, amazon |
|
| 1855 | Maximum Distance Between a Pair of Values | Python | O(m + n) | O(1) | Medium | two pointers, TWO POINTERS (both arrays are non-increasing -> j never moves back), new, google |
|
| 1868 | Product of Two Run-Length Encoded Arrays | Python | O(m + n) | O(m + n) for the output | Medium | two pointers, 🔒, TWO POINTERS OVER THE RUNS (never expand the arrays), new, fb |
|
| 1885 | Count Pairs in Two Arrays | Python | O(n log n) | O(n) | Medium | two pointers, 🔒, REWRITE THE INEQUALITY, THEN SORT + TWO POINTERS, new | |
| 1989 | Maximum Number of People That Can Be Caught in Tag | Python | O(n) | O(1) | Medium | two pointers, 🔒, GREEDY TWO POINTERS (match each catcher to the leftmost free target), new | |
| 2024 | Maximize the Confusion of an Exam | Python | O(n) | O(1) | Medium | two pointers, SLIDING WINDOW, TWICE (same as LC 424 “longest repeating char replacement”), new, amazon |
|
| 2040 | Kth Smallest Product of Two Sorted Arrays | Python | O(n log m log R) | O(1) | Hard | two pointers, BINARY SEARCH ON THE ANSWER + O(n log m) COUNTER, new | |
| 2046 | Sort Linked List Already Sorted Using Absolute Values | Python | O(n) | O(1) | Medium | two pointers, 🔒, THE NEGATIVES ARE ALREADY IN REVERSE ORDER — MOVE THEM TO THE FRONT, new | |
| 2062 | Count Vowel Substrings of a String | Python | O(n^2) | O(1) (the set holds at most 5 letters) | Easy | two pointers, EXPAND EVERY LEFT ENDPOINT, STOP AT THE FIRST CONSONANT, new | |
| 2067 | Number of Equal Count Substrings | Python | O(26 * n) | O(26) | Medium | two pointers, 🔒, FIXED-SIZE SLIDING WINDOW, ONE PASS PER DISTINCT-LETTER COUNT, new | |
| 2090 | K Radius Subarray Averages | Python | O(n) | O(n) | Medium | two pointers, PREFIX SUM (fixed-width window of size 2k+1), new | |
| 2105 | Watering Plants II | Python | O(n) | O(1) | Medium | two pointers, STRAIGHT TWO-POINTER SIMULATION FROM BOTH ENDS, new, google |
|
| 2107 | Number of Unique Flavors After Sharing K Candies | Python | O(n) | O(n) | Medium | two pointers, 🔒, FIXED-SIZE SLIDING WINDOW OF THE REMOVED CANDIES, new | |
| 2134 | Minimum Swaps to Group All 1’s Together II | Python | O(n) | O(1) | Medium | two pointers, FIXED-WIDTH CIRCULAR SLIDING WINDOW — MINIMIZE THE ZEROS INSIDE, new | |
| 2149 | Rearrange Array Elements by Sign | Python | O(n) | O(n) for the output | Medium | two pointers, TWO WRITE POINTERS — EVEN SLOTS FOR POSITIVES, ODD FOR NEGATIVES, new, amazon |
|
| 2161 | Partition Array According to Given Pivot | Python | O(n) | O(n) | Medium | two pointers, STABLE THREE-WAY SPLIT IN ONE PASS, new, amazon |
|
| 2200 | Find All K-Distant Indices in an Array | Python | O(n * k) | O(n) | Easy | two pointers, PAINT AN INTERVAL AROUND EVERY key OCCURRENCE, new |
|
| 2234 | Maximum Total Beauty of the Gardens | Python | O(n log n) | O(n) | Hard | two pointers, SORT + ENUMERATE HOW MANY GARDENS END UP COMPLETE + BINARY SEARCH, new | |
| 2302 | Count Subarrays With Score Less Than K | Python | O(n) | O(1) | Hard | two pointers, SLIDING WINDOW (score is monotonic when the window grows), new | |
| 2330 | Valid Palindrome IV | Python | O(n) | O(1) | Medium | two pointers, 🔒, COUNT THE MISMATCHED MIRROR PAIRS — THE ANSWER IS “AT MOST 2”, new | |
| 2332 | The Latest Time to Catch a Bus | Python | O(n log n + m log m) | O(m) | Medium | two pointers, SIMULATE THE BOARDING, THEN WALK BACK FROM THE BEST SEAT, new | |
| 2337 | Move Pieces to Obtain a String | Python | O(n) | O(n) | Medium | two pointers, PIECES CANNOT PASS EACH OTHER — COMPARE THEM IN ORDER, POSITION BY POSITION, new | |
| 2379 | Minimum Recolors to Get K Consecutive Black Blocks | Python | O(n) | O(1) | Easy | two pointers, FIXED-WIDTH SLIDING WINDOW — MINIMISE THE WHITES INSIDE, new | |
| 2393 | Count Strictly Increasing Subarrays | Python | O(n) | O(1) | Medium | two pointers, 🔒, SPLIT INTO MAXIMAL INCREASING RUNS AND COUNT EACH ONE’S SUBARRAYS, new | |
| 2401 | Longest Nice Subarray | Python | O(n) | O(1) | Medium | two pointers, “ALL PAIRWISE ANDs ARE 0” == “NO TWO ELEMENTS SHARE A SET BIT”, new | |
| 2444 | Count Subarrays With Fixed Bounds | Python | O(n) | O(1) | Hard | two pointers, THREE POINTERS (last bad index + last minK index + last maxK index), new | |
| 2465 | Number of Distinct Averages | Python | O(n log n) | O(n) | Easy | two pointers, SORT, THEN PAIR THE ENDS INWARD, new | |
| 2511 | Maximum Enemy Forts That Can Be Captured | Python | O(n) | O(1) | Easy | two pointers, TWO POINTERS (scan between consecutive non-zero forts), new | |
| 2516 | Take K of Each Character From Left and Right | Python | O(n) | O(1) | Medium | two pointers, SLIDING WINDOW ON THE COMPLEMENT (two pointers), new | |
| 2524 | Maximum Frequency Score of a Subarray | Python | O(n * log(max(nums))) | O(n) (log factor = modular pow) | Hard | two pointers, 🔒, SLIDING WINDOW + COUNTER + INCREMENTAL MODULAR UPDATE, new | |
| 2537 | Count the Number of Good Subarrays | Python | O(n) | O(n) | Medium | two pointers, SLIDING WINDOW (TWO POINTERS) + HASH COUNTER, new | |
| 2540 | Minimum Common Value | Python | O(m + n) | O(1) | Easy | two pointers, TWO POINTERS (merge-style walk over two sorted arrays), new | |
| 2563 | Count the Number of Fair Pairs | Python | O(n log n) | O(1) beyond the sort | Medium | two pointers, SORTING + TWO POINTERS (count(<= x) via a shrinking window), new | |
| 2570 | Merge Two 2D Arrays by Summing Values | Python | O(n + m) | O(1) beyond the output | Easy | two pointers, TWO POINTERS (classic merge step of merge-sort), new | |
| 2609 | Find the Longest Balanced Substring of a Binary String | Python | O(n) | O(1) | Easy | two pointers, RUN-LENGTH COUNTERS (two pointers over the 0-run / 1-run boundary), new | |
| 2653 | Sliding Subarray Beauty | Python | O(n * 50) | O(1) (the table has a fixed size of 50) | Medium | two pointers, SLIDING WINDOW + COUNTING SORT (values are bounded by [-50, 50]), new | |
| 2730 | Find the Longest Semi-Repetitive Substring | Python | O(n) | O(1) | Medium | two pointers, TWO POINTERS / SLIDING WINDOW ON ADJACENT-EQUAL PAIRS, new | |
| 2743 | Count Substrings Without Repeating Character | Python | O(n) | O© with C = 26 | Medium | two pointers, 🔒, SLIDING WINDOW (TWO POINTERS) + “COUNT SUBSTRINGS ENDING AT i”, new | |
| 2747 | Count Zero Request Servers | Python | O(LlogL + MlogM + n) | O(L + M) (L = len(logs), M = len(queries)) | Medium | two pointers, OFFLINE QUERIES + SORTING + SLIDING WINDOW (two pointers), new | |
| 2762 | Continuous Subarrays | Python | O(n) | O(n) | Medium | two pointers, SLIDING WINDOW + TWO MONOTONIC DEQUES (window max & window min), new | |
| 2763 | Sum of Imbalance Numbers of All Subarrays | Python | O(n^2) | O(n) | Hard | two pointers, GROW THE RIGHT END + REWRITE IMBALANCE AS A COUNT OVER THE VALUE SET, new | |
| 2779 | Maximum Beauty of an Array After Applying Operation | Python | O(n log n) | O(n) for the sort | Medium | two pointers, SORT + SLIDING WINDOW OF WIDTH 2k, new | |
| 2781 | Length of the Longest Valid Substring | Python | O(n * L^2) with L = 10 (substring slicing) | O(total forbidden chars) | Hard | two pointers, SLIDING WINDOW + BOUNDED SUFFIX LOOKUP, new | |
| 2799 | Count Complete Subarrays in an Array | Python | O(n) | O(n) | Medium | two pointers, SLIDING WINDOW (TWO POINTERS) + COUNTER, new | |
| 2824 | Count Pairs Whose Sum is Less than Target | Python | O(n * log n) | O(n) # O(1) extra if sorting in place | Easy | two pointers, SORT + TWO POINTERS, new | |
| 2831 | Find the Longest Equal Subarray | Python | O(n) | O(n) | Medium | two pointers, TWO POINTERS OVER THE INDEX LIST OF EACH VALUE, new | |
| 2838 | Maximum Coins Heroes Can Collect | Python | O(n log n + m log m) | O(n + m) | Medium | two pointers, 🔒, SORT + PREFIX SUM + TWO POINTERS, new | |
| 2841 | Maximum Sum of Almost Unique Subarray | Python | O(n) | O(k) | Medium | two pointers, FIXED-SIZE SLIDING WINDOW + HASH TABLE (running sum & distinct count), new | |
| 2904 | Shortest and Lexicographically Smallest Beautiful String | Python | O(n^2) (slicing the window is O(n) per step) | O(n) | Medium | two pointers, TWO POINTERS (SLIDING WINDOW PINNED TO ‘1’ BOUNDARIES), new | |
| 3006 | Find Beautiful Indices in the Given Array I | Python | O(n * m + n log n) | O(n) | Medium | two pointers, COLLECT BOTH OCCURRENCE LISTS, THEN BINARY SEARCH THE WINDOW, new | |
| 3008 | Find Beautiful Indices in the Given Array II | Python | O(|s| + |a| + |b|) | O(|s| + |a| + |b|) | Hard | two pointers, KMP FOR BOTH PATTERNS, THEN A SINGLE MERGE PASS, new | |
| 3013 | Divide an Array Into Subarrays With Minimum Cost II | Python | O(n log n) | O(n) | Hard | two pointers, SLIDING WINDOW OF WIDTH dist+1, KEEPING THE k-1 SMALLEST STARTS, new | |
| 3085 | Minimum Deletions to Make String K-Special | Python | O(n + 26^2) | O(1) | Medium | two pointers, FIX THE SURVIVING MINIMUM FREQUENCY AND CHARGE EVERY LETTER, new | |
| 3095 | Shortest Subarray With OR at Least K I | Python | O(n^2) | O(1) | Easy | two pointers, n <= 50 — GROW EVERY SUBARRAY AND STOP AS SOON AS THE OR CLEARS k, new | |
| 3097 | Shortest Subarray With OR at Least K II | Python | O(30 * n) | O(1) | Medium | two pointers, SLIDING WINDOW WITH A COUNTER PER BIT (OR IS NOT INVERTIBLE), new | |
| 3171 | Find Subarray With Bitwise OR Closest to K | Python | O(30 * n) | O(30) | Hard | two pointers, THE ORs OF ALL SUBARRAYS ENDING AT i FORM AT MOST ~30 DISTINCT VALUES, new | |
| 3206 | Alternating Groups I | Python | O(n) | O(1) | Easy | two pointers, CHECK EVERY WINDOW OF THREE, WRAPPING WITH MODULO, new | |
| 3208 | Alternating Groups II | Python | O(n + k) | O(1) | Medium | two pointers, TRACK THE CURRENT ALTERNATING RUN LENGTH AROUND THE CIRCLE, new | |
| 3234 | Count the Number of Substrings With Dominant Ones | Python | O(n * sqrt(n)) | O(n) | Medium | two pointers, THE ZERO COUNT IS BOUNDED BY sqrt(n) — ENUMERATE IT, new | |
| 3254 | Find the Power of K-Size Subarrays I | Python | O(n * k) | O(n) | Medium | two pointers, “CONSECUTIVE AND ASCENDING” JUST MEANS EVERY STEP IS EXACTLY +1, new | |
| 3255 | Find the Power of K-Size Subarrays II | Python | O(n) | O(n) for the output | Medium | two pointers, ONE RUNNING STREAK OF “+1 STEPS” ANSWERS EVERY WINDOW, new | |
| 3258 | Count Substrings That Satisfy K-Constraint I | Python | O(n) | O(1) | Easy | two pointers, SLIDING WINDOW — THE CONSTRAINT IS MONOTONE IN THE WINDOW SIZE, new | |
| 3261 | Count Substrings That Satisfy K-Constraint II | Python | O(n + q log n) | O(n) | Hard | two pointers, PRECOMPUTE THE SHORTEST VALID LEFT END PER RIGHT END, THEN PREFIX SUM, new | |
| 3264 | Final Array State After K Multiplication Operations I | Python | O((n + k) log n) | O(n) | Easy | two pointers, MIN-HEAP KEYED BY (VALUE, INDEX) — THE TIE-BREAK IS THE INDEX, new | |
| 3266 | Final Array State After K Multiplication Operations II | Python | O(n log(max) * log n + n log n) | O(n) | Hard | two pointers, SIMULATE UNTIL THE VALUES LEVEL OFF, THEN FINISH IN BULK, new | |
| 3297 | Count Substrings That Can Be Rearranged to Contain a String I | Python | O(n + m) | O(1) (26 counters) | Medium | two pointers, “REARRANGEABLE TO HAVE word2 AS A PREFIX” == COVERS ITS LETTER COUNTS, new | |
| 3298 | Count Substrings That Can Be Rearranged to Contain a String II | Python | O(n + m) | O(1) (26 counters) | Hard | two pointers, SAME SLIDING WINDOW AS LC 3297 — IT WAS ALREADY LINEAR, new | |
| 3305 | Count of Substrings Containing Every Vowel and K Consonants I | Python | O(n) | O(1) | Medium | two pointers, “EXACTLY k” = “AT LEAST k” MINUS “AT LEAST k+1”, new | |
| 3306 | Count of Substrings Containing Every Vowel and K Consonants II | Python | O(n) | O(1) | Medium | two pointers, SAME “AT LEAST k MINUS AT LEAST k+1” TRICK, AT 2*10^5 SCALE, new | |
| 3318 | Find X-Sum of All K-Long Subarrays I | Python | O(n * k log k) | O(k) | Easy | two pointers, n <= 50 — RECOUNT EACH WINDOW AND RANK BY (COUNT, VALUE), new | |
| 3321 | Find X-Sum of All K-Long Subarrays II | Python | O(n log n) | O(n) | Hard | two pointers, TWO HEAPS STRADDLING THE “TOP x” CUT, WITH LAZY DELETION, new | |
| 3325 | Count Substrings With K-Frequency Characters I | Python | O(n) | O(1) (26 counters) | Medium | two pointers, SLIDING WINDOW — “SOME CHARACTER HITS k” ONLY GETS EASIER AS THE WINDOW GROWS, new | |
| 3346 | Maximum Frequency of an Element After Performing Operations I | Python | O(n log n) | O(n) | Medium | two pointers, FIX THE TARGET VALUE — THEN IT IS “ALREADY THERE” PLUS “CAN BE NUDGED”, new | |
| 3347 | Maximum Frequency of an Element After Performing Operations II | Python | O(n log n) | O(n) | Hard | two pointers, SAME CANDIDATE ARGUMENT AS LC 3346 — THE VALUES JUST GET BIGGER, new | |
| 3364 | Minimum Positive Sum Subarray | Python | O(n^2) | O(1) | Easy | two pointers, n <= 100 — ENUMERATE EVERY SUBARRAY IN THE LENGTH RANGE, new | |
| 3413 | Maximum Coins From K Consecutive Bags | Python | O(n log n) | O(n) | Medium | two pointers, THE BEST WINDOW ALWAYS TOUCHES A SEGMENT EDGE — SLIDE TWICE, new | |
| 3420 | Count Non-Decreasing Subarrays After K Operations | Python | O(n) | O(n) | Hard | two pointers, SLIDING WINDOW OVER A RUNNING-MAXIMUM STAIRCASE, new | |
| 3422 | Minimum Operations to Make Subarray Elements Equal | Python | O(n log n) | O(n) | Medium | two pointers, 🔒, SLIDING WINDOW MEDIAN VIA TWO FENWICK TREES, new | |
| 3425 | Longest Special Path | Python | O(n) | O(n) | Hard | two pointers, DFS CARRYING A SLIDING WINDOW ALONG THE ROOT PATH, new | |
| 3430 | Maximum and Minimum Sums of at Most Size K Subarrays | Python | O(n) | O(n) | Hard | two pointers, CONTRIBUTION BY MONOTONIC STACK, WITH A LATTICE-COUNT FOR THE LENGTH CAP, new | |
| 3439 | Reschedule Meetings for Maximum Free Time I | Python | O(n) | O(n) | Medium | two pointers, THE MEETINGS ARE JUST SPACERS — SLIDE A WINDOW OVER THE GAPS, new | |
| 3445 | Maximum Difference Between Even and Odd Frequency II | Python | O(20 * n) | O(n) | Hard | two pointers, PREFIX COUNTS + PARITY BUCKETS, WITH A SECOND POINTER FOR “NON-ZERO”, new | |
| 3555 | Smallest Subarray to Sort in Every Sliding Window | Python | O(n * k) | O(k) | Medium | two pointers, 🔒, PER WINDOW, PEEL OFF THE ALREADY-SETTLED PREFIX AND SUFFIX, new | |
| 3567 | Minimum Absolute Difference in Sliding Submatrix | Python | O(m * n * k^2 * log(k^2)) | O(k^2) | Medium | two pointers, BRUTE FORCE PER WINDOW + SORT THE DISTINCT VALUES, new | |
| 3584 | Maximum Product of First and Last Elements of a Subsequence | Python | O(n) | O(1) | Medium | two pointers, ONLY THE TWO ENDPOINTS MATTER, SO SLIDE A GAP OF m-1, new | |
| 3589 | Count Prime-Gap Balanced Subarrays | Python | O(n log log max + n) | O(max) | Medium | two pointers, TWO OPPOSING BOUNDS ON THE LEFT ENDPOINT, FOR EACH RIGHT ENDPOINT, new | |
| 3634 | Minimum Removals to Balance Array | Python | O(n log n) | O(1) beyond the sort | Medium | two pointers, SORT + SLIDING WINDOW (KEEP THE LONGEST BALANCED WINDOW), new | |
| 3640 | Trionic Array II | Python | O(n) | O(1) | Hard | two pointers, LINEAR DP OVER THE THREE PHASES (UP -> DOWN -> UP), new | |
| 3641 | Longest Semi-Repeating Subarray | Python | O(n) | O(n) | Medium | two pointers, 🔒, SLIDING WINDOW ON THE NUMBER OF DISTINCT VALUES THAT REPEAT, new | |
| 3649 | Number of Perfect Pairs | Python | O(n log n) | O(n) | Medium | two pointers, SIGNS CANCEL — THE CONDITION IS JUST max|.| <= 2 * min|.|, new | |
| 3652 | Best Time to Buy and Sell Stock using Strategy | Python | O(n) | O(n) | Medium | two pointers, PREFIX SUMS OF strategy*prices AND OF prices, new | |
| 3672 | Sum of Weighted Modes in Subarrays | Python | O(n log n) | O(n) | Medium | two pointers, 🔒, SLIDING WINDOW + BUCKETS-BY-FREQUENCY WITH LAZY HEAPS, new | |
| 3679 | Minimum Discards to Balance Inventory | Python | O(n) | O(n) | Medium | two pointers, THE RULE IS FORCED, SO SIMULATE A SLIDING WINDOW OF KEPT ITEMS, new |