Solutions to the LeetCode evergoing problems in Java
- Bit Manipulation
- Array
- String
- Linked List
- Stack
- Queue
- Heap
- Tree
- Hash Table
- Math
- Two Pointers
- Sort
- Recursion
- Binary Search
- Binary Search Tree
- Breadth-First Search
- Depth-First Search
- Backtracking
- Dynamic Programming
- Greedy
- Graph
- Geometry
- Simulation
- Design
Id | Title | Solution | Time | Space | Difficulty | Note |
---|---|---|---|---|---|---|
461 | Hamming Distance | Java | O(1) | O(1) | Easy | Thoughtful for max optimisation |
476 | Number Complement | Java | O(logn) | O(1) | Easy | |
868 | Binary Gap | Java | O(logn) | O(1) | Easy | n is here constant = 32, O(logn) = O(1) |
136 | Single Number | Java | O(n) | O(1) | Easy | |
693 | Binary Number with Alternating Bits | Java | O(1) | O(1) | Easy | |
762 | Prime Number of Set Bits in Binary Representation | Java | O(R-L) | O(1) | Easy | Good Question |
Id | Title | Solution | Time | Space | Difficulty | Note |
---|---|---|---|---|---|---|
832 | Flipping an Image | Java | O(n*m) | O(1) | Easy | Thoughtful for max optimisation |
561 | Array Partition I | Java | O(nlogn) | O(1) | Easy | |
867 | Transpose Matrix | Java | O(r*c) | O(r*c) | Easy | |
806 | Number of Lines To Write String | Java | O(n) | O(1) | Easy | n = string length |
766 | Toeplitz Matrix | Java | O(n*m) | O(1) | Easy | |
463 | Island Perimeter | Java | O(n*m) | O(1) | Easy | |
412 | Fizz Buzz | Java | O(n) | O(1) | Easy | |
566 | Reshape the Matrix | Java | O(n*m) | O(n*m) | Easy | |
892 | Surface Area of 3D Shapes | Java | O(n^2) | O(1) | Easy | |
485 | Max Consecutive Ones | Java | O(n) | O(1) | Easy |
Id | Title | Solution | Time | Space | Difficulty | Note |
---|---|---|---|---|---|---|
709 | To Lower Case | Java | O(n) | O(1) | Easy | n is of input |
804 | Unique Morse Code Words | Java | O(n) | O(n) | Easy | n is sum of all words length |
657 | Judge Route Circle | Java | O(n) | O(1) | Easy | n is string length |
557 | Reverse Words in a String III | Java | O(n) | O(n) | Easy | n is of A |
344 | Reverse String | Java | O(n) | O(n) | Easy | n is of A |
821 | Shortest Distance to a Character | Java | O(n) | O(n) | Easy | n is of A ; Tricky to think for simplest solution |
521 | Longest Uncommon Subsequence I | Java | O(min(a,b)) | O(1) | Easy | Good puzzle |
824 | Goat Latin | Java | O(N + W^2) | O(N) | Easy | Good to visualise complexity |
443 | String Compression | Java | O(n) | O(1) | Easy |
Id | Title | Solution | Time | Space | Difficulty | Note |
---|---|---|---|---|---|---|
876 | Middle of the Linked List | Java | O(n) | O(1) | Easy | fast and slow pointers |
Id | Title | Solution | Time | Space | Difficulty | Note |
---|---|---|---|---|---|---|
682 | Baseball Game | Java | O(n) | O(n) | Easy | |
225 | Implement Stack using Queues | Java | (O(n) - push, O(1) - rest ops) | O(1) | Easy |
Id | Title | Solution | Time | Space | Difficulty | Note |
---|---|---|---|---|---|---|
617 | Merge Two Binary Trees | Java | O(n ) | O(n)(Worst Case) | Easy | n is min. num of nodes |
872 | Leaf-Similar Trees | Java | O(n) | O(h) | Easy | h = max height of tree, n = max num of nodes |
559 | Maximum Depth of N-ary Tree | Java | O(n) | O(h) | Easy | h = max height of tree, n = max num of nodes |
590 | N-ary Tree Postorder Traversal | Java | O(n) | O(n) | Easy | n = Total num of nodes, Iterative solution is a must |
669 | Trim a Binary Search Tree | Java | O(n) | O(n) | Easy | n = Total num of nodes |
104 | Maximum Depth of Binary Tree | Java | O(n) | O(n) | Easy | n = Total num of nodes |
589 | N-ary Tree Preorder Traversal | Java | O(n) | O(n) | Easy | n = Total num of nodes |
226 | Invert Binary Tree | Java | O(n) | O(n) | Easy | n = Total num of nodes |
Id | Title | Solution | Time | Space | Difficulty | Note |
---|---|---|---|---|---|---|
771 | Jewels and Stones | Java | O(n + m) | O(n) | Easy | n is of J and m is of S |
884 | Uncommon Words from Two Sentences | Java | O(n + m) | O(n + m) | Easy | n is of A and m is of B |
811 | Subdomain Visit Count | Java | O(n) | O(n) | Easy | n is of cpDomains |
500 | Keyboard Row | Java | O(n) | O(n) | Easy | n is of all words length sum |
575 | Distribute Candies | Java | O(n) | O(n) | Easy | Good question for thinking and optimising |
888 | Fair Candy Swap | Java | O(n) | O(n) | Easy | |
496 | Next Greater Element I | Java | O(n) | O(n) | Easy | Good question to consider |
Id | Title | Solution | Time | Space | Difficulty | Note |
---|---|---|---|---|---|---|
883 | Projection Area of 3D Shapes | Java | O(n*n) | O(1) | Easy | |
728 | Self Dividing Numbers | Java | O(n)(n = num of numbers between [l,r]) | O(n) | Easy | Assuming R is bounded |
292 | Nim Game | Java | O(1) | O(1) | Easy | |
812 | Largest Triangle Area | Java | O(n^3) | O(1) | Easy | Know formula to solve this |
67 | Add Binary | Java | O(max(a,b)) | O(1) | Easy |
Id | Title | Solution | Time | Space | Difficulty | Note |
---|---|---|---|---|---|---|
852 | Peak Index in a Mountain Array | Java | O(n) | O(1) | Easy | |
704 | Binary Search | Java | O(log(n)) | O(1) | Easy |
Id | Title | Solution | Time | Space | Difficulty | Note |
---|---|---|---|---|---|---|
700 | Search in a Binary Search Tree | Java | O(logn) | O(1) | Easy |
Id | Title | Solution | Time | Space | Difficulty | Note |
---|---|---|---|---|---|---|
637 | Average of Levels in Binary Tree | Java | O(n) | O(m) | Easy | n = total nodes, m = max nodes at any level; Can be solved by DFS as well, Must look |
429 | N-ary Tree Level Order Traversal | Java | O(n) | O(m) | Easy | n = total nodes, m = max nodes at any level; |
Id | Title | Solution | Time | Space | Difficulty | Note |
---|---|---|---|---|---|---|
897 | Increasing Order Search Tree | Java | O(n) | O(h) | Easy | n = total nodes, h = max height; Iterative Solution; Bookmarked |
112 | Path Sum | Java | O(n) | O(h) | Easy | n = total nodes, h = max height; |