As a student I solved many leetcode problems but unable to identify the most efficient solution and this repo will help you with explanation and data structure wise questions. It's easy to access and time saver before the interview.
Often careercup contains buggy code and most inefficient algorithms. I try to add an effcient one with explanation in my own words.
Feel free to submit pull requests, add issues and be a contributer.
On the day before interview, don't forget to review these problems. Credit to DevkaPupara
- Bit Manipulation
- Arrays
- String
- HashMap
- Trees
- Dynamic-Programming
- Depth First Search
- LinkedList
- TwoPointers
- Math
- SQL
Website | Title | Solution | Time | Space | Difficulty | Note |
---|---|---|---|---|---|---|
Careercup | Permutation Casewise | Java | O(2^n) | O(1) | Medium | |
Leetcode | 50. Pow(x, n) | Java | O(n) | O(1) | Medium | |
Leetcode | 89. Gray Code | Java | O(n) | O(1) | Medium | |
Leetcode | 137. Single Number II | Java | O(n) | O(1) | Medium | |
Leetcode | 190. Reverse Bits | Java | O(n) | O(n) | Easy | |
Leetcode | 191. Number of 1 Bits | Java | O(n) | O(1) | Easy | |
Leetcode | 260. Single Number III | Java | O(n) | O(1) | Medium | |
Leetcode | 401. Binary Watch | Java | O(n) | O(1) | Easy | |
Leetcode | 461. Hamming Distance | Java | O(n) | O(1) | Easy | |
Leetcode | 338. Counting Bits | Java | O(nk) | O(n) | Medium |
Website | Title | Solution | Time | Space | Difficulty | Note |
---|---|---|---|---|---|---|
Leetcode | 12. Integer to Roman | Java | O(n) | O(1) | Medium | |
Leetcode | 15. 3Sum | Java | O(n) | O(1) | Medium | |
Leetcode | 16. 3Sum Closest | Java | O(n^2) | O(1) | Medium | |
Leetcode | 26. Remove Duplicates from Sorted Array | Java | O(n) | O(1) | Easy | |
Leetcode | 27. Remove Element | Java | O(n) | O(1) | Easy | |
Leetcode | 31. Next Permutation | Java | O(n) | O(1) | Easy | |
Leetcode | 39. Combination Sum | Java | O(2^n) | O(1) | Medium | |
Leetcode | 40. Combination Sum II | Java | O(2^n) | O(1) | Medium | |
Leetcode | 46. Permutations | Java | O(2^n) | O(1) | Medium | |
Leetcode | 47. Permutations II | Java | O(2^n) | O(1) | Medium | |
Leetcode | 66. Plus One | Java | O(n) | O(1) | Easy | |
Leetcode | 78. Subsets | Java | O(2^n) | O(n) | Medium | |
Leetcode | 90. Subsets II | Java | O(2^n) | O(n) | Medium | |
Leetcode | 88. Merge Sorted Array | Java | O(n) | O(1) | Easy | |
Leetcode | 120. Triangle | Java | O(m*n) | O(1) | Medium | |
Leetcode | 121. Best Time to Buy and Sell Stock | Java | O(n) | O(1) | Easy | |
Leetcode | 189. Rotate Array | Java | O(n) | O(1) | Easy | |
Leetcode | 217. Contains Duplicate | Java | O(n) | O(1) | Easy | |
Leetcode | 228. Summary Ranges | Java | O(n) | O(1) | Medium | |
Leetcode | 268. Missing Number | Java | O(n) | O(1) | Easy | |
Leetcode | 283. Move Zeroes | Java | O(n) | O(1) | Easy | |
Leetcode | 311. Sparse Matrix Multiplication | Java | O(mnl) | O(m*l) | Medium | |
Leetcode | 350. Intersection of Two Arrays II | Java | O(m+n) | O(1) | Easy | |
Leetcode | 383. Ransom Note | Java | O(n) | O(1) | Easy | |
Leetcode | 419. Battleships in a Board | Java | O(mn) | O(1) | Medium | |
Leetcode | 442. Find All Duplicates in an Array | Java Python | O(n) | O(1) | Easy | |
Leetcode | 561. Array Partition I | Java | O(nlogn) | O(1) | Easy | |
Leetcode | 566. Reshape the Matrix | Java | O(m*n) | O(m*n) | Easy | |
Leetcode | 598. Range Addition II | Java | O(n) | O(1) | Easy | |
Leetcode | 605. Can Place Flowers | Java | O(n) | O(1) | Easy | |
Leetcode | 611. Valid Triangle Number | Java | O(n) | O(1) | Easy | |
Leetcode | 624. Maximum Distance in Arrays | Java | O(m*n) | O(m*n) | Easy | |
Leetcode | 628. Maximum Product of Three Numbers | Java | O(n) | O(1) | Easy | |
Leetcode | 643. Maximum Average Subarray I | Java | O(n) | O(1) | Easy | |
Leetcode | 674. Longest Continuous Increasing Subsequence | Java | O(n) | O(1) | Easy | |
Leetcode | 713. Subarray Product Less Than K | Java | O(n) | O(1) | Medium | |
Leetcode | 714. Best Time to Buy and Sell Stock with Transaction Fee | Java | O(n) | O(1) | Medium | |
Leetcode | 724. Find Pivot Index | Java | O(n) | O(1) | Easy |
Website | Title | Solution | Time | Space | Difficulty | Note |
---|---|---|---|---|---|---|
Leetcode | 53. Maximum Sum Subarray | Java | O(n) | O(1) | Easy | |
Leetcode | 62. Unique Paths | Java | O(m*n) | O(m+n) | Easy | |
Leetcode | 70. Climbing Stairs | Java | O(n) | O(1) | Easy | |
Leetcode | 91. Decode Ways | Java | O(n) | O(n) | Medium | |
Leetcode | 152. Maximum Product Subarray | Java | O(n) | O(1) | Medium | |
Leetcode | 198. House Robber | Java | O(n) | O(1) | Easy | |
Leetcode | 221. Maximal Square | Java | O(mn) | O(mn) | Medium | |
Leetcode | 264. Ugly Number II | Java | O(n) | O(1) | Easy | |
Leetcode | 628. Maximum Product of Three Numbers | Java | O(n) | O(1) | Easy | |
Leetcode | 646. Maximum Length of Pair Chain | Java | O(n) | O(1) | Easy | |
Leetcode | 746. Min Cost Climbing Stairs | Java | O(n) | O(1) | Easy |
Website | Title | Solution | Time | Space | Difficulty | Note |
---|---|---|---|---|---|---|
Leetcode | 22. Generate Parentheses | Java | O(4^n) | O(n) | Medium | |
Leetcode | 50. Pow(x, n) | Java | O() | O(n) | Medium | |
Leetcode | 109. Convert Sorted List to Binary Search Tree | Java | O(n) | O(logn) | Medium | |
Leetcode | 339. Nested List Weight Sum | Java | O( ) | O( ) | Easy | |
Leetcode | 654. Maximum Binary Tree | Java | O(n log n) | O(n) | Easy |
Website | Title | Solution | Time | Space | Difficulty | Note |
---|---|---|---|---|---|---|
Leetcode | 414. Third Maximum Number | Java | O(n) | O(1) | Easy | |
Leetcode | 621. Task Scheduler | Java | O(n) | O(n) | Medium |
Website | Title | Solution | Time | Space | Difficulty | Note |
---|---|---|---|---|---|---|
Leetcode | 253. Meeting Rooms II | Java | O(nlogn) | O(n) | Medium | |
Leetcode | 278. First Bad Version | Java | O(logn) | O(1) | Easy | |
Leetcode | 540. Single Element in a Sorted Array | Java | O(logn) | O(1) | Medium |
Website | Title | Solution | Time | Space | Difficulty | Note |
---|---|---|---|---|---|---|
Leetcode | 20. Valid Parentheses | Java | O(n) | O(n) | Easy | |
Leetcode | 155. Min Stack | Java | O(n) | O(1) | Easy | |
Leetcode | 232. Implement Queue using Stacks | Java | O(n) | O(n) | Easy | |
Leetcode | 388. Longest Absolute File Path | Java | O(n) | O(n) | Medium | |
Leetcode | 496. Next Greater Element I | Java | O(mn) | O(m+n) | Easy | |
Leetcode | 503. Next Greater Element II | Java | O(n) | O(n) | Medium |
Website | Title | Solution | Time | Space | Difficulty | Note |
---|---|---|---|---|---|---|
Leetcode | 225. Implement Stack using Queues | Java | O(n) | O(1) | Easy | |
Leetcode | 346. Moving Average from Data Stream | Java | O(n) | O(1) | Easy |
Website | Title | Solution | Time | Space | Difficulty | Note |
---|---|---|---|---|---|---|
Leetcode | 2. Add Two Numbers | Java | O(n+m) | O(n+m) | Medium | |
Leetcode | 21. Merge Two Sorted Lists | Java | O(n) | O(1) | Easy | |
Leetcode | 24. Swap Nodes in Pairs | Java | O(n) | O(1) | Medium | |
Leetcode | 23. Merge k Sorted Lists | Java | O(n logk) | O(1) | Hard | |
Leetcode | 83. Remove Duplicates from Sorted List | Java | O(n) | O(1) | Easy | |
Leetcode | 148. Sort List | Java | O(nlogn) | O(logn) | Medium | |
Leetcode | 203. Remove Linked List Elements | Java | O(n) | O(1) | Easy | |
Leetcode | 206. Reverse Linked List | Java | O(n) | O(1) | Easy | |
Leetcode | 237. Delete Node in a Linked List | Java | O(1) | O(1) | Easy | |
Leetcode | 234. Palindrome Linked List | Java | O(n) | O(1) | Medium | |
Leetcode | 328. Odd Even Linked List | Java | O(n) | O(1) | Medium | |
Leetcode | 445. Add Two Numbers II | Java | O(nm) | O(m+n) | Medium |
Website | Title | Solution | Time | Space | Difficulty | Note |
---|---|---|---|---|---|---|
Leetcode | 11. Container With Most Water | Java | O(n) | O(1) | Medium | |
Leetcode | 209. Minimum Size Subarray Sum | Java | O(n) | O(1) | Medium | |
Leetcode | 259. 3Sum Smaller | Java | O(n) | O(1) | Medium | |
Leetcode | 360. Sort Transformed Array | Java | O(n) | O(1) | Medium | |
Leetcode | 487. Max Consecutive Ones II | Java | O(n) | O(1) | Medium | |
Leetcode | 567. Permutation in String | Java | O(n) | O(1) | Medium | |
Leetcode | 680. Valid Palindrome II | Java | O(n) | O(1) | Easy |
Website | Title | Solution | Time | Space | Difficulty | Note |
---|---|---|---|---|---|---|
Leetcode | 690. Employee Importance | Java | O(v+e) | O(1) | Easy |
Website | Title | Solution | Time | Space | Difficulty | Note |
---|---|---|---|---|---|---|
Leetcode | 56. Merge Intervals | Java | O(nlogn) | O(1) | Medium | |
Leetcode | 57. Insert Interval | Java | O(n) | O(1) | Hard | |
Leetcode | 75. Sort Colors | Java | O(n) | O(1) | Medium | |
Leetcode | 147. Insertion Sort List | Java | O(nlogn) | O(1) | Medium | |
Leetcode | 179. Largest Number | Java | O(nlogn) | O(n) | Medium | |
Leetcode | 280. Wiggle Sort | Java | O(n) | O(1) | Medium | |
Leetcode | 581. Shortest Unsorted Continuous Subarray | Java | O(nlogn) | O(n) | Easy |
Website | Title | Solution | Time | Space | Difficulty | Note |
---|---|---|---|---|---|---|
Leetcode | 204. Count Primes | Java | O(n) | O(n) | Easy | |
Leetcode | 223. Rectangle Area | Java | O(1) | O(1) | Medium | |
Leetcode | 319. Bulb Switcher | Java | O(n) | O(1) | Medium | |
Leetcode | 728. Self Dividing Numbers | Java | O(n) | O(1) | Easy |
Website | Title | Solution | Time | Space | Difficulty | Note |
---|---|---|---|---|---|---|
Leetcode | 177. Nth Highest Salary | SQL | O(n) | O(1) | Medium | |
Leetcode | 181. Employees Earning More Than Their Managers | SQL | O(n) | O(1) | Easy | |
Leetcode | 197. Rising Temperature | SQL | O(n) | O(1) | Easy | |
Leetcode | 597. Friend Requests I: Overall Acceptance Rate | SQL | O(n) | O(1) | Easy | |
Leetcode | 627. Swap Salary | SQL | O(n) | O(1) | Easy |