LeetCode-Solutions
🏋️ Python / Modern C++ Solutions of All 3283 LeetCode Problems (Weekly Update)
Top Related Projects
LeetCode Solutions: A Record of My Problem Solving Journey.( leetcode题解,记录自己的leetcode解题之路。)
Demonstrate all the questions on LeetCode in the form of animation.(用动画的形式呈现解LeetCode题目的思路)
✅ Solutions to LeetCode by Go, 100% test coverage, runtime beats 100% / LeetCode 题解
Solutions to LeetCode problems; updated daily. Subscribe to my YouTube channel for more.
:pencil2: LeetCode solutions in C++ 11 and Python3
Quick Overview
The kamyu104/LeetCode-Solutions repository is a comprehensive collection of solutions to LeetCode problems, implemented in various programming languages. It serves as a valuable resource for developers preparing for technical interviews or looking to improve their problem-solving skills.
Pros
- Extensive coverage of LeetCode problems with solutions in multiple languages
- Well-organized structure, making it easy to find specific problem solutions
- Regularly updated with new solutions and improvements
- Includes explanations and time/space complexity analysis for many solutions
Cons
- May discourage independent problem-solving if relied upon too heavily
- Some solutions might not be optimized or may lack detailed explanations
- The large number of solutions can be overwhelming for beginners
- Not all problems have solutions in every supported language
Code Examples
Here are a few examples of solutions from the repository:
- Two Sum problem (Python):
class Solution:
def twoSum(self, nums: List[int], target: int) -> List[int]:
num_map = {}
for i, num in enumerate(nums):
complement = target - num
if complement in num_map:
return [num_map[complement], i]
num_map[num] = i
return []
This solution uses a hash map to efficiently find the pair of numbers that sum up to the target.
- Reverse Linked List (C++):
class Solution {
public:
ListNode* reverseList(ListNode* head) {
ListNode* prev = nullptr;
ListNode* curr = head;
while (curr) {
ListNode* next = curr->next;
curr->next = prev;
prev = curr;
curr = next;
}
return prev;
}
};
This code reverses a singly linked list iteratively.
- Valid Parentheses (Java):
class Solution {
public boolean isValid(String s) {
Stack<Character> stack = new Stack<>();
for (char c : s.toCharArray()) {
if (c == '(' || c == '[' || c == '{') {
stack.push(c);
} else if (stack.isEmpty() || !isMatching(stack.pop(), c)) {
return false;
}
}
return stack.isEmpty();
}
private boolean isMatching(char open, char close) {
return (open == '(' && close == ')') ||
(open == '[' && close == ']') ||
(open == '{' && close == '}');
}
}
This solution uses a stack to check if a string of parentheses is valid.
Getting Started
To use these solutions:
- Clone the repository:
git clone https://github.com/kamyu104/LeetCode-Solutions.git
- Navigate to the desired problem's solution in your preferred language.
- Study the solution, understand the approach, and try to implement it yourself.
- Run the code with your own test cases to verify the solution.
Remember to use these solutions as a reference and learning tool, rather than simply copying them for LeetCode submissions.
Competitor Comparisons
LeetCode Solutions: A Record of My Problem Solving Journey.( leetcode题解,记录自己的leetcode解题之路。)
Pros of leetcode
- More comprehensive explanations and detailed problem-solving approaches
- Includes solutions in multiple programming languages (JavaScript, Python, C++, etc.)
- Active community contributions and regular updates
Cons of leetcode
- Less organized structure compared to LeetCode-Solutions
- May contain some outdated or less optimized solutions
- Inconsistent coding style across different contributors
Code Comparison
LeetCode-Solutions (Python):
class Solution:
def twoSum(self, nums: List[int], target: int) -> List[int]:
num_map = {}
for i, num in enumerate(nums):
if target - num in num_map:
return [num_map[target - num], i]
num_map[num] = i
return []
leetcode (JavaScript):
var twoSum = function(nums, target) {
const map = new Map();
for (let i = 0; i < nums.length; i++) {
const complement = target - nums[i];
if (map.has(complement)) {
return [map.get(complement), i];
}
map.set(nums[i], i);
}
};
Both repositories provide efficient solutions to the "Two Sum" problem, but LeetCode-Solutions tends to have more concise and standardized code across different problems. The leetcode repository offers more explanations and alternative approaches, which can be beneficial for learning purposes.
Demonstrate all the questions on LeetCode in the form of animation.(用动画的形式呈现解LeetCode题目的思路)
Pros of LeetCodeAnimation
- Provides visual animations for algorithm explanations, making concepts easier to understand
- Includes explanations in Chinese, beneficial for Chinese-speaking users
- Offers a more engaging learning experience through visual representations
Cons of LeetCodeAnimation
- Limited coverage of LeetCode problems compared to LeetCode-Solutions
- Animations may not be as comprehensive as detailed code explanations
- Updates less frequently than LeetCode-Solutions
Code Comparison
LeetCode-Solutions (Python):
class Solution:
def twoSum(self, nums: List[int], target: int) -> List[int]:
num_map = {}
for i, num in enumerate(nums):
if target - num in num_map:
return [num_map[target - num], i]
num_map[num] = i
LeetCodeAnimation (Java):
public int[] twoSum(int[] nums, int target) {
Map<Integer, Integer> map = new HashMap<>();
for (int i = 0; i < nums.length; i++) {
int complement = target - nums[i];
if (map.containsKey(complement)) {
return new int[] { map.get(complement), i };
}
map.put(nums[i], i);
}
throw new IllegalArgumentException("No two sum solution");
}
Both repositories provide solutions to LeetCode problems, but LeetCode-Solutions offers a wider range of problems and languages. LeetCodeAnimation focuses on visual explanations, which can be helpful for understanding complex algorithms, but may not cover as many problems or provide as detailed code explanations.
✅ Solutions to LeetCode by Go, 100% test coverage, runtime beats 100% / LeetCode 题解
Pros of LeetCode-Go
- Written in Go, which may be preferred by some developers
- Includes detailed explanations and time/space complexity analysis for solutions
- Offers a more comprehensive set of problems (1000+) compared to LeetCode-Solutions
Cons of LeetCode-Go
- Less frequently updated compared to LeetCode-Solutions
- May have a steeper learning curve for those not familiar with Go
Code Comparison
LeetCode-Go (Go):
func twoSum(nums []int, target int) []int {
m := make(map[int]int)
for i, num := range nums {
if j, ok := m[target-num]; ok {
return []int{j, i}
}
m[num] = i
}
return nil
}
LeetCode-Solutions (Python):
def twoSum(self, nums: List[int], target: int) -> List[int]:
num_map = {}
for i, num in enumerate(nums):
if target - num in num_map:
return [num_map[target - num], i]
num_map[num] = i
return []
Both repositories provide solutions to LeetCode problems, but they differ in language and approach. LeetCode-Go offers more detailed explanations and a larger problem set, while LeetCode-Solutions provides solutions in multiple languages and is updated more frequently. The choice between the two depends on the user's preferred programming language and learning style.
Solutions to LeetCode problems; updated daily. Subscribe to my YouTube channel for more.
Pros of Leetcode
- More comprehensive coverage of LeetCode problems, with solutions for a larger number of questions
- Includes detailed explanations and comments for many solutions, making it easier for learners to understand the code
- Offers solutions in multiple programming languages, catering to a wider audience
Cons of Leetcode
- Less frequent updates compared to LeetCode-Solutions
- Some solutions may not be as optimized or concise as those in LeetCode-Solutions
- Repository structure is less organized, making it harder to navigate and find specific problems
Code Comparison
LeetCode-Solutions (Python):
def twoSum(self, nums: List[int], target: int) -> List[int]:
lookup = {}
for i, num in enumerate(nums):
if target - num in lookup:
return [lookup[target - num], i]
lookup[num] = i
return []
Leetcode (Java):
public int[] twoSum(int[] nums, int target) {
Map<Integer, Integer> map = new HashMap<>();
for (int i = 0; i < nums.length; i++) {
if (map.containsKey(target - nums[i])) {
return new int[]{map.get(target - nums[i]), i};
}
map.put(nums[i], i);
}
throw new IllegalArgumentException("No two sum solution");
}
Both solutions implement the Two Sum problem efficiently using a hash map, but LeetCode-Solutions uses Python while Leetcode uses Java. The overall approach is similar, demonstrating that both repositories provide effective solutions to LeetCode problems.
:pencil2: LeetCode solutions in C++ 11 and Python3
Pros of LeetCode
- Organized by difficulty level (Easy, Medium, Hard), making it easier for users to find problems matching their skill level
- Includes explanations and comments in the code, helping users understand the solutions better
- Supports multiple programming languages, including C++, Python, and Java
Cons of LeetCode
- Has fewer problems solved compared to LeetCode-Solutions
- Less frequently updated, potentially missing newer LeetCode problems
- May lack some of the more advanced or optimized solutions found in LeetCode-Solutions
Code Comparison
LeetCode (C++):
class Solution {
public:
vector<int> twoSum(vector<int>& nums, int target) {
unordered_map<int, int> mapping;
vector<int> result;
for (int i = 0; i < nums.size(); i++) {
mapping[nums[i]] = i;
}
// ... (rest of the solution)
}
};
LeetCode-Solutions (Python):
class Solution:
def twoSum(self, nums: List[int], target: int) -> List[int]:
lookup = {}
for i, num in enumerate(nums):
if target - num in lookup:
return [lookup[target - num], i]
lookup[num] = i
The LeetCode-Solutions example is more concise and uses a single-pass approach, while the LeetCode example separates the mapping creation and lookup steps.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
LeetCode
- R.I.P. to my old Leetcode repository, where there were
5.7k+
stars and2.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, GoogleKickStart, GoogleCodeJamIO repositories.
- For more challenging problem solutions, you can also see my GoogleCodeJam, MetaHackerCup 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.
Solutions
Algorithms
- Bit Manipulation
- Array
- String
- Linked List
- Stack
- Queue
- Binary Heap
- Tree
- Hash Table
- Math
- Sort
- Two Pointers
- Recursion
- Binary Search
- Binary Search Tree
- Breadth-First Search
- Depth-First Search
- Backtracking
- Dynamic Programming
- Greedy
- Graph
- Geometry
- Simulation
- Constructive Algorithms
- Design
JavaScript
Database
Pandas
Reference
Bit Manipulation
# | Title | Solution | Time | Space | Difficulty | Tag | Note |
---|---|---|---|---|---|---|---|
2151 | Maximum Good People Based on Statements | C++ Python | O(n^2 * 2^n) | O(1) | Hard | Bitmasks, Brute Force | |
2212 | Maximum Points in an Archery Competition | C++ Python | O(n * 2^n) | O(n) | Medium | Bitmasks, Brute Force | |
2220 | Minimum Bit Flips to Convert Number | C++ Python | O(logn) | O(1) | Easy | Bit Manipulation | |
2275 | Largest Combination With Bitwise AND Greater Than Zero | C++ Python | O(nlogr) | O(logr) | Medium | Bit Manipulation, Freq Table | |
2317 | Maximum XOR After Operations | C++ Python | O(n) | O(1) | Medium | Bit Manipulation, Greedy | |
2397 | Maximum Rows Covered by Columns | C++ Python | O(m * n + m * C(n, k)) | O(m) | Medium | Bitmasks, Hakmem Item 175 | |
2411 | Smallest Subarrays With Maximum Bitwise OR | C++ Python | O(n) | O(1) | Medium | Bitmasks, Hash Table | |
2419 | Longest Subarray With Maximum Bitwise AND | C++ Python | O(n) | O(1) | Medium | Bit Manipulation | |
2425 | Bitwise XOR of All Pairings | C++ Python | O(n) | O(1) | Medium | Bit Manipulation | |
2429 | Minimize XOR | C++ Python | O(logn) | O(1) | Medium | Bit Manipulation, Greedy | |
2505 | Bitwise OR of All Subsequence Sums | C++ Python | O(n) | O(1) | Medium | ð | Bit Manipulation |
2527 | Find Xor-Beauty of Array | C++ Python | O(n) | O(1) | Medium | Bit Manipulation, Math | |
2595 | Number of Even and Odd Bits | C++ Python | O(1) | O(1) | Easy | Bit Manipulation | |
2859 | Sum of Values at Indices With K Set Bits | C++ Python | O(C(ceil(log2(n)), k)) | O(1) | Easy | Bitmasks, Hakmem Item 175 | |
2917 | Find the K-or of an Array | C++ Python | O(nlogr) | O(1) | Easy | Bit Manipulation | |
2932 | Maximum Strong Pair XOR I | C++ Python | O(nlogr) | O(t) | Easy | variant of Maximum XOR of Two Numbers in an Array | Bit Manipulation, Greedy, Trie, DP, Sort, Two Pointers, Brute Force |
2935 | Maximum Strong Pair XOR II | C++ Python | O(nlogr) | O(t) | Hard | variant of Maximum XOR of Two Numbers in an Array | Bit Manipulation, Greedy, Trie, DP, Sort, Two Pointers |
2980 | Check if Bitwise OR Has Trailing Zeros | C++ Python | O(n) | O(1) | Easy | Bit Manipulation | |
2997 | Minimum Number of Operations to Make Array XOR Equal to K | C++ Python | O(n) | O(1) | Medium | Bit Manipulation | |
3064 | Guess the Number Using Bitwise Questions I | C++ Python | O(logn) | O(1) | Medium | ð | Bit Manipulation |
3094 | Guess the Number Using Bitwise Questions II | C++ Python | O(logr) | O(1) | Medium | ð | Bit Manipulation |
3125 | Maximum Number That Makes Result of Bitwise AND Zero | C++ Python | O(1) | O(1) | Medium | ð | Bit Manipulation |
3133 | Minimum Array End | C++ Python | O(logn) | O(1) | Medium | Bit Manipulation | |
3199 | Count Triplets with Even XOR Set Bits I | C++ Python | O(nlogr) | O(1) | Easy | ð | Brute Force, Bit Manipulation, Parity |
3215 | Count Triplets with Even XOR Set Bits II | C++ Python | O(nlogr) | O(1) | Medium | ð | Bit Manipulation, Parity |
3226 | Number of Bit Changes to Make Two Integers Equal | C++ Python | O(logn) | O(1) | Easy | Bit Manipulation |
Array
String
Linked List
Stack
Queue
# | Title | Solution | Time | Space | Difficulty | Tag | Note |
---|---|---|---|---|---|---|---|
2398 | Maximum Number of Robots Within Budget | C++ Python | O(n) | O(n) | Hard | Mono Deque, Sliding Window, Two Pointers |
Binary Heap
# | Title | Solution | Time | Space | Difficulty | Tag | Note |
---|---|---|---|---|---|---|---|
2054 | Two Best Non-Overlapping Events | C++ Python | O(nlogn) | O(n) | Medium | Line Sweep, Heap | |
2163 | Minimum Difference in Sums After Removal of Elements | C++ Python | O(nlogn) | O(n) | Hard | Heap, Prefix Sum | |
2208 | Minimum Operations to Halve Array Sum | C++ Python | O(nlogn) | O(n) | Medium | Heap | |
2386 | Find the K-Sum of an Array | C++ Python | O(nlogn + klogk) | O(n + k) | Hard | BFS, Heap | |
2402 | Meeting Rooms III | C++ Python | O(mlogm + n + mlogn) | O(n) | Hard | Heap | |
2462 | Total Cost to Hire K Workers | C++ Python | O(c + klogc) | O(c) | Medium | Heap, Two Pointers | |
2519 | Count the Number of K-Big Indices | C++ Python | O(nlogk) | O(n) | Hard | ð | Heap, Ordered Set, Sorted List |
2530 | Maximal Score After Applying K Operations | C++ Python | O(n + klogn) | O(1) | Medium | Heap, Simulation | |
2558 | Take Gifts From the Richest Pile | C++ Python | O(n + klogn) | O(1) | Easy | Heap, Simulation | |
2818 | Apply Operations to Maximize Score | C++ Python | O(sqrt(r) + n * (logr + sqrt(r)/log(sqrt(r))) + klogn) | O(sqrt(r) + n) | Hard | Number Theory, Linear Sieve of Eratosthenes , Mono Stack, Greedy, Sort, Heap | |
3066 | Minimum Operations to Exceed Threshold Value II | C++ Python | O(nlogn) | O(n) | Medium | Simulation, Heap | |
3080 | Mark Elements on Array by Performing Queries | C++ Python | O(q + nlogn) | O(n) | Medium | Hash Table, Heap | |
3092 | Most Frequent IDs | C++ Python | O(nlogn) | O(n) | Medium | Heap, BST, Sorted List | |
3256 | Maximum Value Sum by Placing Three Rooks I | C++ Python | O(m * n) | O(m + n) | Hard | Heap, Brute Force | |
3257 | Maximum Value Sum by Placing Three Rooks II | C++ Python | O(m * n) | O(m + n) | Hard | Heap, Brute Force | |
3275 | K-th Nearest Obstacle Queries | C++ Python | O(qlogk) | O(k) | Medium | Heap |
Tree
Hash Table
Math
Sort
# | Title | Solution | Time | Space | Difficulty | Tag | Note |
---|---|---|---|---|---|---|---|
2015 | Average Height of Buildings in Each Segment | C++ Python | O(nlogn) | O(n) | Medium | ð | Line Sweep |
2021 | Brightest Position on Street | C++ Python | O(nlogn) | O(n) | Medium | ð | Line Sweep |
2070 | Most Beautiful Item for Each Query | C++ Python | O(nlogn + qlogn) | O(1) | Medium | Sort, Binary Search | |
2089 | Find Target Indices After Sorting Array | C++ Python | O(n) | O(1) | Easy | Counting Sort | |
2158 | Amount of New Area Painted Each Day | C++ Python | O(nlogr) | O(r) | Hard | ð | Line Sweep, Sorted List, Heap, Segment Tree |
2164 | Sort Even and Odd Indices Independently | C++ Python | O(n) | O(c) | Easy | Counting Sort, Inplace | |
2191 | Sort the Jumbled Numbers | C++ Python | O(nlogm + nlogn) | O(n) | Medium | Sort | |
2231 | Largest Number After Digit Swaps by Parity | C++ Python | O(logn) | O(1) | Easy | Counting Sort | |
2233 | Maximum Product After K Increments | C++ Python | O(n + k) | O(n) | Medium | Heap, Freq Table, Sort, Math | |
2248 | Intersection of Multiple Arrays | C++ Python | O(n * l + r) | O(l) | Easy | Hash Table, Counting Sort | |
2251 | Number of Flowers in Full Bloom | C++ Python | O(nlogn + mlogn) | O(n) | Hard | Line Sweep, Binary Search | |
2343 | Query Kth Smallest Trimmed Number | C++ Python | O(q + n * t) | O(t + n + q) | Medium | Sort, Quick Select, Radix Sort | |
2418 | Sort the People | C++ Python | O(nlogn) | O(n) | Easy | Sort | |
2497 | Maximum Star Sum of a Graph | C++ Python | O(n) | O(n) | Medium | Sort, Quick Select | |
2512 | Reward Top K Students | C++ Python | O(pf * l + nf * l + n * l + klogk) | O(pf * l + nf * l + n) | Medium | Partial Sort, Quick Select | |
2545 | Sort the Students by Their Kth Score | C++ Python | O(mlogm) | O(1) | Medium | Sort | |
2659 | Make Array Empty | C++ Python | O(nlogn) | O(n) | Hard | Sort, BIT, Fenwick Tree | |
2679 | Sum in a Matrix | C++ Python | O(m * nlogn) | O(1) | Medium | Sort | |
2740 | Find the Value of the Partition | C++ Python | O(nlogn) | O(1) | Medium | Sort | |
2785 | Sort Vowels in a String | C++ Python | O(n) | O(1) | Medium | Counting Sort | |
2792 | Count Nodes That Are Great Enough | C++ Python | O(k * h) | O(k + h) | Hard | ð | Merge Sort |
2948 | Make Lexicographically Smallest Array by Swapping Elements | C++ Python | O(nlogn) | O(n) | Medium | Sort | |
2974 | Minimum Number Game | C++ Python | O(nlogn) | O(1) | Easy | Sort | |
3011 | Find if Array Can Be Sorted | C++ Python | O(n) | O(1) | Medium | Sort | |
3025 | Find the Number of Ways to Place People I | C++ Python | O(n^2) | O(1) | Medium | Sort, Array | |
3027 | Find the Number of Ways to Place People II | C++ Python | O(n^2) | O(1) | Hard | Sort, Array | |
3081 | Replace Question Marks in String to Minimize Its Value | C++ Python | O(n + 26 * log(26)) | O(n + 26) | Medium | Greedy, Counting Sort, Heap, Prefix Sum | |
3132 | Find the Integer Added to Array II | C++ Python | O(n) | O(n) | Medium | Sort, Paritial Sort, Freq Table | |
3169 | Count Days Without Meetings | C++ Python | O(nlogn) | O(1) | Medium | Sort | |
3194 | Minimum Average of Smallest and Largest Elements | C++ Python | O(nlogn) | O(1) | Easy | Sort |
Two Pointers
# | Title | Solution | Time | Space | Difficulty | Tag | Note |
---|---|---|---|---|---|---|---|
2009 | Minimum Number of Operations to Make Array Continuous | C++ Python | O(nlogn) | O(1) | Hard | Two Pointers, Sliding Window | |
2024 | Maximize the Confusion of an Exam | C++ Python | O(n) | O(1) | Medium | variant of Longest Repeating Character Replacement | Sliding Window |
2040 | Kth Smallest Product of Two Sorted Arrays | C++ Python | O((m + n) * logr) | O(1) | Hard | Binary Search, Two Pointers | |
2046 | Sort Linked List Already Sorted Using Absolute Values | C++ Python | O(n) | O(1) | Medium | ð | Linked List |
2062 | Count Vowel Substrings of a String | C++ Python | O(n) | O(1) | Easy | variant of Count Number of Nice Subarrays | Sliding Window |
2067 | Number of Equal Count Substrings | C++ Python | O(n) | O(1) | Medium | ð | Sliding Window |
2090 | K Radius Subarray Averages | C++ Python | O(n) | O(1) | Medium | Sliding Window | |
2105 | Watering Plants II | C++ Python | O(n) | O(1) | Medium | Simulation | |
2107 | Number of Unique Flavors After Sharing K Candies | C++ Python | O(n) | O(n) | Medium | ð | Sliding Window |
2134 | Minimum Swaps to Group All 1's Together II | C++ Python | O(n) | O(1) | Medium | Sliding Window | |
2149 | Rearrange Array Elements by Sign | C++ Python | O(n) | O(1) | Medium | Two Pointers | |
2161 | Partition Array According to Given Pivot | C++ Python | O(n) | O(n) | Medium | Two Pointers | |
2200 | Find All K-Distant Indices in an Array | C++ Python | O(n) | O(1) | Easy | Two Pointers | |
2234 | Maximum Total Beauty of the Gardens | C++ Python | O(nlogn) | O(1) | Hard | Sort, Prefix Sum, Greedy, Binary Search, Two Pointers | |
2302 | Count Subarrays With Score Less Than K | C++ Python | O(n) | O(1) | Hard | Two Pointers, Sliding Window | |
2330 | Valid Palindrome IV | C++ Python | O(n) | O(1) | Medium | ð | String, Two Pointers |
2332 | The Latest Time to Catch a Bus | C++ Python | O(nlogn + mlogm) | O(1) | Medium | String, Two Pointers | |
2337 | Move Pieces to Obtain a String | C++ Python | O(n + m) | O(1) | Medium | String, Two Pointers | |
2348 | Number of Zero-Filled Subarrays | C++ Python | O(n) | O(1) | Medium | Two Pointers, Combinatorics | |
2379 | Minimum Recolors to Get K Consecutive Black Blocks | C++ Python | O(n) | O(1) | Easy | Sliding Window | |
2393 | Count Strictly Increasing Subarrays | C++ Python | O(n) | O(1) | Medium | ð | Two Pointers |
2401 | Longest Nice Subarray | C++ Python | O(n) | O(1) | Medium | Sliding Window, Two Pointers | |
2444 | Count Subarrays With Fixed Bounds | C++ Python | O(n) | O(1) | Hard | variant of Number of Substrings Containing All Three Characters | Two Pointers |
2461 | Maximum Sum of Distinct Subarrays With Length K | C++ Python | O(n) | O(k) | Medium | Two Pointers | |
2465 | Number of Distinct Averages | C++ Python | O(nlogn) | O(n) | Easy | Two Pointers, Hash Table | |
2511 | Maximum Enemy Forts That Can Be Captured | C++ Python | O(n) | O(1) | Easy | Array, Two Pointers | |
2516 | Take K of Each Character From Left and Right | C++ Python | O(n) | O(1) | Medium | Sliding Window, Two Pointers | |
2524 | Maximum Frequency Score of a Subarray | C++ Python | O(n) | O(n) | Hard | ð | Sliding Window, Two Pointers, Freq Table, Hash Table |
2537 | Count the Number of Good Subarrays | C++ Python | O(n) | O(n) | Medium | Sliding Window, Two Pointers | |
2540 | Minimum Common Value | C++ Python | O(n) | O(1) | Easy | Two Pointers | |
2555 | Maximize Win From Two Segments | C++ Python | O(n) | O(n) | Medium | Two Pointers, Sliding Window, DP | |
2563 | Count the Number of Fair Pairs | C++ Python | O(nlogn) | O(1) | Medium | Sort, Two Pointers | |
2570 | Merge Two 2D Arrays by Summing Values | C++ Python | O(n) | O(1) | Easy | Two Pointers | |
2609 | Find the Longest Balanced Substring of a Binary String | C++ Python | O(n) | O(1) | Easy | String, Two Pointers | |
2653 | Sliding Subarray Beauty | C++ Python | O(nlogk) | O(k) | Medium | Sorted List, Ordered Set, Two Pointers | |
2730 | Find the Longest Semi-Repetitive Substring | C++ Python | O(n) | O(1) | Medium | Two Pointers | |
2743 | Count Substrings Without Repeating Character | C++ Python | O(n) | O(1) | Medium | ð, variant of Longest Substring Without Repeating Characters | Two Pointers, Sliding Window |
2747 | Count Zero Request Servers | C++ Python | O(nlogn + mlogm) | O(n + m) | Hard | Sort, Two Pointers, Line Sweep | |
2762 | Continuous Subarrays | C++ Python | O(n) | O(1) | Medium | Mono Deque, BST, Ordered Dict, Two Pointers, Sliding Window | |
2763 | Sum of Imbalance Numbers of All Subarrays | C++ Python | O(n) | O(n) | Hard | Two Pointers, Sliding Window, Hash Table, Combinatorics | |
2779 | Maximum Beauty of an Array After Applying Operation | C++ Python | O(nlogn) | O(1) | Medium | Sort, Two Pointers, Sliding Window | |
2781 | Length of the Longest Valid Substring | C++ Python | O((m + n) * l) | O(t) | Hard | Two Pointers, Sliding Window, Trie | |
2799 | Count Complete Subarrays in an Array | C++ Python | O(n) | O(n) | Medium | Freq Table, Two Pointers, Sliding Window | |
2824 | Count Pairs Whose Sum is Less than Target | C++ Python | O(nlogn) | O(1) | Easy | Sort, Two Pointers | |
2831 | Find the Longest Equal Subarray | C++ Python | O(n) | O(n) | Medium | Freq Table, Two Pointers, Sliding Window | |
2838 | Maximum Coins Heroes Can Collect | C++ Python | O(nlogn + mlogm) | O(n + m) | Medium | ð | Sort, Two Pointers |
2841 | Maximum Sum of Almost Unique Subarray | C++ Python | O(n) | O(n) | Medium | Freq Table, Two Pointers, Sliding Window | |
2875 | Minimum Size Subarray in Infinite Array | C++ Python | O(n) | O(1) | Medium | Prefix Sum, Hash Table, Two Pointers, Sliding Window | |
2904 | Shortest and Lexicographically Smallest Beautiful String | C++ Python | O(n^2) | O(1) | Medium | Two Pointers, Sliding Window | |
2933 | High-Access Employees | C++ Python | O(nlogn) | O(n) | Medium | Sort, Two Pointers, Sliding Window | |
2938 | Separate Black and White Balls | C++ Python | O(n) | O(1) | Medium | Two Pointers | |
2953 | Count Complete Substrings | C++ Python | O(26 + d * n) | O(26) | Medium | Freq Table, Two Pointers, Sliding Window | |
2958 | Length of Longest Subarray With at Most K Frequency | C++ Python | O(n) | O(n) | Medium | Freq Table, Two Pointers, Sliding Window | |
2962 | Count Subarrays Where Max Element Appears at Least K Times | C++ Python | O(n) | O(1) | Medium | Two Pointers, Sliding Window | |
2968 | Apply Operations to Maximize Frequency Score | C++ Python | O(nlogn) | O(1) | Hard | Sort, Two Pointers, Sliding Window, Prefix Sum, Binary Search | |
2970 | Count the Number of Incremovable Subarrays I | C++ Python | O(n) | O(1) | Easy | Two Pointers, Brute Force | |
2972 | Count the Number of Incremovable Subarrays II | C++ Python | O(n) | O(1) | Hard | Two Pointers | |
3006 | Find Beautiful Indices in the Given Array I | C++ Python | O(n) | O(min(a + b + x + y, n)) | Medium | KMP Algorithm , Binary Search, Two Pointers | |
3008 | Find Beautiful Indices in the Given Array II | C++ Python | O(n) | O(min(a + b + x + y, n)) | Hard | KMP Algorithm , Binary Search, Two Pointers | |
3013 | Divide an Array Into Subarrays With Minimum Cost II | C++ Python | O(nlogd) | O(d) | Hard | Sliding Window, Heap, Freq Table, Ordered Set, BST, Sorted List | |
3085 | Minimum Deletions to Make String K-Special | C++ Python | O(n + 26) | O(n + 26) | Medium | Freq Table, Counting Sort, Two Pointers | |
3090 | Maximum Length Substring With Two Occurrences | C++ Python | O(n + 26) | O(26) | Easy | Freq Table, Sliding Window, Two Pointers | |
3095 | Shortest Subarray With OR at Least K I | C++ Python | O(n * 30) | O(30) | Easy | Brute Force, Freq Table, Two Pointers | |
3097 | Shortest Subarray With OR at Least K II | C++ Python | O(n * 30) | O(30) | Medium | Freq Table, Two Pointers | |
3171 | Find Subarray With Bitwise OR Closest to K | C++ Python | O(nlogr) | O(logr) | Hard | variant of Find a Value of a Mysterious Function Closest to Target | DP, Freq Table, Two Pointers, Sliding Window |
3206 | Alternating Groups I | C++ Python | O(n) | O(1) | Easy | Two Pointers, Sliding Window | |
3208 | Alternating Groups II | C++ Python | O(n) | O(1) | Medium | Two Pointers, Sliding Window | |
3234 | Count the Number of Substrings With Dominant Ones | C++ Python | O(n^(3/2)) | O(1) | Medium | Two Pointers, Sliding Window | |
3254 | Find the Power of K-Size Subarrays I | C++ Python | O(n) | O(1) | Medium | Two Pointers, Sliding Window | |
3255 | Find the Power of K-Size Subarrays II | C++ Python | O(n) | O(1) | Medium | Two Pointers, Sliding Window | |
3258 | Count Substrings That Satisfy K-Constraint I | C++ Python | O(n) | O(1) | Easy | Two Pointers, Sliding Window | |
3261 | Count Substrings That Satisfy K-Constraint II | C++ Python | O(n) | O(n) | Hard | Two Pointers, Sliding Window, Prefix Sum, Hash Table | |
3264 | Final Array State After K Multiplication Operations I | C++ Python | O(nlogn) | O(n) | Easy | Sort, Two Pointers, Sliding Window, Fast Exponentiation, Heap, Binary Search, Simulation | |
3266 | Final Array State After K Multiplication Operations II | C++ Python | O(nlogn) | O(n) | Hard | Sort, Two Pointers, Sliding Window, Fast Exponentiation, Heap, Binary Search |
Recursion
# | Title | Solution | Time | Space | Difficulty | Tag | Note |
---|---|---|---|---|---|---|---|
2613 | Beautiful Pairs | C++ Python | O(n) on average | O(n) | Hard | ð, variant of SPOJ - Closest Point Pair | Random Algorithms, Divide and Conquer, Merge Sort, Segment Tree |
Binary Search
# | Title | Solution | Time | Space | Difficulty | Tag | Note |
---|---|---|---|---|---|---|---|
2064 | Minimized Maximum of Products Distributed to Any Store | C++ Python | O(nlogm) | O(1) | Medium | variant of Minimum Limit of Balls in a Bag | |
2111 | Minimum Operations to Make the Array K-Increasing | C++ Python | O(nlog(n/k)) | O(n/k) | Hard | variant of Longest Increasing Subsequence | |
2137 | Pour Water Between Buckets to Make Water Levels Equal | C++ Python | O(nlogr) | O(1) | Medium | ð | |
2187 | Minimum Time to Complete Trips | C++ Python | O(nlogr) | O(1) | Medium | ||
2226 | Maximum Candies Allocated to K Children | C++ Python | O(nlogr) | O(1) | Medium | Binary Search | |
2250 | Count Number of Rectangles Containing Each Point | C++ Python | O(nlogn + m * max_y * logn) | O(n) | Medium | Bucket Sort, Binary Search | |
2300 | Successful Pairs of Spells and Potions | C++ Python | O(mlogm + nlogm) | O(1) | Medium | Binary Search | |
2333 | Minimum Sum of Squared Difference | C++ Python | O(nlogn + nlogr) | O(1) | Medium | Binary Search | |
2387 | Median of a Row Wise Sorted Matrix | C++ Python | O(logr * mlogn) | O(1) | Medium | ð | Binary Search |
2389 | Longest Subsequence With Limited Sum | C++ Python | O(nlogn + qlogn) | O(1) | Easy | Greedy, Sort, Binary Search | |
2448 | Minimum Cost to Make Array Equal | C++ Python | O(nlogn) | O(n) | Hard | Math, Binary Search, Prefix Sum | |
2476 | Closest Nodes Queries in a Binary Search Tree | C++ Python | O(n + qlogn) | O(n) | Hard | DFS, Binary Search | |
2513 | Minimize the Maximum of Two Arrays | C++ Python | O(log(min(d1, d2))) | O(1) | Medium | Number Theory, Binary Search | |
2517 | Maximum Tastiness of Candy Basket | C++ Python | O(nlogr) | O(1) | Medium | Binary Search, Greedy | |
2528 | Maximize the Minimum Powered City | C++ Python | O(nlogk) | O(n) | Hard | Binary Search, Sliding Window, Greedy | |
2529 | Maximum Count of Positive Integer and Negative Integer | C++ Python | O(logn) | O(1) | Easy | Binary Search | |
2554 | Maximum Number of Integers to Choose From a Range I | C++ Python | O(b) | O(b) | Medium | Math, Binary Search, Prefix Sum, Greedy | |
2557 | Maximum Number of Integers to Choose From a Range II | C++ Python | O(b) | O(b) | Medium | ð | Math, Binary Search, Prefix Sum |
2560 | House Robber IV | C++ Python | O(nlogn) | O(n) | Medium | Binary Search, Greedy | |
2594 | Minimum Time to Repair Cars | C++ Python | O(mx * (logc + log(mn))) | O(mx) | Medium | Freq Table, Binary Search, Heap, Simulation | |
2602 | Minimum Operations to Make All Array Elements Equal | C++ Python | O(nlogn + qlogn) | O(n) | Medium | Sort, Binary Search, Prefix Sum | |
2616 | Minimize the Maximum Difference of Pairs | C++ Python | O(nlogn + nlogr) | O(1) | Medium | Sort, Binary Search, Greedy | |
2702 | Minimum Operations to Make Numbers Non-positive | C++ Python | O(nlogr) | O(1) | Hard | ð | Binary Search, Greedy |
2936 | Number of Equal Numbers Blocks | C++ Python | O(klogn) | O(1) | Medium | ð | Binary Search |
2940 | Find Building Where Alice and Bob Can Meet | C++ Python | O(n + qlogn) | O(n) | Hard | Heap, Mono Stack, Binary Search, Online Solution, Segment Tree | |
3048 | Earliest Second to Mark Indices I | C++ Python | O(mlogm) | O(n) | Medium | Binary Search, Greedy | |
3049 | Earliest Second to Mark Indices II | C++ Python | O((m + nlogn) *logm) | O(n) | Hard | Binary Search, Greedy, Heap | |
3104 | Find Longest Self-Contained Substring | C++ Python | O(n + 26^3 * logn) | O(n) | Hard | ð | Brute Force, Freq Table, Two Pointers, Hash Table, Binary Search |
3116 | Kth Smallest Amount With Single Denomination Combination | C++ Python | O(n * 2^n * logk) | O(2^n) | Hard | Binary Search, Principle of Inclusion and Exclusion, Number Theory | |
3134 | Find the Median of the Uniqueness Array | C++ Python | O(nlogn) | O(n) | Hard | Binary Search, Two Pointers, Sliding Window | |
3135 | Equalize Strings by Adding or Removing Characters at Ends | C++ Python | O((n + m) * log(min(n, m))) | O(min(n, m)) | Medium | ð | Binary Search, Rabin-Karp Algorithm , Rolling Hash, DP |
3145 | Find Products of Elements of Big Array | C++ Python | O(q * (logr)^2) | O(1) | Hard | Binary Search, Combinatorics, Bitmasks, Fast Exponentiation | |
3231 | Minimum Number of Increasing Subsequence to Be Removed | C++ Python | O(nlogn) | O(n) | Hard | ð, variant of Longest Increasing Subsequence | Binary Search |
3233 | Find the Count of Numbers Which Are Not Special | C++ Python | precompute: O(sqrt(r)) runtime: O(logr) | O(sqrt(r)) | Medium | Number Theory, Linear Sieve of Eratosthenes , Binary Search | |
3281 | Maximize Score of Numbers in Ranges | C++ Python | O(nlogr) | O(1) | Medium | Binary Search, Greedy |
Binary Search Tree
# | Title | Solution | Time | Space | Difficulty | Tag | Note |
---|---|---|---|---|---|---|---|
2426 | Number of Pairs Satisfying Inequality | C++ Python | O(nlogn) | O(n) | Hard | Merge Sort, Two Pointers, BIT, Fenwick Tree, Coordinate Compression, Sorted List, Ordered Set, Binary Search | |
2689 | Extract Kth Character From The Rope Tree | C++ Python | O(h) | O(1) | Medium | ð | BST |
2817 | Minimum Absolute Difference Between Elements With Constraint | C++ Python | O(nlogn) | O(n) | Medium | Sorted List, BST, Binary Search | |
2907 | Maximum Profitable Triplets With Increasing Prices I | C++ Python | O(nlogn) | O(n) | Medium | ð | Prefix Sum, Sorted List, BST, Binary Search, Mono Stack, BIT, Fenwick Tree, Segment Tree |
2921 | Maximum Profitable Triplets With Increasing Prices II | C++ Python | O(nlogn) | O(n) | Hard | ð | Prefix Sum, Sorted List, BST, Binary Search, Mono Stack, BIT, Fenwick Tree, Segment Tree |
2926 | Maximum Balanced Subsequence Sum | C++ Python | O(nlogn) | O(n) | Hard | Sorted List, BST, Binary Search, Mono Stack, BIT, Fenwick Tree, Segment Tree | |
3072 | Distribute Elements Into Two Arrays II | C++ Python | O(nlogn) | O(n) | Hard | Sorted List, Ordered Set | |
3073 | Maximum Increasing Triplet Value | C++ Python | O(nlogn) | O(n) | Medium | ð | Sorted List, BST, Prefix Sum |
3161 | Block Placement Queries | C++ Python | O(qlogq) | O(q) | Hard | Sorted List, BST, BIT, Fenwick Tree, Segment Tree | |
3165 | Maximum Sum of Subsequence With Non-adjacent Elements | C++ Python | O(n + qlogn) | O(n) | Hard | Segment Tree |
Breadth-First Search
Depth-First Search
Backtracking
# | Title | Solution | Time | Space | Difficulty | Tag | Note |
---|---|---|---|---|---|---|---|
2014 | Longest Subsequence Repeated k Times | C++ Python | O(n * (n/k)!) | O(n/k) | Hard | ||
2056 | Number of Valid Move Combinations On Chessboard | C++ Python | O(1) | O(1) | Hard | ||
2094 | Finding 3-Digit Even Numbers | C++ Python | O(n) | O(1) | Easy | ||
2443 | Sum of Number and Its Reverse | C++ Python | O(n^(1/(2*log2(10)))) | O(log10(n)/2) | Medium | Brute Force, Backtracking | |
2664 | The Knightâs Tour | C++ Python | O(m * n) | O(1) | Medium | ð | Backtracking, Greedy, Warnsdorff's Rule |
2698 | Find the Punishment Number of an Integer | C++ Python | O(n * (logn)^(2*logn)) | O(logn) | Medium | Backtracking | |
2741 | Special Permutations | C++ Python | O(n^2 * 2^n) | O(n * 2^n) | Medium | Backtracking, Memoization | |
3211 | Generate Binary Strings Without Adjacent Zeros | C++ Python | O(n * 2^n) | O(n) | Medium | Backtracking, BFS |
Dynamic Programming
Greedy
Graph
# | Title | Solution | Time | Space | Difficulty | Tag | Note |
---|---|---|---|---|---|---|---|
2076 | Process Restricted Friend Requests | C++ Python | O(n * r) | O(n) | Hard | Union Find | |
2077 | Paths in Maze That Lead to Same Room | C++ Python | O(|V|^3) | O(|E|) | Medium | ð | |
2092 | Find All People With Secret | C++ Python | O(nlogn) | O(nlogn) | Hard | BFS, DFS, Union Find | |
2093 | Minimum Path Cost in a Hidden Grid | C++ Python | O(|E| * log|V|) | O(|V| + |E|) | Medium | variant of Cheapest Flights Within K Stops, ð | Dijkstra's Algorithm , DP |
2097 | Valid Arrangement of Pairs | C++ Python | O(|V| + |E|) | O(|V| + |E|) | Hard | variant of Reconstruct Itinerary | Hierholzer's Algorithm , Eulerian Path |
2123 | Minimum Operations to Remove Adjacent Ones in Matrix | C++ Python | O(m * n * sqrt(m * n)) | O(m + n) | Hard | variant of Maximum Students Taking Exam, ð | Hopcroft-Karp Bipartite Matching , Maximum Independent Set |
2127 | Maximum Employees to Be Invited to a Meeting | C++ Python | O(n) | O(n) | Hard | ||
2172 | Maximum AND Sum of Array | C++ Python | O(n^3) | O(n^2) | Hard | variant of Maximum Compatibility Score Sum | DP, Hungarian Weighted Bipartite Matching |
2203 | Minimum Weighted Subgraph With the Required Paths | C++ Python | O(|E| * log|V|) | O(|E|) | Hard | Dijkstra's Algorithm | |
2204 | Distance to a Cycle in Undirected Graph | C++ Python | O(|V| + |E|) | O(|V| + |E|) | Hard | ð | Graph, DFS, BFS |
2242 | Maximum Score of a Node Sequence | C++ Python | O(|V| + |E|) | O(|V|) | Hard | Graph | |
2307 | Check for Contradictions in Equations | C++ Python | O(e + q) | O(n) | Hard | ð, variant of Evaluate Division | DFS, Union Find |
2359 | Find Closest Node to Given Two Nodes | C++ Python | O(n) | O(n) | Medium | Graph, Hash Table, DFS | |
2360 | Longest Cycle in a Graph | C++ Python | O(n) | O(n) | Hard | Graph, Hash Table, DFS | |
2392 | Build a Matrix With Conditions | C++ Python | O(k^2 + r + c) | O(k + r + c) | Hard | Graph, Topological Sort | |
2473 | Minimum Cost to Buy Apples | C++ Python | O(n * rlogn) | O(n) | Medium | ð | Dijkstra's Algorithm |
2508 | Add Edges to Make Degrees of All Nodes Even | C++ Python | O(n) | O(n) | Hard | Graph | |
2608 | Shortest Cycle in a Graph | C++ Python | O(n^2) | O(n + e) | Hard | Graph, BFS | |
2662 | Minimum Cost of a Path With Special Roads | C++ Python | O(n^2) | O(n^2) | Medium | Graph, Dijkstra's Algorithm | |
2699 | Modify Graph Edge Weights | C++ Python | O(|E| * log|V|) | O(|E|) | Hard | Graph, Dijkstra's Algorithm | |
2714 | Find Shortest Path with K Hops | C++ Python | O(n * k + (k * e) * log(n * k)) | O(n * k + e) | Hard | ð | Graph, Dijkstra's Algorithm |
2737 | Find the Closest Marked Node | C++ Python | O(|E| * log|V|) | O(|E|) | Medium | ð | Graph, Dijkstra's Algorithm |
2836 | Maximize Value of Function in a Ball Passing Game | C++ Python | O(n) | O(n) | Hard | Graph, Prefix Sum, Two Pointers, Sliding Window, Binary Lifting | |
2850 | Minimum Moves to Spread Stones Over Grid | C++ Python | O(n^3) | O(n^2) | Medium | Backtracking, Hungarian Weighted Bipartite Matching | |
2876 | Count Visited Nodes in a Directed Graph | C++ Python | O(n) | O(n) | Hard | Graph, Hash Table, Stack | |
2924 | Find Champion II | C++ Python | O(n) | O(n) | Medium | Graph, Hash Table | |
2959 | Number of Possible Sets of Closing Branches | C++ Python | O(r + 2^n * n^2) | O(n^3) | Medium | Graph, Bitmasks, Floyd-Warshall Algorithm , Backtracking | |
3108 | Minimum Cost Walk in Weighted Graph | C++ Python | O(n + e + q) | O(n) | Hard | Union Find | |
3112 | Minimum Time to Visit Disappearing Nodes | C++ Python | O(|E| * log|V|) | O(|E|) | Medium | Graph, Dijkstra's Algorithm | |
3123 | Find Edges in Shortest Paths | C++ Python | O(|E| * log|V|) | O(|E|) | Hard | Graph, Dijkstra's Algorithm | |
3235 | Check if the Rectangle Corner Is Reachable | C++ Python | O(n^2) | O(n) | Hard | Graph, BFS, DFS, Union Find | |
3243 | Shortest Distance After Road Addition Queries I | C++ Python | O(n^2) | O(n^2) | Medium | Graph, Dijkstra's Algorithm , BFS | |
3244 | Shortest Distance After Road Addition Queries II | C++ Python | O(nlogn) | O(n) | Hard | Graph, BST, Sorted List | |
3265 | Count Almost Equal Pairs I | C++ Python | O(n * l^2) | O(n) | Medium | Freq Table, Combinatorics, Graph, BFS | |
3267 | Count Almost Equal Pairs II | C++ Python | O(n * l^4) | O(n) | Hard | Freq Table, Combinatorics, Graph, BFS | |
3276 | Select Cells in Grid With Maximum Score | C++ Python | O(n^2 * max(n, r)) | O(n * max(n, r)) | Hard | variant of Maximum Compatibility Score Sum | Hungarian Weighted Bipartite Matching , DP, Bitmasks |
Geometry
# | Title | Solution | Time | Space | Difficulty | Tag | Note |
---|---|---|---|---|---|---|---|
2101 | Detonate the Maximum Bombs | C++ Python | O(|V|^2 + \V| * |E|) | O(\V| + |E|) | Medium | Graph, DFS, BFS |
Simulation
Constructive Algorithms
# | Title | Solution | Time | Space | Difficulty | Tag | Note |
---|---|---|---|---|---|---|---|
2202 | Maximize the Topmost Element After K Moves | C++ Python | O(min(n, k)) | O(1) | Medium | Constructive Algorithms | |
2335 | Minimum Amount of Time to Fill Cups | C++ Python | O(1) | O(1) | Easy | Math, Constructive Algorithms | |
2350 | Shortest Impossible Sequence of Rolls | C++ Python | O(n) | O(k) | Hard | Constructive Algorithms | |
2546 | Apply Bitwise Operations to Make Strings Equal | C++ Python | O(n) | O(1) | Medium | Constructive Algorithms | |
2358 | Maximum Number of Groups Entering a Competition | C++ Python | O(1) | O(1) | Medium | Constructive Algorithms, Math | |
2610 | Convert an Array Into a 2D Array With Conditions | C++ Python | O(n) | O(n) | Medium | Freq Table, Constructive Algorithms | |
2647 | Color the Triangle Red | C++ Python | O(n^2) | O(1) | Hard | ð | Constructive Algorithms |
2654 | Minimum Number of Operations to Make All Array Elements Equal to 1 | C++ Python | O(n^2) | O(1) | Medium | Math, Number Theory, Constructive Algorithms | |
2728 | Count Houses in a Circular Street | C++ Python | O(k) | O(1) | Easy | ð | Constructive Algorithms |
2732 | Find a Good Subset of the Matrix | C++ Python | O(m * 2^n) | O(2^n) | Hard | Bitmasks, Constructive Algorithms, Greedy | |
2745 | Construct the Longest New String | C++ Python | O(1) | O(1) | Medium | Constructive Algorithms, Math | |
2753 | Count Houses in a Circular Street II | C++ Python | O(k) | O(1) | Hard | ð | Constructive Algorithms |
2811 | Check if it is Possible to Split Array | C++ Python | O(n) | O(1) | Medium | Constructive Algorithms | |
2829 | Determine the Minimum Sum of a k-avoiding Array | C++ Python | O(1) | O(1) | Medium | Greedy, Constructive Algorithms, Math | |
2834 | Find the Minimum Possible Sum of a Beautiful Array | C++ Python | O(1) | O(1) | Medium | Determine the Minimum Sum of a k-avoiding Array | Greedy, Constructive Algorithms, Math |
2849 | Determine if a Cell Is Reachable at a Given Time | C++ Python | O(1) | O(1) | Medium | Constructive Algorithms, Math | |
2856 | Minimum Array Length After Pair Removals | C++ Python | O(n) | O(n) | Medium | Freq Table, Constructive Algorithms | |
3139 | Minimum Cost to Equalize Array | C++ Python | O(n) | O(1) | Hard | Constructive Algorithms, Math | |
3260 | Find the Largest Palindrome Divisible by K | C++ Python | O(n) | O(1) | Hard | String, Constructive Algorithms, Math |
Design
# | Title | Solution | Time | Space | Difficulty | Tag | Note |
---|---|---|---|---|---|---|---|
2013 | Detect Squares | C++ Python | ctor: O(1) add: O(1) count: O(n) | O(n) | Medium | ||
2034 | Stock Price Fluctuation | C++ Python | ctor: O(1) update: O(logn) current: O(1) max: O(1) min: O(1) | O(n) | Medium | Sorted List, Heap | |
2043 | Simple Bank System | C++ Python | ctor: O(1) transer: O(1) deposit: O(1) withdraw: O(1) | O(1) | Medium | ||
2069 | Walking Robot Simulation II | C++ Python | O(1) | O(1) | Medium | Simulation, Math | |
2080 | Range Frequency Queries | C++ Python | ctor: O(n) query: O(logn) | O(n) | Medium | Binary Search | |
2102 | Sequentially Ordinal Rank Tracker | C++ Python | add: O(logn) get: O(logn) | O(n) | Hard | Sorted List | |
2166 | Design Bitset | C++ Python | ctor: O(n) fix: O(1) fix: O(1) unfix: O(1) flip: O(1) all: O(1) one: O(1) count: O(1) toString: O(n) | O(n) | Medium | ||
2227 | Encrypt and Decrypt Strings | C++ Python | ctor: O(m + d) encrypt: O(n) decrypt: O(n) | O(n) | Hard | Freq Table | |
2241 | Design an ATM Machine | C++ Python | ctor: O(1) deposit: O(1) withdraw: O(1) | O(1) | Medium | Greedy | |
2254 | Design Video Sharing Platform | C++ Python | ctor: O(1) upload: O(logn + l) remove: O(logn) like: O(1) dislike: O(1) view: O(1) getLikesAndDislikes: O(1) getViews: O(1) | O(n * l) | Hard | ð | Heap |
2276 | Count Integers in Intervals | C++ Python | ctor: O(1) add: O(logn), amortized Count: O(1) | O(n) | Hard | Sorted List | |
2286 | Booking Concert Tickets in Groups | C++ Python | ctor: O(n) gather: O(logn) scatter: O(logn), amortized | O(n) | Hard | Segment Tree, Binary Search | |
2296 | Design a Text Editor | C++ Python | ctor: O(1) addText: O(l) deleteText: O(k) cursorLeft: O(k) cursorRight: O(k) | O(n) | Hard | Stack | |
2336 | Smallest Number in Infinite Set | C++ Python | ctor: O(1) popSmallest: O(logn) addBack: O(logn) | O(n) | Medium | Heap, BST | |
2349 | Design a Number Container System | C++ Python | ctor: O(1) change: O(logn) find: O(1) | O(n) | Medium | Sorted List, BST | |
2353 | Design a Food Rating System | C++ Python | ctor: O(nlogn) changeRating: O(logn) highestRated: O(1) | O(n) | Medium | Sorted List, BST | |
2408 | Design SQL | C++ Python | ctor: O(t * max_m) insertRow: O(m) deleteRow: O(1) selectCell: O(m) | O(d) | Medium | ð | Hash Table |
2424 | Longest Uploaded Prefix | C++ Python | ctor: O(1) upload: O(1), amortized longest: O(1) | O(n) | Medium | Hash Table | |
2502 | Design Memory Allocator | C++ Python | ctor: O(1) allocate: O(logn) free: O(logn) | O(n) | Medium | Sorted List | |
2526 | Find Consecutive Integers from a Data Stream | C++ Python | O(1) | O(1) | Medium | Array | |
2590 | Design a Todo List | C++ Python | ctor: O(1) addTask: O(l + logn) getAllTasks: O(r) getTasksForTag: O(r * c) completeTask: O(l + logn) | O(n * l) | Medium | ð | BST, Sorted List |
2642 | Design Graph With Shortest Path Calculator | C++ Python | ctor: O(|V| + |E|) addEdge: O(1) shortestPath: O(|E| * log|V|) | O(|E|) | Hard | Dijkstra's Algorithm | |
2671 | Frequency Tracker | C++ Python | ctor: O(1) add: O(1) deleteOne: O(1) hasFrequency: O(1) | O(min(n, r)) | Medium | Freq Table | |
3242 | Design Neighbor Sum Service | C++ Python | ctor: O(n^2) adjacentSum: O(1) diagonalSum: O(1) | O(n^2) | Easy | Hash Table |
JS
SQL
PD
# | Title | Solution | Time | Space | Difficulty | Tag | Note |
---|---|---|---|---|---|---|---|
2877 | Create a DataFrame from List | Python3 | O(n) | O(1) | Easy | ||
2878 | Get the Size of a DataFrame | Python3 | O(1) | O(1) | Easy | ||
2879 | Display the First Three Rows | Python3 | O(1) | O(1) | Easy | ||
2880 | Select Data | Python3 | O(n) | O(n) | Easy | ||
2881 | Create a New Column | Python3 | O(n) | O(1) | Easy | ||
2882 | Drop Duplicate Rows | Python3 | O(n) | O(n) | Easy | ||
2883 | Drop Missing Data | Python3 | O(n) | O(1) | Easy | ||
2884 | Modify Columns | Python3 | O(n) | O(1) | Easy | ||
2885 | Rename Columns | Python3 | O(n) | O(1) | Easy | ||
2886 | Change Data Type | Python3 | O(n) | O(1) | Easy | ||
2887 | Fill Missing Data | Python3 | O(n) | O(1) | Easy | ||
2888 | Reshape Data: Concatenate | Python3 | O(n + m) | O(1) | Easy | ||
2889 | Reshape Data: Pivot | Python3 | O(n) | O(1) | Easy | ||
2890 | Reshape Data: Melt | Python3 | O(n) | O(1) | Easy | ||
2891 | Method Chaining | Python3 | O(nlogn) | O(n) | Easy |
Top Related Projects
LeetCode Solutions: A Record of My Problem Solving Journey.( leetcode题解,记录自己的leetcode解题之路。)
Demonstrate all the questions on LeetCode in the form of animation.(用动画的形式呈现解LeetCode题目的思路)
✅ Solutions to LeetCode by Go, 100% test coverage, runtime beats 100% / LeetCode 题解
Solutions to LeetCode problems; updated daily. Subscribe to my YouTube channel for more.
:pencil2: LeetCode solutions in C++ 11 and Python3
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot