LeetCode Solutions

My solutions to LeetCode, ongoing personal project.

LeetCode is perhaps the most popular online platform for coding related questions for practice. My solutions are written in Python3, the complete list of problems solved is given below. Almost all the solutions are written in Python, except for database related questions, which are written in MySQL. Some solutions may be revised over time as I will be revisiting some questions eventually, and might be updated if I find better ways of solving them.

List of Problems Solved


The following table contains the number of the problem, title of the problem with a link to it, a link to my solution, and the problem’s difficulty.

# Title Solution Difficulty
1 Two Sum Solution Easy
2 Add Two Numbers Solution Medium
3 Longest Substring Without Repeating Characters Solution Medium
4 Median of Two Sorted Arrays Solution Hard
7 Reverse Integer Solution Medium
9 Palindrome Number Solution Easy
14 Longest Common Prefix Solution Easy
20 Valid Parentheses Solution Easy
26 Remove Duplicates from Sorted Array Solution Easy
27 Remove Element Solution Easy
28 Find the Index of the First Occurrence in a String Solution Easy
34 Find First and Last Position of Element in Sorted Array Solution Medium
43 Multiply Strings Solution Medium
66 Plus One Solution Easy
69 Sqrt(x) Solution Easy
70 Climbing Stairs Solution Easy
94 Binary Tree Inorder Traversal Solution Easy
102 Binary Tree Level Order Traversal Solution Medium
104 Maximum Depth of Binary Tree Solution Easy
111 Minimum Depth of Binary Tree Solution Easy
125 Valid Palindrome Solution Easy
136 Single Number Solution Easy
169 Majority Element Solution Easy
171 Excel Sheet Column Number Solution Easy
172 Factorial Trailing Zeroes Solution Medium
176 Second Highest Salary Solution Medium
181 Employees Earning More Than Their Managers Solution Easy
182 Duplicate Emails Solution Easy
183 Customers Who Never Order Solution Easy
184 Department Highest Salary Solution Medium
196 Delete Duplicate Emails Solution Easy
204 Count Primes Solution Medium
215 Kth Largest Element in an Array Solution Medium
217 Contains Duplicate Solution Easy
231 Power of Two Solution Easy
237 Delete Node in a Linked List Solution Medium
242 Valid Anagram Solution Easy
258 Add Digits Solution Easy
263 Ugly Number Solution Easy
268 Missing Number Solution Easy
283 Move Zeroes Solution Easy
326 Power of Three Solution Easy
342 Power of Four Solution Easy
344 Reverse String Solution Easy
367 Valid Perfect Square Solution Easy
378 Kth Smallest Element in a Sorted Matrix Solution Medium
387 First Unique Character in a String Solution Easy
412 Fizz Buzz Solution Easy
415 Add Strings Solution Easy
441 Arranging Coins Solution Easy
461 Hamming Distance Solution Easy
500 Keyboard Row Solution Easy
504 Base 7 Solution Easy
509 Fibonacci Number Solution Easy
511 Game Play Analysis I Solution Easy
537 Complex Number Multiplication Solution Medium
557 Reverse Words in a String III Solution Easy
584 Find Customer Referee Solution Easy
586 Customer Placing the Largest Number of Orders Solution Easy
595 Big Countries Solution Easy
596 Classes More Than 5 Students Solution Easy
620 Not Boring Movies Solution Easy
627 Swap Salary Solution Easy
657 Robot Return to Origin Solution Easy
709 To Lower Case Solution Easy
728 Self Dividing Numbers Solution Easy
771 Jewels and Stones Solution Easy
804 Unique Morse Code Words Solution Easy
807 Max Increase to Keep City Skyline Solution Medium
868 Binary Gap Solution Easy
914 X of a Kind in a Deck of Cards Solution Easy
1050 Actors and Directors Who Cooperated At Least Three Times Solution Easy
1051 Height Checker Solution Easy
1108 Defanging an IP Address Solution Easy
1148 Article Views I Solution Easy
1281 Subtract the Product and Sum of Digits of an Integer Solution Easy
1282 Group the People Given the Group Size They Belong To Solution Medium
1290 Convert Binary Number in a Linked List to Integer Solution Easy
1295 Find Numbers with Even Number of Digits Solution Easy
1299 Replace Elements with Greatest Element on Right Side Solution Easy
1302 Deepest Leaves Sum Solution Medium
1304 Find N Unique Integers Sum up to Zero Solution Easy
1309 Decrypt String from Alphabet to Integer Mapping Solution Easy
1323 Maximum 69 Number Solution Easy
1342 Number of Steps to Reduce a Number to Zero Solution Easy
1365 How Many Numbers Are Smaller Than the Current Number Solution Easy
1374 Generate a String With Characters That Have Odd Counts Solution Easy
1389 Create Target Array in the Given Order Solution Easy
1393 Capital Gain/Loss Solution Medium
1407 Top Travellers Solution Easy
1431 Kids With the Greatest Number of Candies Solution Easy
1436 Destination City Solution Easy
1446 Consecutive Characters Solution Easy
1450 Number of Students Doing Homework at a Given Time Solution Easy
1464 Maximum Product of Two Elements in an Array Solution Easy
1470 Shuffle the Array Solution Easy
1476 Subrectangle Queries Solution Medium
1480 Running Sum of 1d Array Solution Easy
1486 XOR Operation in an Array Solution Easy
1512 Number of Good Pairs Solution Easy
1528 Shuffle String Solution Easy
1581 Customer Who Visited but Did Not Make Any Transactions Solution Easy
1587 Bank Account Summary II Solution Easy
1603 Design Parking System Solution Easy
1662 Check If Two String Arrays are Equivalent Solution Easy
1672 Richest Customer Wealth Solution Easy
1684 Count the Number of Consistent Strings Solution Easy
1688 Count of Matches in Tournament Solution Easy
1689 Partitioning Into Minimum Number Of Deci-Binary Numbers Solution Medium
1693 Daily Leads and Partners Solution Easy
1704 Determine if String Halves Are Alike Solution Easy
1725 Number Of Rectangles That Can Form The Largest Square Solution Easy
1729 Find Followers Count Solution Easy
1732 Find the Highest Altitude Solution Easy
1741 Find Total Time Spent by Each Employee Solution Easy
1748 Sum of Unique Elements Solution Easy
1757 Recyclable and Low Fat Products Solution Easy
1768 Merge Strings Alternately Solution Easy
1773 Count Items Matching a Rule Solution Easy
1791 Find Center of Star Graph Solution Easy
1812 Determine Color of a Chessboard Square Solution Easy
1816 Truncate Sentence Solution Easy
1817 Finding the Users Active Minutes Solution Medium
1828 Queries on Number of Points Inside a Circle Solution Medium
1832 Check if the Sentence Is Pangram Solution Easy
1844 Replace All Digits with Characters Solution Easy
1859 Sorting the Sentence Solution Easy
1873 Calculate Special Bonus Solution Easy
1880 Check if Word Equals Summation of Two Words Solution Easy
1929 Concatenation of Array Solution Easy
1935 Maximum Number of Words You Can Type Solution Easy
1941 Check if All Characters Have Equal Number of Occurrences Solution Easy
1967 Number of Strings That Appear as Substrings in Word Solution Easy
1979 Find Greatest Common Divisor of Array Solution Easy
2000 Reverse Prefix of Word Solution Easy
2006 Count Number of Pairs With Absolute Difference K Solution Easy
2011 Final Value of Variable After Performing Operations Solution Easy
2053 Kth Distinct String in an Array Solution Easy
2079 Watering Plants Solution Medium
2085 Count Common Words With One Occurrence Solution Easy
2089 Find Target Indices After Sorting Array Solution Easy
2108 Find First Palindromic String in the Array Solution Easy
2114 Maximum Number of Words Found in Sentences Solution Easy
2119 A Number After a Double Reversal Solution Easy
2124 Check if All A's Appears Before All B's Solution Easy
2149 Rearrange Array Elements by Sign Solution Medium
2169 Count Operations to Obtain Zero Solution Easy
2194 Cells in a Range on an Excel Sheet Solution Easy
2220 Minimum Bit Flips to Convert Number Solution Easy
2221 Find Triangular Sum of an Array Solution Medium
2235 Add Two Integers Solution Easy
2283 Check if Number Has Equal Digit Count and Digit Value Solution Easy
2325 Decode the Message Solution Easy
2351 First Letter to Appear Twice Solution Easy