title
stringlengths
1
100
titleSlug
stringlengths
3
77
Java
int64
0
1
Python3
int64
1
1
content
stringlengths
28
44.4k
voteCount
int64
0
3.67k
question_content
stringlengths
65
5k
question_hints
stringclasses
970 values
clean commented code
minimum-number-of-people-to-teach
0
1
the question is tricky to understand but easy to implement when you overcome that intial hurdle. \n\n```\nclass Solution:\n def minimumTeachings(self, n: int, languages: List[List[int]], friendships: List[List[int]]) -> int:\n # modify languages to be a set for quick intersection \n languages = {person...
0
You are given `n`​​​​​​ tasks labeled from `0` to `n - 1` represented by a 2D integer array `tasks`, where `tasks[i] = [enqueueTimei, processingTimei]` means that the `i​​​​​​th`​​​​ task will be available to process at `enqueueTimei` and will take `processingTimei` to finish processing. You have a single-threaded CPU...
You can just use brute force and find out for each language the number of users you need to teach Note that a user can appear in multiple friendships but you need to teach that user only once
Solution
minimum-number-of-people-to-teach
1
1
```C++ []\nclass Solution {\nprivate:\n bool intersects(vector<int>& a, vector<int>& b, vector<bool>& vis){\n for(int elem: a){\n vis[elem] = true;\n }\n\n bool intersectionFound = false;\n for(int elem: b){\n if(vis[elem]){\n intersectionFound = true;...
0
On a social network consisting of `m` users and some friendships between users, two users can communicate with each other if they know a common language. You are given an integer `n`, an array `languages`, and an array `friendships` where: * There are `n` languages numbered `1` through `n`, * `languages[i]` is th...
Sort the points by polar angle with the original position. Now only a consecutive collection of points would be visible from any coordinate. We can use two pointers to keep track of visible points for each start point For handling the cyclic condition, it’d be helpful to append the point list to itself after sorting.
Solution
minimum-number-of-people-to-teach
1
1
```C++ []\nclass Solution {\nprivate:\n bool intersects(vector<int>& a, vector<int>& b, vector<bool>& vis){\n for(int elem: a){\n vis[elem] = true;\n }\n\n bool intersectionFound = false;\n for(int elem: b){\n if(vis[elem]){\n intersectionFound = true;...
0
You are given `n`​​​​​​ tasks labeled from `0` to `n - 1` represented by a 2D integer array `tasks`, where `tasks[i] = [enqueueTimei, processingTimei]` means that the `i​​​​​​th`​​​​ task will be available to process at `enqueueTimei` and will take `processingTimei` to finish processing. You have a single-threaded CPU...
You can just use brute force and find out for each language the number of users you need to teach Note that a user can appear in multiple friendships but you need to teach that user only once
Python(Simple Maths)
minimum-number-of-people-to-teach
0
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
0
On a social network consisting of `m` users and some friendships between users, two users can communicate with each other if they know a common language. You are given an integer `n`, an array `languages`, and an array `friendships` where: * There are `n` languages numbered `1` through `n`, * `languages[i]` is th...
Sort the points by polar angle with the original position. Now only a consecutive collection of points would be visible from any coordinate. We can use two pointers to keep track of visible points for each start point For handling the cyclic condition, it’d be helpful to append the point list to itself after sorting.
Python(Simple Maths)
minimum-number-of-people-to-teach
0
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
0
You are given `n`​​​​​​ tasks labeled from `0` to `n - 1` represented by a 2D integer array `tasks`, where `tasks[i] = [enqueueTimei, processingTimei]` means that the `i​​​​​​th`​​​​ task will be available to process at `enqueueTimei` and will take `processingTimei` to finish processing. You have a single-threaded CPU...
You can just use brute force and find out for each language the number of users you need to teach Note that a user can appear in multiple friendships but you need to teach that user only once
[Python] - Commented and Simple Python Solution
minimum-number-of-people-to-teach
0
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nI think this problem is in the harder range of medium problems.\n\nThere are some things you need to consider:\n1) We only deal with users that are disconnected from other users\n2) We need to keep track of the most common known language ...
0
On a social network consisting of `m` users and some friendships between users, two users can communicate with each other if they know a common language. You are given an integer `n`, an array `languages`, and an array `friendships` where: * There are `n` languages numbered `1` through `n`, * `languages[i]` is th...
Sort the points by polar angle with the original position. Now only a consecutive collection of points would be visible from any coordinate. We can use two pointers to keep track of visible points for each start point For handling the cyclic condition, it’d be helpful to append the point list to itself after sorting.
[Python] - Commented and Simple Python Solution
minimum-number-of-people-to-teach
0
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nI think this problem is in the harder range of medium problems.\n\nThere are some things you need to consider:\n1) We only deal with users that are disconnected from other users\n2) We need to keep track of the most common known language ...
0
You are given `n`​​​​​​ tasks labeled from `0` to `n - 1` represented by a 2D integer array `tasks`, where `tasks[i] = [enqueueTimei, processingTimei]` means that the `i​​​​​​th`​​​​ task will be available to process at `enqueueTimei` and will take `processingTimei` to finish processing. You have a single-threaded CPU...
You can just use brute force and find out for each language the number of users you need to teach Note that a user can appear in multiple friendships but you need to teach that user only once
[Python3] Faster than 100% submissions in time and memory, detailed explanation step by step,
minimum-number-of-people-to-teach
0
1
```\nclass Solution:\n def minimumTeachings(self, n: int, languages: List[List[int]], friendships: List[List[int]]) -> int:\n """\n 1. Find out users who need to be taught\n 2. If no user needs to be taught, return 0\n 3. For all users who need to be taught a language, find the most popul...
4
On a social network consisting of `m` users and some friendships between users, two users can communicate with each other if they know a common language. You are given an integer `n`, an array `languages`, and an array `friendships` where: * There are `n` languages numbered `1` through `n`, * `languages[i]` is th...
Sort the points by polar angle with the original position. Now only a consecutive collection of points would be visible from any coordinate. We can use two pointers to keep track of visible points for each start point For handling the cyclic condition, it’d be helpful to append the point list to itself after sorting.
[Python3] Faster than 100% submissions in time and memory, detailed explanation step by step,
minimum-number-of-people-to-teach
0
1
```\nclass Solution:\n def minimumTeachings(self, n: int, languages: List[List[int]], friendships: List[List[int]]) -> int:\n """\n 1. Find out users who need to be taught\n 2. If no user needs to be taught, return 0\n 3. For all users who need to be taught a language, find the most popul...
4
You are given `n`​​​​​​ tasks labeled from `0` to `n - 1` represented by a 2D integer array `tasks`, where `tasks[i] = [enqueueTimei, processingTimei]` means that the `i​​​​​​th`​​​​ task will be available to process at `enqueueTimei` and will take `processingTimei` to finish processing. You have a single-threaded CPU...
You can just use brute force and find out for each language the number of users you need to teach Note that a user can appear in multiple friendships but you need to teach that user only once
Brute force, 94% speed
minimum-number-of-people-to-teach
0
1
Runtime: 1352 ms, faster than 93.94%\nMemory Usage: 27.2 MB, less than 59.60%\n```\nclass Solution:\n def minimumTeachings(self, n: int, languages: List[List[int]], friendships: List[List[int]]) -> int:\n languages = [set(lst) for lst in languages]\n incommunicado_friends = set()\n for friend_1,...
1
On a social network consisting of `m` users and some friendships between users, two users can communicate with each other if they know a common language. You are given an integer `n`, an array `languages`, and an array `friendships` where: * There are `n` languages numbered `1` through `n`, * `languages[i]` is th...
Sort the points by polar angle with the original position. Now only a consecutive collection of points would be visible from any coordinate. We can use two pointers to keep track of visible points for each start point For handling the cyclic condition, it’d be helpful to append the point list to itself after sorting.
Brute force, 94% speed
minimum-number-of-people-to-teach
0
1
Runtime: 1352 ms, faster than 93.94%\nMemory Usage: 27.2 MB, less than 59.60%\n```\nclass Solution:\n def minimumTeachings(self, n: int, languages: List[List[int]], friendships: List[List[int]]) -> int:\n languages = [set(lst) for lst in languages]\n incommunicado_friends = set()\n for friend_1,...
1
You are given `n`​​​​​​ tasks labeled from `0` to `n - 1` represented by a 2D integer array `tasks`, where `tasks[i] = [enqueueTimei, processingTimei]` means that the `i​​​​​​th`​​​​ task will be available to process at `enqueueTimei` and will take `processingTimei` to finish processing. You have a single-threaded CPU...
You can just use brute force and find out for each language the number of users you need to teach Note that a user can appear in multiple friendships but you need to teach that user only once
[Python3] count properly
minimum-number-of-people-to-teach
0
1
**Algo**\nWe collect those who cannot communicate and find the most languages among them. Teach the language to those who haven\'t spoken it yet. \n\n**Implementation**\n```\nclass Solution:\n def minimumTeachings(self, n: int, languages: List[List[int]], friendships: List[List[int]]) -> int:\n m = len(langua...
1
On a social network consisting of `m` users and some friendships between users, two users can communicate with each other if they know a common language. You are given an integer `n`, an array `languages`, and an array `friendships` where: * There are `n` languages numbered `1` through `n`, * `languages[i]` is th...
Sort the points by polar angle with the original position. Now only a consecutive collection of points would be visible from any coordinate. We can use two pointers to keep track of visible points for each start point For handling the cyclic condition, it’d be helpful to append the point list to itself after sorting.
[Python3] count properly
minimum-number-of-people-to-teach
0
1
**Algo**\nWe collect those who cannot communicate and find the most languages among them. Teach the language to those who haven\'t spoken it yet. \n\n**Implementation**\n```\nclass Solution:\n def minimumTeachings(self, n: int, languages: List[List[int]], friendships: List[List[int]]) -> int:\n m = len(langua...
1
You are given `n`​​​​​​ tasks labeled from `0` to `n - 1` represented by a 2D integer array `tasks`, where `tasks[i] = [enqueueTimei, processingTimei]` means that the `i​​​​​​th`​​​​ task will be available to process at `enqueueTimei` and will take `processingTimei` to finish processing. You have a single-threaded CPU...
You can just use brute force and find out for each language the number of users you need to teach Note that a user can appear in multiple friendships but you need to teach that user only once
Explanations XOR and 1st element [Java, Kotlin, Python]
decode-xored-permutation
1
1
I was stuck in this seemingly easy question in [contest 44](https://leetcode.com/contest/biweekly-contest-44). How could the answer be unique?\n\n**XOR properties and tips**\n\nLet\'s note `xor` as xor instead of ^\n**1) For `a xor b = c` , you can write \n`b = c xor a` \nor `a = c xor b`** . \nYou can use 2) and 3) t...
63
There is an integer array `perm` that is a permutation of the first `n` positive integers, where `n` is always **odd**. It was encoded into another integer array `encoded` of length `n - 1`, such that `encoded[i] = perm[i] XOR perm[i + 1]`. For example, if `perm = [1,3,2]`, then `encoded = [2,1]`. Given the `encoded`...
null
Explanations XOR and 1st element [Java, Kotlin, Python]
decode-xored-permutation
1
1
I was stuck in this seemingly easy question in [contest 44](https://leetcode.com/contest/biweekly-contest-44). How could the answer be unique?\n\n**XOR properties and tips**\n\nLet\'s note `xor` as xor instead of ^\n**1) For `a xor b = c` , you can write \n`b = c xor a` \nor `a = c xor b`** . \nYou can use 2) and 3) t...
63
The **XOR sum** of a list is the bitwise `XOR` of all its elements. If the list only contains one element, then its **XOR sum** will be equal to this element. * For example, the **XOR sum** of `[1,2,3,4]` is equal to `1 XOR 2 XOR 3 XOR 4 = 4`, and the **XOR sum** of `[3]` is equal to `3`. You are given two **0-inde...
Compute the XOR of the numbers between 1 and n, and think about how it can be used. Let it be x. Think why n is odd. perm[0] = x XOR encoded[1] XOR encoded[3] XOR encoded[5] ... perm[i] = perm[i-1] XOR encoded[i-1]
Easy Code in Python
decode-xored-permutation
0
1
# Code\n```\nclass Solution:\n def decode(self, encoded: List[int]) -> List[int]:\n \n # The main goal is to just find the first element in perm\n # After that we can just apply, \n # A XOR B = C ==> B = C XOR A\n\n # So for finding that,\n # We are told that perm has 1 to l...
0
There is an integer array `perm` that is a permutation of the first `n` positive integers, where `n` is always **odd**. It was encoded into another integer array `encoded` of length `n - 1`, such that `encoded[i] = perm[i] XOR perm[i + 1]`. For example, if `perm = [1,3,2]`, then `encoded = [2,1]`. Given the `encoded`...
null
Easy Code in Python
decode-xored-permutation
0
1
# Code\n```\nclass Solution:\n def decode(self, encoded: List[int]) -> List[int]:\n \n # The main goal is to just find the first element in perm\n # After that we can just apply, \n # A XOR B = C ==> B = C XOR A\n\n # So for finding that,\n # We are told that perm has 1 to l...
0
The **XOR sum** of a list is the bitwise `XOR` of all its elements. If the list only contains one element, then its **XOR sum** will be equal to this element. * For example, the **XOR sum** of `[1,2,3,4]` is equal to `1 XOR 2 XOR 3 XOR 4 = 4`, and the **XOR sum** of `[3]` is equal to `3`. You are given two **0-inde...
Compute the XOR of the numbers between 1 and n, and think about how it can be used. Let it be x. Think why n is odd. perm[0] = x XOR encoded[1] XOR encoded[3] XOR encoded[5] ... perm[i] = perm[i-1] XOR encoded[i-1]
Thorough Explanation of Both Usual and Optimized Solution That Gets First Number in O(1)
decode-xored-permutation
0
1
# Disclaimer!\n\nThis is Part of a series on solving LeetCode problems and understanding rounded solutions with ChatGPT to master DS&A as a self-taught programmer. Check other solutions in here for something more sophisticated and short. Here I do explain the solutions including the optimal one but rather go in depths ...
0
There is an integer array `perm` that is a permutation of the first `n` positive integers, where `n` is always **odd**. It was encoded into another integer array `encoded` of length `n - 1`, such that `encoded[i] = perm[i] XOR perm[i + 1]`. For example, if `perm = [1,3,2]`, then `encoded = [2,1]`. Given the `encoded`...
null
Thorough Explanation of Both Usual and Optimized Solution That Gets First Number in O(1)
decode-xored-permutation
0
1
# Disclaimer!\n\nThis is Part of a series on solving LeetCode problems and understanding rounded solutions with ChatGPT to master DS&A as a self-taught programmer. Check other solutions in here for something more sophisticated and short. Here I do explain the solutions including the optimal one but rather go in depths ...
0
The **XOR sum** of a list is the bitwise `XOR` of all its elements. If the list only contains one element, then its **XOR sum** will be equal to this element. * For example, the **XOR sum** of `[1,2,3,4]` is equal to `1 XOR 2 XOR 3 XOR 4 = 4`, and the **XOR sum** of `[3]` is equal to `3`. You are given two **0-inde...
Compute the XOR of the numbers between 1 and n, and think about how it can be used. Let it be x. Think why n is odd. perm[0] = x XOR encoded[1] XOR encoded[3] XOR encoded[5] ... perm[i] = perm[i-1] XOR encoded[i-1]
Python solution
decode-xored-permutation
0
1
# Intuition\nUsing xor, we can calculate the numbers we are missing.\n\n# Approach\nLet\'s say that `[a, b, c, d, e]` are a permutation of `[1..n+1]`.\nAlso, let\'s call `perm = [a, b, c, d, e].`\n\nThe encoded value is `[a^b, b^c, c^d, d^e]`\n\nWe need to calculate a number x, so that:\n`x = a ^ b ^ c ^ d ^ e`\...
0
There is an integer array `perm` that is a permutation of the first `n` positive integers, where `n` is always **odd**. It was encoded into another integer array `encoded` of length `n - 1`, such that `encoded[i] = perm[i] XOR perm[i + 1]`. For example, if `perm = [1,3,2]`, then `encoded = [2,1]`. Given the `encoded`...
null
Python solution
decode-xored-permutation
0
1
# Intuition\nUsing xor, we can calculate the numbers we are missing.\n\n# Approach\nLet\'s say that `[a, b, c, d, e]` are a permutation of `[1..n+1]`.\nAlso, let\'s call `perm = [a, b, c, d, e].`\n\nThe encoded value is `[a^b, b^c, c^d, d^e]`\n\nWe need to calculate a number x, so that:\n`x = a ^ b ^ c ^ d ^ e`\...
0
The **XOR sum** of a list is the bitwise `XOR` of all its elements. If the list only contains one element, then its **XOR sum** will be equal to this element. * For example, the **XOR sum** of `[1,2,3,4]` is equal to `1 XOR 2 XOR 3 XOR 4 = 4`, and the **XOR sum** of `[3]` is equal to `3`. You are given two **0-inde...
Compute the XOR of the numbers between 1 and n, and think about how it can be used. Let it be x. Think why n is odd. perm[0] = x XOR encoded[1] XOR encoded[3] XOR encoded[5] ... perm[i] = perm[i-1] XOR encoded[i-1]
[Python3] Mathematical approach
decode-xored-permutation
0
1
# Intuition\nWe know the numbers ``1``, ``2``,... ``n`` were use to form ``perm``. \nAlso we know that ``n`` is odd. \n\n``encoded[i]`` = ``perm[i]`` xor ``perm[i+1]``\n\nThus:\n\n``xor_even`` = ``encoded[0]`` xor ``encoded[2]`` xor ... xor ``encoded[n-3]`` = ``perm[0]`` xor ``perm[1]`` xor ... xor ``perm[n-2]``\n\nWe ...
0
There is an integer array `perm` that is a permutation of the first `n` positive integers, where `n` is always **odd**. It was encoded into another integer array `encoded` of length `n - 1`, such that `encoded[i] = perm[i] XOR perm[i + 1]`. For example, if `perm = [1,3,2]`, then `encoded = [2,1]`. Given the `encoded`...
null
[Python3] Mathematical approach
decode-xored-permutation
0
1
# Intuition\nWe know the numbers ``1``, ``2``,... ``n`` were use to form ``perm``. \nAlso we know that ``n`` is odd. \n\n``encoded[i]`` = ``perm[i]`` xor ``perm[i+1]``\n\nThus:\n\n``xor_even`` = ``encoded[0]`` xor ``encoded[2]`` xor ... xor ``encoded[n-3]`` = ``perm[0]`` xor ``perm[1]`` xor ... xor ``perm[n-2]``\n\nWe ...
0
The **XOR sum** of a list is the bitwise `XOR` of all its elements. If the list only contains one element, then its **XOR sum** will be equal to this element. * For example, the **XOR sum** of `[1,2,3,4]` is equal to `1 XOR 2 XOR 3 XOR 4 = 4`, and the **XOR sum** of `[3]` is equal to `3`. You are given two **0-inde...
Compute the XOR of the numbers between 1 and n, and think about how it can be used. Let it be x. Think why n is odd. perm[0] = x XOR encoded[1] XOR encoded[3] XOR encoded[5] ... perm[i] = perm[i-1] XOR encoded[i-1]
Solution
decode-xored-permutation
1
1
```C++ []\nclass Solution {\npublic:\n vector<int> decode(vector<int>& encoded) {\n int n = encoded.size()+1;\n \n vector<int> ans(n) ;\n int first = 0;\n\n for(int i = 1 ; i<= n ; i++)\n first ^= i;\n\n for(int i = 0 ; i<n-1 ; i+=2)\n first ^= encoded[i+1];...
0
There is an integer array `perm` that is a permutation of the first `n` positive integers, where `n` is always **odd**. It was encoded into another integer array `encoded` of length `n - 1`, such that `encoded[i] = perm[i] XOR perm[i + 1]`. For example, if `perm = [1,3,2]`, then `encoded = [2,1]`. Given the `encoded`...
null
Solution
decode-xored-permutation
1
1
```C++ []\nclass Solution {\npublic:\n vector<int> decode(vector<int>& encoded) {\n int n = encoded.size()+1;\n \n vector<int> ans(n) ;\n int first = 0;\n\n for(int i = 1 ; i<= n ; i++)\n first ^= i;\n\n for(int i = 0 ; i<n-1 ; i+=2)\n first ^= encoded[i+1];...
0
The **XOR sum** of a list is the bitwise `XOR` of all its elements. If the list only contains one element, then its **XOR sum** will be equal to this element. * For example, the **XOR sum** of `[1,2,3,4]` is equal to `1 XOR 2 XOR 3 XOR 4 = 4`, and the **XOR sum** of `[3]` is equal to `3`. You are given two **0-inde...
Compute the XOR of the numbers between 1 and n, and think about how it can be used. Let it be x. Think why n is odd. perm[0] = x XOR encoded[1] XOR encoded[3] XOR encoded[5] ... perm[i] = perm[i-1] XOR encoded[i-1]
Prime Factors With Memo | Commented and Explained | Better Version Might Store Factor Results
count-ways-to-make-array-with-product
0
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe primarily are dealing with prime factors in this case alongside numerical combinations. As such, the math.comb functionality and a list of prime factors in range is most usable. Since we\'re limited to 10^4, we need only factors up to ...
0
You are given a 2D integer array, `queries`. For each `queries[i]`, where `queries[i] = [ni, ki]`, find the number of different ways you can place positive integers into an array of size `ni` such that the product of the integers is `ki`. As the number of ways may be too large, the answer to the `ith` query is the numb...
null
Prime Factors With Memo | Commented and Explained | Better Version Might Store Factor Results
count-ways-to-make-array-with-product
0
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe primarily are dealing with prime factors in this case alongside numerical combinations. As such, the math.comb functionality and a list of prime factors in range is most usable. Since we\'re limited to 10^4, we need only factors up to ...
0
Given the `head` of a linked list, find all the values that appear **more than once** in the list and delete the nodes that have any of those values. Return _the linked list after the deletions._ **Example 1:** **Input:** head = \[1,2,3,2\] **Output:** \[1,3\] **Explanation:** 2 appears twice in the linked list, so ...
Prime-factorize ki and count how many ways you can distribute the primes among the ni positions. After prime factorizing ki, suppose there are x amount of prime factor. There are (x + n - 1) choose (n - 1) ways to distribute the x prime factors into k positions, allowing repetitions.
Using comb in python for combinations with explanation
count-ways-to-make-array-with-product
0
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nusing permutations and combinations using prime factorization for example 90 = [[2,1],[3,2],[5,1]] which means that 90 = 2^1 * 3^2 * 5^1. Now for each of these 2,3,3,5 we need to assign one value 0,1,...n-1 (n is length of a...
0
You are given a 2D integer array, `queries`. For each `queries[i]`, where `queries[i] = [ni, ki]`, find the number of different ways you can place positive integers into an array of size `ni` such that the product of the integers is `ki`. As the number of ways may be too large, the answer to the `ith` query is the numb...
null
Using comb in python for combinations with explanation
count-ways-to-make-array-with-product
0
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nusing permutations and combinations using prime factorization for example 90 = [[2,1],[3,2],[5,1]] which means that 90 = 2^1 * 3^2 * 5^1. Now for each of these 2,3,3,5 we need to assign one value 0,1,...n-1 (n is length of a...
0
Given the `head` of a linked list, find all the values that appear **more than once** in the list and delete the nodes that have any of those values. Return _the linked list after the deletions._ **Example 1:** **Input:** head = \[1,2,3,2\] **Output:** \[1,3\] **Explanation:** 2 appears twice in the linked list, so ...
Prime-factorize ki and count how many ways you can distribute the primes among the ni positions. After prime factorizing ki, suppose there are x amount of prime factor. There are (x + n - 1) choose (n - 1) ways to distribute the x prime factors into k positions, allowing repetitions.
Solution
count-ways-to-make-array-with-product
1
1
```C++ []\n\n int comb[10013][14] = { 1 }, mod = 1000000007;\nint primes[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, \n 53, 59, 61, 67, 71, 73, 79, 83, 89, 97};\nclass Solution {\npublic:\nvector<int> waysToFillArray(vector<vector<int>>& qs) {\n if (comb[1][1] == 0)\n fo...
0
You are given a 2D integer array, `queries`. For each `queries[i]`, where `queries[i] = [ni, ki]`, find the number of different ways you can place positive integers into an array of size `ni` such that the product of the integers is `ki`. As the number of ways may be too large, the answer to the `ith` query is the numb...
null
Solution
count-ways-to-make-array-with-product
1
1
```C++ []\n\n int comb[10013][14] = { 1 }, mod = 1000000007;\nint primes[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, \n 53, 59, 61, 67, 71, 73, 79, 83, 89, 97};\nclass Solution {\npublic:\nvector<int> waysToFillArray(vector<vector<int>>& qs) {\n if (comb[1][1] == 0)\n fo...
0
Given the `head` of a linked list, find all the values that appear **more than once** in the list and delete the nodes that have any of those values. Return _the linked list after the deletions._ **Example 1:** **Input:** head = \[1,2,3,2\] **Output:** \[1,3\] **Explanation:** 2 appears twice in the linked list, so ...
Prime-factorize ki and count how many ways you can distribute the primes among the ni positions. After prime factorizing ki, suppose there are x amount of prime factor. There are (x + n - 1) choose (n - 1) ways to distribute the x prime factors into k positions, allowing repetitions.
No Maths Just Recursion DP we can come up with in interviews -> WA
count-ways-to-make-array-with-product
0
1
Unable to figure the bug\nGetting Wrong Answer for (73,660)\n\nSolution is just a DP where we take one element\n\ne.g. 6\nwe find a factor e.g. 2\n\nThen subproblem == array of n-1 elements and 6/2 (remaining product)\n\n\n```\nclass Solution:\n def waysToFillArray(self, queries: List[List[int]]) -> List[int]:\n ...
1
You are given a 2D integer array, `queries`. For each `queries[i]`, where `queries[i] = [ni, ki]`, find the number of different ways you can place positive integers into an array of size `ni` such that the product of the integers is `ki`. As the number of ways may be too large, the answer to the `ith` query is the numb...
null
No Maths Just Recursion DP we can come up with in interviews -> WA
count-ways-to-make-array-with-product
0
1
Unable to figure the bug\nGetting Wrong Answer for (73,660)\n\nSolution is just a DP where we take one element\n\ne.g. 6\nwe find a factor e.g. 2\n\nThen subproblem == array of n-1 elements and 6/2 (remaining product)\n\n\n```\nclass Solution:\n def waysToFillArray(self, queries: List[List[int]]) -> List[int]:\n ...
1
Given the `head` of a linked list, find all the values that appear **more than once** in the list and delete the nodes that have any of those values. Return _the linked list after the deletions._ **Example 1:** **Input:** head = \[1,2,3,2\] **Output:** \[1,3\] **Explanation:** 2 appears twice in the linked list, so ...
Prime-factorize ki and count how many ways you can distribute the primes among the ni positions. After prime factorizing ki, suppose there are x amount of prime factor. There are (x + n - 1) choose (n - 1) ways to distribute the x prime factors into k positions, allowing repetitions.
[Python3] via sieve & comb
count-ways-to-make-array-with-product
0
1
**Algo**\nFor any given query, compute prime factorization. For each factor with multiplicity, distribute them into `n` buckets via multiset. \n\n**Implementation**\n```\nclass Solution:\n def waysToFillArray(self, queries: List[List[int]]) -> List[int]:\n spf = list(range(10001)) # spf = smallest prime facto...
0
You are given a 2D integer array, `queries`. For each `queries[i]`, where `queries[i] = [ni, ki]`, find the number of different ways you can place positive integers into an array of size `ni` such that the product of the integers is `ki`. As the number of ways may be too large, the answer to the `ith` query is the numb...
null
[Python3] via sieve & comb
count-ways-to-make-array-with-product
0
1
**Algo**\nFor any given query, compute prime factorization. For each factor with multiplicity, distribute them into `n` buckets via multiset. \n\n**Implementation**\n```\nclass Solution:\n def waysToFillArray(self, queries: List[List[int]]) -> List[int]:\n spf = list(range(10001)) # spf = smallest prime facto...
0
Given the `head` of a linked list, find all the values that appear **more than once** in the list and delete the nodes that have any of those values. Return _the linked list after the deletions._ **Example 1:** **Input:** head = \[1,2,3,2\] **Output:** \[1,3\] **Explanation:** 2 appears twice in the linked list, so ...
Prime-factorize ki and count how many ways you can distribute the primes among the ni positions. After prime factorizing ki, suppose there are x amount of prime factor. There are (x + n - 1) choose (n - 1) ways to distribute the x prime factors into k positions, allowing repetitions.
[Python3] if-elif
latest-time-by-replacing-hidden-digits
0
1
**Algo**\nReplace `?` based on its location and value. \n\n**Implementation**\n```\nclass Solution:\n def maximumTime(self, time: str) -> str:\n time = list(time)\n for i in range(len(time)): \n if time[i] == "?": \n if i == 0: time[i] = "2" if time[i+1] in "?0123" else "1"\n ...
28
You are given a string `time` in the form of `hh:mm`, where some of the digits in the string are hidden (represented by `?`). The valid times are those inclusively between `00:00` and `23:59`. Return _the latest valid time you can get from_ `time` _by replacing the hidden_ _digits_. **Example 1:** **Input:** time =...
Convert infix expression to postfix expression. Build an expression tree from the postfix expression.
[Python3] if-elif
latest-time-by-replacing-hidden-digits
0
1
**Algo**\nReplace `?` based on its location and value. \n\n**Implementation**\n```\nclass Solution:\n def maximumTime(self, time: str) -> str:\n time = list(time)\n for i in range(len(time)): \n if time[i] == "?": \n if i == 0: time[i] = "2" if time[i+1] in "?0123" else "1"\n ...
28
Given an array of strings `words`, find the **longest** string in `words` such that **every prefix** of it is also in `words`. * For example, let `words = [ "a ", "app ", "ap "]`. The string `"app "` has prefixes `"ap "` and `"a "`, all of which are in `words`. Return _the string described above. If there is more t...
Trying out all possible solutions from biggest to smallest would fit in the time limit. To check if the solution is okay, you need to find out if it's valid and matches every character
Very fast (90.58% 🚀) and easy solution!!!
latest-time-by-replacing-hidden-digits
0
1
class Solution:\n def maximumTime(self, time: str) -> str:\n time_l = list(time)\n new_str = \'\'\n\n if time[0] == \'?\' and time[1] == \'?\':\n time_l[0] = time[0].replace(time[0], \'2\')\n time_l[1] = time[1].replace(time[1], \'3\')\n if time[3] == \'?\' and time[...
2
You are given a string `time` in the form of `hh:mm`, where some of the digits in the string are hidden (represented by `?`). The valid times are those inclusively between `00:00` and `23:59`. Return _the latest valid time you can get from_ `time` _by replacing the hidden_ _digits_. **Example 1:** **Input:** time =...
Convert infix expression to postfix expression. Build an expression tree from the postfix expression.
Very fast (90.58% 🚀) and easy solution!!!
latest-time-by-replacing-hidden-digits
0
1
class Solution:\n def maximumTime(self, time: str) -> str:\n time_l = list(time)\n new_str = \'\'\n\n if time[0] == \'?\' and time[1] == \'?\':\n time_l[0] = time[0].replace(time[0], \'2\')\n time_l[1] = time[1].replace(time[1], \'3\')\n if time[3] == \'?\' and time[...
2
Given an array of strings `words`, find the **longest** string in `words` such that **every prefix** of it is also in `words`. * For example, let `words = [ "a ", "app ", "ap "]`. The string `"app "` has prefixes `"ap "` and `"a "`, all of which are in `words`. Return _the string described above. If there is more t...
Trying out all possible solutions from biggest to smallest would fit in the time limit. To check if the solution is okay, you need to find out if it's valid and matches every character
Easiest & Simplest Python3 Solution with if conditions | 100% Faster | Easy to Understand
latest-time-by-replacing-hidden-digits
0
1
```\nclass Solution:\n def maximumTime(self, time: str) -> str:\n s=list(time)\n for i in range(len(s)):\n if s[i]==\'?\':\n if i==0:\n if s[i+1] in [\'0\',\'1\',\'2\',\'3\',\'?\']:\n s[i]=\'2\'\n else:\n ...
5
You are given a string `time` in the form of `hh:mm`, where some of the digits in the string are hidden (represented by `?`). The valid times are those inclusively between `00:00` and `23:59`. Return _the latest valid time you can get from_ `time` _by replacing the hidden_ _digits_. **Example 1:** **Input:** time =...
Convert infix expression to postfix expression. Build an expression tree from the postfix expression.
Easiest & Simplest Python3 Solution with if conditions | 100% Faster | Easy to Understand
latest-time-by-replacing-hidden-digits
0
1
```\nclass Solution:\n def maximumTime(self, time: str) -> str:\n s=list(time)\n for i in range(len(s)):\n if s[i]==\'?\':\n if i==0:\n if s[i+1] in [\'0\',\'1\',\'2\',\'3\',\'?\']:\n s[i]=\'2\'\n else:\n ...
5
Given an array of strings `words`, find the **longest** string in `words` such that **every prefix** of it is also in `words`. * For example, let `words = [ "a ", "app ", "ap "]`. The string `"app "` has prefixes `"ap "` and `"a "`, all of which are in `words`. Return _the string described above. If there is more t...
Trying out all possible solutions from biggest to smallest would fit in the time limit. To check if the solution is okay, you need to find out if it's valid and matches every character
Beats 97.98%of users with Python3
latest-time-by-replacing-hidden-digits
0
1
# Code\n```\nclass Solution:\n def maximumTime(self, time: str) -> str:\n m1, m2 = time[3:]\n h1, h2 = time[:2]\n \n match (h1, h2):\n case ("?", "?"):\n h1, h2 = "2", "3"\n case ("?", _):\n if h2 < "4":\n h1 = "2"\n ...
0
You are given a string `time` in the form of `hh:mm`, where some of the digits in the string are hidden (represented by `?`). The valid times are those inclusively between `00:00` and `23:59`. Return _the latest valid time you can get from_ `time` _by replacing the hidden_ _digits_. **Example 1:** **Input:** time =...
Convert infix expression to postfix expression. Build an expression tree from the postfix expression.
Beats 97.98%of users with Python3
latest-time-by-replacing-hidden-digits
0
1
# Code\n```\nclass Solution:\n def maximumTime(self, time: str) -> str:\n m1, m2 = time[3:]\n h1, h2 = time[:2]\n \n match (h1, h2):\n case ("?", "?"):\n h1, h2 = "2", "3"\n case ("?", _):\n if h2 < "4":\n h1 = "2"\n ...
0
Given an array of strings `words`, find the **longest** string in `words` such that **every prefix** of it is also in `words`. * For example, let `words = [ "a ", "app ", "ap "]`. The string `"app "` has prefixes `"ap "` and `"a "`, all of which are in `words`. Return _the string described above. If there is more t...
Trying out all possible solutions from biggest to smallest would fit in the time limit. To check if the solution is okay, you need to find out if it's valid and matches every character
Python solution
latest-time-by-replacing-hidden-digits
0
1
```\nclass Solution:\n def maximumTime(self, time: str) -> str:\n A, B = time[:2]\n C, D = time[3:]\n\n if A == "?" and B == "?":\n A, B = "2", "3"\n elif A != "?" and A in ["0", "1"] and B == "?":\n B = "9"\n elif A != "?" and B == "?":\n B = "3"\n...
0
You are given a string `time` in the form of `hh:mm`, where some of the digits in the string are hidden (represented by `?`). The valid times are those inclusively between `00:00` and `23:59`. Return _the latest valid time you can get from_ `time` _by replacing the hidden_ _digits_. **Example 1:** **Input:** time =...
Convert infix expression to postfix expression. Build an expression tree from the postfix expression.
Python solution
latest-time-by-replacing-hidden-digits
0
1
```\nclass Solution:\n def maximumTime(self, time: str) -> str:\n A, B = time[:2]\n C, D = time[3:]\n\n if A == "?" and B == "?":\n A, B = "2", "3"\n elif A != "?" and A in ["0", "1"] and B == "?":\n B = "9"\n elif A != "?" and B == "?":\n B = "3"\n...
0
Given an array of strings `words`, find the **longest** string in `words` such that **every prefix** of it is also in `words`. * For example, let `words = [ "a ", "app ", "ap "]`. The string `"app "` has prefixes `"ap "` and `"a "`, all of which are in `words`. Return _the string described above. If there is more t...
Trying out all possible solutions from biggest to smallest would fit in the time limit. To check if the solution is okay, you need to find out if it's valid and matches every character
Python Solution - Easy To Read!! If Statements!!
latest-time-by-replacing-hidden-digits
0
1
\n# Code\n```\nclass Solution:\n def maximumTime(self, time: str) -> str:\n\n if not "?" in time:\n return time\n\n hours, minutes = time.split(":")\n \n if "?" in hours:\n \n if hours == "??": \n hours = "23"\n else:\n ...
0
You are given a string `time` in the form of `hh:mm`, where some of the digits in the string are hidden (represented by `?`). The valid times are those inclusively between `00:00` and `23:59`. Return _the latest valid time you can get from_ `time` _by replacing the hidden_ _digits_. **Example 1:** **Input:** time =...
Convert infix expression to postfix expression. Build an expression tree from the postfix expression.
Python Solution - Easy To Read!! If Statements!!
latest-time-by-replacing-hidden-digits
0
1
\n# Code\n```\nclass Solution:\n def maximumTime(self, time: str) -> str:\n\n if not "?" in time:\n return time\n\n hours, minutes = time.split(":")\n \n if "?" in hours:\n \n if hours == "??": \n hours = "23"\n else:\n ...
0
Given an array of strings `words`, find the **longest** string in `words` such that **every prefix** of it is also in `words`. * For example, let `words = [ "a ", "app ", "ap "]`. The string `"app "` has prefixes `"ap "` and `"a "`, all of which are in `words`. Return _the string described above. If there is more t...
Trying out all possible solutions from biggest to smallest would fit in the time limit. To check if the solution is okay, you need to find out if it's valid and matches every character
Solve with fewer if statements | 24ms (99%)
latest-time-by-replacing-hidden-digits
0
1
![22.png](https://assets.leetcode.com/users/images/61acedf1-f882-4384-9197-37b00adb432c_1699125995.2654161.png)\n\n\n# Intuition\nTo make the code less cumbersome\n\n# Approach\nTake advantage of the bool value in math formula, where *True* equals 1 and *False* equals 0.\n\n# Complexity\n- Time complexity:\n\n- Space c...
0
You are given a string `time` in the form of `hh:mm`, where some of the digits in the string are hidden (represented by `?`). The valid times are those inclusively between `00:00` and `23:59`. Return _the latest valid time you can get from_ `time` _by replacing the hidden_ _digits_. **Example 1:** **Input:** time =...
Convert infix expression to postfix expression. Build an expression tree from the postfix expression.
Solve with fewer if statements | 24ms (99%)
latest-time-by-replacing-hidden-digits
0
1
![22.png](https://assets.leetcode.com/users/images/61acedf1-f882-4384-9197-37b00adb432c_1699125995.2654161.png)\n\n\n# Intuition\nTo make the code less cumbersome\n\n# Approach\nTake advantage of the bool value in math formula, where *True* equals 1 and *False* equals 0.\n\n# Complexity\n- Time complexity:\n\n- Space c...
0
Given an array of strings `words`, find the **longest** string in `words` such that **every prefix** of it is also in `words`. * For example, let `words = [ "a ", "app ", "ap "]`. The string `"app "` has prefixes `"ap "` and `"a "`, all of which are in `words`. Return _the string described above. If there is more t...
Trying out all possible solutions from biggest to smallest would fit in the time limit. To check if the solution is okay, you need to find out if it's valid and matches every character
Frequency Transform | Commented and Explained
change-minimum-characters-to-satisfy-one-of-three-conditions
0
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThis question is again really asking about how well you can do frequency transformations. In this case, we are asked to find the minimum cost to satisfy one of three conditions. However, all of the conditions come down to a comparison cos...
0
You are given two strings `a` and `b` that consist of lowercase letters. In one operation, you can change any character in `a` or `b` to **any lowercase letter**. Your goal is to satisfy **one** of the following three conditions: * **Every** letter in `a` is **strictly less** than **every** letter in `b` in the alp...
The depth of any character in the VPS is the ( number of left brackets before it ) - ( number of right brackets before it )
Frequency Transform | Commented and Explained
change-minimum-characters-to-satisfy-one-of-three-conditions
0
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThis question is again really asking about how well you can do frequency transformations. In this case, we are asked to find the minimum cost to satisfy one of three conditions. However, all of the conditions come down to a comparison cos...
0
A **sentence** is a list of words that are separated by a single space with no leading or trailing spaces. Each word consists of lowercase and uppercase English letters. A sentence can be **shuffled** by appending the **1-indexed word position** to each word then rearranging the words in the sentence. * For example...
Iterate on each letter in the alphabet, and check the smallest number of operations needed to make it one of the following: the largest letter in a and smaller than the smallest one in b, vice versa, or let a and b consist only of this letter. For the first 2 conditions, take care that you can only change characters to...
✅O(N) || counting
change-minimum-characters-to-satisfy-one-of-three-conditions
0
1
# Code\n```\nclass Solution:\n def minCharacters(self, a: str, b: str) -> int:\n a1=[0 for i in range(26)]\n a2=[0 for i in range(26)]\n for i in a:a1[ord(i)-ord(\'a\')]+=1\n for i in b:a2[ord(i)-ord(\'a\')]+=1\n ans=len(a)+len(b)\n maxa=0\n maxb=0\n n=len(a)\n...
0
You are given two strings `a` and `b` that consist of lowercase letters. In one operation, you can change any character in `a` or `b` to **any lowercase letter**. Your goal is to satisfy **one** of the following three conditions: * **Every** letter in `a` is **strictly less** than **every** letter in `b` in the alp...
The depth of any character in the VPS is the ( number of left brackets before it ) - ( number of right brackets before it )
✅O(N) || counting
change-minimum-characters-to-satisfy-one-of-three-conditions
0
1
# Code\n```\nclass Solution:\n def minCharacters(self, a: str, b: str) -> int:\n a1=[0 for i in range(26)]\n a2=[0 for i in range(26)]\n for i in a:a1[ord(i)-ord(\'a\')]+=1\n for i in b:a2[ord(i)-ord(\'a\')]+=1\n ans=len(a)+len(b)\n maxa=0\n maxb=0\n n=len(a)\n...
0
A **sentence** is a list of words that are separated by a single space with no leading or trailing spaces. Each word consists of lowercase and uppercase English letters. A sentence can be **shuffled** by appending the **1-indexed word position** to each word then rearranging the words in the sentence. * For example...
Iterate on each letter in the alphabet, and check the smallest number of operations needed to make it one of the following: the largest letter in a and smaller than the smallest one in b, vice versa, or let a and b consist only of this letter. For the first 2 conditions, take care that you can only change characters to...
Python solution beats 78.41%
change-minimum-characters-to-satisfy-one-of-three-conditions
0
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(1)\n<!-- Add your space complexity here, e.g. $$O...
0
You are given two strings `a` and `b` that consist of lowercase letters. In one operation, you can change any character in `a` or `b` to **any lowercase letter**. Your goal is to satisfy **one** of the following three conditions: * **Every** letter in `a` is **strictly less** than **every** letter in `b` in the alp...
The depth of any character in the VPS is the ( number of left brackets before it ) - ( number of right brackets before it )
Python solution beats 78.41%
change-minimum-characters-to-satisfy-one-of-three-conditions
0
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(1)\n<!-- Add your space complexity here, e.g. $$O...
0
A **sentence** is a list of words that are separated by a single space with no leading or trailing spaces. Each word consists of lowercase and uppercase English letters. A sentence can be **shuffled** by appending the **1-indexed word position** to each word then rearranging the words in the sentence. * For example...
Iterate on each letter in the alphabet, and check the smallest number of operations needed to make it one of the following: the largest letter in a and smaller than the smallest one in b, vice versa, or let a and b consist only of this letter. For the first 2 conditions, take care that you can only change characters to...
Python3 O(N) Solution use two counter of chars
change-minimum-characters-to-satisfy-one-of-three-conditions
0
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
0
You are given two strings `a` and `b` that consist of lowercase letters. In one operation, you can change any character in `a` or `b` to **any lowercase letter**. Your goal is to satisfy **one** of the following three conditions: * **Every** letter in `a` is **strictly less** than **every** letter in `b` in the alp...
The depth of any character in the VPS is the ( number of left brackets before it ) - ( number of right brackets before it )
Python3 O(N) Solution use two counter of chars
change-minimum-characters-to-satisfy-one-of-three-conditions
0
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
0
A **sentence** is a list of words that are separated by a single space with no leading or trailing spaces. Each word consists of lowercase and uppercase English letters. A sentence can be **shuffled** by appending the **1-indexed word position** to each word then rearranging the words in the sentence. * For example...
Iterate on each letter in the alphabet, and check the smallest number of operations needed to make it one of the following: the largest letter in a and smaller than the smallest one in b, vice versa, or let a and b consist only of this letter. For the first 2 conditions, take care that you can only change characters to...
Simple Solution with HashMap
change-minimum-characters-to-satisfy-one-of-three-conditions
0
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(n)\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$...
0
You are given two strings `a` and `b` that consist of lowercase letters. In one operation, you can change any character in `a` or `b` to **any lowercase letter**. Your goal is to satisfy **one** of the following three conditions: * **Every** letter in `a` is **strictly less** than **every** letter in `b` in the alp...
The depth of any character in the VPS is the ( number of left brackets before it ) - ( number of right brackets before it )
Simple Solution with HashMap
change-minimum-characters-to-satisfy-one-of-three-conditions
0
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(n)\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$...
0
A **sentence** is a list of words that are separated by a single space with no leading or trailing spaces. Each word consists of lowercase and uppercase English letters. A sentence can be **shuffled** by appending the **1-indexed word position** to each word then rearranging the words in the sentence. * For example...
Iterate on each letter in the alphabet, and check the smallest number of operations needed to make it one of the following: the largest letter in a and smaller than the smallest one in b, vice versa, or let a and b consist only of this letter. For the first 2 conditions, take care that you can only change characters to...
Alternative Binary Search approach
change-minimum-characters-to-satisfy-one-of-three-conditions
0
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
0
You are given two strings `a` and `b` that consist of lowercase letters. In one operation, you can change any character in `a` or `b` to **any lowercase letter**. Your goal is to satisfy **one** of the following three conditions: * **Every** letter in `a` is **strictly less** than **every** letter in `b` in the alp...
The depth of any character in the VPS is the ( number of left brackets before it ) - ( number of right brackets before it )
Alternative Binary Search approach
change-minimum-characters-to-satisfy-one-of-three-conditions
0
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
0
A **sentence** is a list of words that are separated by a single space with no leading or trailing spaces. Each word consists of lowercase and uppercase English letters. A sentence can be **shuffled** by appending the **1-indexed word position** to each word then rearranging the words in the sentence. * For example...
Iterate on each letter in the alphabet, and check the smallest number of operations needed to make it one of the following: the largest letter in a and smaller than the smallest one in b, vice versa, or let a and b consist only of this letter. For the first 2 conditions, take care that you can only change characters to...
Python | PrefixSum | O(n)
change-minimum-characters-to-satisfy-one-of-three-conditions
0
1
# Code\n```\nfrom collections import Counter\nclass Solution:\n def minCharacters(self, a: str, b: str) -> int:\n m, n = len(a), len(b)\n countera = Counter(a)\n counterb = Counter(b)\n prefixa = [0]\n prefixb = [0]\n for c in \'abcdefghijklmnopqrstuvwxyz\':\n pre...
0
You are given two strings `a` and `b` that consist of lowercase letters. In one operation, you can change any character in `a` or `b` to **any lowercase letter**. Your goal is to satisfy **one** of the following three conditions: * **Every** letter in `a` is **strictly less** than **every** letter in `b` in the alp...
The depth of any character in the VPS is the ( number of left brackets before it ) - ( number of right brackets before it )
Python | PrefixSum | O(n)
change-minimum-characters-to-satisfy-one-of-three-conditions
0
1
# Code\n```\nfrom collections import Counter\nclass Solution:\n def minCharacters(self, a: str, b: str) -> int:\n m, n = len(a), len(b)\n countera = Counter(a)\n counterb = Counter(b)\n prefixa = [0]\n prefixb = [0]\n for c in \'abcdefghijklmnopqrstuvwxyz\':\n pre...
0
A **sentence** is a list of words that are separated by a single space with no leading or trailing spaces. Each word consists of lowercase and uppercase English letters. A sentence can be **shuffled** by appending the **1-indexed word position** to each word then rearranging the words in the sentence. * For example...
Iterate on each letter in the alphabet, and check the smallest number of operations needed to make it one of the following: the largest letter in a and smaller than the smallest one in b, vice versa, or let a and b consist only of this letter. For the first 2 conditions, take care that you can only change characters to...
[Python] with explanation
change-minimum-characters-to-satisfy-one-of-three-conditions
0
1
Key idea here for satisfying condition 1 and 2 is to try out all the lowercase letters.\nFor example, let\'s choose "b" as the boundary letter. Then cost of converting1st word to consists of letters less than and equal to "b" would be\n`cost_a = len(a) - counter_a["b"]`\nNote counter here is acting like a prefix sum of...
3
You are given two strings `a` and `b` that consist of lowercase letters. In one operation, you can change any character in `a` or `b` to **any lowercase letter**. Your goal is to satisfy **one** of the following three conditions: * **Every** letter in `a` is **strictly less** than **every** letter in `b` in the alp...
The depth of any character in the VPS is the ( number of left brackets before it ) - ( number of right brackets before it )
[Python] with explanation
change-minimum-characters-to-satisfy-one-of-three-conditions
0
1
Key idea here for satisfying condition 1 and 2 is to try out all the lowercase letters.\nFor example, let\'s choose "b" as the boundary letter. Then cost of converting1st word to consists of letters less than and equal to "b" would be\n`cost_a = len(a) - counter_a["b"]`\nNote counter here is acting like a prefix sum of...
3
A **sentence** is a list of words that are separated by a single space with no leading or trailing spaces. Each word consists of lowercase and uppercase English letters. A sentence can be **shuffled** by appending the **1-indexed word position** to each word then rearranging the words in the sentence. * For example...
Iterate on each letter in the alphabet, and check the smallest number of operations needed to make it one of the following: the largest letter in a and smaller than the smallest one in b, vice versa, or let a and b consist only of this letter. For the first 2 conditions, take care that you can only change characters to...
Python3 | DP + QuickSelect | Easy to understand
find-kth-largest-xor-coordinate-value
0
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nLet\'s construct all possible xors list and use quick select to find the Kth largest value.\n# Approach\n<!-- Describe your approach to solving the problem. -->\nFirstly I tried brute-forcing the matrix to calculate the i, j xor - solutio...
4
You are given a 2D `matrix` of size `m x n`, consisting of non-negative integers. You are also given an integer `k`. The **value** of coordinate `(a, b)` of the matrix is the XOR of all `matrix[i][j]` where `0 <= i <= a < m` and `0 <= j <= b < n` **(0-indexed)**. Find the `kth` largest value **(1-indexed)** of all th...
Try every pair of different cities and calculate its network rank. The network rank of two vertices is almost the sum of their degrees. How can you efficiently check if there is a road connecting two different cities?
Python3 | DP + QuickSelect | Easy to understand
find-kth-largest-xor-coordinate-value
0
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nLet\'s construct all possible xors list and use quick select to find the Kth largest value.\n# Approach\n<!-- Describe your approach to solving the problem. -->\nFirstly I tried brute-forcing the matrix to calculate the i, j xor - solutio...
4
You are given two integers `memory1` and `memory2` representing the available memory in bits on two memory sticks. There is currently a faulty program running that consumes an increasing amount of memory every second. At the `ith` second (starting from 1), `i` bits of memory are allocated to the stick with **more avai...
Use a 2D prefix sum to precalculate the xor-sum of the upper left submatrix.
[Python3] compute xor O(MNlog(MN)) | O(MNlogK) | O(MN)
find-kth-largest-xor-coordinate-value
0
1
**Algo**\nCompute `xor` of at `(i, j)` as `xor[i][j] = xor[i-1][j] ^ xor[i][j-1] ^ xor[i-1][j-1] ^ matrix[i][j]`. The return the `k`th largest among observed. \n\n**Implementation**\n```\nclass Solution:\n def kthLargestValue(self, matrix: List[List[int]], k: int) -> int:\n m, n = len(matrix), len(matrix[0]) ...
16
You are given a 2D `matrix` of size `m x n`, consisting of non-negative integers. You are also given an integer `k`. The **value** of coordinate `(a, b)` of the matrix is the XOR of all `matrix[i][j]` where `0 <= i <= a < m` and `0 <= j <= b < n` **(0-indexed)**. Find the `kth` largest value **(1-indexed)** of all th...
Try every pair of different cities and calculate its network rank. The network rank of two vertices is almost the sum of their degrees. How can you efficiently check if there is a road connecting two different cities?
[Python3] compute xor O(MNlog(MN)) | O(MNlogK) | O(MN)
find-kth-largest-xor-coordinate-value
0
1
**Algo**\nCompute `xor` of at `(i, j)` as `xor[i][j] = xor[i-1][j] ^ xor[i][j-1] ^ xor[i-1][j-1] ^ matrix[i][j]`. The return the `k`th largest among observed. \n\n**Implementation**\n```\nclass Solution:\n def kthLargestValue(self, matrix: List[List[int]], k: int) -> int:\n m, n = len(matrix), len(matrix[0]) ...
16
You are given two integers `memory1` and `memory2` representing the available memory in bits on two memory sticks. There is currently a faulty program running that consumes an increasing amount of memory every second. At the `ith` second (starting from 1), `i` bits of memory are allocated to the stick with **more avai...
Use a 2D prefix sum to precalculate the xor-sum of the upper left submatrix.
XOR Properties | Commented and Explained
find-kth-largest-xor-coordinate-value
0
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThis problem is really about seeing if a candidate understands xor \nXOR is commutative, associative, self-inverting, and has an identity element of 0. \nBy commutative it really means that a xor b = b xor a (order locally does not matter...
0
You are given a 2D `matrix` of size `m x n`, consisting of non-negative integers. You are also given an integer `k`. The **value** of coordinate `(a, b)` of the matrix is the XOR of all `matrix[i][j]` where `0 <= i <= a < m` and `0 <= j <= b < n` **(0-indexed)**. Find the `kth` largest value **(1-indexed)** of all th...
Try every pair of different cities and calculate its network rank. The network rank of two vertices is almost the sum of their degrees. How can you efficiently check if there is a road connecting two different cities?
XOR Properties | Commented and Explained
find-kth-largest-xor-coordinate-value
0
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThis problem is really about seeing if a candidate understands xor \nXOR is commutative, associative, self-inverting, and has an identity element of 0. \nBy commutative it really means that a xor b = b xor a (order locally does not matter...
0
You are given two integers `memory1` and `memory2` representing the available memory in bits on two memory sticks. There is currently a faulty program running that consumes an increasing amount of memory every second. At the `ith` second (starting from 1), `i` bits of memory are allocated to the stick with **more avai...
Use a 2D prefix sum to precalculate the xor-sum of the upper left submatrix.
Python Easy solution beats 100%.
find-kth-largest-xor-coordinate-value
0
1
# Intuition\nUse Prefix Sums\n\n# Complexity\n- Time complexity:\nO(mn)\n\n- Space complexity:\nO(mn)\n\n# Code\n```\nclass Solution:\n def kthLargestValue(self, matrix: List[List[int]], k: int) -> int:\n m, n = len(matrix), len(matrix[0])\n col_xor = [0] * n\n ans = []\n for i in range(m...
0
You are given a 2D `matrix` of size `m x n`, consisting of non-negative integers. You are also given an integer `k`. The **value** of coordinate `(a, b)` of the matrix is the XOR of all `matrix[i][j]` where `0 <= i <= a < m` and `0 <= j <= b < n` **(0-indexed)**. Find the `kth` largest value **(1-indexed)** of all th...
Try every pair of different cities and calculate its network rank. The network rank of two vertices is almost the sum of their degrees. How can you efficiently check if there is a road connecting two different cities?
Python Easy solution beats 100%.
find-kth-largest-xor-coordinate-value
0
1
# Intuition\nUse Prefix Sums\n\n# Complexity\n- Time complexity:\nO(mn)\n\n- Space complexity:\nO(mn)\n\n# Code\n```\nclass Solution:\n def kthLargestValue(self, matrix: List[List[int]], k: int) -> int:\n m, n = len(matrix), len(matrix[0])\n col_xor = [0] * n\n ans = []\n for i in range(m...
0
You are given two integers `memory1` and `memory2` representing the available memory in bits on two memory sticks. There is currently a faulty program running that consumes an increasing amount of memory every second. At the `ith` second (starting from 1), `i` bits of memory are allocated to the stick with **more avai...
Use a 2D prefix sum to precalculate the xor-sum of the upper left submatrix.
[Python3] Prefix sum & heap
find-kth-largest-xor-coordinate-value
0
1
# Intuition\nWe have two subtasks here:\n1. Calculate coordinate values\n2. Find K-th maximum\n\nFor the first subtask we can use precalculated partial sums for XORs:\n\n```\nps[i][j] = ps[i-1][j-1] ^ ps[i][j-1] ^ ps[i-1][j] ^ matrix[i][j] for i > 0, j > 0\nps[0][0] = matrix[0][0]\nps[i][0] = ps[i-1][0] for i > 0\nps[0...
0
You are given a 2D `matrix` of size `m x n`, consisting of non-negative integers. You are also given an integer `k`. The **value** of coordinate `(a, b)` of the matrix is the XOR of all `matrix[i][j]` where `0 <= i <= a < m` and `0 <= j <= b < n` **(0-indexed)**. Find the `kth` largest value **(1-indexed)** of all th...
Try every pair of different cities and calculate its network rank. The network rank of two vertices is almost the sum of their degrees. How can you efficiently check if there is a road connecting two different cities?
[Python3] Prefix sum & heap
find-kth-largest-xor-coordinate-value
0
1
# Intuition\nWe have two subtasks here:\n1. Calculate coordinate values\n2. Find K-th maximum\n\nFor the first subtask we can use precalculated partial sums for XORs:\n\n```\nps[i][j] = ps[i-1][j-1] ^ ps[i][j-1] ^ ps[i-1][j] ^ matrix[i][j] for i > 0, j > 0\nps[0][0] = matrix[0][0]\nps[i][0] = ps[i-1][0] for i > 0\nps[0...
0
You are given two integers `memory1` and `memory2` representing the available memory in bits on two memory sticks. There is currently a faulty program running that consumes an increasing amount of memory every second. At the `ith` second (starting from 1), `i` bits of memory are allocated to the stick with **more avai...
Use a 2D prefix sum to precalculate the xor-sum of the upper left submatrix.
Python Solution
find-kth-largest-xor-coordinate-value
0
1
![Screenshot 2023-02-24 at 06.16.38.png](https://assets.leetcode.com/users/images/c75dec2a-365a-4e9f-9134-12b240c476a9_1677219499.8486009.png)\n\n# Approach\n1. The Solution class has a method kthLargestValue that takes in a 2D matrix matrix and an integer k.\n2. We create an empty list xor_vals to store all the XOR va...
0
You are given a 2D `matrix` of size `m x n`, consisting of non-negative integers. You are also given an integer `k`. The **value** of coordinate `(a, b)` of the matrix is the XOR of all `matrix[i][j]` where `0 <= i <= a < m` and `0 <= j <= b < n` **(0-indexed)**. Find the `kth` largest value **(1-indexed)** of all th...
Try every pair of different cities and calculate its network rank. The network rank of two vertices is almost the sum of their degrees. How can you efficiently check if there is a road connecting two different cities?
Python Solution
find-kth-largest-xor-coordinate-value
0
1
![Screenshot 2023-02-24 at 06.16.38.png](https://assets.leetcode.com/users/images/c75dec2a-365a-4e9f-9134-12b240c476a9_1677219499.8486009.png)\n\n# Approach\n1. The Solution class has a method kthLargestValue that takes in a 2D matrix matrix and an integer k.\n2. We create an empty list xor_vals to store all the XOR va...
0
You are given two integers `memory1` and `memory2` representing the available memory in bits on two memory sticks. There is currently a faulty program running that consumes an increasing amount of memory every second. At the `ith` second (starting from 1), `i` bits of memory are allocated to the stick with **more avai...
Use a 2D prefix sum to precalculate the xor-sum of the upper left submatrix.
[Python3] math
building-boxes
0
1
**Algo**\nThe **1st observation** is that the base increases as 1, 1+2, 1+2+3, 1+2+3+4, ... When the bases is of the form 1+2+3+...+x, there can be at most `1*x + 2*(x-1) + 3*(x-2) + ... + x*1 = x*(x+1)*(x+2)//6` blocks. So we find the the largest `x` such that `x*(x+1)*(x+2)//6 <= n` as the starting point for which th...
12
You have a cubic storeroom where the width, length, and height of the room are all equal to `n` units. You are asked to place `n` boxes in this room where each box is a cube of unit side length. There are however some rules to placing the boxes: * You can place the boxes anywhere on the floor. * If box `x` is plac...
Try finding the largest prefix form a that matches a suffix in b Try string matching
[Python3] math
building-boxes
0
1
**Algo**\nThe **1st observation** is that the base increases as 1, 1+2, 1+2+3, 1+2+3+4, ... When the bases is of the form 1+2+3+...+x, there can be at most `1*x + 2*(x-1) + 3*(x-2) + ... + x*1 = x*(x+1)*(x+2)//6` blocks. So we find the the largest `x` such that `x*(x+1)*(x+2)//6 <= n` as the starting point for which th...
12
You are given an `m x n` matrix of characters `box` representing a side-view of a box. Each cell of the box is one of the following: * A stone `'#'` * A stationary obstacle `'*'` * Empty `'.'` The box is rotated **90 degrees clockwise**, causing some of the stones to fall due to gravity. Each stone falls down u...
Suppose We can put m boxes on the floor, within all the ways to put the boxes, what’s the maximum number of boxes we can put in? The first box should always start in the corner
Math with breakdown and comments | Based on work by other poster
building-boxes
0
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nCheck the comments for the breakdown and go check the original posters work. Was very well done, reposting only to get the math notated and keep for personal use. \n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n...
0
You have a cubic storeroom where the width, length, and height of the room are all equal to `n` units. You are asked to place `n` boxes in this room where each box is a cube of unit side length. There are however some rules to placing the boxes: * You can place the boxes anywhere on the floor. * If box `x` is plac...
Try finding the largest prefix form a that matches a suffix in b Try string matching
Math with breakdown and comments | Based on work by other poster
building-boxes
0
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nCheck the comments for the breakdown and go check the original posters work. Was very well done, reposting only to get the math notated and keep for personal use. \n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n...
0
You are given an `m x n` matrix of characters `box` representing a side-view of a box. Each cell of the box is one of the following: * A stone `'#'` * A stationary obstacle `'*'` * Empty `'.'` The box is rotated **90 degrees clockwise**, causing some of the stones to fall due to gravity. Each stone falls down u...
Suppose We can put m boxes on the floor, within all the ways to put the boxes, what’s the maximum number of boxes we can put in? The first box should always start in the corner
Python (Simple Maths)
building-boxes
0
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
0
You have a cubic storeroom where the width, length, and height of the room are all equal to `n` units. You are asked to place `n` boxes in this room where each box is a cube of unit side length. There are however some rules to placing the boxes: * You can place the boxes anywhere on the floor. * If box `x` is plac...
Try finding the largest prefix form a that matches a suffix in b Try string matching
Python (Simple Maths)
building-boxes
0
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
0
You are given an `m x n` matrix of characters `box` representing a side-view of a box. Each cell of the box is one of the following: * A stone `'#'` * A stationary obstacle `'*'` * Empty `'.'` The box is rotated **90 degrees clockwise**, causing some of the stones to fall due to gravity. Each stone falls down u...
Suppose We can put m boxes on the floor, within all the ways to put the boxes, what’s the maximum number of boxes we can put in? The first box should always start in the corner
Solution
building-boxes
1
1
```C++ []\nclass Solution {\npublic:\n int minimumBoxes(int n) {\n int sum = 1, base = 1, row = 1;\n while (sum < n) {\n base += (++row);\n sum += base;\n }\n while (sum > n) {\n --base;\n sum -= (row--);\n }\n return base + (sum < n);\n }\n};\n```\n\n```Python3 []\nclass Solut...
0
You have a cubic storeroom where the width, length, and height of the room are all equal to `n` units. You are asked to place `n` boxes in this room where each box is a cube of unit side length. There are however some rules to placing the boxes: * You can place the boxes anywhere on the floor. * If box `x` is plac...
Try finding the largest prefix form a that matches a suffix in b Try string matching
Solution
building-boxes
1
1
```C++ []\nclass Solution {\npublic:\n int minimumBoxes(int n) {\n int sum = 1, base = 1, row = 1;\n while (sum < n) {\n base += (++row);\n sum += base;\n }\n while (sum > n) {\n --base;\n sum -= (row--);\n }\n return base + (sum < n);\n }\n};\n```\n\n```Python3 []\nclass Solut...
0
You are given an `m x n` matrix of characters `box` representing a side-view of a box. Each cell of the box is one of the following: * A stone `'#'` * A stationary obstacle `'*'` * Empty `'.'` The box is rotated **90 degrees clockwise**, causing some of the stones to fall due to gravity. Each stone falls down u...
Suppose We can put m boxes on the floor, within all the ways to put the boxes, what’s the maximum number of boxes we can put in? The first box should always start in the corner
Loop based O(n) solution
building-boxes
0
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nanswer for n=1--> 1\nn=2 (1+1)-->2\nn=3 (1+1+1)->3\nn=4 (1+1+2)->3\nn=5 (1+1+2+1)-->4\nn=6 (1+1+2+1+1)->5\nn=7 (1+1+2+1+2)->5\nn=8(1+1+2+1+2+1)->6\nn=9 (1+1+2+1+2+2)->6\nn=10 (1+1+2+1+2+3) ->6\n\n# Approach\n<!-- Describe your approach to...
0
You have a cubic storeroom where the width, length, and height of the room are all equal to `n` units. You are asked to place `n` boxes in this room where each box is a cube of unit side length. There are however some rules to placing the boxes: * You can place the boxes anywhere on the floor. * If box `x` is plac...
Try finding the largest prefix form a that matches a suffix in b Try string matching
Loop based O(n) solution
building-boxes
0
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nanswer for n=1--> 1\nn=2 (1+1)-->2\nn=3 (1+1+1)->3\nn=4 (1+1+2)->3\nn=5 (1+1+2+1)-->4\nn=6 (1+1+2+1+1)->5\nn=7 (1+1+2+1+2)->5\nn=8(1+1+2+1+2+1)->6\nn=9 (1+1+2+1+2+2)->6\nn=10 (1+1+2+1+2+3) ->6\n\n# Approach\n<!-- Describe your approach to...
0
You are given an `m x n` matrix of characters `box` representing a side-view of a box. Each cell of the box is one of the following: * A stone `'#'` * A stationary obstacle `'*'` * Empty `'.'` The box is rotated **90 degrees clockwise**, causing some of the stones to fall due to gravity. Each stone falls down u...
Suppose We can put m boxes on the floor, within all the ways to put the boxes, what’s the maximum number of boxes we can put in? The first box should always start in the corner
✅Python 3 - Math - fast (80%+) - detailed explanation - with example 😃
building-boxes
0
1
![image.png](https://assets.leetcode.com/users/images/7b316513-a318-4bc8-b7ff-10062e834eb1_1671845144.409347.png)\n\n# Approach\n1. find parameters of the perfect corner piramide \nfor `n = 38`: `side = 5`, `square = 15`, `volume = 35`\n\n- we can **decompose** corner piramid **into layouts**\n\n\n```\n5 4 3 2 1 ...
0
You have a cubic storeroom where the width, length, and height of the room are all equal to `n` units. You are asked to place `n` boxes in this room where each box is a cube of unit side length. There are however some rules to placing the boxes: * You can place the boxes anywhere on the floor. * If box `x` is plac...
Try finding the largest prefix form a that matches a suffix in b Try string matching
✅Python 3 - Math - fast (80%+) - detailed explanation - with example 😃
building-boxes
0
1
![image.png](https://assets.leetcode.com/users/images/7b316513-a318-4bc8-b7ff-10062e834eb1_1671845144.409347.png)\n\n# Approach\n1. find parameters of the perfect corner piramide \nfor `n = 38`: `side = 5`, `square = 15`, `volume = 35`\n\n- we can **decompose** corner piramid **into layouts**\n\n\n```\n5 4 3 2 1 ...
0
You are given an `m x n` matrix of characters `box` representing a side-view of a box. Each cell of the box is one of the following: * A stone `'#'` * A stationary obstacle `'*'` * Empty `'.'` The box is rotated **90 degrees clockwise**, causing some of the stones to fall due to gravity. Each stone falls down u...
Suppose We can put m boxes on the floor, within all the ways to put the boxes, what’s the maximum number of boxes we can put in? The first box should always start in the corner
Python | Tetrahedral and Triangular Numbers | O(m^1/3)
building-boxes
0
1
# Complexity\n- Time complexity:\nLet $$m$$ be the number number of boxes. The complexity is $$O(m^{1/3})$$ in the worst case, but only $$O(\\log m)$$ if $$m$$ is a tetrahedral number. This follows because the ```while``` loop runs at most $$n$$ times (where $$n$$ refers to the $$n$$th tetrahedral number), and $$m$$ is...
0
You have a cubic storeroom where the width, length, and height of the room are all equal to `n` units. You are asked to place `n` boxes in this room where each box is a cube of unit side length. There are however some rules to placing the boxes: * You can place the boxes anywhere on the floor. * If box `x` is plac...
Try finding the largest prefix form a that matches a suffix in b Try string matching
Python | Tetrahedral and Triangular Numbers | O(m^1/3)
building-boxes
0
1
# Complexity\n- Time complexity:\nLet $$m$$ be the number number of boxes. The complexity is $$O(m^{1/3})$$ in the worst case, but only $$O(\\log m)$$ if $$m$$ is a tetrahedral number. This follows because the ```while``` loop runs at most $$n$$ times (where $$n$$ refers to the $$n$$th tetrahedral number), and $$m$$ is...
0
You are given an `m x n` matrix of characters `box` representing a side-view of a box. Each cell of the box is one of the following: * A stone `'#'` * A stationary obstacle `'*'` * Empty `'.'` The box is rotated **90 degrees clockwise**, causing some of the stones to fall due to gravity. Each stone falls down u...
Suppose We can put m boxes on the floor, within all the ways to put the boxes, what’s the maximum number of boxes we can put in? The first box should always start in the corner
Python | Detailed Explanation
building-boxes
0
1
# Theory\nThe solution I arrived at is based upon a couple of patterns that the problem presents.\n1. The overall shape of the boxes tends toward a quarter-pyramid shape, appearing as a triangle when viewed top-down.\n```\n00000\n0000\n000\n00\n0\n```\n2. Given a full quarter-pyramid taking up `r` rows, the pyramid wil...
1
You have a cubic storeroom where the width, length, and height of the room are all equal to `n` units. You are asked to place `n` boxes in this room where each box is a cube of unit side length. There are however some rules to placing the boxes: * You can place the boxes anywhere on the floor. * If box `x` is plac...
Try finding the largest prefix form a that matches a suffix in b Try string matching
Python | Detailed Explanation
building-boxes
0
1
# Theory\nThe solution I arrived at is based upon a couple of patterns that the problem presents.\n1. The overall shape of the boxes tends toward a quarter-pyramid shape, appearing as a triangle when viewed top-down.\n```\n00000\n0000\n000\n00\n0\n```\n2. Given a full quarter-pyramid taking up `r` rows, the pyramid wil...
1
You are given an `m x n` matrix of characters `box` representing a side-view of a box. Each cell of the box is one of the following: * A stone `'#'` * A stationary obstacle `'*'` * Empty `'.'` The box is rotated **90 degrees clockwise**, causing some of the stones to fall due to gravity. Each stone falls down u...
Suppose We can put m boxes on the floor, within all the ways to put the boxes, what’s the maximum number of boxes we can put in? The first box should always start in the corner
[python3] Fastest & Most Elegant Script
building-boxes
0
1
```\nclass Solution:\n def minimumBoxes(self, n: int) -> int:\n a = 0\n b = 0\n s = 0\n while n > s:\n a += 1\n b += a\n s += b\n while n <= s:\n s -= a\n a -= 1\n b -= 1\n return b + 1\n```
1
You have a cubic storeroom where the width, length, and height of the room are all equal to `n` units. You are asked to place `n` boxes in this room where each box is a cube of unit side length. There are however some rules to placing the boxes: * You can place the boxes anywhere on the floor. * If box `x` is plac...
Try finding the largest prefix form a that matches a suffix in b Try string matching
[python3] Fastest & Most Elegant Script
building-boxes
0
1
```\nclass Solution:\n def minimumBoxes(self, n: int) -> int:\n a = 0\n b = 0\n s = 0\n while n > s:\n a += 1\n b += a\n s += b\n while n <= s:\n s -= a\n a -= 1\n b -= 1\n return b + 1\n```
1
You are given an `m x n` matrix of characters `box` representing a side-view of a box. Each cell of the box is one of the following: * A stone `'#'` * A stationary obstacle `'*'` * Empty `'.'` The box is rotated **90 degrees clockwise**, causing some of the stones to fall due to gravity. Each stone falls down u...
Suppose We can put m boxes on the floor, within all the ways to put the boxes, what’s the maximum number of boxes we can put in? The first box should always start in the corner
Python3 Solution | Well commented | Better than 94% in Runtime and 90% in Memory distribution
maximum-number-of-balls-in-a-box
0
1
```\n\nclass Solution:\n def countBalls(self, lowLimit: int, highLimit: int) -> int:\n \n # Function which will take integer number as an input and return it\'s sum\n # if input is 123 then it\'ll return 6 (1+2+3)\n \n def numberSum(number:int)->int:\n sum1 = 0\n ...
11
You are working in a ball factory where you have `n` balls numbered from `lowLimit` up to `highLimit` **inclusive** (i.e., `n == highLimit - lowLimit + 1`), and an infinite number of boxes numbered from `1` to `infinity`. Your job at this factory is to put each ball in the box with a number equal to the sum of digits ...
Try sorting the points Think is the y-axis of a point relevant
Python3 Solution | Well commented | Better than 94% in Runtime and 90% in Memory distribution
maximum-number-of-balls-in-a-box
0
1
```\n\nclass Solution:\n def countBalls(self, lowLimit: int, highLimit: int) -> int:\n \n # Function which will take integer number as an input and return it\'s sum\n # if input is 123 then it\'ll return 6 (1+2+3)\n \n def numberSum(number:int)->int:\n sum1 = 0\n ...
11
You are given a **0-indexed** string `s` that has lowercase English letters in its **even** indices and digits in its **odd** indices. There is a function `shift(c, x)`, where `c` is a character and `x` is a digit, that returns the `xth` character after `c`. * For example, `shift('a', 5) = 'f'` and `shift('x', 0) =...
Note that both lowLimit and highLimit are of small constraints so you can iterate on all nubmer between them You can simulate the boxes by counting for each box the number of balls with digit sum equal to that box number
[Python3] freq table
maximum-number-of-balls-in-a-box
0
1
**Algo**\nScan through all numbers from `lowLimit` to `highLimit` and calculate their sum of digits. Maintain a frequency table to keep track of their frequency. \n\n**Implementation**\n```\nclass Solution:\n def countBalls(self, lowLimit: int, highLimit: int) -> int:\n freq = defaultdict(int)\n for x ...
13
You are working in a ball factory where you have `n` balls numbered from `lowLimit` up to `highLimit` **inclusive** (i.e., `n == highLimit - lowLimit + 1`), and an infinite number of boxes numbered from `1` to `infinity`. Your job at this factory is to put each ball in the box with a number equal to the sum of digits ...
Try sorting the points Think is the y-axis of a point relevant
[Python3] freq table
maximum-number-of-balls-in-a-box
0
1
**Algo**\nScan through all numbers from `lowLimit` to `highLimit` and calculate their sum of digits. Maintain a frequency table to keep track of their frequency. \n\n**Implementation**\n```\nclass Solution:\n def countBalls(self, lowLimit: int, highLimit: int) -> int:\n freq = defaultdict(int)\n for x ...
13
You are given a **0-indexed** string `s` that has lowercase English letters in its **even** indices and digits in its **odd** indices. There is a function `shift(c, x)`, where `c` is a character and `x` is a digit, that returns the `xth` character after `c`. * For example, `shift('a', 5) = 'f'` and `shift('x', 0) =...
Note that both lowLimit and highLimit are of small constraints so you can iterate on all nubmer between them You can simulate the boxes by counting for each box the number of balls with digit sum equal to that box number
[Python 3] - Easy to understand COMMENTED solution.
maximum-number-of-balls-in-a-box
0
1
Approach:\n\nIterate through the ```lowLimit``` and ```highLimit```. While doing so, compute the sum of all the elements of the current number and update it\'s count in the frequency table. \nBasically, ```boxes[sum(element)] += 1```, (boxes is my frequency table). Finally, return ```max(boxes)```.\n```\nclass Solution...
7
You are working in a ball factory where you have `n` balls numbered from `lowLimit` up to `highLimit` **inclusive** (i.e., `n == highLimit - lowLimit + 1`), and an infinite number of boxes numbered from `1` to `infinity`. Your job at this factory is to put each ball in the box with a number equal to the sum of digits ...
Try sorting the points Think is the y-axis of a point relevant