Here you can find solutions in JavaScript, Python and SQL languages for some problems from LeetCode. You also can participate in solving these problems by proposing your solution. Don't hesitate to pull your ideas here and enjoy LeetCode.
Number | Question | Hint | JS Solution | Python Solution |
---|---|---|---|---|
1 | Two Sum | Use a hash table to keep track of the indices of the numbers you've encountered so far. | JS Solution | Python Solution |
3 | Longest Substring Without Repeating Chars | What if index of the first occurrence might help? | JS Solution | Python Solution |
7 | Reverse Integer | JS Solution | Python Solution | |
9 | Palindrome Number | Use two pointers to make it work faster. Beware of overflow. | JS Solution | Python Solution |
20 | Valid Parentheses | Use a stack of characters. When you encounter a closing bracket, check if the top of the stack was the opening for it. If yes, pop it from the stack. Otherwise, return false. | JS Solution | Python Solution |
28 | Find the Index of the First Occurrence in a String | JS Solution | Python Solution | |
32 | Longest Valid Parentheses | Use a stack of characters. | JS Solution | Python Solution |
34 | Find First and Last Position of Element in Sorted Array | Binary Search | JS Solution | Python Solution |
35 | Search Insert Position | Use binary search | JS Solution | Python Solution |
42 | Trapping Rain Water | JS Solution | Python Solution | |
58 | Length of Last Word | Filter out the words and empty strings in the words array. Don't forget about removing spaces. | JS Solution | Python Solution |
62 | Unique Paths | Dynamic programming is one of the effective ways to solve it. Just find recurrent formula. | JS Solution | Python Solution |
63 | Unique Paths II | Use dynamic programming since, from each cell, you can move to the right or down. | JS Solution | Python Solution |
64 | Minimum Path Sum | Remember that from the second cell, the value of the current cell is the price of the current cell plus the minimum value of the previous ones | JS Solution | Python Solution |
66 | Plus One | Try iterating through each digit backwards. What do you do when the digit is a 9? | JS Solution | Python Solution |
69 | Sqrt | Use binary search to make algorithm work faster | JS Solution | Python Solution |
70 | Climbing Stairs | To reach nth step, what could have been your previous steps? | JS Solution | Python Solution |
75 | Sort Colors | Overwrite array with the total number of 0's, then 1's and followed by 2's. Any sort might be appropriate solution. | JS Solution | Python Solution |
88 | Merge Sorted Array | You can easily solve this problem if you simply think about two elements at a time rather than two arrays. We know that each of the individual arrays is sorted. What we don't know is how they will intertwine. Can we take a local decision and arrive at an optimal solution? | JS Solution | Python Solution |
122 | Best Time to Buy and Sell Stock II | What should we do every time there is a valley followed by a peak in price? | JS Solution | Python Solution |
125 | Valid Palindrome | Use Two Pointers | JS Solutions | Python Solution |
136 | Single Number | Use Bit Manipulations (XOR) | JS Solution | Python Solution |
151 | Reverse Words in a String | JS Solution | Python Solution | |
155 | Min Stack | JS Solution | Python Solution | |
169 | Majority Element | JS Solution | Python Solution | |
191 | Number of 1 Bits | Use Bit Manipulations | JS Solution | Python Solution |
197 | Rising Temperature | SQL Solution | Pandas Solution | |
202 | Happy Number | JS Solution | Python Solution | |
204 | Count Primes | Use Sieve of Eratosthenes. | JS Solution | Python Solution |
206 | Reverse Linked List | JS Solution | Python Solution | |
217 | Contains Duplicate | JS Solution | Python Solution | |
231 | Power Of Two | Think of Bit Manipulations | JS Solution | Python Solution |
232 | Implement Queue using Stacks | JS Solution | Python Solution | |
242 | Valid Anagram | JS Solution | Python Solution | |
263 | Ugly Number | JS Solution | Python Solution | |
264 | Ugly Number II | Dynamic Programming | JS Solution | Python Solution |
268 | Missing Number | Bit Manipulation is One of the Options | JS Solution | Python Solution |
300 | Longest Increasing Subsequence | Compare two last nums in sequence and subsequence. If both are equal, length of LIS is increased by 1 | JS Solution | Python Solution |
322 | Coin Change | Think how to use a knapsack problem | JS Solution | Python Solution |
326 | Power of Three | JS Solution | Python Solution | |
342 | Power of Four | Bit Manipulations | JS Solutions | Python Solution |
344 | Reverse String | The entire logic for reversing a string is based on using the opposite directional two-pointer approach | JS Solution | Python Solution |
345 | Reverse Vowels of a String | JS Solution | Python Solution | |
367 | Valid Perfect Square | JS Solution | Python Solution | |
389 | Find The Difference | JS Solution | Python Solution | |
392 | Is Subsequence | Use two pointers to iterate through the two strings simultaneously. | JS Solution | Python Solution |
412 | Fizz Buzz | The first non-standard value must satisfy both conditions. | JS Solution | Python Solution |
421 | Maximum XOR of Two Numbers in an Array | JS Solution | Python Solution | |
451 | Sort Characters By Frequency | JS Solution | Python Solution | |
461 | Hamming Distance | Bit Manipulation (XOR) | JS Solution | Python Solution |
504 | Base 7 | Gorner's algorithm can help with this problem | JS Solution | Python Solution |
516 | Longest Palindromic Subsequence | JS Solution | Python Solution | |
557 | Reverse Words in a String III | JS Solution | Python Solution | |
550 | Game Analysis IV | SQL Solution | Pandas Solution | |
577 | Employee Bonus | SQL Solution | Pandas Solution | |
580 | Managers With At Least 5 Direct Reports | SQL Solution | Pandas Solution | |
584 | Find Customer Referee | SQL Solution | Pandas Solution | |
595 | Big Countries | SQL Solution | Pandas Solution | |
596 | Classes More Than 5 Students | SQL Solution | Pandas Solution | |
610 | Triangle Judgement | SQL Solution | Pandas Solution | |
619 | Biggest Single Number | SQL Solution | Pandas Solution | |
620 | Not Boring Movies | SQL Solution | Pandas Solution | |
704 | Binary Search | JS Solution | Python Solution | |
771 | Jewels and Stones | JS Solution | Python Solution | |
1045 | Customers Who Bought All Products | SQL Solution | Pandas Solution | |
1068 | Products Sales Analysis I | SQL Solution | Pandas Solution | |
1070 | Products Sales Analysis III | SQL Solution | Pandas Solution | |
1075 | Project Employees I | SQL Solution | Pandas Solution | |
1137 | N-th Tribonacci Number | Use dynamic programming | JS Solution | Python Solution |
1141 | User Activity for the Past 30 Days I | SQL Solution | Pandas Solution | |
1143 | Longest Common Subsequence | Try dynamic programming. DP[i][j] represents the longest common subsequence of text1[0 ... i] & text2[0 ... j]. | JS Solution | Python Solution |
1148 | Article Views I | SQL Solution | Pandas Solution | |
1174 | Immediate Food Delivery II | SQL Solution | Pandas Solution | |
1193 | Monthly Transactions I | SQL Solution | Pandas Solution | |
1207 | Unique Number of Occurrences | Find the number of occurrences of each element in the array using a hash map. | JS Solution | Python Solution |
1211 | Queries Quality And Percentage | SQL Solution | Pandas Solution | |
1251 | Average Selling Price | SQL Solution | Pandas Solution | |
1280 | Students And Examinations | SQL Solution | Pandas Solution | |
1287 | Element Appearing More Than 25% In Sorted Array | JS Solution | Python Solution | |
1378 | Replace Employee ID With The Unique Identifier | SQL Solution | Pandas Solution | |
1381 | Design a Stack With Increment Operation | JS Solution | Python Solution | |
1523 | Count Odd Numbers in an Interval Range | JS Solution | Python Solution | |
1581 | Customer Who Visited But Did Not Make Any Transactions | SQL Solution | Pandas Solution | |
1633 | Percentage Of Users Attended A Contest | SQL Solution | Pandas Solution | |
1661 | Average Time Of Process Per Machine | SQL Solution | Pandas Solution | |
1683 | Invalid Tweets | SQL Solution | Pandas Solution | |
1729 | Find Followers Count | SQL Solution | Pandas Solution | |
1731 | The Number Of Employee Which Report To Each Employee | SQL Solution | Pandas Solution | |
1757 | Recycle And Low Fat Products | SQL Solution | Pandas Solution | |
1934 | Confirmation Rate | SQL Solution | Pandas Solution | |
1934 | Confirmation Rate | SQL Solution | Pandas Solution | |
2356 | Number of Unique Subjects Taught by Each Teacher | SQL Solution | Pandas Solution | |
2455 | Average Value of Even Numbers That Are Divisible by Three | JS Solution | Python Solution |