868 |
Transpose Matrix |
[ Solution ] |
867 |
Prime Palindrome |
[ Fast Primality Test ] |
866 |
Smallest Subtree with All the Deepest Nodes |
[ Tree-DP ] |
865 |
Shortest Path to Get All Keys |
[ SPFA ] |
863 |
All Nodes Distance K in Binary Tree |
[ DFS ] |
862 |
Shortest Subarray with Sum at Least K |
[ Augmented-BST ] |
861 |
Score After Flipping Matrix |
[ Greedy+Math ] |
860 |
Lemonade Change |
[ Greedy ] |
859 |
Buddy Strings |
[ Solution ] |
856 |
Score of Parentheses |
[ Divide-and-conquer ] |
855 |
Exam Room |
[ TreeSet + PriorityQueue ] |
853 |
Car Fleet |
[ Math ] |
852 |
Peak Index in a Mountain Array |
[ Binary Search ] |
851 |
Loud and Rich |
[ DAG ] |
850 |
Rectangle Area II |
[ Rectangle Cutting | Index Compressing ] |
849 |
Maximize Distance to Closest Person |
[ Solution ] |
848 |
Shifting Letters |
[ Suffix-sum ] |
847 |
Shortest Path Visiting All Nodes |
[ Hamiltonian-path ] |
846 |
Hand of Straights |
[ Solution ] |
845 |
Longest Mountain in Array |
[ Solution ] |
844 |
Backspace String Compare |
[ Solution ] |
843 |
Guess the Word |
[ Min-max Greedy ] |
842 |
Split Array into Fibonacci Sequence |
[ Brute-force ] |
841 |
Keys and Rooms |
[ DFS ] |
840 |
Magic Squares in Grid |
[ Solution ] |
838 |
Push Dominoes |
[ Solution ] |
837 |
Sliding Window |
[ DP + Sliding Window ] |
836 |
Rectangle Overlap |
[ Solution ] |
835 |
Image Overlap |
[ Math ] |
834 |
Sum of Distances in Tree |
[ Tree DP ] |
833 |
Find and replace in String |
[ Solution ] |
832 |
Flipping an Image |
[ Solution ] |
831 |
Masking Personal Information |
[ Solution ] |
830 |
Positions of Large Groups |
[ Solution ] |
829 |
Consecutive Numbers Sum |
[ Math ] |
828 |
Unique Number String |
[ Counting ] |
827 |
Making a Large Island |
[ Union-Find Set ] |
826 |
Most Profit Assigning Work |
[ Greedy | BIT ] |
825 |
Friends of Appropriate Ages |
[ Solution ] |
824 |
Goat Latin |
[ Solution ] |
823 |
Binary Trees with Factors |
[ DP + Two-pointers ] |
822 |
Card Flipping Game |
[ Solution ] |
821 |
Shortest Distance to a Character |
[ Brute-force | Linear-time Solution ] |
820 |
Short Encoding of Words |
[ Greedy ] |
815 |
Bus Routes |
[ BFS ] |
814 |
Binary Tree Pruning |
[ DFS ] |
813 |
Largest Sum of Averages |
[ DP ] |
812 |
Largest Triangle Area |
[ Brute-force ] |
811 |
Subdomain Visit Count |
[ HashMap ] |
810 |
Chalkboard XOR game |
[ Game Theory ] |
809 |
Expressive Words |
[ Solution ] |
808 |
Soup Servings |
[ DP + Math ] |
807 |
Max Increase to Keep City Skyline |
[ Solution ] |
806 |
Number of Lines To Write String |
[ Solution ] |
805 |
Split Array with Same Average |
[ Pruning + DP | Pruning + DFS ] |
804 |
Unique Morse Code Words |
[ Solution ] |
799 |
Champagne Tower |
[ Solution ] |
798 |
Smallest Rotation with Highest Score |
[ Sliding Window ] |
797 |
All Paths from Source to Target |
[ Backtracking ] |
796 |
Rotate String |
[ Solution ] |
795 |
Number of Subarrays with Bounded Maximum |
[ Divide-and-Conquer | O(n)-time Solution ] |
794 |
Valid Tic-Tac-Toe State |
[ Solution ] |
793 |
Preimage Size of Factorial Zeroes Function |
[ Binary Search + Math ] |
792 |
Number of Matching Subsequences |
[ Linear-time Solution ] |
791 |
Custom Sort String |
[ Quick-sort | Counting-sort ] |
790 |
Domino and Tromino Tiling |
[ DP ] |
789 |
Escape the Ghosts |
[ Math ] |
788 |
Rotated Digits |
[ Solution ] |
787 |
Cheapest Flights Within K Stops |
[ DP ] |
786 |
K-th Smallest Prime Fraction |
[ Partition | Young Tableau ] |
785 |
Is Graph Bipartite? |
[ DFS ] |
784 |
Letter Case Permutation |
[ Solution ] |
783 |
Minimum Distance Between BST Nodes |
[ In-order Traversal ] |
781 |
Rabbits in Forest |
[ Math ] |
780 |
Reaching Points |
[ Math ] |
779 |
K-th Symbol in Grammar |
[ Recursion ] |
778 |
Swim in Rising Water |
[ Binary Search + DFS | Dijkstra ] |
777 |
Swap Adjacent in LR String |
[ Greedy ] |
776 |
Split BST |
[ Recursion ] |
775 |
Global and Local Inversions |
[ BIT ] |
774 |
Minimize Max Distance to Gas Station |
[ Binary Search ] |
773 |
Sliding Puzzle |
[ BFS ] |
771 |
Jewels and Stones |
[ Solution ] |
769 |
Max Chunks To Make Sorted |
[ Greedy ] |
768 |
Max Chunks To Make Sorted II |
[ Greedy | HashMap ] |
767 |
Reorganize String |
[ Greedy ] |
766 |
Toeplitz Matrix |
[ Solution ] |
761 |
Special Binary String |
[ Greedy + Stack ] |
760 |
Find Anagram Mappings |
[ Solution ] |
759 |
Employee Free Time |
[ Segment Tree ] |
758 |
Bold Words in String |
[ Greedy ] |
757 |
Set Intersection Size At Least Two |
[ Sweepline + Greedy ] |
756 |
Pyramid Transition Matrix |
[ DP ] |
755 |
Pour Water |
[ Solution ] |
754 |
Reach a Number |
[ Math ] |
753 |
Cracking the Safe |
[ Eulerian Circuit ] |
752 |
Open the Lock |
[ BFS ] |
751 |
IP to CIDR |
[ Greedy + Bit Manipulation ] |
750 |
Number of Corner Rectangles |
[ Solution ] |
749 |
Contain Virus |
[ DFS ] |
748 |
Shortest Completing Word |
[ Solution ] |
747 |
Largest Number Greater Than Twice of Others |
[ Solution ] |
746 |
Min Cost Climbing Stairs |
[ DP ] |
745 |
Prefix and Suffix Search |
[ Solution1 | Solution2 ] |
744 |
Find Smallest Letter Greater Than Target |
[ Solution ] |
743 |
Network Delay Time |
[ Floyd | SPFA ] |
742 |
Closest Leaf in a Binary Tree |
[ DFS ] |
741 |
Cherry Pickup |
[ DP ] |
740 |
Delete and Earn |
[ DP ] |
739 |
Daily Temperatures |
[ Stack ] |
738 |
Monotone Increasing Digits |
[ Greedy ] |
737 |
Sentence Similarity II |
[ Union-find Set ] |
736 |
Parse Lisp Expression |
[ Parser ] |
735 |
Asteroid Collision |
[ Stack ] |
734 |
Sentence Similarity |
[ Solution ] |
733 |
Flood Fill |
[ DFS ] |
731 |
My Calendar II |
[ Sweepline | Segment Tree ] |
730 |
Count Different Palindromic Subsequences |
[ DP ] |
729 |
My Calendar I |
[ Sweepline | Segment Tree ] |
728 |
Self Dividing Numbers |
[ Solution ] |
727 |
Minimum Window Subsequence |
[ DP ] |
726 |
Number of Atoms |
[ LL-Parser | Python Solution | Non-recursive Solution ] |
725 |
Split Linked List in Parts |
[ Greedy ] |
724 |
Find Pivot Index |
[ Prefix-Sum ] |
723 |
Candy Crush |
[ Solution ] |
722 |
Remove Comments |
[ Solution ] |
721 |
Accounts Merge |
[ Disjoint Set + Hashset ] |
720 |
Longest Word in Dictionary |
[ Sorting + DP ] |
719 |
Find K-th Smallest Pair Distance |
[ Binary Search + Sliding Window ] |
718 |
Maximum Length of Repeated Subarray |
[ DP | Binary Search + Rolling Hash ] |
717 |
1-bit and 2-bit Characters |
[ Solution ] |
715 |
Range Module |
[ O(n log q)-time Solution via Dynamic Segment Tree ] |
714 |
Best Time to Buy and Sell Stock with Transaction Fee |
[ O(n)-time DP ] |
713 |
Subarray Product Less Than K |
[ O(n)-time sliding window ] |
712 |
Minimum ASCII Delete Sum for Two Strings |
[ DP ] |
699 |
Falling Squares |
[ Simple O(n^2)-time Solution | O(n log n)-time Solution via Segment Tree ] |
698 |
Partition to K Equal Sum Subsets |
[ Bit-DP ] |
697 |
Degree of an Array |
[ HashMap ] |
696 |
Count Binary Substrings |
[ DP | Linear Scan ] |
695 |
Max Area of Island |
[ DFS ] |
694 |
Number of Distinct Islands |
[ DFS + Sorting + Hashing ] |
693 |
Binary Number with Alternating Bits |
[ Solution ] |
693 |
Stickers to Spell Word |
[ DP + Optimization ] |
689 |
Maximum Sum of 3 Non-overlapping Subarrays |
[ DP + Solution Finding ] |
688 |
Knight Probability in Chessboard |
[ DP ] |
687 |
Longest Univalue Path |
[ Tree-DP ] |
686 |
Repeated String Match |
[ Brute-force | KMP ] |
685 |
Redundant Connection II |
[ DFS ] |
683 |
K Empty Slots |
[ BST ] |
682 |
Baseball Game |
[ Implementation ] |
681 |
Next Closest Time |
[ Brute-force ] |
680 |
Valid Palindrome II |
[ Greedy ] |
679 |
24 Game |
[ Backtracking ] |
678 |
Valid Parenthesis String |
[ DP ] |
677 |
Map Sum Pairs |
[ Trie ] |
676 |
Implement Magic Dictionary |
[ Brute-force | Trie + Fuzzy Search ] |
675 |
Cut Off Trees for Golf Event |
[ BFS ] |
674 |
Longest Continuous Increasing Subsequence |
[ O(n)-time Solution ] |
673 |
Number of Longest Increasing Subsequence |
[ O(n^2)-time DP | O(n log n)-time DP via Treap ] |
672 |
Bulb Switcher II |
[ Brute-force + Math ] |
671 |
Second Minimum Node in a Binary Tree |
[ DFS ] |
670 |
Maximum Swap |
[ Brute-force ] |
669 |
Trim a Binary Search Tree |
[ DFS ] |
668 |
Kth Smallest Number in Multiplication Table |
[ Binary Search ] |
667 |
Beautiful Arrangement II |
[ Constructive Approach ] |
666 |
Path Sum IV |
[ DFS ] |
665 |
Non-decreasing Array |
[ Greedy ] |
664 |
Strange Printer |
[ DP ] |
663 |
Equal Tree Partition |
[ DFS ] |
662 |
Maximum Width of Binary Tree |
[ DFS "Solution" | BFS Solution ] |
661 |
Image Smoother |
[ Solution ] |
660 |
Remove 9 |
[ Base-9 ] |
656 |
Coin Path |
[ DP + Printing Solution ] |
655 |
Print Binary Tree |
[ DFS + Math ] |
654 |
Maximum Binary Tree |
[ DFS ] |
653 |
Two Sum IV - Input is a BST |
[ Solution ] |
652 |
Find Duplicate Subtrees |
[ Tree-DP | Tree Encoding ] |
651 |
4 Keys Keyboard |
[ DP ] |
650 |
2 Keys Keyboard |
[ O(n log n)-time DP ] |
649 |
Dota2 Senate |
[ Greedy + Queue ] |
648 |
Replace Words |
[ Trie ] |
647 |
Palindromic Substrings |
[ DP ] |
646 |
Maximum Length of Pair Chain |
[ Sweepline ] |
645 |
Set Mismatch |
[ Counting Sort ] |
644 |
Maximum Average Subarray II |
[ Binary Search + Sliding Window ] |
643 |
Maximum Average Subarray I |
[ Sliding Window ] |
642 |
Design Search Autocomplete System |
[ Brute-force | Trie ] |
640 |
Solve the Equation |
[ Parser ] |
639 |
Decode Ways II |
[ Counting ] |
638 |
Shopping Offers |
[ DP | Search + Pruning ] |
637 |
Average of Levels in Binary Tree |
[ DFS ] |
636 |
Exclusive Time of Functions |
[ Stack ] |
635 |
Design Log Storage System |
[ Brute-force + Lexicographical Order ] |
634 |
Find the Derangement of an Array |
[ Combinatorics ] |
633 |
Sum of Square Numbers |
[ Solution | Another Solution ] |
632 |
Smallest Range |
[ Greedy + BST ] |
631 |
Design Excel Sum Formula |
[ DAG + Implementation ] |
630 |
Course Schedule III |
[ Sweep Line + Greedy ] |
629 |
K Inverse Pairs Array |
[ Counting ] |
628 |
Maximum Product of Three Numbers |
[ Math ] |
625 |
Minimum Factorization |
[ Greedy | DP ] |
624 |
Maximum Distance in Arrays |
[ Solution ] |
623 |
Add One Row to Tree |
[ DFS ] |
621 |
Task Scheduler |
[ Simulation + Greedy ] |
617 |
Merge Two Binary Trees |
[ DFS ] |
616 |
Add Bold Tag in String |
[ O(1000^2)-time Solution ] |
611 |
Valid Triangle Number |
[ Three-sum ] |
609 |
Find Duplicate File in System |
[ Solution ] |
606 |
Construct String from Binary Tree |
[ DFS ] |
605 |
Can Place Flowers |
[ Greedy ] |
604 |
Design Compressed String Iterator |
[ Lazy Solution ] |
600 |
Non-negative Integers without Consecutive Ones |
[ Counting | Digit-DP ] |
599 |
Minimum Index Sum of Two Lists |
[ Brute-force ] |
598 |
Range Addition II |
[ Solution ] |
594 |
Longest Harmonious Subsequence |
[ Brute-force ] |
593 |
Valid Square |
[ Elegant Solution ] |
592 |
Fraction Addition and Subtraction |
[ Solution ] |
591 |
Tag Validator |
[ Recursive Solution ] |
588 |
Design In-memory File System |
[ Trie ] |
583 |
Delete Operation for Two Strings |
[ LCS ] |
582 |
Kill Process |
[ Tree Traversal | Union-find-set-like Solution ] |
581 |
Shortest Unsorted Continuous Subarray |
[ Sorting ] |
576 |
Out of Boundary Paths |
[ DP ] |
575 |
Distribute Candies |
[ Greedy ] |
573 |
Squirrel Simulation |
[ Greedy ] |
572 |
Subtree of Another Tree |
[ O(n^2)-time Brute-force | O(n)-time Solution | Tree Encoding ] |
568 |
Maximum Vacation Days |
[ DP ] |
567 |
Permutation in String |
[ Sliding-window ] |
566 |
Reshape the Matrix |
[ Brute-force ] |
565 |
Array Nesting |
[ Solution ] |
564 |
Find the Closest Palindrome |
[ Greedy ] |
563 |
Binary Tree Tilt |
[ DFS ] |
562 |
Longest Line of Consecutive One in Matrix |
[ Brute-force ] |
561 |
Array Partition I |
[ Greedy ] |
560 |
Subarray Sum Equals K |
[ Prefix-sum ] |
555 |
Split Assembled Strings |
[ Brute-force ] |
553 |
Optimal Division |
[ Greedy ] |
552 |
Student Attendance Record II |
[ Counting | More Elegant Solution | O(log n)-time Solution | O(log n)-time Solution with Shorter Code ] |
551 |
Student Attendance Record I |
[ 1-Liner ] |
546 |
Remove Boxes |
[ O(n^4)-time DP ] |
545 |
Boundary of Binary Tree |
[ (Careful) Tree Traversal ] |
544 |
Output Contest Matches |
[ Brute-force | O(n)-time Solution ] |
543 |
Diameter of Binary Tree |
[ DP ] |
542 |
01 Matrix |
[ BFS ] |
541 |
Reverse String II |
[ Brute-force ] |
540 |
Single Element in a Sorted Array |
[ Binary Search ] |
539 |
Minimum Time Difference |
[ Sorting ] |
538 |
Convert BST to Greater Tree |
[ Right-root-left-traversal ] |
537 |
Complex Number Multiplication |
[ Brute-force ] |
536 |
Construct Binary Tree from String |
[ LL(1)-parser ] |
533 |
Lonely Pixel II |
[ Solution ] |
532 |
K-diff Pairs in an Array |
[ O(n)-time Solution | Two-pointer ] |
531 |
Lonely Pixel I |
[ Brute-force ] |
530 |
Minimum Absolute Difference in BST |
[ DFS ] |
529 |
Minesweeper |
[ DFS ] |
527 |
Word Abbreviation |
[ Brute-force ] |
526 |
Beautiful Arrangement |
[ Permutation ] |
525 |
Contiguous Array |
[ Prefix Sum | Divide-and-conquer ] |
524 |
Longest Word in Dictionary through Deleting |
[ Greedy ] |
523 |
Continuous Subarray Sum |
[ Prefix Sum ] |
520 |
Detect Capital |
[ Regex ] |
517 |
Super Washing Machines |
[ O(n)-time Solution ] |
515 |
Find Largest Value in Each Tree Row |
[ DFS ] |
514 |
Freedom Trail |
[ DP | Faster DP ] |
513 |
Find Bottom Left Tree Value |
[ DFS ] |
509 |
Most Frequent Subtree Sum |
[ Tree Traversal ] |
507 |
Perfect Number |
[ O(sqrt(n))-time Solution ] |
506 |
Relative Ranks |
[ Sorting ] |
505 |
The Maze II |
[ DFS + Pruning | A* Search | DFS + Multithreading ] |
504 |
Base 7 |
[ 1-line Solution | Conventional Method ] |
503 |
Next Greater Element II |
[ Monotone Stack ] |
502 |
IPO |
[ Greedy ] |
501 |
Find Mode in Binary Tree |
[ DFS + HashMap | O(1)-extra-space Solution ] |
500 |
Keyboard Row |
[ 1-Line Solution ] |
499 |
The Maze III |
[ A* | DFS ] |
498 |
Diagonal Traversal |
[ Sorting | Direct Approach ] |
496 |
Next Greater Element I |
[ Brute-force ] |
495 |
Teemo Attacking |
[ Sweepline ] |
494 |
Target Sum |
[ Knapsack ] |
493 |
Reverse Pairs |
[ Merge-sort | Merge-sort Shorter Code | BIT ] |
492 |
Construct the Rectangle |
[ Brute-force ] |
491 |
Increasing Subsequences |
[ Brute-force ] |
490 |
The Maze |
[ DFS ] |
488 |
Zuma Game |
[ BFS ] |
487 |
Max Consecutive Ones II |
[ O(1)-space Solution ] |
486 |
Predict the Winner |
[ DP + Game Theory | Shorter Code ] |
485 |
Max Consecutive Ones |
[ Brute-force ] |
484 |
Find Permutation |
[ Topological-sort | Constructive Approach ] |
483 |
Smallest Good Base |
[ Brute-force + Binary Search ] |
482 |
License Key Formatting |
[ Short Solution ] |
481 |
Magical String |
[ BFS ] |
480 |
Sliding Window Median |
[ Order Statistic Tree via Fenwick Tree ] |
477 |
Total Hamming Distance |
[ Bit-by-bit Counting ] |
476 |
Number Complement |
[ One-line Solution ] |
475 |
Heaters |
[ Direct Approach | Binary Search ] |
474 |
One and Zeroes |
[ 0/1-Knapsack ] |
473 |
Matchsticks to Square |
[ Backtracking ] |
472 |
Concatenated Words |
[ DP + Trie ] |
471 |
Encode String with Shortest Length |
[ DP ] |
469 |
Convex Polygon |
[ Cross Product ] |
468 |
Validate IP Address |
[ Solution ] |
467 |
Unique Substring in Wraparound String |
[ String Breaking and Encoding ] |
466 |
Count the Repetitions |
[ DP ] |
465 |
Optimal Account Balancing |
[ Subset-Sum ] |
464 |
Can I Win |
[ DP + Game Theory ] |
463 |
Island Perimeter |
[ Brute-force ] |
462 |
Minimum Moves to Equal Array Elements II |
[ Median Finding + Quick-Selection ] |
461 |
Hamming Distance |
[ Brute-force ] |
459 |
Repeated Substring Pattern |
[ O(n^1.5) Solution | 1-Liner | 1-Liner via Regex | Miller-Rabin | KMP ] |
456 |
123 Pattern |
[ O(n log n) Solution via BST ] |
455 |
Assign Cookies |
[ Greedy ] |
454 |
4Sum II |
[ HashMap ] |
453 |
Minimum Moves to Equal Array Elements |
[ Solution ] |
452 |
Minimum Number of Arrows to Burst Balloons |
[ Greedy via Sweepline ] |
451 |
Sort Characters by Frequency |
[ Counting-sort ] |
450 |
Delete Node in a BST |
[ Iterative Solution | Shorter Solution ] |
449 |
Serialize and Deserialize BST |
[ Pre-order Traversal | Optimized Version ] |
448 |
Find All Numbers Disappeared in an Array |
[ Cycle-finding ] |
447 |
Number of Boomerangs |
[ Counting via HashMap ] |
446 |
Arithmetic Slices II - Subsequence |
[ Very Fast O(n^3) DP Solution | O(n^2) DP Solution with Pruning ] |
444 |
Sequence Reconstruction |
[ Topological Sort ] |
443 |
String Compression |
[ Solution ] |
442 |
Find All Duplicates in an Array |
[ Mod Trick ] |
441 |
Arranging Coins |
[ O(1) Brute-force ] |
440 |
K-th Smallest in Lexicographical Order |
[ Counting + Greedy ] |
439 |
Ternary Expression Parser |
[ Top-down Approach ] |
438 |
Find All Anagrams in a String |
[ Sliding-window ] |
437 |
Path Sum III |
[ One-pass DFS | One-pass DFS Version 2 | Two-pass DFS ] |
436 |
Find Right Interval |
[ TreeMap ] |
435 |
Non-overlapping Intervals |
[ Greedy | Activity Selection ] |
435 |
Number of Segments in a String |
[ Regex ] |
433 |
Minimum Genetic Mutation |
[ BFS ] |
432 |
All O`one Data Structure |
[ HashMap + Doubly Circular Linked List ] |
425 |
Word Squares |
[ Backtracking + Pruning with Prefix Structure | Hueristic Backtracking + Pruning with BitSet ] |
424 |
Longest Repeating Character Replacement |
[ Binary Search | Sliding-window ] |
423 |
Reconstruct Original Digits from English |
[ Greedy ] |
422 |
Valid World Square |
[ Brute-force ] |
421 |
Maximum XOR of Two Numbers in an Array |
[ Binary Trie ] |
420 |
Strong Password Checker |
[ Stupid Solution ] |
419 |
Battleships in a Board |
[ Single-pass + In-place + No modification ] |
418 |
Sentence Screen Fitting |
[ Simulation ] |
417 |
Pacific Atlantic Water Flow |
[ Graph Reachability | DP + Vertex Contraction ] |
416 |
Partition Equal Subset Sum |
[ 0/1-Knapsack ] |
415 |
Add Strings |
[ BigInteger Addition ] |
414 |
Third Maximum Number |
[ One-pass Solution ] |
413 |
Arithmetic Slices |
[ Solution | In-place Solution ] |
412 |
Fizz Buzz |
[ Brute-force ] |
411 |
Minimum Unique Word Abbreviation |
[ Brute-force + Pruning ] |
410 |
Split Array Largest Sum |
[ Bisect + Greedy ] |
409 |
Longest Palindrome |
[ Counting ] |
408 |
Valid Word Abbreviation |
[ Brute-force ] |
407 |
Trapping Rain Water II |
[ Priority Queue | Dijkstra | SPFA ] |
406 |
Queue Reconstruction by Height |
[ Greedy + Sorting ] |
405 |
Convert a Number to Hexadecimal |
[ Bit Manipulation ] |
404 |
Sum of Left Leaves |
[ DFS ] |
403 |
Frog Jump |
[ DP ] |
402 |
Remove K Digits |
[ Greedy + Monotone Stack ] |
401 |
Binary Watch |
[ Brute-force 1 | Brute-force 2] |
400 |
Nth Digit |
[ Counting + Bisect ] |
399 |
Evaluate Division |
[ Floyed | DFS ] |
398 |
Random Pick Index |
[ Solution1 | Solution2 | Solution3 ] |
397 |
Integer Replacement |
[ BFS ] |
396 |
Rotate Fucntion |
[ Solution ] |
395 |
Longest Substring with At Least K Repeating Characters |
[ O(256N) Solution | Solution with Pruning ] |
394 |
Decode String |
[ Top-down Approach ] |
393 |
UTF-8 Validation |
[ Solution ] |
392 |
Is Subsequence |
[ Solution ] |
391 |
Perfect Rectangle |
[ Sweepline + TreeMap | Sweepline + Segment Tree ] |
390 |
Elimination Game |
[ O(log n) Math ] |
389 |
Find the Difference |
[ Solution ] |
388 |
Longest Absolute File Path |
[ Using a Stack | Recursively Solution ] |
387 |
First Unique Character in a String |
[ Brute-Force ] |
386 |
Lexicographical Numbers |
[ Using a stack | Recursive Solution ] |
385 |
Mini Parser |
[ Char-by-char Approach | Using Scanner ] |
384 |
Shuffle an Array |
[ Solution ] |
383 |
Ransom Note |
[ Solution ] |
381 |
Insert Delete GetRandom O(1) Duplicate Allowed |
[ Solution ] |
379 |
Design Phone Directory |
[ Simple Solution ] |
378 |
Kth Smallest Element in a Sorted Matrix |
[ Bisect + Young Tableau ] |
377 |
Combination Sum IV |
[ DP ] |
376 |
Wiggle Subsequence |
[ O(n) Climbing Mountain | O(n) In-place Maximal/Minimal Finding ] |
375 |
Guess Number Higher or Lower II |
[ O(n^3) DP ] |
374 |
Guess Number Higher or Lower |
[ Binary Search ] |
373 |
Find K Pairs with Smallest Sums |
[ O(k log k) Solution | O(k log(min(k, m, n)) + min(k, m, n)) Solution ] |
372 |
Super Pow |
[ Most-significant Bit -> Least-significant Bit | Least-significant Bit -> Most-significant Bit ] |
371 |
Sum of Two Integers |
[ Bit Manipulation ] |
370 |
Range Addition |
[ Fenwick Tree | Sweepline | O(n) Prefix Trick | Segment Tree ] |
369 |
Plus One Linked Listđź”’ |
|
368 |
Largest Divisible Subset |
[ DP ] |
367 |
Valid Perfect Square |
[ Binary Search ] |
366 |
Find Leaves of Binary Tree |
[ Computing Tree Height ] |
365 |
Water and Jug Problem |
[ Math ] |
364 |
Nested List Weight Sum IIđź”’ |
|
363 |
Max Sum of Rectangle No Larger Than K |
[ BST ] |
362 |
Design Hit Counter |
[ Sliding Window ] |
361 |
Bomb Enemy |
[ DP ] |
360 |
Sort Transformed Array |
[ O(n)-time Solution ] |
359 |
Logger Rate Limiter |
[ Simple Solution | Sliding Window ] |
358 |
Rearrange String k Distance Apart |
[ Greedy + Sliding Window ] |
357 |
Count Numbers with Unique Digits |
[ Product Rule ] |
356 |
Line Reflection |
[ In-place Solution ] |
355 |
Design Twitter |
[ k-way Merging ] |
354 |
Russian Doll Envelopes |
[ Longest Path | Longest Increasing Subsequence ] |
353 |
Design Snake Game |
[ Deque + HashTable ] |
352 |
Data Stream as Disjoint Intervals |
[ BST ] |
351 |
Android Unlock Patternsđź”’ |
|
350 |
Intersection of Two Arrays II |
[ Mergesort ] |
349 |
Intersection of Two Arrays |
[ Java Stream ] |
348 |
Design Tic-Tac-Toe |
[ O(1)-time Solution ] |
347 |
Top K Frequent Elements |
[ Map+QuickSelection | Map+CountingSort ] |
346 |
Moving Average from Data Stream |
[ Sliding Window ] |
345 |
Reverse Vowels of a String |
[ Two-Pointer ] |
344 |
Reverse String |
[ String ] |
343 |
Integer Break |
[ Math/DP ] |
342 |
Power of Four |
[ Bit Manipulate ] |
341 |
Flatten Nested List Iterator |
[ Stack/DFS | Lazier ] |
340 |
Longest Substring with At Most K Distinct Characters |
[ O(n) Sliding Window | O(n log n) Bisect | Slinding Window Shorter Code | Sliding Window for Streaming Data (1 pass) ] |
339 |
Nested List Weight Sum |
[ DFS ] |
338 |
Counting Bits |
[ Counting ] |
337 |
House Robber III |
[ Tree DP ] |
336 |
Palindrome Pairs |
[ A Naive Solution ] |
335 |
Self Crossing |
[ Geometry ] |
334 |
Increasing Triplet Subsequence |
[ LIS ] |
333 |
Largest BST Subtree |
[ Tree-DP ] |
332 |
Reconstruct Itinerary |
[ Euler Path ] |
331 |
Verify Preorder Serialization of a Binary Tree |
[ Using a Stack | Property of Full Binary Tree ] |
330 |
Patching Array |
[ Greedy Algorithm ] |
329 |
Longest Increasing Path in a Matrix |
[ O(nm) DP ] |
328 |
Odd Even Linked List |
[ O(n) in-place ] |
327 |
Count of Range Sum |
[ O(n log n) solution via Fenwick Tree ] |
326 |
Power of Three |
[ An interesting O(log log n) solution ] |
325 |
Maximum Size Subarray Sum Equals k |
[ Prefix-sum + HashTable ] |
324 |
Wiggle Sort II |
[ Median Finding, Dutch National Flag ] |
323 |
Number of Connected Components in an Undirected Graph |
[ DFS ] |
322 |
Coin Change |
[ Knapsack ] |
321 |
Create Maximum Number |
[ Stack + Greedy ] |
320 |
Generalized Abbreviation |
[ Bit-manipulation ] |
319 |
Bulb Switcher |
[ O(1) Math ] |
318 |
Maximum Product of Word Lengths |
[ O(n^2) brute-force ] |
317 |
Shortest Distance from All Buildings |
[ BFS ] |
316 |
Remove Duplicate Letters |
[ O(n) Greedy Solution | O(n) Solution via Stack ] |
315 |
Count of Small Numbers After Self |
[ Discretization + Fenwick Tree | Mergesort ] |
314 |
Binary Tree Vertical Order TGraversal |
[ BFS | BFS (slower, but shorter) ] |
313 |
Super Ugly Number |
[ O(nk) Constructive Algorithm ] |
312 |
Burst Balloons |
[ O(n^3) DP ] |
311 |
Sparse Matrix Multiplicationđź”’ |
|
310 |
Minimum Height Trees |
[ Longest Path in Tree | Tree DP ] |
309 |
Best Time to Buy and Sell Stock with Cooldown |
[ O(n^2) DP | O(n) DP ] |
308 |
Range Sum Query 2D - Mutable |
[ 2D-Sqrt Partition | 2D Fenwick Tree ] |
307 |
Range Sum Query - Mutable |
[ sqrt(n) Trick | Fenwick Tree | Segment Tree ] |
306 |
Additive Number |
[ Fibonacci Sequence ] |
305 |
Number of Islands II |
[ Union-Find Set ] |
304 |
Range Sum Query 2D - Immutable |
[ Inclusion-Exclusion ] |
303 |
Range Sum Query - Immutable |
[ Prefix Sum ] |
302 |
Smallest Rectangle Enclosing Black Pixels |
[ DFS ] |
301 |
Remove Invalid Parentheses |
[ Backtracking | DP ] |
298 |
Binary Tree Longest Consecutive Sequence |
[ Tree-DP | DFS | Another DFS Solution] |
297 |
Serialize and Deserialize Binary Tree |
[ DFS ] |
294 |
Flip Game II |
[ Nim + Sprague-Grundy Theorem ] |
293 |
Flip Game |
[ Brute-force ] |
291 |
Word Pattern II |
[ Backtracking | Backtracking + Pruning ] |
289 |
Game of Life |
[ In-place Solution | Infinite Board ] |
288 |
Unique Word Abbreviation |
[ HashMap ] |
286 |
Walls and Gates |
[ BFS] |
285 |
Inorder Successor in BST |
[ Top-down Approach | Using Parent Pointers ] |
283 |
Move Zeroes |
[ Partition | Cheating ] |
281 |
Zigzag Iterator |
[ Solution ] |
280 |
Wiggle Sort |
[ One-pass Solution ] |
277 |
Find the Celebrity |
[ Universal Sink ] |
276 |
Paint Fence |
[ Combinatorial ] |
274 |
H-Index |
[ Counting Sort ] |
272 |
Closest Binary Search Tree Value II |
[ Predesessor + Successor in BST ] |
271 |
Encode and Decode Strings |
[ Escaping Character | Trie Serialization/Deserialization ] |
270 |
Closest Binary Search Tree Value |
[ Solution ] |
269 |
Alien Dictionary |
[ Topological Sort (BFS) | BFS with Smaller Constant | Topological Sort (DFS)] |
267 |
Palindrome Permutation II |
[ Counting + Next Permutation ] |
266 |
Palindrome Permutation |
[ Counting ] |
265 |
Paint House II |
[ O(nk) DP ] |
262 |
Trips and Users |
[ Solution ] |
261 |
Graph Valid Tree |
[ Union-find Set ] |
259 |
3Sum Smaller |
[ Two-pointer ] |
256 |
Paint House |
[ DP ] |
255 |
Verify Preorder Sequence in Binary Search Tree |
[ Construction Method | RMQ + Binary Search ] |
254 |
Factor Combinations |
[ Backtracking ] |
253 |
Meeting Rooms II |
[ Sweepline Algorithm ] |
252 |
Meeting Rooms |
[ Sweepline ] |
251 |
Flatten 2D Vector |
[ Iterator ] |
250 |
Count Univalue Subtrees |
[ DFS ] |
249 |
Group Shifted Strings |
[ Keyed-by ] |
246 |
Strobogrammatic Number |
[ Brute-force ] |
245 |
Shortest Word Distance III |
[ Linear Scan ] |
244 |
Shortest Word Distance II |
[ Solution ] |
218 |
The Skyline Problem |
[ Sweepline | Java Code] |
214 |
Shortest Palindrome |
[ Rabin-Karp rolling hash | KMP ] |
212 |
Word Search II |
[ DP + Trie ] |
206 |
Reverse Linked List |
[ Solution ] |
197 |
Rising Temperature |
[ Solution ] |
196 |
Delete Duplicate Emails |
[ Solution ] |
186 |
Reverse Words in a String II |
[ In-place Solution ] |
184 |
Department Highest Salary |
[ Solution ] |
183 |
Customers Who Never Order |
[ Solution ] |
182 |
Duplicate Emails |
[ Solution ] |
181 |
Employees Earning More Than Their Managers |
[ Solution ] |
180 |
Consecutive Numbers |
[ Solution ] |
178 |
Rank Scores |
[ Solution ] |
177 |
Nth Highest Salary |
[ Solution ] |
176 |
Second Highest Salary |
[ Solution ] |
175 |
Combine Two Tables |
[ Solution ] |
170 |
Two Sum III - Data structure design |
[ Hash Table ] |
167 |
Two Sum II - Input array is sorted |
[ Two-pointer ] |
165 |
Compare version Numbers |
[ Lexicographical Order ] |
163 |
Missing Ranges |
[ Sorting ] |
161 |
One Edit Distance |
[ Short Java Code ] |
159 |
Longest Substring with At Most Two Distinct Characters |
[ Sliding-window ] |
158 |
Read N Characters Given Read4 II - Call multiple times |
[ Reader ] |
157 |
Read N Characters Given Read4 |
[ Reader ] |
156 |
Binary Tree Upside Down |
[ Post-order Traversal ] |
155 |
Min Stack |
[ More Memory, Shorter Code | As Little Memory as Possible ] |
151 |
Reverse Words in a String |
[ Java Solution | C In-place Solution ] |
146 |
LRU Cache |
[ Doubly Connected Linked List + Hash Table ] |
140 |
Word Break II |
[ DP + DFS ] |
139 |
Word Break |
[ Short DP | DP + Trie ] |
136 |
Single Number |
[ Xor | Randomized Partition ] |
128 |
Longest Consecutive Sequence |
[ O(n) HashSet ] |
127 |
Word Ladder |
[ BFS ] |
96 |
Unique Binary Search Trees |
[ DP ] |
79 |
Word Search |
[ DFS ] |
76 |
Minimum Window Substring |
[ Sliding-window ] |
72 |
Edit Distance |
[ DP ] |
47 |
Permutations II |
[ next_permutation ] |
44 |
Wildcard Matching |
[ DP | Greedy ] |
40 |
Combination Sum II |
[ DP Knapsack ] |
39 |
Combination Sum |
[ DP + Backtracking ] |
37 |
Sudoku Solver |
[ Greedy Backtracking Using Bitmask | Greedy Backtracking ] |
36 |
Valid Sudoku |
[ Solution ] |
22 |
Generate Parentheses |
[ DP | Recursion ] |
10 |
Regular Expression Matching |
[ DP ] |
4 |
Median of Two Sorted Arrays |
[ Binary Search ] |
2 |
Add Two Numbers |
[ Not in-place | In-place ] |
1 |
Two Sum |
[ Two Pointers | Hash Table ] |