Skip to content

:octocat: (Weekly Update) Python / Modern C++ Solutions of All 1643 LeetCode Problems

License

Notifications You must be signed in to change notification settings

amanchadha/LeetCode-Solutions

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

LanguageΒ  LicenseΒ  UpdateΒ  ProgressΒ  TravisΒ  Visitors

  • R.I.P. to my old Leetcode repository, where there were 5.7k+ stars and 2.2k+ forks (ever the top 3 in the field).
  • Since free questions may be even mistakenly taken down by some companies, only solutions will be post on now.
  • There are new LeetCode questions every week. I'll keep updating for full summary and better solutions.
  • For more problem solutions, you can see my LintCode repository.
  • For more challenging problem solutions, you can also see my GoogleCodeJam, FacebookHackerCup repositories.
  • Hope you enjoy the journey of learning data structures and algorithms.
  • Notes: "πŸ”’" means your subscription of LeetCode premium membership is required for reading the question.

Algorithms

Database

Shell

Reference

Bit Manipulation

# Title Solution Time Space Difficulty Tag Note
0136 Single Number C++ Python O(n) O(1) Easy
0137 Single Number II C++ Python O(n) O(1) Medium
0190 Reverse Bits C++ Python O(1) O(1) Easy
0191 Number of 1 Bits C++ Python O(1) O(1) Easy
0201 Bitwise AND of Numbers Range C++ Python O(1) O(1) Medium
0231 Power of Two C++ Python O(1) O(1) Easy LintCode
0260 Single Number III C++ Python O(n) O(1) Medium
0268 Missing Number C++ Python O(n) O(1) Medium LintCode
0318 Maximum Product of Word Lengths C++ Python O(n) ~ O(n^2) O(n) Medium Bit Manipulation, Counting Sort, Pruning
0342 Power of Four C++ Python O(1) O(1) Easy
0371 Sum of Two Integers C++ Python O(1) O(1) Easy LintCode
0389 Find the Difference C++ Python O(n) O(1) Easy
0393 UTF-8 Validation C++ Python O(n) O(1) Medium
0401 Binary Watch C++ Python O(1) O(1) Easy
0411 Minimum Unique Word Abbreviation C++ Python O((d + n) * 2^n) O(d) Hard πŸ”’
0421 Maximum XOR of Two Numbers in an Array C++ Python O(n) O(n) Medium
0461 Hamming Distance C++ Python O(1) O(1) Easy
0477 Total Hamming Distance C++ Python O(n) O(1) Medium
0645 Set Mismatch C++ Python O(n) O(1) Easy
0693 Binary Number with Alternating Bits C++ Python O(1) O(1) Easy
0762 Prime Number of Set Bits in Binary Representation C++ Python O(1) O(1) Easy
0868 Binary Gap C++ Python O(1) O(1) Easy
0898 Bitwise ORs of Subarrays C++ Python O(n) O(1) Medium
1310 XOR Queries of a Subarray C++ Python O(n) O(1) Medium
1318 Minimum Flips to Make a OR b Equal to c C++ Python O(1) O(1) Medium
1342 Number of Steps to Reduce a Number to Zero C++ Python O(logn) O(1) Easy
1558 Minimum Numbers of Function Calls to Make Target Array C++ Python O(nlogn) O(1) Medium Greedy


Array

# Title Solution Time Space Difficulty Tag Note
0026 Remove Duplicates from Sorted Array C++ Python O(n) O(1) Easy Two Pointers
0027 Remove Element C++ Python O(n) O(1) Easy
0031 Next Permutation C++ Python O(n) O(1) Medium Tricky
0041 First Missing Positive C++ Python O(n) O(1) Hard Tricky
0048 Rotate Image C++ Python O(n^2) O(1) Medium
0054 Spiral Matrix C++ Python O(m * n) O(1) Medium
0059 Spiral Matrix II C++ Python O(n^2) O(1) Medium
0066 Plus One C++ Python O(n) O(1) Easy
0073 Set Matrix Zeroes C++ Python O(m * n) O(1) Medium
0080 Remove Duplicates from Sorted Array II C++ Python O(n) O(1) Medium Two Pointers
0118 Pascal's Triangle C++ Python O(n^2) O(1) Easy
0119 Pascal's Triangle II C++ Python O(n^2) O(1) Easy
0121 Best Time to Buy and Sell Stock C++ Python O(n) O(1) Easy
0128 Longest Consecutive Sequence C++ Python O(n) O(n) Hard Tricky
0157 Read N Characters Given Read4 C++ Python O(n) O(1) Easy πŸ”’
0158 Read N Characters Given Read4 II - Call multiple times C++ Python O(n) O(1) Hard πŸ”’
0163 Missing Ranges C++ Python O(n) O(1) Medium πŸ”’
0169 Majority Element C++ Python O(n) O(1) Easy Boyer–Moore Majority Vote Algorithm
0189 Rotate Array C++ Python O(n) O(1) Easy
0215 Kth Largest Element in an Array C++ Python O(n) on average O(1) Medium EPI Quick Select, Tri Partition
0228 Summary Ranges C++ Python O(n) O(1) Medium
0229 Majority Element II C++ Python O(n) O(1) Medium
0238 Product of Array Except Self C++ Python O(n) O(1) Medium LintCode
0240 Search a 2D Matrix II C++ Python O(m + n) O(1) Medium EPI, LintCode
0243 Shortest Word Distance C++ Python O(n) O(1) Easy πŸ”’
0245 Shortest Word Distance III C++ Python O(n) O(1) Medium πŸ”’
0251 Flatten 2D Vector C++ Python O(1) O(1) Medium πŸ”’
0277 Find the Celebrity C++ Python O(n) O(1) Medium πŸ”’, EPI
0289 Game of Life C++ Python O(m * n) O(1) Medium
0293 Flip Game C++ Python O(n * (c+1)) O(1) Easy πŸ”’
0296 Best Meeting Point C++ Python O(m * n) O(m + n) Hard πŸ”’
0311 Sparse Matrix Multiplication C++ Python O(m * n * l) O(m * l) Medium πŸ”’
0334 Increasing Triplet Subsequence C++ Python O(n) O(1) Medium
0370 Range Addition C++ Python O(k + n) O(1) Medium πŸ”’
0384 Shuffle an Array C++ Python O(n) O(n) Medium EPI
0396 Rotate Function C++ Python O(n) O(1) Easy
0412 Fizz Buzz C++ Python O(n) O(1) Easy
0414 Third Maximum Number C++ Python O(n) O(1) Easy
0419 Battleships in a Board C++ Python O(m * n) O(1) Medium
0422 Valid Word Square C++ Python O(m * n) O(1) Easy πŸ”’
0442 Find All Duplicates in an Array C++ Python O(n) O(1) Medium
0448 Find All Numbers Disappeared in an Array C++ Python O(n) O(1) Easy
0462 Minimum Moves to Equal Array Elements II C++ Python O(n) on average O(1) Medium Quick Select
0531 Lonely Pixel I C++ Python O(m * n) O(m + n) Medium πŸ”’
0533 Lonely Pixel II C++ Python O(m * n) O(m * n) Medium πŸ”’
0565 Array Nesting C++ Python O(n) O(1) Medium
0566 Reshape the Matrix C++ Python O(m * n) O(m * n) Easy
0581 Shortest Unsorted Continuous Subarray C++ Python O(n) O(1) Easy
0605 Can Place Flowers C++ Python O(n) O(1) Easy
0624 Maximum Distance in Arrays C++ Python O(n) O(1) Easy πŸ”’
0643 Maximum Average Subarray I C++ Python O(n) O(1) Easy Math
0644 Maximum Average Subarray II C++ Python O(n) O(n) Hard πŸ”’ Math
0661 Image Smoother C++ Python O(m * n) O(1) Easy
0665 Non-decreasing Array C++ Python O(n) O(1) Easy
0667 Beautiful Arrangement II C++ Python O(n) O(1) Medium
0670 Maximum Swap C++ Python O(logn) O(logn) Medium
0674 Longest Continuous Increasing Subsequence C++ Python O(n) O(1) Easy
0683 K Empty Slots C++ Python O(n) O(n) Hard
0697 Degree of an Array C++ Python O(n) O(n) Easy
0713 Subarray Product Less Than K C++ Python O(n) O(1) Medium
0717 1-bit and 2-bit Characters C++ Python O(n) O(1) Easy Greedy
0723 Candy Crush C++ Python O((R * C)^2) O(1) Medium
0724 Find Pivot Index C++ Python O(n) O(1) Easy
0729 My Calendar I C++ Python O(nlogn) O(n) Medium
0731 My Calendar II C++ Python O(n^2) O(n) Medium
0732 My Calendar III C++ Python O(nlogn) ~ O(n^2) O(n) Hard
0747 Largest Number At Least Twice of Others C++ Python O(n) O(1) Easy
0755 Pour Water C++ Python O(v * n) O(1) Medium
0766 Toeplitz Matrix C++ Python O(m * n) O(1) Easy
0768 Max Chunks To Make Sorted II C++ Python O(n) O(n) Hard Mono Stack
0769 Max Chunks To Make Sorted C++ Python O(n) O(1) Medium
0778 Swim in Rising Water C++ Python O(n^2) O(n^2) Hard Union Find
0792 Number of Matching Subsequences C++ Python O(n + w) O(k) Medium
0794 Valid Tic-Tac-Toe State C++ Python O(1) O(1) Medium
0795 Number of Subarrays with Bounded Maximum C++ Python O(n) O(1) Medium
0803 Bricks Falling When Hit C++ Python O(r * c) O(r * c) Hard Union Find
0807 Max Increase to Keep City Skyline C++ Python O(n^2) O(n) Medium
0821 Shortest Distance to a Character C++ Python O(n) O(1) Easy
0830 Positions of Large Groups C++ Python O(n) O(1) Easy
0832 Flipping an Image C++ Python O(n^2) O(1) Easy
0835 Image Overlap C++ Python O(n^4) O(n^2) Medium
0840 Magic Squares In Grid C++ Python O(m * n) O(1) Easy
0842 Split Array into Fibonacci Sequence C++ Python O(n^3) O(n) Medium
0845 Longest Mountain in Array C++ Python O(n) O(1) Medium
0849 Maximize Distance to Closest Person C++ Python O(n) O(1) Easy
0860 Lemonade Change C++ Python O(n) O(1) Easy
0868 Transpose Matrix C++ Python O(r * c) O(1) Easy
0885 Spiral Matrix III C++ Python O(max(m, n)^2) O(1) Medium
0888 Fair Candy Swap C++ Python O(m + n) O(m + n) Easy
0896 Monotonic Array C++ Python O(n) O(1) Easy
0905 Sort Array By Parity C++ Python O(n) O(1) Easy
0909 Snakes and Ladders C++ Python O(n^2) O(n^2) Medium
0915 Partition Array into Disjoint Intervals C++ Python O(n) O(n) Medium
0918 Maximum Sum Circular Subarray C++ Python O(n) O(1) Medium
0922 Sort Array By Parity II C++ Python O(n) O(1) Easy
0923 3Sum With Multiplicity C++ Python O(n^2) O(n) Medium
0927 Three Equal Parts C++ Python O(n) O(1) Hard
0932 Beautiful Array C++ Python O(n) O(n) Medium
0941 Valid Mountain Array C++ Python O(n) O(1) Easy
0945 Minimum Increment to Make Array Unique C++ Python O(nlogn) O(n) Medium
0947 Most Stones Removed with Same Row or Column C++ Python O(n) O(n) Medium Union Find
0949 Largest Time for Given Digits C++ Python O(1) O(1) Easy
0950 Reveal Cards In Increasing Order C++ Python O(n) O(n) Medium
0952 Largest Component Size by Common Factor C++ Python O(f * n) O(p + n) Hard Union Find
0954 Array of Doubled Pairs C++ Python O(n + klogk) O(k) Medium
0961 N-Repeated Element in Size 2N Array C++ Python O(n) O(1) Easy
0978 Longest Turbulent Subarray C++ Python O(n) O(1) Medium
0985 Sum of Even Numbers After Queries C++ Python O(n + q) O(1) Easy
0989 Add to Array-Form of Integer C++ Python O(n + logk) O(1) Easy
0997 Find the Town Judge C++ Python O(t + n) O(n) Easy
0999 Available Captures for Rook C++ Python O(1) O(1) Easy
1002 Find Common Characters C++ Python O(n * l) O(1) Easy
1007 Minimum Domino Rotations For Equal Row C++ Python O(n) O(1) Medium
1013 Pairs of Songs With Total Durations Divisible by 60 C++ Python O(n) O(1) Easy
1014 Best Sightseeing Pair C++ Python O(n) O(1) Medium
1018 Binary Prefix Divisible By 5 C++ Python O(n) O(1) Easy
1020 Partition Array Into Three Parts With Equal Sum C++ Python O(n) O(1) Easy
1030 Matrix Cells in Distance Order C++ Python O(m * n) O(1) Easy
1031 Maximum Sum of Two Non-Overlapping Subarrays C++ Python O(n) O(1) Medium
1051 Height Checker C++ Python O(nlogn) O(n) Easy
1052 Grumpy Bookstore Owner C++ Python O(n) O(1) Medium
1072 Flip Columns For Maximum Number of Equal Rows C++ Python O(m * n) O(m * n) Medium
1074 Number of Submatrices That Sum to Target C++ Python O(m^2 * n) O(n) Hard
1085 Sum of Digits in the Minimum Number C++ Python O(n * l) O(l) Easy πŸ”’
1089 Duplicate Zeros C++ Python O(n) O(1) Easy
1093 Statistics from a Large Sample C++ Python O(n) O(1) Medium
1099 Two Sum Less Than K C++ Python O(nlogn) O(1) Easy πŸ”’
1109 Corporate Flight Bookings C++ Python O(n) O(1) Medium Line Sweep
1144 Decrease Elements To Make Array Zigzag C++ Python O(n) O(1) Medium
1184 Distance Between Bus Stops C++ Python O(n) O(1) Easy
1200 Minimum Absolute Difference C++ Python O(nlogn) O(n) Easy
1222 Queens That Can Attack the King C++ Python O(1) O(1) Medium
1252 Cells with Odd Values in a Matrix C++ Python O(n + m) O(n + m) Easy
1260 Shift 2D Grid C++ Python O(n) O(1) Easy
1267 Count Servers that Communicate C++ Python O(m * n) O(m + n) Medium
1275 Find Winner on a Tic Tac Toe Game C++ Python O(1) O(1) Easy
1295 Find Numbers with Even Number of Digits C++ Python O(nlog(logm)) O(logm) Easy
1299 Replace Elements with Greatest Element on Right Side C++ Python O(n) O(1) Easy
1304 Find N Unique Integers Sum up to Zero C++ Python O(n) O(1) Easy
1313 Decompress Run-Length Encoded List C++ Python O(n) O(1) Easy
1329 Sort the Matrix Diagonally C++ Python O(m * n * log(min(m, n)) O(m * n) Medium Sort
1331 Rank Transform of an Array C++ Python O(nlogn) O(n) Easy
1333 Filter Restaurants by Vegan-Friendly, Price and Distance C++ Python O(rlogr) O(r) Medium Sort
1337 The K Weakest Rows in a Matrix C++ Python O(m * n) O(k) Easy OrderedDict, Quick Select
1343 Number of Sub-arrays of Size K and Average Greater than or Equal to Threshold C++ Python O(n) O(1) Medium
1346 Check If N and Its Double Exist C++ Python O(n) O(n) Easy
1351 Count Negative Numbers in a Sorted Matrix C++ Python O(m + n) O(1) Easy
1375 Bulb Switcher III C++ Python O(n) O(1) Medium
1380 Lucky Numbers in a Matrix C++ Python O(m * n) O(m + n) Easy
1389 Create Target Array in the Given Order C++ Python O(n^2) O(1) Easy
1394 Find Lucky Integer in an Array C++ Python O(n) O(n) Easy
1399 Count Largest Group C++ Python O(nlogn) O(n) Easy
1404 Number of Steps to Reduce a Number in Binary Representation to One C++ Python O(n) O(1) Medium
1413 Minimum Value to Get Positive Step by Step Sum C++ Python O(n) O(1) Easy
1426 Counting Elements C++ Python O(n) O(n) Easy πŸ”’
1427 Perform String Shifts C++ Python O(n + l) O(1) Easy πŸ”’
1428 Leftmost Column with at Least a One C++ Python O(m + n) O(1) Medium πŸ”’
1431 Kids With the Greatest Number of Candies C++ Python O(n) O(1) Easy
1437 Check If All 1's Are at Least Length K Places Away C++ Python O(n) O(1) Medium
1450 Number of Students Doing Homework at a Given Time C++ Python O(n) O(1) Easy
1460 Make Two Arrays Equal by Reversing Sub-arrays C++ Python O(n) O(n) Easy
1464 Maximum Product of Two Elements in an Array C++ Python O(n) O(1) Easy
1465 Maximum Area of a Piece of Cake After Horizontal and Vertical Cuts C++ Python O(hlogh + wlogw) O(1) Medium
1470 Shuffle the Array C++ Python O(n) O(1) Easy
1471 The k Strongest Values in an Array C++ Python O(n) O(1) Medium Quick Select
1475 Final Prices With a Special Discount in a Shop C++ Python O(n) O(n) Easy Mono Stack
1480 Running Sum of 1d Array C++ Python O(n) O(1) Easy
1491 Average Salary Excluding the Minimum and Maximum Salary C++ Python O(n) O(1) Easy
1502 Can Make Arithmetic Progression From Sequence C++ Python O(n) O(1) Easy
1503 Last Moment Before All Ants Fall Out of a Plank C++ Python O(n) O(1) Medium
1534 Count Good Triplets C++ Python O(n^3) O(1) Easy
1535 Find the Winner of an Array Game C++ Python O(n) O(1) Medium
1538 Guess the Majority in a Hidden Array C++ Python O(n) O(1) Medium πŸ”’
1550 Three Consecutive Odds C++ Python O(n) O(1) Easy
1559 Detect Cycles in 2D Grid C++ Python O(m * n) O(m * n) Hard Union Find, BFS
1560 Most Visited Sector in a Circular Track C++ Python O(n) O(1) Easy
1562 Find Latest Group of Size M C++ Python O(n) O(n) Medium
1566 Detect Pattern of Length M Repeated K or More Times C++ Python O(n) O(1) Easy
1572 Matrix Diagonal Sum C++ Python O(n) O(1) Easy
1574 Shortest Subarray to be Removed to Make Array Sorted C++ Python O(n) O(1) Medium
1582 Special Positions in a Binary Matrix C++ Python O(n^2) O(n) Easy
1583 Count Unhappy Friends C++ Python O(n^2) O(n^2) Medium
1619 Mean of Array After Removing Some Elements C++ Python O(n) O(1) Easy Quick Select
1629 Slowest Key C++ Python O(n) O(1) Easy


String

# Title Solution Time Space Difficulty Tag Note
0005 Longest Palindromic Substring C++ Python O(n) O(n) Medium Manacher's Algorithm
0006 ZigZag Conversion C++ Python O(n) O(1) Easy
0008 String to Integer (atoi) C++ Python O(n) O(1) Easy
0014 Longest Common Prefix C++ Python O(n * k) O(1) Easy
0028 Implement strStr() C++ Python O(n + k) O(k) Easy KMP Algorithm
0038 Count and Say C++ Python O(n * 2^n) O(2^n) Easy
0043 Multiply Strings C++ Python O(m * n) O(m + n) Medium
0058 Length of Last Word C++ Python O(n) O(1) Easy
0067 Add Binary C++ Python O(n) O(1) Easy
0068 Text Justification C++ Python O(n) O(1) Hard
0125 Valid Palindrome C++ Python O(n) O(1) Easy
0151 Reverse Words in a String C++ Python O(n) O(1) Medium
0161 One Edit Distance C++ Python O(m + n) O(1) Medium πŸ”’
0165 Compare Version Numbers C++ Python O(n) O(1) Easy
0186 Reverse Words in a String II C++ Python O(n) O(1) Medium πŸ”’
0214 Shortest Palindrome C++ Python O(n) O(n) Hard KMP Algorithm Manacher's Algorithm
0242 Valid Anagram C++ Python O(n) O(1) Easy LintCode
0271 Encode and Decode Strings C++ Python O(n) O(1) Medium πŸ”’
0273 Integer to English Words C++ Python O(1) O(1) Hard
0306 Addictive Number C++ Python O(n^3) O(n) Medium
0383 Ransom Note C++ Python O(n) O(1) Easy EPI
0405 Convert a Number to Hexadecimal C++ Python O(n) O(1) Easy
0408 Valid Word Abbreviation C++ Python O(n) O(1) Easy πŸ”’
0415 Add Strings C++ Python O(n) O(1) Easy
0420 Strong Password Checker C++ Python O(n) O(1) Hard
0434 Number of Segments in a String C++ Python O(n) O(1) Easy
0443 String Compression C++ Python O(n) O(1) Easy
0459 Repeated Substring Pattern C++ Python O(n) O(n) Easy KMP Algorithm
0468 Validate IP Address C++ Python O(1) O(1) Medium
0482 License Key Formatting C++ Python O(n) O(1) Easy
0520 Detect Capital C++ Python O(l) O(1) Easy
0521 Longest Uncommon Subsequence I C++ Python O(min(a, b)) O(1) Easy
0522 Longest Uncommon Subsequence II C++ Python O(l * n^2) O(1) Medium Sort
0524 Longest Word in Dictionary through Deleting C++ Python O((d * l) * logd) O(1) Medium Sort
0527 Word Abbreviation C++ Python O(n * l) ~ O(n^2 * l^2) O(n * l) Hard πŸ”’
0539 Minimum Time Difference C++ Python O(nlogn) O(n) Medium
0541 Reverse String II C++ Python O(n) O(1) Easy
0551 Student Attendance Record I C++ Python O(n) O(1) Easy
0556 Next Greater Element III C++ Python O(1) O(1) Medium
0557 Reverse Words in a String III C++ Python O(n) O(1) Easy
0564 Find the Closest Palindrome C++ Python O(l) O(l) Hard
0591 Tag Validator C++ Python O(n) O(n) Hard
0616 Add Bold Tag in String C++ Python O(n * d * l) O(n) Medium πŸ”’
0647 Palindromic Substrings C++ Python O(n) O(n) Medium Manacher's Algorithm
0648 Replace Words C++ Python O(n) O(t) Medium Trie
0657 Robot Return to Origin C++ Python O(n) O(1) Easy
0678 Valid Parenthesis String C++ Python O(n) O(1) Medium
0680 Valid Palindrome II C++ Python O(n) O(1) Easy
0681 Next Closest Time C++ Python O(1) O(1) Medium
0686 Repeated String Match C++ Python O(n + m) O(1) Easy Rabin-Karp Algorithm
0696 Count Binary Substrings C++ Python O(n) O(1) Easy
0720 Longest Word in Dictionary C++ Python O(n) O(t) Easy Trie
0722 Remove Comments C++ Python O(n) O(k) Medium
0751 IP to CIDR C++ Python O(n) O(1) Medium
0758 Bold Words in String C++ Python O(n * l) O(t) Easy πŸ”’, variant of Add Bold Tag in String
0791 Custom Sort String C++ Python O(n) O(1) Medium
0796 Rotate String C++ Python O(n) O(1) Easy KMP Algorithm Rabin-Karp Algorithm
0804 Unique Morse Code Words C++ Python O(n) O(n) Easy
0806 Number of Lines To Write String C++ Python O(n) O(1) Easy
0809 Expressive Words C++ Python O(n + s) O(l + s) Medium
0816 Ambiguous Coordinates C++ Python O(n^4) O(n) Medium
0819 Most Common Word C++ Python O(m + n) O(m + n) Easy
0820 Short Encoding of Words C++ Python O(n) O(t) Medium Trie
0824 Goat Latin C++ Python O(n + w^2) O(l) Easy
0831 Masking Personal Information C++ Python O(1) O(1) Medium
0833 Find And Replace in String C++ Python O(n + m) O(n) Medium
0839 Similar String Groups C++ Python O(n^2 * l) O(n) Hard Union Find
0848 Shifting Letters C++ Python O(n) O(1) Medium
0859 Buddy Strings C++ Python O(n) O(1) Easy
0880 Decoded String at Index C++ Python O(n) O(1) Medium
0884 Uncommon Words from Two Sentences C++ Python O(m + n) O(m + n) Easy
0890 Find and Replace Pattern C++ Python O(n * l) O(1) Medium
0893 Groups of Special-Equivalent Strings C++ Python O(n * l) O(n) Easy
0916 Word Subsets C++ Python O(m + n) O(1) Medium
0917 Reverse Only Letters C++ Python O(n) O(1) Easy
0925 Long Pressed Name C++ Python O(n) O(1) Easy
0929 Unique Email Addresses C++ Python O(n * l) O(n * l) Easy
0939 Minimum Area Rectangle C++ Python O(n^1.5) on average O(n) Medium
0942 DI String Match C++ Python O(n) O(1) Easy
0944 Delete Columns to Make Sorted C++ Python O(n * l) O(1) Medium
0953 Verifying an Alien Dictionary C++ Python O(n * l) O(1) Easy
0955 Delete Columns to Make Sorted II C++ Python O(n * l) O(n) Medium
1016 Binary String With Substrings Representing 1 To N C++ Python O(n^2) O(1) Medium
1023 Camelcase Matching C++ Python O(n * l) O(1) Medium
1061 Lexicographically Smallest Equivalent String C++ Python O(n) O(n) Medium πŸ”’ Union Find
1056 Confusing Number C++ Python O(logn) O(logn) Easy πŸ”’
1071 Greatest Common Divisor of Strings C++ Python O(m + n) O(1) Easy
1078 Occurrences After Bigram C++ Python O(n) O(1) Easy
1100 Find K-Length Substrings With No Repeated Characters C++ Python O(n) O(k) Medium πŸ”’
1108 Defanging an IP Address C++ Python O(n) O(1) Easy
1119 Remove Vowels from a String C++ Python O(n) O(1) Easy πŸ”’
1147 Longest Chunked Palindrome Decomposition C++ Python O(n) O(1) Hard Rabin-Karp Algorithm
1177 Can Make Palindrome from Substring C++ Python O(m + n) O(n) Medium
1178 Number of Valid Words for Each Puzzle C++ Python O(n * l + m * L) O(L!) Hard Trie, Bit Manipulation
1189 Maximum Number of Balloons C++ Python O(n) O(1) Easy Hash
1233 Remove Sub-Folders from the Filesystem C++ Python O(n) O(t) Medium Trie
1271 Hexspeak C++ Python O(n) O(1) Easy
1309 Decrypt String from Alphabet to Integer Mapping C++ Python O(n) O(1) Easy
1324 Print Words Vertically C++ Python O(n) O(n) Medium
1328 Break a Palindrome C++ Python O(n) O(1) Medium
1332 Remove Palindromic Subsequences C++ Python O(n) O(1) Easy
1347 Minimum Number of Steps to Make Two Strings Anagram C++ Python O(n) O(1) Medium
1370 Increasing Decreasing String C++ Python O(n) O(1) Easy Sort
1371 Find the Longest Substring Containing Vowels in Even Counts C++ Python O(n) O(1) Medium
1374 Generate a String With Characters That Have Odd Count C++ Python O(n) O(1) Easy
1392 Longest Happy Prefix C++ Python O(n) O(n) Hard KMP Algorithm Rabin-Karp Algorithm
1408 String Matching in an Array C++ Python O(n) O(t) Easy KMP Algorithm, Aho-Corasick Automata, Trie
1410 HTML Entity Parser C++ Python O(n) O(t) Medium Aho-Corasick Automata, Trie
1417 Reformat The String C++ Python O(n) O(1) Easy
1422 Maximum Score After Splitting a String C++ Python O(n) O(1) Easy
1432 Max Difference You Can Get From Changing an Integer C++ Python O(logn) O(logn) Medium
1436 Destination City C++ Python O(n) O(n) Easy
1446 Consecutive Characters C++ Python O(n) O(1) Easy
1455 Check If a Word Occurs As a Prefix of Any Word in a Sentence C++ Python O(n) O(n) Easy KMP Algorithm
1461 Check If a String Contains All Binary Codes of Size K C++ Python O(n * k) O(k * 2^k) Medium Bit Manipulation
1496 Path Crossing C++ Python O(n) O(n) Easy
1507 Reformat Date C++ Python O(n) O(1) Easy
1528 Shuffle String C++ Python O(n) O(1) Easy
1529 Bulb Switcher IV C++ Python O(n) O(1) Medium
1540 Can Convert String in K Moves C++ Python O(n) O(1) Medium
1542 Find Longest Awesome Substring C++ Python O(n) O(1) Hard
1544 Make The String Great C++ Python O(n) O(1) Easy
1545 Find Kth Bit in Nth Binary String C++ Python O(n) O(1) Medium
1554 Strings Differ by One Character C++ Python O(n * m) O(n) Medium Rabin-Karp Algorithm
1556 Thousand Separator C++ Python O(n) O(1) Easy
1573 Number of Ways to Split a String C++ Python O(n) O(1) Medium
1576 Replace All ?'s to Avoid Consecutive Repeating Characters C++ Python O(n) O(1) Easy
1592 Rearrange Spaces Between Words C++ Python O(n) O(1) Easy
1598 Crawler Log Folder C++ Python O(n) O(1) Easy
1614 Maximum Nesting Depth of the Parentheses C++ Python O(n) O(1) Easy
1624 Largest Substring Between Two Equal Characters C++ Python O(n) O(1) Easy
1638 Count Substrings That Differ by One Character C++ Python O(m * n) O(1) Medium variant of Count Unique Characters of All Substrings of a Given String Tricky


Linked List

# Title Solution Time Space Difficulty Tag Note
0002 Add Two Numbers C++ Python O(n) O(1) Medium
0021 Merge Two Sorted Lists C++ Python O(n) O(1) Easy
0023 Merge k Sorted Lists C++ Python O(nlogk) O(1) Hard Heap, Divide and Conquer
0024 Swap Nodes in Pairs C++ Python O(n) O(1) Easy
0025 Reverse Nodes in k-Group C++ Python O(n) O(1) Hard
0061 Rotate List C++ Python O(n) O(1) Medium
0082 Remove Duplicates from Sorted List II C++ Python O(n) O(1) Medium
0083 Remove Duplicates from Sorted List C++ Python O(n) O(1) Easy
0092 Reverse Linked List II C++ Python O(n) O(1) Medium
0138 Copy List with Random Pointer C++ Python O(n) O(1) Medium
0160 Intersection of Two Linked Lists C++ Python O(m + n) O(1) Easy
0203 Remove Linked List Elements C++ Python O(n) O(1) Easy
0206 Reverse Linked List C++ Python O(n) O(1) Easy
0234 Palindrome Linked List C++ Python O(n) O(1) Easy
0237 Delete Node in a Linked List C++ Python O(1) O(1) Easy LintCode
0328 Odd Even Linked List C++ Python O(n) O(1) Medium
0369 Plus One Linked List C++ Python O(n) O(1) Medium πŸ”’ Two Pointers
0445 Add Two Numbers II C++ Python O(m + n) O(m + n) Medium
0725 Split Linked List in Parts C++ Python O(n + k) O(1) Medium
0817 Linked List Components C++ Python O(m + n) O(m) Medium
0986 Interval List Intersections C++ Python O(m + n) O(1) Medium
1171 Remove Zero Sum Consecutive Nodes from Linked List C++ Python O(n) O(n) Medium OrderedDict, Hash
1180 Count Substrings with Only One Distinct Letter C++ Python O(n) O(1) Easy πŸ”’
1181 Before and After Puzzle C++ Python O(l * rlogr) O(l * (n + r)) Medium πŸ”’ Hash
1265 Print Immutable Linked List in Reverse C++ Python O(n) O(sqrt(n)) Medium πŸ”’
1290 Convert Binary Number in a Linked List to Integer C++ Python O(n) O(1) Easy
1474 Delete N Nodes After M Nodes of a Linked List C++ Python O(n) O(1) Easy πŸ”’
1634 Add Two Polynomials Represented as Linked Lists C++ Python O(m + n) O(1) Medium πŸ”’


Stack

# Title Solution Time Space Difficulty Tag Note
0020 Valid Parentheses C++ Python O(n) O(n) Easy
0032 Longest Valid Parentheses C++ Python O(n) O(1) Hard
0071 Simplify Path C++ Python O(n) O(n) Medium
0084 Largest Rectangle in Histogram C++ Python O(n) O(n) Hard Mono Stack, DP
0085 Maximal Rectangle C++ Python O(m * n) O(n) Hard EPI Mono Stack
0101 Symmetric Tree C++ Python O(n) O(h) Easy
0150 Evaluate Reverse Polish Notation C++ Python O(n) O(n) Medium
0155 Min Stack C++ Python O(n) O(1) Easy
0224 Basic Calculator C++ Python O(n) O(n) Hard
0227 Basic Calculator II C++ Python O(n) O(n) Medium
0232 Implement Queue using Stacks C++ Python O(1), amortized O(n) Easy EPI, LintCode
0255 Verify Preorder Sequence in Binary Search Tree C++ Python O(n) O(1) Medium πŸ”’
0272 Closest Binary Search Tree Value II C++ Python O(h + k) O(h) Hard πŸ”’
0331 Verify Preorder Serialization of a Binary Tree C++ Python O(n) O(1) Medium
0341 Flatten Nested List Iterator C++ Python O(n) O(h) Medium πŸ”’ Iterator
0385 Mini Parser C++ Python O(n) O(h) Medium
0394 Decode String C++ Python O(n) O(n) Medium
0439 Ternary Expression Parser C++ Python O(n) O(1) Medium πŸ”’
0456 132 Pattern C++ Python O(n) O(n) Medium
0636 Exclusive Time of Functions C++ Python O(n) O(n) Medium
0682 Baseball Game C++ Python O(n) O(n) Easy
0726 Number of Atoms C++ Python O(n) O(n) Hard
0735 Asteroid Collision C++ Python O(n) O(n) Medium
0736 Parse Lisp Expression C++ Python O(n^2) O(n^2) Hard
0739 Daily Temperatures C++ Python O(n) O(n) Medium
0770 Basic Calculator IV C++ Python add: O(d * t)
sub: O(d * t)
mul: O(d * t^2)
eval: O(d * t)
to_list: O(d * tlogt)
O(e + d * t) Hard
0772 Basic Calculator III C++ Python O(n) O(n) Hard
0853 Car Fleet C++ Python O(nlogn) O(n) Medium
0856 Score of Parentheses C++ Python O(n) O(1) Medium
0872 Leaf-Similar Trees C++ Python O(n) O(h) Easy
0895 Maximum Frequency Stack C++ Python O(1) O(n) Hard Hash
0901 Online Stock Span C++ Python O(n) O(n) Medium
0921 Minimum Add to Make Parentheses Valid C++ Python O(n) O(1) Medium
0946 Validate Stack Sequences C++ Python O(n) O(n) Medium
1003 Check If Word Is Valid After Substitutions C++ Python O(n) O(n) Medium
1019 Next Greater Node In Linked List C++ Python O(n) O(n) Medium Mono Stack
1021 Remove Outermost Parentheses C++ Python O(n) O(1) Easy
1047 Remove All Adjacent Duplicates In String C++ Python O(n) O(n) Easy
1063 Number of Valid Subarrays C++ Python O(n) O(n) Hard πŸ”’ Mono Stack
1130 Minimum Cost Tree From Leaf Values C++ Python O(n) O(n) Medium Mono Stack
1190 Reverse Substrings Between Each Pair of Parentheses C++ Python O(n) O(n) Medium
1209 Remove All Adjacent Duplicates in String II C++ Python O(n) O(n) Medium
1441 Build an Array With Stack Operations C++ Python O(n) O(1) Easy
1541 Minimum Insertions to Balance a Parentheses String C++ Python O(n) O(1) Medium
1597 Build Binary Expression Tree From Infix Expression C++ Python O(n) O(n) Medium πŸ”’, variant of Basic Calculator III


Queue

# Title Solution Time Space Difficulty Tag Note
0239 Sliding Window Maximum C++ Python O(n) O(k) Hard EPI, LintCode Mono Deque
0281 Zigzag Iterator C++ Python O(n) O(k) Medium πŸ”’
0346 Moving Average from Data Stream C++ Python O(1) O(w) Easy πŸ”’
0933 Number of Recent Calls C++ Python O(1) on average O(w) Easy
1424 Diagonal Traverse II C++ Python O(m * n) O(m) Medium
1438 Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit C++ Python O(n) O(n) Hard Mono Deque
1499 Max Value of Equation C++ Python O(n) O(n) Hard Mono Deque


Binary Heap

# Title Solution Time Space Difficulty Tag Note
0264 Ugly Number II C++ Python O(n) O(1) Medium CTCI, LintCode BST, Heap
0295 Find Median from Data Stream C++ Python O(nlogn) O(n) Hard EPI, LintCode BST, Heap
0313 Super Ugly Number C++ Python O(n * k) O(n + k) Medium BST, Heap
0358 Rearrange String k Distance Apart C++ Python O(n) O(n) Hard πŸ”’ Greedy, Heap
0373 Find K Pairs with Smallest Sums C++ Python O(k * log(min(n, m, k))) O(min(n, m, k)) Medium
0378 Kth Smallest Element in a Sorted Matrix C++ Python O(k * log(min(n, m, k))) O(min(n, m, k)) Medium LintCode
0407 Trapping Rain Water II C++ Python O(m * n * (logm + logn)) O(m * n) Hard LintCode
0632 Smallest Range C++ Python O(nlogk) O(k) Hard
0703 Kth Largest Element in a Stream C++ Python O(nlogk) O(k) Easy
0846 Hand of Straights C++ Python O(nlogn) O(n) Medium
0855 Exam Room C++ Python seat: O(logn)
leave: O(logn)
O(n) Medium BST, Hash
0857 Minimum Cost to Hire K Workers C++ Python O(nlogn) O(n) Hard Sort
0871 Minimum Number of Refueling Stops C++ Python O(nlogn) O(n) Hard Sort
1046 Last Stone Weight C++ Python O(nlogn) O(n) Easy
1057 Campus Bikes C++ Python O((w * b) * log(w * b)) O(w * b) Medium πŸ”’
1383 Maximum Performance of a Team C++ Python O(nlogn) O(n) Hard variant of Minimum Cost to Hire K Workers Sort
1439 Find the Kth Smallest Sum of a Matrix With Sorted Rows C++ Python O(m * klogk) O(k) Hard Binary Search
1606 Find Servers That Handled Most Number of Requests C++ Python O(nlogk) O(k) Hard SortedList
1642 Furthest Building You Can Reach C++ Python O(nlogk) O(k) Medium


Tree

# Title Solution Time Space Difficulty Tag Note
0094 Binary Tree Inorder Traversal C++ Python O(n) O(1) Medium Morris Traversal
0099 Recover Binary Search Tree C++ Python O(n) O(1) Hard Morris Traversal
0144 Binary Tree Preorder Traversal C++ Python O(n) O(1) Medium Morris Traversal
0145 Binary Tree Postorder Traversal C++ Python O(n) O(1) Hard Morris Traversal
0208 Implement Trie (Prefix Tree) C++ Python O(n) O(1) Medium Trie
0211 Add and Search Word - Data structure design C++ Python O(min(n, h)) O(min(n, h)) Medium Trie, DFS
0226 Invert Binary Tree C++ Python O(n) O(h), O(w) Easy
0297 Serialize and Deserialize Binary Tree C++ Python O(n) O(h) Hard LintCode DFS
0307 Range Sum Query - Mutable C++ Python ctor: O(n), update: O(logn), query: O(logn) O(n) Medium LintCode DFS, Segment Tree, BIT, Fenwick Tree
0308 Range Sum Query 2D - Mutable C++ Python ctor: O(m * n), update: O(logm * logn), query: O(logm * logn) O(m * n) Hard πŸ”’ DFS, Quad Tree, 2D BIT, 2D Fenwick Tree
0315 Count of Smaller Numbers After Self C++ Python O(nlogn) O(n) Hard LintCode BST, BIT, Fenwick Tree, Divide and Conquer
0525 Contiguous Array C++ Python O(n) O(n) Medium
0529 Minesweeper C++ Python O(m * n) O(m + n) Medium
0536 Construct Binary Tree from String C++ Python O(n) O(h) Medium πŸ”’
0538 Convert BST to Greater Tree C++ Python O(n) O(h) Easy
0543 Diameter of Binary Tree C++ Python O(n) O(h) Easy
0545 Boundary of Binary Tree C++ Python O(n) O(h) Medium πŸ”’
0548 Split Array with Equal Sum C++ Python O(n^2) O(n) Medium πŸ”’
0563 Binary Tree Tilt C++ Python O(n) O(n) Easy
0572 Subtree of Another Tree C++ Python O(m * n) O(h) Easy
0606 Construct String from Binary Tree C++ Python O(n) O(h) Easy
0617 Merge Two Binary Trees C++ Python O(n) O(h) Easy
0623 Add One Row to Tree C++ Python O(n) O(h) Medium
0637 Average of Levels in Binary Tree C++ Python O(n) O(h) Easy
0652 Find Duplicate Subtrees C++ Python O(n) O(n) Medium DFS, Hash
0653 Two Sum IV - Input is a BST C++ Python O(n) O(h) Easy Two Pointers
0654 Maximum Binary Tree C++ Python O(n) O(n) Medium LintCode Mono Stack
0655 Print Binary Tree C++ Python O(n) O(h) Medium
0662 Maximum Width of Binary Tree C++ Python O(n) O(h) Medium DFS
0663 Equal Tree Partition C++ Python O(n) O(n) Medium πŸ”’ Hash
0677 Map Sum Pairs C++ Python O(n) O(t) Medium Trie
0684 Redundant Connection C++ Python O(n) O(n) Medium Union Find
0685 Redundant Connection II C++ Python O(n) O(n) Hard Union Find
0687 Longest Univalue Path C++ Python O(n) O(h) Easy
0699 Falling Squares C++ Python O(nlogn) O(n) Hard Segment Tree
0814 Binary Tree Pruning C++ Python O(n) O(h) Medium DFS
0850 Rectangle Area II C++ Python O(nlogn) O(n) Hard Segment Tree
0863 All Nodes Distance K in Binary Tree C++ Python O(n) O(n) Medium DFS + BFS
0866 Smallest Subtree with all the Deepest Nodes C++ Python O(n) O(h) Medium DFS
0889 Construct Binary Tree from Preorder and Postorder Traversal C++ Python O(n) O(h) Medium DFS, stack
0897 Increasing Order Search Tree C++ Python O(n) O(h) Easy DFS
0919 Complete Binary Tree Inserter C++ Python ctor: O(n)
insert: O(1)
get_root: O(1)
O(n) Medium
0938 Range Sum of BST C++ Python O(n) O(h) Medium DFS
0951 Flip Equivalent Binary Trees C++ Python O(n) O(h) Medium DFS
0958 Check Completeness of a Binary Tree C++ Python O(n) O(w) Medium BFS
0965 Univalued Binary Tree C++ Python O(n) O(h) Easy DFS
0971 Flip Binary Tree To Match Preorder Traversal C++ Python O(n) O(h) Medium DFS
0979 Distribute Coins in Binary Tree C++ Python O(n) O(h) Medium DFS
0987 Vertical Order Traversal of a Binary Tree C++ Python O(nlogn) O(n) Medium DFS
0988 Smallest String Starting From Leaf C++ Python O(n + l * h) O(h) Medium DFS
0993 Cousins in Binary Tree C++ Python O(n) O(h) Easy DFS
0998 Maximum Binary Tree II C++ Python O(h) O(1) Medium
1008 Construct Binary Search Tree from Preorder Traversal C++ Python O(n) O(h) Medium
1022 Sum of Root To Leaf Binary Numbers C++ Python O(n) O(h) Easy
1026 Maximum Difference Between Node and Ancestor C++ Python O(n) O(h) Medium DFS
1028 Recover a Tree From Preorder Traversal C++ Python O(n) O(h) Hard DFS
1032 Stream of Characters C++ C++ Python Python ctor: O(n)
query: O(m)
O(t) Hard Aho-Corasick Automata, Trie
1038 Binary Search Tree to Greater Sum Tree C++ Python O(n) O(h) Medium DFS
1065 Index Pairs of a String C++ Python O(n + m + z) O(t) Easy πŸ”’ Aho-Corasick Automata, Trie
1080 Insufficient Nodes in Root to Leaf Paths C++ Python O(n) O(h) Medium DFS
1104 Path In Zigzag Labelled Binary Tree C++ Python O(logn) O(logn) Easy Math
1120 Maximum Average Subtree C++ Python O(n) O(h) Easy πŸ”’ DFS
1123 Lowest Common Ancestor of Deepest Leaves C++ Python O(n) O(h) Medium DFS
1145 Binary Tree Coloring Game C++ Python O(n) O(h) Medium DFS
1257 Smallest Common Region C++ Python O(m * n) O(n) Medium
1261 Find Elements in a Contaminated Binary Tree C++ Python O(n) O(h) Medium DFS
1325 Delete Leaves With a Given Value C++ Python O(n) O(h) Medium DFS
1339 Maximum Product of Splitted Binary Tree C++ Python O(n) O(h) Medium DFS
1409 Queries on a Permutation With Key C++ Python O(nlogn) O(n) Medium BIT, Fenwick Tree
1430 Check If a String Is a Valid Sequence from Root to Leaves Path in a Binary Tree C++ Python O(n) O(h) Medium πŸ”’ BFS, DFS, Stack
1443 Minimum Time to Collect All Apples in a Tree C++ Python O(n) O(n) Medium DFS, Stack
1448 Count Good Nodes in Binary Tree C++ Python O(n) O(h) Medium DFS, Stack
1457 Pseudo-Palindromic Paths in a Binary Tree C++ Python O(n) O(h) Medium DFS, Stack
1469 Find All The Lonely Nodes C++ Python O(n) O(h) Easy πŸ”’ DFS, Stack
1490 Clone N-ary Tree C++ Python O(n) O(h) Medium πŸ”’ DFS, Stack
1505 Minimum Possible Integer After at Most K Adjacent Swaps On Digits C++ Python O(nlogn) O(n) Hard BIT, Fenwick Tree
1506 Find Root of N-Ary Tree C++ Python O(n) O(1) Medium πŸ”’ Bit Manipulation
1516 Move Sub-Tree of N-Ary Tree C++ Python O(n) O(h) Hard πŸ”’ DFS, Stack
1519 Number of Nodes in the Sub-Tree With the Same Label C++ Python O(n) O(h) Medium DFS, Stack
1522 Diameter of N-Ary Tree C++ Python O(n) O(h) Medium πŸ”’ DFS, Stack
1530 Number of Good Leaf Nodes Pairs C++ Python O(n) O(h) Medium DFS, Stack
1612 Check If Two Expression Trees are Equivalent C++ Python O(n) O(1) Medium πŸ”’ Morris Traversal, Inorder Traversal, Stack, Hash Table


Hash Table

# Title Solution Time Space Difficulty Tag Note
0001 Two Sum C++ Python O(n) O(n) Easy
0003 Longest Substring Without Repeating Characters C++ Python O(n) O(1) Medium
0030 Substring with Concatenation of All Words C++ Python O((m + n) * k) O(n * k) Hard
0036 Valid Sudoku C++ Python O(9^2) O(9) Easy
0049 Group Anagrams C++ Python O(n * glogg) O(n) Medium
0076 Minimum Window Substring C++ Python O(n) O(k) Hard
0149 Max Points on a Line C++ Python O(n^2) O(n) Hard
0159 Longest Substring with At Most Two Distinct Characters C++ Python O(n) O(1) Hard πŸ”’
0170 Two Sum III - Data structure design C++ Python O(n) O(n) Easy πŸ”’
0187 Repeated DNA Sequences Python O(n) O(n) Medium
0202 Happy Number C++ Python O(k) O(k) Easy
0204 Count Primes C++ Python O(nlog(logn)) O(n) Easy Sieve of Eratosthenes
0205 Isomorphic Strings C++ Python O(n) O(1) Easy
0217 Contains Duplicate C++ Python O(n) O(n) Easy
0219 Contains Duplicate II C++ Python O(n) O(n) Easy
0244 Shortest Word Distance II C++ Python ctor: O(n), lookup: O(a + b) O(n) Medium πŸ”’
0246 Strobogrammatic Number C++ Python O(n) O(1) Easy πŸ”’
0249 Group Shifted Strings C++ Python O(nlogn) O(n) Easy πŸ”’
0266 Palindrome Permutation C++ Python O(n) O(1) Easy πŸ”’
0288 Unique Word Abbreviation C++ Python ctor: O(n), lookup: O(1) O(k) Easy πŸ”’
0290 Word Pattern C++ Python O(n) O(c) Easy variant of Isomorphic Strings
0299 Bulls and Cows C++ Python O(n) O(1) Easy
0305 Number of Islands II C++ Python O(k) O(k) Hard LintCode, πŸ”’ Union Find
0314 Binary Tree Vertical Order Traversal C++ Python O(n) O(n) Medium πŸ”’ BFS
0323 Number of Connected Components in an Undirected Graph C++ Python O(n) O(n) Medium πŸ”’ Union Find
0325 Maximum Size Subarray Sum Equals k C++ Python O(n) O(n) Medium πŸ”’
0336 Palindrome Pairs C++ Python O(n * k^2) O(n * k) Hard
0340 Longest Substring with At Most K Distinct Characters C++ Python O(n) O(1) Hard πŸ”’
0356 Line Reflection C++ Python O(n) O(n) Medium πŸ”’ Hash, Two Pointers
0387 First Unique Character in a String C++ Python O(n) O(n) Easy
0388 Longest Absolute File Path C++ Python O(n) O(d) Medium Stack
0409 Longest Palindrome C++ Python O(n) O(1) Easy
0438 Find All Anagrams in a String C++ Python O(n) O(1) Easy
0447 Number of Boomerangs C++ Python O(n^2) O(n) Easy
0454 4Sum II C++ Python O(n^2) O(n^2) Medium
0470 Implement Rand10() Using Rand7() C++ Python O(1) O(1) Medium
0473 Matchsticks to Square C++ Python O(n * s * 2^n) O(n * (2^n + s)) Medium
0523 Continuous Subarray Sum C++ Python O(n) O(k) Medium
0532 K-diff Pairs in an Array C++ Python O(n) O(n) Easy
0554 Brick Wall C++ Python O(n) O(m) Medium
0560 Subarray Sum Equals K C++ Python O(n) O(n) Medium
0561 Array Partition I C++ Python O(r) O(r) Easy
0575 Distribute Candies C++ Python O(n) O(n) Easy
0594 Longest Harmonious Subsequence C++ Python O(n) O(n) Easy
0599 Minimum Index Sum of Two Lists C++ Python O((m + n) * l) O(m * l) Easy
0609 Find Duplicate File in System C++ Python O(n * l) O(n * l) Medium
0721 Accounts Merge C++ Python O(nlogn) O(n) Medium Union Find
0734 Sentence Similarity C++ Python O(n + p) O(p) Easy
0737 Sentence Similarity II C++ Python O(n + p) O(p) Medium Union Find
0748 Shortest Completing Word C++ Python O(n) O(1) Easy
0760 Find Anagram Mappings C++ Python O(n) O(n) Easy
0771 Jewels and Stones C++ Python O(m + n) O(n) Easy
0811 Subdomain Visit Count C++ Python O(n) O(n) Easy
0822 Card Flipping Game C++ Python O(n) O(n) Medium
0825 Friends Of Appropriate Ages C++ Python O(a^2 + n) O(a) Medium
0869 Reordered Power of 2 C++ Python O(1) O(1) Medium
0873 Length of Longest Fibonacci Subsequence C++ Python O(n^2) O(n) Medium
0957 Prison Cells After N Days C++ Python O(1) O(1) Medium
0966 Vowel Spellchecker C++ Python O(n) O(w) Medium
0974 Subarray Sums Divisible by K C++ Python O(n) O(k) Medium variant of Subarray Sum Equals K
0982 Triples with Bitwise AND Equal To Zero C++ Python O(nlogn) O(n) Hard Math, Fast Wavelet Transform (FWT)
1001 Grid Illumination C++ Python O(l + q) O(l) Hard
1124 Longest Well-Performing Interval C++ Python O(n) O(n) Medium
1133 Largest Unique Number C++ Python O(n) O(n) Easy πŸ”’ Hash
1152 Analyze User Website Visit Pattern C++ Python O(n^3) O(n^3) Medium πŸ”’ Hash
1153 String Transforms Into Another String C++ Python O(n) O(1) Hard πŸ”’ Hash
1160 Find Words That Can Be Formed by Characters C++ Python O(m * n) O(1) Easy
1165 Single-Row Keyboard C++ Python O(n) O(1) Easy πŸ”’
1198 Find Smallest Common Element in All Rows C++ Python O(m * n) O(n) Medium πŸ”’
1207 Unique Number of Occurrences C++ Python O(n) O(n) Easy
1224 Maximum Equal Frequency C++ Python O(n) O(n) Hard
1418 Display Table of Food Orders in a Restaurant C++ Python O(n + tlogt + flogf) O(n) Medium
1452 People Whose List of Favorite Companies Is Not a Subset of Another List C++ Python O(n * m * l + n^2 * m) O(n * m * l) Medium
1487 Making File Names Unique C++ Python O(n) O(n) Medium
1577 Number of Ways Where Square of Number Is Equal to Product of Two Numbers C++ Python O(m * n) O(m + n) Medium
1590 Make Sum Divisible by P C++ Python O(n) O(p) Medium variant of Subarray Sums Divisible by K
1640 Check Array Formation Through Concatenation C++ Python O(n) O(n) Easy


Math

# Title Solution Time Space Difficulty Tag Note
0007 Reverse Integer C++ Python O(1) O(1) Easy
0009 Palindrome Number C++ Python O(1) O(1) Easy
0012 Integer to Roman C++ Python O(n) O(1) Medium
0013 Roman to Integer C++ Python O(n) O(1) Easy
0029 Divide Two Integers C++ Python O(1) O(1) Medium
0050 Pow(x, n) C++ Python O(1) O(1) Medium
0060 Permutation Sequence C++ Python O(n^2) O(n) Medium Cantor Ordering
0065 Valid Number C++ Python O(n) O(1) Hard Automata
0089 Gray Code C++ Python O(2^n) O(1) Medium
0166 Fraction to Recurring Decimal C++ Python O(logn) O(1) Medium
0168 Excel Sheet Column Title C++ Python O(logn) O(1) Easy
0171 Excel Sheet Column Number C++ Python O(n) O(1) Easy
0172 Factorial Trailing Zeroes C++ Python O(1) O(1) Easy
0223 Rectangle Area C++ Python O(1) O(1) Easy
0233 Number of Digit One C++ Python O(1) O(1) Hard CTCI, LintCode
0248 Strobogrammatic Number III C++ Python O(5^(n/2)) O(n) Hard πŸ”’
0258 Add Digits C++ Python O(1) O(1) Easy
0263 Ugly Number C++ Python O(1) O(1) Easy
0292 Nim Game C++ Python O(1) O(1) Easy LintCode
0319 Bulb Switcher C++ Python O(1) O(1) Medium
0326 Power of Three C++ Python O(1) O(1) Easy
0335 Self Crossing C++ Python O(n) O(1) Hard
0338 Counting Bits C++ Python O(n) O(n) Medium
0343 Integer Break C++ Python O(logn) O(1) Medium Tricky, DP
0365 Water and Jug Problem C++ Python O(logn) O(1) Medium BΓ©zout's identity
0372 Super Pow C++ Python O(n) O(1) Medium
0382 Linked List Random Node C++ Python O(n) O(1) Medium Reservoir Sampling
0386 Lexicographical Numbers C++ Python O(n) O(1) Medium
0390 Elimination Game C++ Python O(logn) O(1) Medium
0391 Perfect Rectangle C++ Python O(n) O(n) Hard
0398 Random Pick Index C++ Python O(n) O(1) Medium Reservoir Sampling
0400 Nth Digit C++ Python O(logn) O(1) Easy
0413 Arithmetic Slices C++ Python O(n) O(1) Medium
0423 Reconstruct Original Digits from English C++ Python O(n) O(1) Medium GCJ2016 - Round 1B
0441 Arranging Coins C++ Python O(nlogn) O(1) Easy Binary Search
0453 Minimum Moves to Equal Array Elements C++ Python O(n) O(1) Easy
0458 Poor Pigs C++ Python O(n) O(1) Easy
0469 Convex Polygon C++ Python O(n) O(1) Medium πŸ”’
0470 Implement Rand10() Using Rand7() C++ Python O(1) O(1) Medium
0478 Generate Random Point in a Circle C++ Python O(1) O(1) Medium
0497 Random Point in Non-overlapping Rectangles C++ Python ctor: O(n)
pick: O(logn)
O(n) Medium
0517 Super Washing Machines C++ Python O(n) O(1) Hard
0519 Random Flip Matrix C++ Python ctor: O(1)
pick: O(1) reset: O(n)
O(n) Medium
0528 Random Pick with Weight C++ Python ctor: O(n)
pick: O(logn)
O(n) Medium
0537 Complex Number Multiplication C++ Python O(1) O(1) Medium
0553 Optimal Division C++ Python O(n) O(1) Medium
0573 Squirrel Simulation C++ Python O(n) O(1) Medium πŸ”’
0592 Fraction Addition and Subtraction C++ Python O(nlogx) O(n) Medium
0593 Valid Square C++ Python O(1) O(1) Medium
0598 Range Addition II C++ Python O(p) O(1) Easy
0625 Minimum Factorization C++ Python O(loga) O(1) Medium πŸ”’
0628 Maximum Product of Three Numbers C++ Python O(n) O(1) Easy
0633 Sum of Square Numbers C++ Python O(sqrt(c) * logc) O(1) Easy
0634 Find the Derangement of An Array C++ Python O(n) O(1) Medium πŸ”’
0640 Solve the Equation C++ Python O(n) O(n) Medium
0651 4 Keys Keyboard C++ Python O(1) O(1) Medium πŸ”’ Math, DP
0660 Remove 9 C++ Python O(logn) O(1) Hard πŸ”’
0672 Bulb Switcher II C++ Python O(1) O(1) Medium
0728 Self Dividing Numbers C++ Python O(n) O(1) Medium
0754 Reach a Number C++ Python O(logn) O(1) Medium
0775 Global and Local Inversions C++ Python O(n) O(1) Medium
0779 K-th Symbol in Grammar C++ Python O(1) O(1) Medium
0780 Reaching Points C++ Python O(log(max(m, n))) O(1) Hard
0781 Rabbits in Forest C++ Python O(n) O(n) Medium
0782 Transform to Chessboard C++ Python O(n^2) O(n) Hard
0789 Escape The Ghosts C++ Python O(n) O(1) Medium
0800 Similar RGB Color C++ Python O(1) O(1) Easy πŸ”’
0810 Chalkboard XOR Game C++ Python O(1) O(1) Hard
0812 Largest Triangle Area C++ Python O(n^3) O(1) Easy
0829 Consecutive Numbers Sum C++ Python O(sqrt(n)) O(1) Medium
0836 Rectangle Overlap C++ Python O(1) O(1) Easy
0858 Mirror Reflection C++ Python O(1) O(1) Medium
0867 Prime Palindrome C++ Python O(n^(1/2) * (logn + n^(1/2))) O(logn) Medium
0883 Projection Area of 3D Shapes C++ Python O(n^2) O(1) Easy
0887 Super Egg Drop C++ Python O(klogn) O(1) Hard
0891 Sum of Subsequence Widths C++ Python O(n) O(1) Hard
0899 Orderly Queue C++ Python O(n^2) O(n) Hard
0902 Numbers At Most N Given Digit Set C++ Python O(logn) O(logn) Hard
0906 Super Palindromes C++ Python O(n^0.25 * logn) O(logn) Hard
0907 Sum of Subarray Minimums C++ Python O(n) O(n) Medium Mono Stack
0908 Smallest Range I C++ Python O(n) O(1) Easy
0910 Smallest Range II C++ Python O(nlogn) O(1) Medium
0914 X of a Kind in a Deck of Cards C++ Python O(n * (logn)^2) O(n) Easy
0963 Minimum Area Rectangle II C++ Python O(n^2) ~ O(n^3) O(n^2) Medium
0970 Powerful Integers C++ Python O((logn)^2) O(r) Easy
0972 Equal Rational Numbers C++ Python O(1) O(1) Hard
1006 Clumsy Factorial C++ Python O(1) O(1) Medium
1009 Complement of Base 10 Integer C++ Python O(logn) O(1) Easy
1012 Numbers With Repeated Digits C++ Python O(logn) O(logn) Hard
1015 Smallest Integer Divisible by K C++ Python O(k) O(1) Medium
1017 Convert to Base -2 C++ Python O(logn) O(1) Medium
1025 Divisor Game C++ Python O(1) O(1) Easy DP
1037 Valid Boomerang C++ Python O(1) O(1) Easy
1041 Robot Bounded In Circle C++ Python O(n) O(1) Medium
1067 Digit Count in Range C++ Python O(logn) O(1) Hard πŸ”’, variant of Number of Digit One
1073 Adding Two Negabinary Numbers C++ Python O(n) O(n) Medium
1079 Letter Tile Possibilities C++ Python O(n^2) O(n) Medium Generating Function, Backtracking
1088 Confusing Number II C++ Python O(logn) O(logn) Hard πŸ”’
1103 Distribute Candies to People C++ Python O(n + logc) O(1) Easy Binary Search
1118 Number of Days in a Month C++ Python O(1) O(1) Easy πŸ”’
1121 Divide Array Into Increasing Sequences C++ Python O(n) O(1) Hard πŸ”’
1128 Number of Equivalent Domino Pairs C++ Python O(n) O(n) Easy
1131 Maximum of Absolute Value Expression C++ Python O(n) O(1) Medium
1134 Armstrong Number C++ Python O(klogk) O(k) Easy πŸ”’
1150 Check If a Number Is Majority Element in a Sorted Array C++ Python O(nlogn) O(1) Easy πŸ”’ Binary Search
1157 Online Majority Element In Subarray C++ Python ctor: O(n)
query: O(klogn)
O(n) Hard Binary Search, Segment Tree, Boyer–Moore Majority Vote Algorithm
1154 Day of the Year C++ Python O(1) O(1) Easy
1175 Prime Arrangements C++ Python O(nlog(logn)) O(n) Easy Sieve of Eratosthenes
1185 Day of the Week C++ Python O(1) O(1) Easy Zeller Formula
1197 Minimum Knight Moves C++ Python O(1) O(1) Medium πŸ”’ DP, Math
1217 Play with Chips C++ Python O(n) O(1) Medium
1227 Airplane Seat Assignment Probability C++ Python O(1) O(1) Medium
1232 Check If It Is a Straight Line C++ Python O(1) O(1) Easy
1237 Find Positive Integer Solution for a Given Equation C++ Python O(n) O(1) Easy
1238 Circular Permutation in Binary Representation C++ Python O(2^n) O(1) Medium variant of Gray Code
1250 Check If It Is a Good Array C++ Python O(nlogn) O(1) Hard BΓ©zout's identity
1256 Encode Number C++ Python O(logn) O(1) Medium
1259 Handshakes That Don't Cross C++ Python O(n) O(1) Hard Catalan Number, DP
1266 Minimum Time Visiting All Points C++ Python O(n) O(1) Easy
1276 Number of Burgers with No Waste of Ingredients C++ Python O(1) O(1) Medium
1281 Subtract the Product and Sum of Digits of an Integer C++ Python O(logn) O(1) Easy
1300 Sum of Mutated Array Closest to Target C++ Python O(nlogn) O(1) Medium Binary Search
1317 Convert Integer to the Sum of Two No-Zero Integers C++ Python O(logn) O(1) Easy
1323 Maximum 69 Number C++ Python O(logn) O(1) Easy
1330 Reverse Subarray To Maximize Array Value C++ Python O(n) O(1) Hard
1344 Angle Between Hands of a Clock C++ Python O(1) O(1) Medium
1359 Count All Valid Pickup and Delivery Options C++ Python O(n) O(1) Hard
1360 Number of Days Between Two Dates C++ Python O(1) O(1) Easy variant of Day of the Year
1362 Closest Divisors C++ Python O(sqrt(n)) O(1) Medium
1363 Largest Multiple of Three C++ Python O(n) O(1) Hard
1390 Four Divisors C++ Python O(n * sqrt(n)) O(1) Medium
1401 Circle and Rectangle Overlapping C++ Python O(1) O(1) Medium
1415 The k-th Lexicographical String of All Happy Strings of Length n C++ Python O(n) O(1) Medium
1442 Count Triplets That Can Form Two Arrays of Equal XOR C++ Python O(n) O(n) Medium
1447 Simplified Fractions C++ Python O(n^2 * logn) O(n^2) Medium
1486 XOR Operation in an Array C++ Python O(1) O(1) Easy
1492 The kth Factor of n C++ Python O(sqrt(n)) O(1) Medium
1497 Check If Array Pairs Are Divisible by k C++ Python O(n) O(k) Medium
1512 Number of Good Pairs C++ Python O(n) O(1) Easy
1513 Number of Substrings With Only 1s C++ Python O(n) O(1) Medium
1525 Number of Good Ways to Split a String C++ Python O(n) O(1) Medium
1537 Get the Maximum Score C++ Python O(m + n) O(1) Hard
1551 Minimum Operations to Make Array Equal C++ Python O(1) O(1) Medium
1611 Minimum One Bit Operations to Make Integers Zero C++ Python O(logn) O(1) Hard variant of Gray Code
1641 Count Sorted Vowel Strings C++ Python O(1) O(1) Medium Binomial Coefficients
1643 Kth Smallest Instructions C++ Python O((m + n)^2) O(1) Hard Binomial Coefficients


Sort

# Title Solution Time Space Difficulty Tag Note
0056 Merge Intervals C++ Python O(nlogn) O(1) Hard
0057 Insert Interval C++ Python O(n) O(1) Hard
0075 Sort Colors C++ Python O(n) O(1) Medium Tri Partition
0088 Merge Sorted Array C++ Python O(n) O(1) Easy
0147 Insertion Sort List C++ Python O(n^2) O(1) Medium
0148 Sort List C++ Python O(nlogn) O(logn) Medium
0164 Maximum Gap C++ Python O(n) O(n) Hard Tricky
0179 Largest Number C++ Python O(nlogn) O(1) Medium
0218 The Skyline Problem C++ Python O(nlogn) O(n) Hard Sort, BST
0252 Meeting Rooms C++ Python O(nlogn) O(n) Easy πŸ”’
0253 Meeting Rooms II C++ Python O(nlogn) O(n) Medium πŸ”’
0274 H-Index C++ Python O(n) O(n) Medium Counting Sort
0280 Wiggle Sort C++ Python O(n) O(1) Medium πŸ”’
0324 Wiggle Sort II C++ Python O(n) on average O(1) Medium variant of Sort Colors Tri Partition
0347 Top K Frequent Elements C++ Python O(n) O(n) Medium Quick Select, Heap, Bucket Sort
0406 Queue Reconstruction by Height C++ Python O(n * sqrt(n)) O(n) Medium Tricky
0451 Sort Characters By Frequency C++ Python O(n) O(n) Medium
0692 Top K Frequent Words C++ Python O(n + klogk) on average O(n) Medium Quick Select, Heap, Bucket Sort
0912 Sort an Array C++ Python O(nlogn) O(n) Medium Merge Sort, Quick Sort
0937 Reorder Log Files C++ Python O(nlogn * l) O(l) Easy
0969 Pancake Sorting C++ Python O(n^2) O(l) Medium
0973 K Closest Points to Origin C++ Python O(n) on average O(1) Easy Quick Select, Heap
0976 Largest Perimeter Triangle C++ Python O(nlogn) O(1) Easy
1054 Distant Barcodes C++ Python O(klogk) O(k) Medium variant of Rearrange String k Distance Apart
1086 High Five C++ Python O(nlogn) O(n) Easy πŸ”’
1094 Car Pooling C++ Python O(nlogn) O(n) Medium variant of Meeting Rooms II
1122 Relative Sort Array C++ Python O(nlogn) O(n) Easy
1229 Meeting Scheduler C++ Python O(nlogn) O(n) Medium Line Sweep, Heap
1356 Sort Integers by The Number of 1 Bits C++ Python O(nlogn) O(1) Easy Bit Manipulation
1365 How Many Numbers Are Smaller Than the Current Number C++ Python O(n + m) O(m) Easy Counting Sort
1366 Rank Teams by Votes C++ Python O(m * (n + mlogm)) O(m^2) Medium
1451 Rearrange Words in a Sentence C++ Python O(nlogn) O(n) Medium String
1481 Least Number of Unique Integers after K Removals C++ Python O(n) O(n) Medium Counting Sort
1509 Minimum Difference Between Largest and Smallest Value in Three Moves C++ Python O(n + klogk) O(1) Medium Quick Select
1523 Count Odd Numbers in an Interval Range C++ Python O(1) O(1) Easy
1561 Maximum Number of Coins You Can Get C++ Python O(nlogn) O(1) Medium
1588 Sum of All Odd Length Subarrays C++ Python O(n) O(1) Easy
1608 Special Array With X Elements Greater Than or Equal X C++ Python O(n) O(1) Easy variant of H-Index Counting Sort, Binary Search
1620 Coordinate With Maximum Network Quality C++ Python O(n^2) O(1) Medium
1621 Number of Sets of K Non-Overlapping Line Segments C++ Python O(1) O(n) Medium Binomial Coefficients, Euler's Theorem
1630 Arithmetic Subarrays C++ Python O(n * q) O(n) Medium Arithmetic Series
1636 Sort Array by Increasing Frequency C++ Python O(nlogn) O(n) Easy
1637 Widest Vertical Area Between Two Points Containing No Points C++ Python O(nlogn) O(n) Medium


Two Pointers

# Title Solution Time Space Difficulty Tag Note
0015 3 Sum C++ Python O(n^2) O(1) Medium Two Pointers
0016 3 Sum Closest C++ Python O(n^2) O(1) Medium Two Pointers
0018 4 Sum C++ Python O(n^3) O(1) Medium Two Pointers
0019 Remove Nth Node From End of List C++ Python O(n) O(1) Medium
0086 Partition List C++ Python O(n) O(1) Medium
0141 Linked List Cycle C++ Python O(n) O(1) Easy
0142 Linked List Cycle II C++ Python O(n) O(1) Medium
0143 Reorder List C++ Python O(n) O(1) Medium
0167 Two Sum II - Input array is sorted C++ Python O(n) O(1) Medium
0209 Minimum Size Subarray Sum C++ Python O(n) O(1) Medium Binary Search, Sliding Window
0259 3Sum Smaller C++ Python O(n^2) O(1) Medium πŸ”’, LintCode
0283 Move Zeroes C++ Python O(n) O(1) Easy
0287 Find the Duplicate Number C++ Python O(n) O(1) Hard Binary Search, Two Pointers
0344 Reverse String C++ Python O(n) O(1) Easy
0345 Reverse Vowels of a String C++ Python O(n) O(1) Easy
0349 Intersection of Two Arrays C++ Python O(m + n) O(min(m, n)) Easy EPI Hash, Binary Search
0350 Intersection of Two Arrays II C++ Python O(m + n) O(1) Easy EPI Hash, Binary Search
0360 Sort Transformed Array C++ Python O(n) O(1) Medium πŸ”’
0424 Longest Repeating Character Replacement C++ Python O(n) O(1) Medium Sliding Window
0457 Circular Array Loop C++ Python O(n) O(1) Medium
0567 Permutation in String C++ Python O(n) O(1) Medium
0611 Valid Triangle Number C++ Python O(n^2) O(1) Medium
0777 Swap Adjacent in LR String C++ Python O(n) O(1) Medium
0826 Most Profit Assigning Work C++ Python O(mlogm + nlogn) O(n) Medium
0828 Count Unique Characters of All Substrings of a Given String C++ Python O(n) O(1) Hard
0844 Backspace String Compare C++ Python O(m + n) O(1) Easy
0862 Shortest Subarray with Sum at Least K C++ Python O(n) O(n) Hard Mono Deque, Sliding Window
0876 Middle of the Linked List C++ Python O(n) O(1) Easy
0904 Fruit Into Baskets C++ Python O(n) O(1) Medium Sliding Window
0930 Binary Subarrays With Sum C++ Python O(n) O(1) Medium Sliding Window
0977 Squares of a Sorted Array C++ Python O(n) O(1) Easy
0992 Subarrays with K Different Integers C++ Python O(n) O(k) Hard Two Pointers, Sliding Window
1004 Max Consecutive Ones III C++ Python O(n) O(1) Medium Sliding Window
1033 Moving Stones Until Consecutive C++ Python O(1) O(1) Easy
1040 Moving Stones Until Consecutive II C++ Python O(nlogn) O(1) Medium
1151 Minimum Swaps to Group All 1's Together C++ Python O(n) O(1) Medium πŸ”’ Sliding Window
1156 Swap For Longest Repeated Character Substring C++ Python O(n) O(1) Medium Sliding Window
1176 Diet Plan Performance C++ Python O(n) O(1) Easy Sliding Window
1208 Get Equal Substrings Within Budget C++ Python O(n) O(1) Medium Sliding Window
1213 Intersection of Three Sorted Arrays C++ Python O(n) O(1) Easy πŸ”’
1169 Invalid Transactions C++ Python O(nlogn) O(n) Medium Sliding Window, Line Sweep
1214 Two Sum BSTs C++ Python O(n) O(n) Medium πŸ”’ Stack
1234 Replace the Substring for Balanced String C++ Python O(n) O(t) Medium Two Pointers, Sliding Window
1248 Count Number of Nice Subarrays C++ Python O(n) O(k) Medium variant of Subarrays with K Different Integers Two Pointers, Sliding Window
1297 Maximum Number of Occurrences of a Substring C++ Python O(n) O(n) Medium Sliding Window, Rabin-Karp Algorithm
1305 All Elements in Two Binary Search Trees C++ Python O(n) O(h) Medium Stack
1316 Distinct Echo Substrings C++ Python O(n^2 + d) O(r) Hard KMP Algorithm, Sliding Window, Rabin-Karp Algorithm
1358 Number of Substrings Containing All Three Characters C++ Python O(n) O(1) Medium Sliding Window
1423 Maximum Points You Can Obtain from Cards C++ Python O(n) O(1) Medium Sliding Window
1425 Constrained Subset Sum C++ Python O(n) O(k) Hard variant of Sliding Window Maximum Mono Deque, Sliding Window
1456 Maximum Number of Vowels in a Substring of Given Length C++ Python O(n) O(1) Medium Sliding Window
1493 Longest Subarray of 1's After Deleting One Element C++ Python O(n) O(1) Medium Sliding Window
1498 Number of Subsequences That Satisfy the Given Sum Condition C++ Python O(nlogn) O(n) Medium Two Pointers
1508 Range Sum of Sorted Subarray Sums C++ Python O(nlog(sum(nums))) O(n) Medium Binary Search, Two Pointers, Sliding Window
1521 Find a Value of a Mysterious Function Closest to Target C++ Python O(nlogm) O(logm) Hard DP, Two Pointers, Sliding Window
1604 Alert Using Same Key-Card Three or More Times in a One Hour Period C++ Python O(nlogn) O(n) Medium Two Pointers, Sliding Window


Recursion

# Title Solution Time Space Difficulty Tag Note
0095 Unique Binary Search Trees II C++ Python O(4^n / n^(3/2) O(4^n / n^(3/2) Medium
0098 Validate Binary Search Tree C++ Python O(n) O(1) Medium
0100 Same Tree C+ Python O(n) O(h) Easy
0104 Maximum Depth of Binary Tree C++ Python O(n) O(h) Easy
0105 Construct Binary Tree from Preorder and Inorder Traversal C++ Python O(n) O(n) Medium
0106 Construct Binary Tree from Inorder and Postorder Traversal C++ Python O(n) O(n) Medium
0108 Convert Sorted Array to Binary Search Tree C++ Python O(n) O(logn) Medium
0109 Convert Sorted List to Binary Search Tree C++ Python O(n) O(logn) Medium
0110 Balanced Binary Tree Python O(n) O(h) Easy
0111 Minimum Depth of Binary Tree Python O(n) O(h) Easy
0114 Flatten Binary Tree to Linked List Python O(n) O(h) Medium
0116 Populating Next Right Pointers in Each Node Python O(n) O(1) Medium
0124 Binary Tree Maximum Path Sum C++ Python O(n) O(h) Hard
0129 Sum Root to Leaf Numbers Python O(n) O(h) Medium
0156 Binary Tree Upside Down Python O(n) O(1) Medium πŸ”’
0241 Different Ways to Add Parentheses C++ Python O(n * 4^n / n^(3/2)) O(n * 4^n / n^(3/2)) Medium
0298 Binary Tree Longest Consecutive Sequence C++ Python O(n) O(h) Medium πŸ”’
0327 Count of Range Sum C++ Python O(nlogn) O(n) Hard
0333 Largest BST Subtree C++ Python O(n) O(h) Medium πŸ”’
0337 House Robber III C++ Python O(n) O(h) Medium
0395 Longest Substring with At Least K Repeating Characters C++ Python O(n) O(1) Medium
0404 Sum of Left Leaves C++ Python O(n) O(h) Easy
0437 Path Sum III C++ Python O(n) O(h) Easy
0544 Output Contest Matches C++ Python O(n) O(n) Medium
0549 Binary Tree Longest Consecutive Sequence II C++ Python O(n) O(h) Medium πŸ”’
0669 Trim a Binary Search Tree C++ Python O(n) O(h) Easy
0671 Second Minimum Node In a Binary Tree C++ Python O(n) O(h) Easy
0761 Special Binary String C++ Python O(n^2) O(n) Hard
1106 Parsing A Boolean Expression C++ Python O(n) O(n) Hard


Binary Search

# Title Solution Time Space Difficulty Tag Note
0004 Median of Two Sorted Arrays C++ Python O(log(min(m, n))) O(1) Hard
0033 Search in Rotated Sorted Array C++ Python O(logn) O(1) Medium CTCI
0034 Search for a Range C++ Python O(logn) O(1) Medium
0035 Search Insert Position C++ Python O(logn) O(1) Medium
0069 Sqrt(x) C++ Python O(logn) O(1) Medium
0074 Search a 2D Matrix C++ Python O(logm + logn) O(1) Medium
0081 Search in Rotated Sorted Array II C++ Python O(logn) ~ O(n) O(1) Medium CTCI
0153 Find Minimum in Rotated Sorted Array C++ Python O(logn) O(1) Medium
0154 Find Minimum in Rotated Sorted Array II C++ Python O(logn) ~ O(n) O(1) Hard
0162 Find Peak Element C++ Python O(logn) O(1) Medium
0222 Count Complete Tree Nodes C++ Python O((logn)^2) O(1) Medium
0275 H-Index II C++ Python O(logn) O(1) Medium Binary Search
0278 First Bad Version C++ Python O(logn) O(1) Easy LintCode
0300 Longest Increasing Subsequence C++ Python O(nlogn) O(n) Medium CTCI, LintCode Binary Search, Segment Tree, DP
0302 Smallest Rectangle Enclosing Black Pixels C++ Python O(nlogn) O(1) Hard πŸ”’
0354 Russian Doll Envelopes C++ Python O(nlogn) O(1) Hard
0363 Max Sum of Rectangle No Larger Than K C++ Python O(min(m, n)^2 * max(m, n) * logn(max(m, n))) O(max(m, n)) Hard
0367 Valid Perfect Square C++ Python O(logn) O(1) Medium
0374 Guess Number Higher or Lower C++ Python O(logn) O(1) Easy
0410 Split Array Largest Sum C++ Python O(nlogs) O(1) Hard
0436 Find Right Interval C++ Python O(nlogn) O(n) Medium
0475 Heaters C++ Python O((m + n) * logn) O(1) Easy
0540 Single Element in a Sorted Array C++ Python O(logn) O(1) Medium
0658 Find K Closest Elements C++ Python O(logn + k) O(1) Medium
0668 Kth Smallest Number in Multiplication Table C++ Python O(m * log(m * n)) O(1) Hard
0719 Find K-th Smallest Pair Distance C++ Python O(nlogn + nlogw) O(1) Hard
0744 Find Smallest Letter Greater Than Target C++ Python O(logn) O(1) Easy
0774 Minimize Max Distance to Gas Station C++ Python O(nlogr) O(1) Hard
0786 K-th Smallest Prime Fraction C++ Python O(nlogr) O(1) Hard
0793 Preimage Size of Factorial Zeroes Function C++ Python O((logn)^2) O(1) Hard
0852 Peak Index in a Mountain Array C++ Python O(logn) O(1) Easy
0864 Random Pick with Blacklist C++ Python ctor: O(b)
pick: O(1)
O(b) Hard
0875 Koko Eating Bananas C++ Python O(nlogr) O(1) Medium
0878 Nth Magical Number C++ Python O(logn) O(1) Hard
0894 All Possible Full Binary Trees C++ Python O(n * 4^n / n^(3/2)) O(n * 4^n / n^(3/2)) Medium
0911 Online Election C++ Python ctor: O(n)
query : O(logn)
O(n) Medium
0981 Time Based Key-Value Store C++ Python set: O(1)
get : O(logn)
O(n) Medium
1011 Capacity To Ship Packages Within D Days C++ Python O(nlogr) O(1) Medium
1044 Longest Duplicate Substring C++ Python O(nlogn) O(n) Hard Rabin-Karp Algorithm, Suffix Tree, Ukkonen's Algorithm
1060 Missing Element in Sorted Array C++ Python O(logn) O(1) Medium πŸ”’
1062 Longest Repeating Substring C++ Python O(nlogn) O(n) Medium πŸ”’ Rabin-Karp Algorithm
1064 Fixed Point C++ Python O(logn) O(1) Easy πŸ”’
1095 Find in Mountain Array C++ Python O(logn) O(1) Hard
1110 Delete Nodes And Return Forest C++ Python O(n) O(h + d) Medium
1170 Compare Strings by Frequency of the Smallest Character C++ Python O((m + n)logn) O(n) Easy
1201 Ugly Number III C++ Python O(logn) O(1) Medium Inclusion-Exclusion Principle
1228 Missing Number In Arithmetic Progression C++ Python O(logn) O(1) Easy
1231 Divide Chocolate C++ Python O(nlogn) O(1) Hard
1274 Number of Ships in a Rectangle C++ Python O(log(m * n)) O(log(m * n)) Hard Divide and Conquer
1283 Find the Smallest Divisor Given a Threshold C++ Python O(logn) O(1) Medium
1287 Element Appearing More Than 25% In Sorted Array C++ Python O(logn) O(1) Easy
1385 Find the Distance Value Between Two Arrays C++ Python O((n + m) * logm) O(1) Easy Binary Search, Two Pointers
1482 Minimum Number of Days to Make m Bouquets C++ Python O(nlogd) O(1) Medium
1533 Find the Index of the Large Integer C++ Python O(logn) O(1) Medium πŸ”’
1539 Kth Missing Positive Number C++ Python O(logn) O(1) Easy
1552 Magnetic Force Between Two Balls C++ Python O(nlogn + nlogr) O(1) Medium
1618 Maximum Font to Fit a Sentence in a Screen C++ Python O(n + logm) O(1) Medium πŸ”’


Binary Search Tree

# Title Solution Time Space Difficulty Tag Note
0220 Contains Duplicate III C++ Python O(nlogk) O(k) Medium
0230 Kth Smallest Element in a BST C++ Python O(max(h, k)) O(min(h, k)) Medium
0235 Lowest Common Ancestor of a Binary Search Tree C++ Python O(h) O(1) Easy EPI
0270 Closest Binary Search Tree Value C++ Python O(h) O(1) Easy πŸ”’
0285 Inorder Successor in BST C++ Python O(h) O(1) Medium πŸ”’
0352 Data Stream as Disjoint Intervals C++ Python O(logn) O(n) Hard
0449 Serialize and Deserialize BST C++ Python O(n) O(h) Medium
0450 Delete Node in a BST C++ Python O(h) O(h) Medium
0530 Minimum Absolute Difference in BST C++ Python O(n) O(h) Easy
0776 Split BST C++ Python O(n) O(h) Medium πŸ”’
0783 Minimum Distance Between BST Nodes C++ Python O(n) O(h) Easy
0510 Inorder Successor in BST II C++ Python O(h) O(1) Medium πŸ”’
1373 Maximum Sum BST in Binary Tree C++ Python O(n) O(h) Hard DFS, Stack
1382 Balance a Binary Search Tree C++ Python O(n) O(h) Medium DFS, Stack


Breadth-First Search

# Title Solution Time Space Difficulty Tag Note
0102 Binary Tree Level Order Traversal C++ Python O(n) O(n) Easy
0107 Binary Tree Level Order Traversal II C++ Python O(n) O(n) Easy
0103 Binary Tree Zigzag Level Order Traversal Python O(n) O(n) Medium
0117 Populating Next Right Pointers in Each Node II Python O(n) O(1) Hard
0127 Word Ladder C++ Python O(b^(d/2)) O(w * l) Medium CTCI Bi-BFS
0130 Surrounded Regions C++ Python O(m * n) O(m + n) Medium
0133 Clone Graph Python O(n) O(n) Medium
0207 Course Schedule C++ Python O(|V| + |E|) O(|E|) Medium Topological Sort
0210 Course Schedule II C++ Python O(|V| + |E|) O(|E|) Medium Topological Sort
0261 Graph Valid Tree C++ Python O(|V| + |E|) O(|V| + |E|) Medium πŸ”’
0269 Alien Dictionary C++ Python O(n) O(1) Hard πŸ”’ Topological Sort, BFS, DFS
0286 Walls and Gates C++ Python O(m * n) O(g) Medium πŸ”’
0310 Minimum Height Trees C++ Python O(n) O(n) Medium
0317 Shortest Distance from All Buildings C++ Python O(k * m * n) O(m * n) Hard πŸ”’
0433 Minimum Genetic Mutation C++ Python O(n * b) O(b) Medium
0444 Sequence Reconstruction C++ Python O(n * s) O(n) Medium πŸ”’ Topological Sort
0490 The Maze C++ Python O(max(r, c) * w) O(w) Medium
0499 The Maze III C++ Python O(max(r, c) * wlogw) O(w^2) Hard
0505 The Maze II C++ Python O(max(r, c) * wlogw) O(w) Medium
0542 01 Matrix C++ Python O(m * n) O(1) Medium DP
0666 Path Sum IV C++ Python O(n) O(w) Medium πŸ”’ Topological Sort
0675 Cut Off Trees for Golf Event C++ Python O(t * m * n) O(m * n) Hard A* Search Algorithm
0742 Closest Leaf in a Binary Tree C++ Python O(n) O(n) Medium
0743 Network Delay Time C++ Python O(|E| * log|V|) O(|E|) Medium Dijkstra's Algorithm
0752 Open the Lock C++ Python O(k * n^k + d) O(k * n^k + d) Medium
0773 Sliding Puzzle C++ Python O((m * n) * (m * n)!) O((m * n) * (m * n)!) Hard A* Search Algorithm
0787 Cheapest Flights Within K Stops C++ Python O(|E| * log|V|) O(|E|) Medium Dijkstra's Algorithm
0815 Bus Routes C++ Python O(|E| + |V|) O(|E| + |V|) Hard
0854 K-Similar Strings C++ Python O(n * n!/(c_a!*...*c_z!)) O(n * n!/(c_a!*...*c_z!)) Hard
0865 Shortest Path to Get All Keys C++ Python O(k * r * c + k^3*2^k) O(k*2^k) Hard Dijkstra's Algorithm
0882 Reachable Nodes In Subdivided Graph C++ Python O(|E| * log|V|) O(|E|) Hard Dijkstra's Algorithm
0886 Possible Bipartition C++ Python O(|V| + |E|) O(|V| + |E|) Medium
0934 Shortest Bridge C++ Python O(n^2) O(n^2) Medium BFS, DFS
0967 Numbers With Same Consecutive Differences C++ Python O(2^n) O(2^n) Medium
0994 Rotting Oranges C++ Python O(m * n) O(m * n) Easy
1034 Coloring A Border C++ Python O(m * n) O(m + n) Medium
1036 Escape a Large Maze C++ Python O(n^2) O(n) Hard
1091 Shortest Path in Binary Matrix C++ Python O(n^2) O(n) Medium
1102 Path With Maximum Minimum Value C++ Python O((m * n) * log(m * n)) O(m * n) Medium πŸ”’ Binary Search, DFS, Dijkstra's Algorithm
1129 Shortest Path with Alternating Colors C++ Python O(n + e) O(n + e) Medium
1136 Parallel Courses C++ Python O(|V| + |E|) O(|E|) Hard πŸ”’ Topological Sort
1161 Maximum Level Sum of a Binary Tree C++ Python O(n) O(w) Medium DFS
1162 As Far from Land as Possible C++ Python O(m * n) O(m * n) Medium
1163 Last Substring in Lexicographical Order C++ Python O(n) O(n) Hard
1203 Sort Items by Groups Respecting Dependencies C++ Python O(n + e) O(n + e) Hard Topological Sort
1210 Minimum Moves to Reach Target with Rotations C++ Python O(n) O(n) Hard
1215 Stepping Numbers C++ Python O(logk + r) O(k) Medium πŸ”’ Precompute, Binary Search
1245 Tree Diameter C++ Python O(|V| + |E|) O(|E|) Medium
1263 Minimum Moves to Move a Box to Their Target Location C++ Python O(m^2 * n^2) O(m^2 * n^2) Hard A* Search Algorithm
1284 Minimum Number of Flips to Convert Binary Matrix to Zero Matrix C++ Python O((m * n) * 2^(m * n)) O((m * n) * 2^(m * n)) Hard
1291 Sequential Digits C++ Python O(1) O(1) Medium
1293 Shortest Path in a Grid with Obstacles Elimination C++ Python O(m * n * k) O(m * n) Hard A* Search Algorithm
1298 Maximum Candies You Can Get from Boxes C++ Python O(n^2) O(n) Hard
1302 Deepest Leaves Sum C++ Python O(n) O(w) Medium
1306 Jump Game III C++ Python O(n) O(n) Medium
1311 Get Watched Videos by Your Friends C++ Python O(n + vlogv) O(w) Medium
1345 Jump Game IV C++ Python O(n) O(n) Hard
1368 Minimum Cost to Make at Least One Valid Path in a Grid C++ Python O(m * n) O(m * n) Hard A* Search Algorithm, 0-1 BFS, Deque
1514 Path with Maximum Probability C++ Python O(|E| * log|V|) O(|E|) Medium Dijkstra's Algorithm
1602 Find Nearest Right Node in Binary Tree C++ Python O(n) O(w) Medium πŸ”’
1609 Even Odd Tree C++ Python O(n) O(w) Medium
1625 Lexicographically Smallest String After Applying Operations C++ Python O(n^2) O(1) Medium BFS, String


Depth-First Search

# Title Solution Time Space Difficulty Tag Note
0112 Path Sum Python O(n) O(h) Easy
0113 Path Sum II Python O(n) O(h) Medium
0199 Binary Tree Right Side View Python O(n) O(h) Medium
0200 Number of Islands C++ Python O(m * n) O(m * n) Medium BFS, DFS, Union Find
0236 Lowest Common Ancestor of a Binary Tree C++ Python O(n) O(h) Medium EPI
0247 Strobogrammatic Number II C++ Python O(n * 5^(n/2)) O(n) Medium πŸ”’
0250 Count Univalue Subtrees C++ Python O(n) O(h) Medium πŸ”’
0257 Binary Tree Paths C++ Python O(n * h) O(h) Easy
0282 Expression Add Operators C++ Python O(4^n) O(n) Hard
0301 Remove Invalid Parentheses C++ Python O(C(n, c)) O(c) Hard
0329 Longest Increasing Path in a Matrix C++ Python O(m * n) O(m * n) Hard DFS, Topological Sort
0332 Reconstruct Itinerary C++ Python O(t! / (n1! * n2! * ... nk!)) O(t) Medium
0339 Nested List Weight Sum C++ Python O(n) O(h) Easy πŸ”’
0364 Nested List Weight Sum II C++ Python O(n) O(h) Medium πŸ”’
0366 Find Leaves of Binary Tree C++ Python O(n) O(h) Medium πŸ”’
0417 Pacific Atlantic Water Flow C++ Python O(m * n) O(m * n) Medium
0440 K-th Smallest in Lexicographical Order C++ Python O(logn) O(logn) Hard
0464 Can I Win C++ Python O(n!) O(n) Medium
0515 Find Largest Value in Each Tree Row C++ Python O(n) O(h) Medium
0547 Friend Circles C++ Python O(n^2) O(n) Medium Union Find
0582 Kill Process C++ Python O(n) O(n) Medium πŸ”’ DFS, BFS
0638 Shopping Offers C++ Python O(n * 2^n) O(n) Medium
0690 Employee Importance C++ Python O(n) O(h) Easy DFS, BFS
0694 Number of Distinct Islands C++ Python O(m * n) O(m * n) Medium πŸ”’
0695 Max Area of Island C++ Python O(m * n) O(m * n) Easy
0711 Number of Distinct Islands II C++ Python O((m * n) * log(m * n)) O(m * n) Hard πŸ”’ Hash
0733 Max Area of Island C++ Python O(m * n) O(m * n) Easy
0749 Contain Virus C++ Python O((m * n)^(4/3)) O(m * n) Hard Simulation
0753 Cracking the Safe C++ Python O(k^n) O(k^n) Hard de Bruijn sequences, Lyndon word, Rolling Hash, Backtracking, Greedy
0756 Pyramid Transition Matrix C++ Python O(a^b) O(a^b) Medium
0785 Is Graph Bipartite? C++ Python O(|V| + |E|) O(|V|) Medium
0797 All Paths From Source to Target C++ Python O(p + r * n) O(n) Medium
0802 Find Eventual Safe States C++ Python O(|V| + |E|) O(|V|) Medium
0827 Making A Large Island C++ Python O(n^2) O(n^2) Hard
0834 Sum of Distances in Tree C++ Python O(n) O(n) Hard
0841 Keys and Rooms C++ Python O(n!) O(n) Medium
0851 Loud and Rich C++ Python O(q + r) O(q + r) Medium
0913 Cat and Mouse C++ Python O(n^3) O(n^2) Hard
1020 Number of Enclaves C++ Python O(m * n) O(m * n) Medium
1059 All Paths from Source Lead to Destination C++ Python O(n + e) O(n + e) Medium πŸ”’
1192 Critical Connections in a Network C++ Python O(|V| + |E|) O(|V| + |E|) Hard Tarjan's Algorithm, Bridge Finding Algorithm
1202 Smallest String With Swaps C++ Python O(nlogn) O(n) Medium Union Find
1254 Number of Closed Islands C++ Python O(m * n) O(1) Medium
1273 Delete Tree Nodes C++ Python O(n) O(n) Medium DFS, DP
1315 Sum of Nodes with Even-Valued Grandparent C++ Python O(n) O(h) Medium
1319 Number of Operations to Make Network Connected C++ Python O(|E| + |V|) O(|V|) Medium Union Find
1367 Linked List in Binary Tree C++ Python O(n + l) O(h + l) Medium KMP Algorithm
1372 Longest ZigZag Path in a Binary Tree C++ Python O(n) O(h) Medium
1376 Time Needed to Inform All Employees C++ Python O(n) O(n) Medium
1377 Frog Position After T Seconds C++ Python O(n) O(n) Hard DFS, Stack, BFS
1391 Check if There is a Valid Path in a Grid C++ Python O(m * n) O(1) Medium Simulation
1466 Reorder Routes to Make All Paths Lead to the City Zero C++ Python O(n) O(n) Medium DFS, Stack
1485 Clone Binary Tree With Random Pointer C++ Python O(n) O(h) Medium πŸ”’ DFS, Stack


Backtracking

# Title Solution Time Space Difficulty Tag Note
0017 Letter Combinations of a Phone Number C++ Python O(n * 4^n) O(1) Medium
0022 Generate Parentheses C++ Python O(4^n / n^(3/2)) O(n) Medium
0037 Sudoku Solver Python O((9!)^9) O(1) Hard
0039 Combination Sum Python O(k * n^k) O(k) Medium
0040 Combination Sum II Python O(k * C(n, k)) O(k) Medium
0046 Permutations Python O(n * n!) O(n) Medium
0047 Permutations II Python O(n * n!) O(n) Medium
0051 N-Queens Python O(n!) O(n) Hard
0052 N-Queens-II Python O(n!) O(n) Hard
0077 Combinations C++ Python O(O(k * C(n, k))) O(k) Medium
0079 Word Search C++ Python O(m * n * 3^l) O(l) Medium
0093 Restore IP Addresses Python O(1) O(1) Medium
0078 Subsets C++ Python O(n * 2^n) O(1) Medium
0090 Subsets II C++ Python O(n * 2^n) O(1) Medium
0126 Word Ladder II C++ Python O(b^(d/2)) O(w * l) Hard CTCI Bi-BFS
0131 Palindrome Partitioning Python O(n^2) ~ O(2^n) O(n^2) Medium
0140 Word Break II C++ Python O(n * l^2 + n * r) O(n^2) Hard
0212 Word Search II C++ Python O(m * n * 3^h) O(t) Hard LintCode Trie, DFS
0216 Combination Sum III C++ Python O(k * C(n, k)) O(k) Medium
0254 Factor Combinations C++ Python O(nlogn) O(logn) Medium πŸ”’
0267 Palindrome Permutation II C++ Python O(n * n!) O(n) Medium πŸ”’
0291 Word Pattern II C++ Python O(n * C(n - 1, c - 1)) O(n + c) Hard πŸ”’
0294 Flip Game II C++ Python O(n + c^2) O(c) Medium πŸ”’ DP, Hash
0320 Generalized Abbreviation C++ Python O(n * 2^n) O(n) Medium πŸ”’
0425 Word Squares C++ Python O(n^2 * n!) O(n^2) Hard πŸ”’
0526 Beautiful Arrangement C++ Python O(n!) O(n) Medium
0676 Implement Magic Dictionary C++ Python O(n) O(d) Medium Trie, DFS
0679 24 Game C++ Python O(1) O(1) Hard DFS
0698 Partition to K Equal Sum Subsets C++ Python O(n * 2^n) O(2^n) Medium DFS, DP, Memoization
0718 Maximum Length of Repeated Subarray C++ Python O(m * n) O(min(m, n)) Medium DP, Hash, Binary Search
0784 Letter Case Permutation C++ Python O(n * 2^n) O(1) Easy
0996 Number of Squareful Arrays C++ Python O(n!) O(n^2) Hard
1087 Brace Expansion C++ Python O(p * l * log(p * l)) O(p * l) Medium πŸ”’
1096 Brace Expansion II C++ Python O(p * l * log(p * l)) O(p * l) Hard
1219 Path with Maximum Gold C++ Python O(m^2 * n^2) O(m * n) Medium
1240 Tiling a Rectangle with the Fewest Squares C++ Python O(n^2 * m^2 * m^(n * m)) O(n * m) Hard
1255 Maximum Score Words Formed by Letters C++ Python O(n * 2^n) O(n) Hard
1258 Synonymous Sentences C++ Python O(p * l * log(p * l)) O(p * l) Medium Union Find
1307 Verbal Arithmetic Puzzle C++ Python O(10! * n * l) O(n * l) Hard
1379 Find a Corresponding Node of a Binary Tree in a Clone of That Tree C++ Python O(n) O(h) Medium Stack
1593 Split a String Into the Max Number of Unique Substrings C++ Python O(n * 2^(n - 1)) O(n) Medium


Dynamic Programming

# Title Solution Time Space Difficulty Tag Note
0010 Regular Expression Matching Python O(m * n) O(n) Hard
0044 Wildcard Matching Python O(m * n) O(1) Hard Greedy
0053 Maximum Subarray C++ Python O(n) O(1) Medium
0062 Unique Paths Python O(m * n) O(m + n) Medium
0063 Unique Paths II Python O(m * n) O(m + n) Medium
0064 Minimum Path Sum Python O(m * n) O(m + n) Medium
0070 Climbing Stairs C++ Python O(logn) O(1) Easy Matrix Exponentiation
0072 Edit Distance Python O(m * n) O(m + n) Hard
0087 Scramble String Python O(n^4) O(n^3) Hard
0091 Decode Ways C++ Python O(n) O(1) Medium
0096 Unique Binary Search Trees Python O(n) O(1) Medium Math
0097 Interleaving String Python O(m * n) O(m + n) Hard
0115 Distinct Subsequences Python O(n^2) O(n) Hard
0120 Triangle Python O(m * n) O(n) Medium
0123 Best Time to Buy and Sell Stock III Python O(n) O(1) Hard
0132 Palindrome Partitioning II Python O(n^2) O(n^2) Hard
0139 Word Break C++ Python O(n * l^2) O(n) Medium
0152 Maximum Product Subarray C++ Python O(n) O(1) Medium
0174 Dungeon Game Python O(m * n) O(m + n) Hard
0188 Best Time to Buy and Sell Stock IV C++ Python O(n) O(n) Hard Quick Select, Mono Stack
0198 House Robber C++ Python O(n) O(1) Easy
0213 House Robber II C++ Python O(n) O(1) Medium
0221 Maximal Square C++ Python O(n^2) O(n) Medium EPI
0256 Paint House C++ Python O(n) O(1) Medium πŸ”’
0265 Paint House II C++ Python O(n * k) O(k) Hard πŸ”’
0276 Paint Fence C++ Python O(n) O(1) Easy πŸ”’
0279 Perfect Squares C++ Python O(n * sqrt(n)) O(n) Medium Hash
0303 Range Sum Query - Immutable C++ Python ctor: O(n), lookup: O(1) O(n) Easy
0304 Range Sum Query 2D - Immutable C++ Python ctor: O(m * n), lookup: O(1) O(m * n) Medium
0309 Best Time to Buy and Sell Stock with Cooldown C++ Python O(n) O(1) Medium
0312 Burst Balloons C++ Python O(n^3) O(n^2) Hard
0322 Coin Change C++ Python O(n * k) O(k) Medium
0351 Android Unlock Patterns C++ Python O(9^2 * 2^9) O(9 * 2^9) Medium πŸ”’ Backtracking
0357 Count Numbers with Unique Digits C++ Python O(n) O(1) Medium Backtracking, Math
0361 Bomb Enemy C++ Python O(m * n) O(m * n) Medium πŸ”’
0368 Largest Divisible Subset C++ Python O(n^2) O(n) Medium
0375 Guess Number Higher or Lower II C++ Python O(n^2) O(n^2) Medium
0377 Combination Sum IV C++ Python O(nlogn + n * t) O(t) Medium
0403 Frog Jump C++ Python O(n^2) O(n^2) Hard
0416 Partition Equal Subset Sum C++ Python O(n * s) O(s) Medium
0418 Sentence Screen Fitting C++ Python O(r + n * c) O(n) Medium πŸ”’
0446 Arithmetic Slices II - Subsequence C++ Python O(n^2) O(n * d) Hard
0465 Optimal Account Balancing C++ Python O(n * 2^n) O(2^n) Hard πŸ”’
0466 Count The Repetitions C++ Python O(s1 * min(s2, n1)) O(s2) Hard
0467 Unique Substrings in Wraparound String C++ Python O(n) O(1) Medium
0471 Encode String with Shortest Length C++ Python O(n^3) on average O(n^2) Medium πŸ”’
0472 Concatenated Words C++ Python O(n * l^2) O(n * l) Medium
0474 Ones and Zeroes C++ Python O(s * m * n) O(m * n) Medium
0486 Predict the Winner C++ Python O(n^2) O(n) Medium
0509 Fibonacci Number C++ Python O(logn) O(1) Easy variant of Climbing Stairs Matrix Exponentiation
0514 Freedom Trail C++ Python O(k) ~ O(k * r^2) O(r) Hard
0516 Longest Palindromic Subsequence C++ Python O(n^2) O(n) Medium
0546 Remove Boxes C++ Python O(n^3) ~ O(n^4) O(n^3) Hard
0552 Student Attendance Record II C++ Python O(n) O(1) Hard
0562 Longest Line of Consecutive One in Matrix C++ Python O(m * n) O(n) Medium πŸ”’
0568 Maximum Vacation Days C++ Python O(n^2 * k) O(k) Hard πŸ”’
0576 Out of Boundary Paths C++ Python O(N * m * n) O(m * n) Medium
0583 Delete Operation for Two Strings C++ Python O(m * n) O(n) Medium
0600 Non-negative Integers without Consecutive Ones C++ Python O(1) O(1) Hard
0629 K Inverse Pairs Array C++ Python O(n * k) O(k) Hard
0639 Decode Ways II C++ Python O(n) O(1) Hard
0650 2 Keys Keyboard C++ Python O(sqrt(n)) O(1) Medium
0656 Coin Path C++ Python O(n * B) O(n) Hard πŸ”’
0664 Strange Printer C++ Python O(n^3) O(n^2) Hard
0673 Number of Longest Increasing Subsequence C++ Python O(n^2) O(n) Medium
0688 Knight Probability in Chessboard C++ Python O(k * n^2) O(n^2) Medium
0689 Maximum Sum of 3 Non-Overlapping Subarrays C++ Python O(n) O(n) Hard
0691 Stickers to Spell Word C++ Python O(T * S^T) O(T * S^T) Hard Backtracking, Memoization
0712 Minimum ASCII Delete Sum for Two Strings C++ Python O(m * n) O(n) Medium
0714 Best Time to Buy and Sell Stock with Transaction Fee C++ Python O(n) O(1) Medium
0727 Minimum Window Subsequence C++ Python O(s * t) O(s) Hard πŸ”’
0730 Count Different Palindromic Subsequences C++ Python O(n^2) O(n) Hard
0740 Delete and Earn C++ Python O(n) O(1) Medium
0741 Cherry Pickup C++ Python O(n^3) O(n^2) Hard
0746 Min Cost Climbing Stairs C++ Python O(n) O(1) Easy
0750 Number Of Corner Rectangles C++ Python O(n * m^2) O(n * m) Medium
0764 Largest Plus Sign C++ Python O(n^2) O(n^2) Medium
0788 Rotated Digits C++ Python O(logn) O(logn) Easy Memoization
0790 Domino and Tromino Tiling C++ Python O(logn) O(1) Medium Matrix Exponentiation
0799 Champagne Tower C++ Python O(n^2) O(n) Medium
0801 Minimum Swaps To Make Sequences Increasing C++ Python O(n) O(1) Medium
0805 Split Array With Same Average C++ Python O(n^4) O(n^3) Hard
0808 Soup Servings C++ Python O(1) O(1) Medium Memoization
0813 Largest Sum of Averages C++ Python O(k * n^2) O(n) Medium
0818 Race Car C++ Python O(nlogn) O(n) Hard
0823 Binary Trees With Factors C++ Python O(n^2) O(n) Medium
0837 New 21 Game C++ Python O(n) O(n) Medium
0838 Push Dominoes C++ Python O(n) O(n) Medium
0847 Shortest Path Visiting All Nodes C++ Python O(n *2^n) O(n * 2^n) Hard BFS
0877 Stone Game C++ Python O(n^2) O(n) Medium variant of Predict the Winner
0879 Profitable Schemes C++ Python O(n * p * g) O(p * g) Hard
0903 Valid Permutations for DI Sequence C++ Python O(n^2) O(n) Hard
0920 Number of Music Playlists C++ Python O(n * l) O(l) Hard
0926 Flip String to Monotone Increasing C++ Python O(n) O(1) Medium
0931 Minimum Falling Path Sum C++ Python O(n^2) O(1) Medium
0935 Knight Dialer C++ Python O(logn) O(1) Medium Matrix Exponentiation
0940 Distinct Subsequences II C++ Python O(n) O(1) Hard
0943 Find the Shortest Superstring C++ Python O(n^2 * (l^2 + 2^n)) O(n^2) Hard
0956 Tallest Billboard C++ Python O(n * 3^(n/2)) O(3^(n/2)) Hard
0960 Delete Columns to Make Sorted III C++ Python O(n * l^2) O(l) Hard
0964 Least Operators to Express Number C++ Python O(logn / logx) O(logn) Hard Math
0975 Odd Even Jump C++ Python O(nlogn) O(n) Hard Mono Stack, BST
0980 Unique Paths III C++ Python O((m * n) * 2^(m * n)) O((m * n) * 2^(m * n)) Hard
0983 Minimum Cost For Tickets C++ Python O(n) O(1) Medium
1000 Minimum Cost to Merge Stones C++ Python O(n^3 / k) O(n^2) Hard
1027 Longest Arithmetic Sequence C++ Python O(n^2) O(n^2) Medium
1035 Uncrossed Lines C++ Python O(m * n) O(min(m, n)) Medium
1039 Minimum Score Triangulation of Polygon C++ Python O(n^3) O(n^2) Medium
1043 Partition Array for Maximum Sum C++ Python O(n * k) O(k) Medium
1048 Longest String Chain C++ Python O(n * l^2) O(n * l) Medium
1049 Last Stone Weight II C++ Python O(2^n) O(2^n) Medium
1066 Campus Bikes II C++ Python O(w * b * 2^b) O(w * b * 2^b) Medium πŸ”’
1092 Shortest Common Supersequence C++ Python O(m * n) O(m * n) Hard
1105 Filling Bookcase Shelves C++ Python O(n^2) O(n) Medium
1125 Smallest Sufficient Team C++ Python O(m * 2^n) O(2^n) Hard
1137 N-th Tribonacci Number C++ Python O(logn) O(1) Easy variant of Fibonacci Number Matrix Exponentiation
1139 Largest 1-Bordered Square C++ Python O(n^3) O(n^2) Medium
1140 Stone Game II C++ Python O(n*(logn)^2) O(nlogn) Medium
1143 Longest Common Subsequence C++ Python O(m * n) O(min(m, n)) Medium
1155 Number of Dice Rolls With Target Sum C++ Python O(d * f * t) O(t) Medium
1182 Shortest Distance to Target Color C++ Python O(n) O(n) Medium πŸ”’
1186 Maximum Subarray Sum with One Deletion C++ Python O(n) O(1) Medium
1187 Make Array Strictly Increasing C++ Python O(n^2 * logn) O(n) Hard
1191 K-Concatenation Maximum Sum C++ Python O(n) O(1) Medium
1216 Valid Palindrome III C++ Python O(n^2) O(n) Hard πŸ”’, variant of Longest Palindromic Subsequence
1218 Longest Arithmetic Subsequence of Given Difference C++ Python O(n) O(n) Medium
1220 Count Vowels Permutation C++ Python O(logn) O(1) Hard Matrix Exponentiation
1223 Dice Roll Simulation C++ Python O(m * n) O(m) Medium
1230 Toss Strange Coins C++ Python O(n^2) O(n) Medium
1235 Maximum Profit in Job Scheduling C++ Python O(nlogn) O(n) Hard DP, Heap
1239 Maximum Length of a Concatenated String with Unique Characters C++ Python O(n) ~ O(2^n) O(1) ~ O(2^n) Medium DP, Bit Manipulation
1246 Palindrome Removal C++ Python O(n^3) O(n^2) Hard
1262 Greatest Sum Divisible by Three C++ Python O(n) O(1) Medium
1269 Number of Ways to Stay in the Same Place After Some Steps C++ Python O(n^2) O(n) Hard
1277 Count Square Submatrices with All Ones C++ Python O(m * n) O(1) Medium
1278 Palindrome Partitioning III C++ Python O(k * n^2) O(n^2) Hard
1289 Minimum Falling Path Sum II C++ Python O(m * n) O(1) Hard
1292 Maximum Side Length of a Square with Sum Less than or Equal to Threshold C++ Python O(m * n * log(min(m, n))) O(m * n) Medium Binary Search
1301 Number of Paths with Max Score C++ Python O(n^2) O(n) Hard
1312 Minimum Insertion Steps to Make a String Palindrome C++ Python O(n^2) O(n) Hard variant of Longest Common Subsequence
1314 Matrix Block Sum C++ Python O(m * n) O(m * n) Medium variant of Range Sum Query 2D - Immutable
1320 Minimum Distance to Type a Word Using Two Fingers C++ Python O(n) O(1) Hard
1335 Minimum Difficulty of a Job Schedule C++ Python O(d * n^2) O(d * n) Hard
1340 Jump Game V C++ Python O(n) O(n) Hard Sliding Window, Mono Stack, Segment Tree
1349 Maximum Students Taking Exam C++ Python O(m * n * sqrt(m * n)) O(m + n) Hard GCJ2008 - Round 3 Hopcroft-Karp Bipartite Matching, Hungarian Bipartite Matching
1387 Sort Integers by The Power Value C++ Python O(n) on average O(n) Medium Quick Select
1388 Pizza With 3n Slices C++ Python O(n^2) O(n) Hard variant of House Robber II
1395 Count Number of Teams C++ Python O(n^2) O(1) Medium
1397 Find All Good Strings C++ Python O(m * n) O(m) Hard KMP Algorithm
1406 Stone Game III C++ Python O(n) O(1) Hard
1411 Number of Ways to Paint N Γ— 3 Grid C++ Python O(logn) O(1) Hard Matrix Exponentiation
1416 Restore The Array C++ Python O(nlogk) O(logk) Hard
1420 Build Array Where You Can Find The Maximum Exactly K Comparisons C++ Python O(n * m * k) O(m * k) Hard
1434 Number of Ways to Wear Different Hats to Each Other C++ Python O(h * 2^n) O(2^n) Hard
1444 Number of Ways of Cutting a Pizza C++ Python O(m * n * k * (m + n)) O(m * n * k) Hard
1449 Form Largest Integer With Digits That Add up to Target C++ Python O(t) O(t) Hard
1458 Max Dot Product of Two Subsequences C++ Python O(m * n) O(min(m, n)) Hard
1463 Cherry Pickup II C++ Python O(m * n^2) O(n^2) Hard
1467 Probability of a Two Boxes Having The Same Number of Distinct Balls C++ Python O(k^3 * n^2) O(k^2 * n) Hard Binomial Coefficients
1473 Paint House III C++ Python O(m * t * n^2) O(t * n) Hard
1477 Find Two Non-overlapping Sub-arrays Each With Target Sum C++ Python O(n) O(n) Medium
1478 Allocate Mailboxes C++ Python O(m * n^2) O(n) Hard DP, Math
1494 Parallel Courses II C++ Python O((n * C(c, min(c, k))) * 2^n) O(2^n) Hard Combinations
1504 Count Submatrices With All Ones C++ Python O(m * n) O(n) Medium Mono Stack
1510 Stone Game IV C++ Python O(n * sqrt(n)) O(n) Hard
1524 Number of Sub-arrays With Odd Sum C++ Python O(n) O(1) Medium
1531 String Compression II C++ Python O(n^2 * k) O(n * k) Hard
1547 Minimum Cost to Cut a Stick C++ Python O(n^3) O(n^2) Hard
1548 The Most Similar Path in a Graph C++ Python O(n^ * m) O(n * m) Hard πŸ”’
1553 Minimum Number of Days to Eat N Oranges C++ Python O((logn)^2) O((logn)^2) Hard
1563 Stone Game V C++ Python O(n^2) O(n^2) Hard
1569 Number of Ways to Reorder Array to Get Same BST C++ Python O(n^2) O(n^2) Hard DFS
1575 Count All Possible Routes C++ Python O(nlogn + n * f) O(n * f) Hard Math
1594 Maximum Non Negative Product in a Matrix C++ Python O(m * n) O(n) Medium
1595 Minimum Cost to Connect Two Groups of Points C++ Python O(m * n * 2^n) O(2^n) Hard
1617 Count Subtrees With Max Distance Between Cities C++ Python O(n^6) O(n^3) Hard Backtracking, Graph
1626 Best Team With No Conflicts C++ Python O(nloga) O(n) Medium variant of Longest Increasing Subsequence Sort, DP, Segment Tree
1639 Number of Ways to Form a Target String Given a Dictionary C++ Python O(l * (w + n)) O(n) Hard


Greedy

# Title Solution Time Space Difficulty Tag Note
0011 Container With Most Water C++ Python O(n) O(1) Medium
0042 Trapping Rain Water C++ Python O(n) O(1) Hard Tricky
0045 Jump Game II Python O(n) O(1) Hard
0055 Jump Game C++ Python O(n) O(1) Medium
0122 Best Time to Buy and Sell Stock II C++ Python O(n) O(1) Easy
0134 Gas Station Python O(n) O(1) Medium
0135 Candy C++ Python O(n) O(n) Hard
0316 Remove Duplicate Letters C++ Python O(n) O(1) Hard Mono Stack
0321 Create Maximum Number C++ Python O(k * (m + n + k)) ~ O(k * (m + n + k^2)) O(m + n + k^2) Hard variant of Delete Digits Greedy, DP
0330 Patching Array C++ Python O(s + logn) O(1) Hard
0376 Wiggle Subsequence C++ Python O(n) O(1) Medium
0392 Is Subsequence C++ Python O(n) O(1) Medium
0397 Integer Replacement C++ Python O(n) O(1) Medium Math
0402 Remove K Digits C++ Python O(n) O(n) Medium LintCode
0435 Non-overlapping Intervals C++ Python O(nlogn) O(1) Medium Line Sweep
0452 Minimum Number of Arrows to Burst Balloons C++ Python O(nlogn) O(1) Medium
0455 Assign Cookies C++ Python O(nlogn) O(1) Easy
0621 Task Scheduler C++ Python O(n) O(1) Medium
0630 Course Schedule III C++ Python O(nlogn) O(k) Hard
0646 Maximum Length of Pair Chain C++ Python O(nlogn) O(1) Medium variant of Non-overlapping Intervals Line Sweep
0649 Dota2 Senate C++ Python O(n) O(n) Medium
0659 Split Array into Consecutive Subsequences C++ Python O(n) O(1) Medium
0738 Monotone Increasing Digits C++ Python O(1) O(1) Medium
0757 Set Intersection Size At Least Two C++ Python O(nlogn) O(n) Hard
0759 Employee Free Time C++ Python O(m * logn) O(n) Hard
0763 Partition Labels C++ Python O(n) O(n) Medium
0767 Reorganize String C++ Python O(n) O(1) Medium
0798 Smallest Rotation with Highest Score C++ Python O(n) O(1) Hard
0843 Guess the Word C++ Python O(n) O(n) Hard MinMax, Math
0861 Score After Flipping Matrix C++ Python O(r * c) O(1) Medium
0870 Advantage Shuffle C++ Python O(nlogn) O(n) Medium
0881 Boats to Save People C++ Python O(nlogn) O(n) Medium
0936 Stamping The Sequence C++ Python O((n - m) * m) O((n - m) * m) Hard
0948 Bag of Tokens C++ Python O(nlogn) O(1) Medium Two Pointers
0962 Maximum Width Ramp C++ Python O(n) O(n) Medium Mono Stack
0968 Binary Tree Cameras C++ Python O(n) O(h) Hard DFS
0984 String Without AAA or BBB C++ Python O(a + b) O(1) Easy
0991 Broken Calculator C++ Python O(logn) O(1) Medium
0995 Minimum Number of K Consecutive Bit Flips C++ Python O(n) O(1) Hard
1005 Maximize Sum Of Array After K Negations C++ Python O(n) on average O(1) Easy Quick Select
1024 Video Stitching C++ Python O(nlogn) O(1) Medium variant of Jump Game II
1029 Two City Scheduling C++ Python O(n) on average O(1) Easy Quick Select
1053 Previous Permutation With One Swap C++ Python O(n) O(1) Medium
1055 Shortest Way to Form String C++ Python O(m + n) O(m) Medium πŸ”’, variant of Minimum Window Subsequence
1058 Minimize Rounding Error to Meet Target C++ Python O(n) on average O(n) Medium πŸ”’ Quick Select
1081 Smallest Subsequence of Distinct Characters C++ Python O(n) O(1) Medium same as Remove Duplicate Letters Mono Stack
1090 Largest Values From Labels C++ Python O(nlogn) O(n) Medium
1111 Maximum Nesting Depth of Two Valid Parentheses Strings C++ Python O(n) O(1) Medium
1167 Minimum Cost to Connect Sticks C++ Python O(nlogn) O(n) Medium πŸ”’
1183 Maximum Number of Ones C++ Python O(1) O(1) Hard πŸ”’
1196 How Many Apples Can You Put into the Basket C++ Python O(nlogn) O(n) Easy πŸ”’
1199 Minimum Time to Build Blocks C++ Python O(nlogn) O(n) Hard πŸ”’
1221 Split a String in Balanced Strings C++ Python O(n) O(1) Easy
1247 Minimum Swaps to Make Strings Equal C++ Python O(n) O(1) Easy
1249 Minimum Remove to Make Valid Parentheses C++ Python O(n) O(1) Medium Stack
1253 Reconstruct a 2-Row Binary Matrix C++ Python O(n) O(1) Medium
1272 Remove Interval C++ Python O(n) O(1) Medium Line Sweep
1282 Group the People Given the Group Size They Belong To C++ Python O(n) O(n) Medium
1288 Remove Covered Intervals C++ Python O(nlogn) O(1) Medium Line Sweep
1296 Divide Array in Sets of K Consecutive Numbers C++ Python O(nlogn) O(n) Medium
1326 Minimum Number of Taps to Open to Water a Garden C++ Python O(n) O(n) Hard variant of Jump Game II
1338 Reduce Array Size to The Half C++ Python O(n) O(n) Medium Counting Sort
1353 Maximum Number of Events That Can Be Attended C++ Python O(r + nlogn) O(n) Medium Heap, Sort
1354 Construct Target Array With Multiple Sums C++ Python O(log(max(t)) * logn) O(n) Hard Heap
1386 Cinema Seat Allocation C++ Python O(n) O(n) Medium
1400 Construct K Palindrome Strings C++ Python O(n) O(1) Medium
1402 Reducing Dishes C++ Python O(nlogn) O(1) Hard
1403 Minimum Subsequence in Non-Increasing Order C++ Python O(nlogn) O(1) Easy
1405 Longest Happy String C++ Python O(n) O(1) Medium
1414 Find the Minimum Number of Fibonacci Numbers Whose Sum Is K C++ Python O(logk) O(1) Medium
1419 Minimum Number of Frogs Croaking C++ Python O(n) O(1) Medium
1433 Check If a String Can Break Another String C++ Python O(n) O(1) Medium
1488 Avoid Flood in The City C++ Python O(nlogn) O(n) Medium
1518 Water Bottles C++ Python O(logn/logm) O(1) Easy
1520 Maximum Number of Non-Overlapping Substrings C++ Python O(n) O(1) Medium
1526 Minimum Number of Increments on Subarrays to Form a Target Array C++ Python O(n) O(1) Hard
1536 Minimum Swaps to Arrange a Binary Grid C++ Python O(n^2) O(1) Medium
1546 Maximum Number of Non-Overlapping Subarrays With Sum Equals Target C++ Python O(n) O(n) Medium
1564 Put Boxes Into the Warehouse I C++ Python O(nlogn) O(1) Medium πŸ”’
1567 Maximum Length of Subarray With Positive Product C++ Python O(n) O(1) Medium
1568 Minimum Number of Days to Disconnect Island C++ Python O(m^2 * n^2) O(m * n) Medium DFS
1578 Minimum Deletion Cost to Avoid Repeating Letters C++ Python O(n) O(1) Medium
1580 Put Boxes Into the Warehouse II C++ Python O(nlogn) O(1) Medium πŸ”’
1585 Check If String Is Transformable With Substring Sort Operations C++ Python O(n) O(n) Hard
1589 Maximum Sum Obtained of Any Permutation C++ Python O(nlogn) O(n) Medium
1591 Strange Printer II C++ Python O(c * m * n + e) O(e) Hard
1599 Maximum Profit of Operating a Centennial Wheel C++ Python O(n) O(1) Medium
1605 Find Valid Matrix Given Row and Column Sums C++ Python O(m + n) O(1) Medium
1616 Split Two Strings to Make Palindrome C++ Python O(n) O(1) Medium Two Pointers
1632 Rank Transform of a Matrix C++ Python O(m * n * log(m * n)) O(m * n) Hard Union Find


Graph

# Title Solution Time Space Difficulty Tag Note
0399 Evaluate Division C++ Python O(e + q) O(e) Medium Floyd-Warshall Algorithm, BFS, Union Find
0765 Couples Holding Hands C++ Python O(n) O(n) Hard
0924 Minimize Malware Spread C++ Python O(n^2) O(n) Hard Union Find
0928 Minimize Malware Spread II C++ Python O(n^2) O(n) Hard Union Find
0959 Regions Cut By Slashes C++ Python O(n^2) O(n^2) Medium Union Find
0990 Satisfiability of Equality Equations C++ Python O(n) O(1) Medium Union Find
1042 Flower Planting With No Adjacent C++ Python O(n) O(n) Easy
1101 The Earliest Moment When Everyone Become Friends C++ Python O(nlogn) O(n) Medium πŸ”’ Union Find
1135 Connecting Cities With Minimum Cost C++ Python O(nlogn) O(n) Medium πŸ”’ Union Find, Kruskal's Algorithm, MST
1168 Optimize Water Distribution in a Village C++ Python O(nlogn) O(n) Hard πŸ”’ Union Find
1334 Find the City With the Smallest Number of Neighbors at a Threshold Distance C++ Python O(n^3) O(n^2) Medium Floyd-Warshall Algorithm
1361 Validate Binary Tree Nodes C++ Python O(n) O(n) Medium DFS, Tree
1462 Course Schedule IV C++ Python O(n^3) O(n^2) Medium Floyd-Warshall Algorithm
1489 Find Critical and Pseudo-Critical Edges in Minimum Spanning Tree C++ Python O(nlogn) O(n) Hard Kruskal Algorithm
1557 Minimum Number of Vertices to Reach All Nodes C++ Python O(e) O(n) Medium
1579 Remove Max Number of Edges to Keep Graph Fully Traversable C++ Python O(n + m) O(n) Hard Union Find
1584 Min Cost to Connect All Points C++ Python O(n^2) O(n) Medium Union Find, Kruskal's Algorithm, MST
1601 Maximum Number of Achievable Transfer Requests C++ Python O((n + r) * 2^r) O(n + r) Hard Combinations, Backtracking
1615 Maximal Network Rank C++ Python O(m + n + k^2) O(m + n) Medium Counting Sort
1627 Graph Connectivity With Threshold C++ Python O(nlogn + q) O(n) Hard Union Find, Math
1631 Path With Minimum Effort C++ Python O(m * n * log(m * n)) O(m * n) Medium Binary Search, DFS, BFS, Bi-BFS, Union Find, Dijkstra's Algorithm


Geometry

# Title Solution Time Space Difficulty Tag Note
0587 Erect the Fence C++ Python O(nlogn) O(n) Hard Convex Hull, Monotone Chain
0892 Surface Area of 3D Shapes C++ Python O(n^2) O(1) Easy
1453 Maximum Number of Darts Inside of a Circular Dartboard C++ Python O(n^2 * logn) O(n) Hard Line Sweep
1515 Best Position for a Service Centre C++ Python O(n * iter) O(n) Hard Geometric Median, Gradient Descent, Weiszfeld's Algorithm
1610 Maximum Number of Visible Points C++ Python O(nlogn) O(n) Hard Two Pointers, Sliding Window


Simulation

# Title Solution Time Space Difficulty Tag Note
0874 Walking Robot Simulation C++ Python O(n + k) O(k) Easy
1138 Alphabet Board Path C++ Python O(n) O(1) Medium
1243 Array Transformation C++ Python O(n^2) O(n) Easy


Design

# Title Solution Time Space Difficulty Tag Note
0146 LRU Cache C++ Python O(1) O(k) Hard OrderedDict
0225 Implement Stack using Queues C++ Python push: O(n), pop: O(1), top: O(1) O(n) Easy
0173 Binary Search Tree Iterator C++ Python O(1), amortized O(h) Medium
0284 Peeking Iterator C++ Python O(1) O(1) Medium
0348 Design Tic-Tac-Toe C++ Python O(1) O(n^2) Medium πŸ”’
0353 Design Snake Game C++ Python O(1) O(s) Medium πŸ”’ Deque
0355 Design Twitter C++ Python O(klogu) O(t + f) Medium LintCode Heap
0359 Logger Rate Limiter C++ Python O(1), amortized O(k) Easy πŸ”’ Deque
0362 Design Hit Counter C++ Python O(1), amortized O(k) Medium πŸ”’ Deque
0379 Design Phone Directory C++ Python O(1) O(n) Medium πŸ”’
0380 Insert Delete GetRandom O(1) C++ Python O(1) O(n) Hard
0381 Insert Delete GetRandom O(1) - Duplicates allowed C++ Python O(1) O(n) Hard
0432 All O`one Data Structure C++ Python O(1) O(n) Hard
0460 LFU Cache C++ Python O(1) O(k) Hard
0489 Robot Room Cleaner C++ Python O(n) O(n) Hard πŸ”’
0535 Encode and Decode TinyURL C++ Python O(1) O(n) Medium
0588 Design In-Memory File System C++ Python ls: O(l + klogk)
mkdir: O(l)
addContentToFile: O(l + c)
readContentFromFile: O(l + c)
O(n + s) Hard πŸ”’
0604 Design Compressed String Iterator C++ Python O(1) O(1) Easy πŸ”’
0631 Design Excel Sum Formula C++ Python set: O((r * c)^2)
get: O(1)
sum: O((r * c)^2)
O(r * c) Hard πŸ”’
0635 Design Log Storage System C++ Python put: O(1)
retrieve: O(n + dlogd)
O(n) Medium πŸ”’
0642 Design Search Autocomplete System C++ Python O(p^2) O(p * t + s) Hard πŸ”’
0715 Range Module C++ Python add: O(n)
remove: O(n)
query: O(logn)
O(n) Hard
0716 Max Stack C++ Python push: O(logn)
pop: O(logn)
popMax: O(logn)
top: O(1)
peekMax: O(1)
O(n) Easy
0745 Prefix and Suffix Search C++ Python ctor: O(w * l^2)
search : O(p + s)
O(t) Hard Trie
0900 RLE Iterator C++ Python O(n) O(1) Medium
1146 Snapshot Array C++ Python set: O(1)
get: O(logn)
O(n) Medium
1166 Design File System C++ Python create: O(n)
get: O(n)
O(n) Medium πŸ”’
1172 Dinner Plate Stacks C++ Python push: O(logn)
pop: O(1), amortized
popAtStack: (logn)
O(n * c) Hard
1206 Design Skiplist C++ Python O(logn), on average O(n) Hard
1236 Web Crawler C++ Python O(|V| + |E|) O(|V|) Medium πŸ”’ BFS, DFS
1244 Design A Leaderboard C++ Python ctor: O(1)
add: O(1)
top: O(n)
reset: O(1)
O(n) Medium
1268 Search Suggestions System C++ Python ctor: O(n * l)
suggest: O(l^2)
O(t) Medium Trie
1286 Iterator for Combination C++ Python O(k) O(k) Medium Stack
1348 Tweet Counts Per Frequency C++ Python add: O(logn)
query: O(c)
O(n) Medium
1352 Product of the Last K Numbers C++ Python ctor: O(1)
add: O(1)
get: O(1)
O(n) Medium
1357 Apply Discount Every n Orders C++ Python ctor: O(m)
getBill: O(p)
O(m) Medium
1381 Design a Stack With Increment Operation C++ Python ctor: O(1)
push: O(1)
pop: O(1)
increment: O(1)
O(n) Medium
1396 Design Underground System C++ Python ctor: O(1)
checkin: O(1)
checkout: O(1)
getaverage: O(1)
O(n) Medium
1429 First Unique Number C++ Python ctor: O(k)
add: O(1)
showFirstUnique: O(1)
O(n) Medium πŸ”’ LinkedHashSet
1472 Design Browser History C++ Python ctor: O(1)
visit: O(1)
back: O(1)
forward: O(1)
O(n) Medium
1476 Subrectangle Queries C++ Python ctor: O(1)
update: O(1)
get: O(u)
O(u) Medium
1483 Kth Ancestor of a Tree Node C++ Python ctor: O(n * logh)
get: O(logh)
O(n * logh) Hard DP, Binary Jump
1500 Design a File Sharing System C++ Python ctor: O(1)
join: O(logu + c)
leave: O(logu + c)
request: O(u)
O(u * c) Medium πŸ”’
1570 Dot Product of Two Sparse Vectors C++ Python ctor: O(n)
dot_product: O(min(n, m))
O(n) Medium πŸ”’
1586 Binary Search Tree Iterator II C++ Python O(1), amortized O(h) Medium πŸ”’
1600 Throne Inheritance C++ Python ctor: O(1)
birth: O(1)
death: O(1)
inherit: O(n)
O(n) Medium
1603 Design Parking System C++ Python O(1) O(1) Easy
1622 Fancy Sequence C++ Python O(1) O(n) Hard Euler's Theorem
1628 Design an Expression Tree With Evaluate Function C++ Python O(n) O(h) Medium πŸ”’


Concurrency

# Title Solution Time Space Difficulty Tag Note
1114 Print in Order C++ Python O(n) O(1) Easy
1115 Print FooBar Alternately C++ Python O(n) O(1) Medium
1116 Print Zero Even Odd C++ Python O(n) O(1) Medium
1117 Building H2O C++ Python O(n) O(1) Hard
1188 Design Bounded Blocking Queue C++ Python O(n) O(1) Medium πŸ”’
1195 Fizz Buzz Multithreaded C++ Python O(n) O(1) Medium
1226 The Dining Philosophers C++ Python O(n) O(1) Medium
1242 Web Crawler Multithreaded C++ Python O(|V| + |E|) O(|V|) Medium πŸ”’
1279 Traffic Light Controlled Intersection C++ Python O(n) O(1) Easy πŸ”’


SQL

# Title Solution Time Space Difficulty Tag Note
0175 Combine Two Tables MySQL O(m + n) O(m + n) Easy
0176 Second Highest Salary MySQL O(n) O(1) Easy
0177 Nth Highest Salary MySQL O(n^2) O(n) Medium
0178 Rank Scores MySQL O(n^2) O(n) Medium
0180 Consecutive Numbers MySQL O(n) O(n) Medium
0181 Employees Earning More Than Their Managers MySQL O(n^2) O(1) Easy
0182 Duplicate Emails MySQL O(n^2) O(n) Easy
0183 Customers Who Never Order MySQL O(n^2) O(1) Easy
0184 Department Highest Salary MySQL O(n^2) O(n) Medium
0185 Department Top Three Salaries MySQL O(n^2) O(n) Hard
0196 Delete Duplicate Emails MySQL O(n^2) O(n) Easy
0197 Rising Temperature MySQL O(n^2) O(n) Easy
0262 Trips and Users MySQL O((t * u) + tlogt) O(t) Hard
0511 Game Play Analysis I MySQL O(n) O(n) Easy πŸ”’
0512 Game Play Analysis II MySQL O(n) O(n) Easy πŸ”’
0534 Game Play Analysis III MySQL O(nlogn) O(n) Medium πŸ”’
0550 Game Play Analysis IV MySQL O(n) O(n) Medium πŸ”’
1045 Customers Who Bought All Products MySQL O(n + k) O(n + k) Medium πŸ”’
1050 Actors and Directors Who Cooperated At Least Three Times MySQL O(n) O(n) Easy πŸ”’
1068 Product Sales Analysis I MySQL O(m + n) O(m + n) Easy πŸ”’
1069 Product Sales Analysis II MySQL O(n) O(n) Easy πŸ”’
1070 Product Sales Analysis III MySQL O(n) O(n) Medium πŸ”’
1075 Project Employees I MySQL O(m + n) O(m + n) Easy πŸ”’
1076 Project Employees II MySQL O(n) O(n) Easy πŸ”’
1077 Project Employees III MySQL O((m + n)^2) O(m + n) Medium πŸ”’
1082 Sales Analysis I MySQL O(n) O(n) Easy πŸ”’
1083 Sales Analysis II MySQL O(m + n) O(m + n) Easy πŸ”’
1084 Sales Analysis III MySQL O(m + n) O(m + n) Easy πŸ”’
1097 Game Play Analysis V MySQL O(n^2) O(n) Hard πŸ”’
1098 Unpopular Books MySQL O(m + n) O(n) Medium πŸ”’
1107 New Users Daily Count MySQL O(n) O(n) Medium πŸ”’
1112 Highest Grade For Each Student MySQL O(nlogn) O(n) Medium πŸ”’
1113 Reported Posts MySQL O(n) O(n) Easy πŸ”’
1126 Active Businesses MySQL O(n) O(n) Medium πŸ”’
1127 User Purchase Platform MySQL O(n) O(n) Hard πŸ”’
1132 Reported Posts II MySQL O(m + n) O(n) Medium πŸ”’
1141 User Activity for the Past 30 Days I MySQL O(n) O(n) Easy πŸ”’
1142 User Activity for the Past 30 Days II MySQL O(n) O(n) Easy πŸ”’
1148 Article Views I MySQL O(nlogn) O(n) Easy πŸ”’
1149 Article Views II MySQL O(nlogn) O(n) Medium πŸ”’
1158 Market Analysis I MySQL O(m + n) O(m + n) Medium πŸ”’
1159 Market Analysis II MySQL O(m + n) O(m + n) Hard πŸ”’
1164 Product Price at a Given Date MySQL O(mlogn) O(m) Medium πŸ”’
1173 Immediate Food Delivery I MySQL O(n) O(1) Easy πŸ”’
1174 Immediate Food Delivery II MySQL O(n) O(m) Medium πŸ”’
1179 Reformat Department Table MySQL O(n) O(n) Easy πŸ”’
1193 Monthly Transactions I MySQL O(n) O(n) Medium πŸ”’
1194 Tournament Winners MySQL O(m + n + nlogn) O(m + n) Hard πŸ”’
1204 Last Person to Fit in the Elevator MySQL O(nlogn) O(n) Medium πŸ”’
1205 Monthly Transactions II MySQL O(n) O(n) Medium πŸ”’
1211 Queries Quality and Percentage MySQL O(n) O(n) Easy
1212 Team Scores in Football Tournament MySQL O(nlogn) O(n) Medium
1225 Report Contiguous Dates MySQL O(nlogn) O(n) Hard πŸ”’
1241 Number of Comments per Post MySQL O(n) O(n) Easy πŸ”’
1251 Average Selling Price MySQL O(n) O(n) Easy πŸ”’
1264 Page Recommendations MySQL O(m + n) O(m) Medium πŸ”’
1270 All People Report to the Given Manager MySQL O(n) O(n) Medium πŸ”’
1280 Students and Examinations MySQL O((m * n) * log(m * n)) O(m * n) Easy πŸ”’
1285 Find the Start and End Number of Continuous Ranges MySQL O(n) O(n) Medium πŸ”’
1294 Weather Type in Each Country MySQL O(m + n) O(n) Easy πŸ”’
1303 Find the Team Size MySQL O(n) O(n) Easy πŸ”’
1308 Running Total for Different Genders MySQL O(nlogn) O(n) Medium πŸ”’
1321 Restaurant Growth MySQL O(n^2) O(n) Medium πŸ”’
1322 Ads Performance MySQL O(nlogn) O(n) Easy πŸ”’
1327 List the Products Ordered in a Period MySQL O(n) O(n) Easy πŸ”’
1336 Number of Transactions per Visit MySQL O(m + n) O(m + n) Medium πŸ”’
1341 Movie Rating MySQL O(nlogn) O(n) Medium πŸ”’
1350 Students With Invalid Departments MySQL O(n) O(n) Easy πŸ”’
1355 Activity Participants MySQL O(n) O(n) Medium πŸ”’
1364 Number of Trusted Contacts of a Customer MySQL O(n + m + l + nlogn) O(n + m + l) Medium πŸ”’
1369 Get the Second Most Recent Activity MySQL O(nlogn) O(n) Hard πŸ”’
1378 Replace Employee ID With The Unique Identifier MySQL O(n) O(n) Easy πŸ”’
1384 Total Sales Amount by Year MySQL O(nlogn) O(n) Hard πŸ”’
1393 Capital Gain/Loss MySQL O(n) O(n) Medium πŸ”’
1398 Customers Who Bought Products A and B but Not C MySQL O(m + n) O(m + n) Medium πŸ”’
1407 Top Travellers MySQL O(m + nlogn) O(m + n) Easy πŸ”’
1412 Find the Quiet Students in All Exams MySQL O(m + nlogn) O(m + n) Hard πŸ”’
1421 NPV Queries MySQL O(n) O(n) Medium πŸ”’
1435 Create a Session Bar Chart MySQL O(n) O(1) Easy πŸ”’
1440 Evaluate Boolean Expression MySQL O(n) O(n) Medium πŸ”’
1445 Apples & Oranges MySQL O(n) O(n) Medium πŸ”’
1454 Active Users MySQL O(nlogn) O(n) Medium πŸ”’
1459 Rectangles Area MySQL O(n^2) O(n^2) Medium πŸ”’
1468 Calculate Salaries MySQL O(m + n) O(m + n) Easy πŸ”’
1479 Sales by Day of the Week MySQL O(m + n) O(n) Hard πŸ”’
1484 Group Sold Products By The Date MySQL O(nlogn) O(n) Easy πŸ”’
1495 Friendly Movies Streamed Last Month MySQL O(n) O(n) Easy πŸ”’
1501 Countries You Can Safely Invest In MySQL O(n) O(n) Medium πŸ”’
1511 Customer Order Frequency MySQL O(n) O(n) Easy πŸ”’
1517 Find Users With Valid E-Mails MySQL O(n) O(n) Easy πŸ”’ Regex
1527 Patients With a Condition MySQL O(n) O(n) Easy πŸ”’ Regex
1532 The Most Recent Three Orders MySQL O(nlogn) O(n) Medium πŸ”’
1543 Fix Product Name Format MySQL O(nlogn) O(n) Easy πŸ”’
1549 The Most Recent Orders for Each Product MySQL O(nlogn) O(n) Medium πŸ”’
1555 Bank Account Summary MySQL O(m + n) O(m + n) Medium πŸ”’
1565 Unique Orders and Customers Per Month MySQL O(n) O(n) Easy πŸ”’
1571 Warehouse Manager MySQL O(n) O(n) Medium πŸ”’
1581 Customer Who Visited but Did Not Make Any Transactions MySQL O(n) O(n) Easy πŸ”’
1587 Bank Account Summary II MySQL O(m + n) O(m + n) Easy πŸ”’
1596 The Most Frequently Ordered Products for Each Customer MySQL O(n) O(n) Medium πŸ”’
1607 Sellers With No Sales MySQL O(nlogm) O(n + m) Medium πŸ”’
1613 Find the Missing IDs MySQL O(n^2) O(n) Medium πŸ”’
1623 All Valid Triplets That Can Represent a Country MySQL O(n^3) O(n^3) Easy πŸ”’
1633 Percentage of Users Attended a Contest MySQL O(m + nlogn) O(n) Easy πŸ”’
1635 Hopper Company Queries I MySQL O(dlogd + r) O(d + r) Hard πŸ”’


Shell Script

# Title Solution Time Space Difficulty Tag Note
0192 Word Frequency Shell O(n) O(k) Medium
0193 Valid Phone Numbers Shell O(n) O(1) Easy
0194 Transpose File Shell O(n^2) O(n^2) Medium
0195 Tenth Line Shell O(n) O(1) Easy


About

:octocat: (Weekly Update) Python / Modern C++ Solutions of All 1643 LeetCode Problems

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 54.6%
  • Python 45.1%
  • Other 0.3%