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 |
|---|---|---|---|---|---|---|---|
BEATS 95.59% OF USERS || BEGINNER FRIENDLY APPROACH 🔥🔥🔥✅✅✅ | minimum-common-value | 0 | 1 | # Approach\n<!-- Describe your approach to solving the problem. -->\nBy converting the given list into set and finding intersection we could find all common elements, and then by using min function we could find the minimum value and solve this problem.\n\n\n\n# Code\n```\n\nclass Solution:\n def getCommon(self, num... | 3 | Given two integer arrays `nums1` and `nums2`, sorted in non-decreasing order, return _the **minimum integer common** to both arrays_. If there is no common integer amongst `nums1` and `nums2`, return `-1`.
Note that an integer is said to be **common** to `nums1` and `nums2` if both arrays have **at least one** occurre... | null |
Beat 97.56% 443ms Set Operation | minimum-common-value | 0 | 1 | \n\n# Code\n```\nclass Solution:\n def getCommon(self, nums1: List[int], nums2: List[int]) -> int:\n if max(nums1) < min(nums2): return -1\n else:\n return min(set(nums1) & set(nums2)) if(set(nums1) & set(nums2)) else -1\n``` | 1 | Given two integer arrays `nums1` and `nums2`, sorted in non-decreasing order, return _the **minimum integer common** to both arrays_. If there is no common integer amongst `nums1` and `nums2`, return `-1`.
Note that an integer is said to be **common** to `nums1` and `nums2` if both arrays have **at least one** occurre... | null |
[ Python ] ✅✅ Simple Python Solution Using Binary Search🥳✌👍 | minimum-common-value | 0 | 1 | # If You like the Solution, Don\'t Forget To UpVote Me, Please UpVote! \uD83D\uDD3C\uD83D\uDE4F\n# Runtime: 2298 ms, faster than 12.50% of Python3 online submissions for Minimum Common Value.\n# Memory Usage: 32.4 MB, less than 100.00% of Python3 online submissions for Minimum Common Value.\n\n\tclass Solution:\n\t\tde... | 1 | Given two integer arrays `nums1` and `nums2`, sorted in non-decreasing order, return _the **minimum integer common** to both arrays_. If there is no common integer amongst `nums1` and `nums2`, return `-1`.
Note that an integer is said to be **common** to `nums1` and `nums2` if both arrays have **at least one** occurre... | null |
[Python] Two Pointers ✅ | minimum-common-value | 0 | 1 | # Complexity\n- Time complexity:\n$$O(n)$$\n\n- Space complexity:\n$$O(1)$$\n\n# Code\n```\nclass Solution:\n def getCommon(self, nums1: List[int], nums2: List[int]) -> int:\n\n l, r = 0, 0\n\n while l < len(nums1) and r < len(nums2):\n if nums1[l] < nums2[r]:\n l += 1\n ... | 1 | Given two integer arrays `nums1` and `nums2`, sorted in non-decreasing order, return _the **minimum integer common** to both arrays_. If there is no common integer amongst `nums1` and `nums2`, return `-1`.
Note that an integer is said to be **common** to `nums1` and `nums2` if both arrays have **at least one** occurre... | null |
[Python3] - Two Pointer + Binary Search - easy to understand | minimum-common-value | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nTwo arrays are sorted, so we can just compare two like merge function in merge sort to find the min similar number start from the left\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nmaintain 2 pointer and do binar... | 4 | Given two integer arrays `nums1` and `nums2`, sorted in non-decreasing order, return _the **minimum integer common** to both arrays_. If there is no common integer amongst `nums1` and `nums2`, return `-1`.
Note that an integer is said to be **common** to `nums1` and `nums2` if both arrays have **at least one** occurre... | null |
Python3 one-liner + Rust three-liner O(n) | minimum-common-value | 0 | 1 | # Approach\nCreate sets of `nums1` and `nums2`, get the intersection and get the minimum of this set. If the intersection is empty return the default -1.\n\n# Complexity\n- Time complexity:\n$$O(n)$$\n\n- Space complexity:\n$$O(n)$$\n\n# Code\n## Python3\nRuntime 457 ms\n```\nclass Solution:\n def getCommon(self, nu... | 2 | Given two integer arrays `nums1` and `nums2`, sorted in non-decreasing order, return _the **minimum integer common** to both arrays_. If there is no common integer amongst `nums1` and `nums2`, return `-1`.
Note that an integer is said to be **common** to `nums1` and `nums2` if both arrays have **at least one** occurre... | null |
Python - simple greedy one linear run | minimum-operations-to-make-array-equal-ii | 0 | 1 | # Intuition\nFind equilibrum if possible following 3 simple rules:\n1. If k is 0, then difference between all positions in nums1 and nums2 should 0, no steps needed.\n2. If any position diference is not divisible with k then it is not possbile to level up with k size increase or decrease work.\n3. to reach equilibrum, ... | 1 | You are given two integer arrays `nums1` and `nums2` of equal length `n` and an integer `k`. You can perform the following operation on `nums1`:
* Choose two indexes `i` and `j` and increment `nums1[i]` by `k` and decrement `nums1[j]` by `k`. In other words, `nums1[i] = nums1[i] + k` and `nums1[j] = nums1[j] - k`.
... | null |
[Java/Python 3] Modulos and balance check w/ brief explanation and analysis. | minimum-operations-to-make-array-equal-ii | 1 | 1 | \n1. Traverse `nums1` and `nums2` and check if each of the corresponding difference is divisible by `k`; If not, impossible to make the two arrays equal; \n2. If yes, accumulate the difference to `bal`, which will be `0` after traversal if it is possible to make the two arrays equal;\n3. Accumulate the times of the po... | 26 | You are given two integer arrays `nums1` and `nums2` of equal length `n` and an integer `k`. You can perform the following operation on `nums1`:
* Choose two indexes `i` and `j` and increment `nums1[i]` by `k` and decrement `nums1[j]` by `k`. In other words, `nums1[i] = nums1[i] + k` and `nums1[j] = nums1[j] - k`.
... | null |
[C++|Java|Python3] difference | minimum-operations-to-make-array-equal-ii | 1 | 1 | Please pull this [commit](https://github.com/gaosanyong/leetcode/commit/7c339707e031611c80809107e7a667b2c6b6f7f0) for solutions of biweekly 96. \n\n**C++**\n```\nclass Solution {\npublic:\n long long minOperations(vector<int>& nums1, vector<int>& nums2, int k) {\n long long ans = 0, total = 0; \n for (... | 2 | You are given two integer arrays `nums1` and `nums2` of equal length `n` and an integer `k`. You can perform the following operation on `nums1`:
* Choose two indexes `i` and `j` and increment `nums1[i]` by `k` and decrement `nums1[j]` by `k`. In other words, `nums1[i] = nums1[i] + k` and `nums1[j] = nums1[j] - k`.
... | null |
🔥Python3🔥Very EASY Solution | minimum-operations-to-make-array-equal-ii | 0 | 1 | - Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n$$O(n)$$\n\n# Code\n```\nclass Solution:\n def minOperations(self, nums1: List[int], nums2: List[int], k: int) -> int:\n s=0\n c=0\n if k==0:\n if nums1==nums2:\n return 0\n return -1\... | 9 | You are given two integer arrays `nums1` and `nums2` of equal length `n` and an integer `k`. You can perform the following operation on `nums1`:
* Choose two indexes `i` and `j` and increment `nums1[i]` by `k` and decrement `nums1[j]` by `k`. In other words, `nums1[i] = nums1[i] + k` and `nums1[j] = nums1[j] - k`.
... | null |
✅ Python| One iteration. | minimum-operations-to-make-array-equal-ii | 0 | 1 | Check if the sum of the elements in nums1 is equal to the sum of the elements in nums2, and if not, return -1.\n\nThe approach is to iterate through the elements of nums1 and nums2 in parallel using the zip function and check if the absolute difference between the elements is divisible by k, and add to count. If it is ... | 1 | You are given two integer arrays `nums1` and `nums2` of equal length `n` and an integer `k`. You can perform the following operation on `nums1`:
* Choose two indexes `i` and `j` and increment `nums1[i]` by `k` and decrement `nums1[j]` by `k`. In other words, `nums1[i] = nums1[i] + k` and `nums1[j] = nums1[j] - k`.
... | null |
Python | O(n) | [EXPLAINED] | minimum-operations-to-make-array-equal-ii | 0 | 1 | # Approach\n- We can modify one array while keeping the other one same.\n- But here won\'t modify any array just simulate the modification and count number of operations.\n- Suppose we will modify second array to convert it into first one.\n- Iterate through the array and find difference between elements at i<sup>th</s... | 1 | You are given two integer arrays `nums1` and `nums2` of equal length `n` and an integer `k`. You can perform the following operation on `nums1`:
* Choose two indexes `i` and `j` and increment `nums1[i]` by `k` and decrement `nums1[j]` by `k`. In other words, `nums1[i] = nums1[i] + k` and `nums1[j] = nums1[j] - k`.
... | null |
EASY PYTHON SOLN USING SORTING AND HEAP SORT | maximum-subsequence-score | 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(nlogn)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(n*2)$$\n<!-- Add your space complexit... | 1 | You are given two **0-indexed** integer arrays `nums1` and `nums2` of equal length `n` and a positive integer `k`. You must choose a **subsequence** of indices from `nums1` of length `k`.
For chosen indices `i0`, `i1`, ..., `ik - 1`, your **score** is defined as:
* The sum of the selected elements from `nums1` mult... | null |
[Python3] Heap + similar questions || beats 94% || 810ms | maximum-subsequence-score | 0 | 1 | ```\nclass Solution:\n def maxScore(self, nums1: List[int], nums2: List[int], k: int) -> int:\n res, prefixSum, minHeap = 0, 0, []\n \n for a, b in sorted(list(zip(nums1, nums2)), key=itemgetter(1), reverse=True):\n prefixSum += a\n heappush(minHeap, a)\n if len(... | 29 | You are given two **0-indexed** integer arrays `nums1` and `nums2` of equal length `n` and a positive integer `k`. You must choose a **subsequence** of indices from `nums1` of length `k`.
For chosen indices `i0`, `i1`, ..., `ik - 1`, your **score** is defined as:
* The sum of the selected elements from `nums1` mult... | null |
heap + sort + one step check | maximum-subsequence-score | 0 | 1 | # Intuition\nimprove a little after reading lee215\'s solution https://leetcode.com/problems/maximum-subsequence-score/solutions/3082106/java-c-python-priority-queue/?orderBy=most_votes\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nheap + sort, but adding a check to see whether we are heap pop... | 1 | You are given two **0-indexed** integer arrays `nums1` and `nums2` of equal length `n` and a positive integer `k`. You must choose a **subsequence** of indices from `nums1` of length `k`.
For chosen indices `i0`, `i1`, ..., `ik - 1`, your **score** is defined as:
* The sum of the selected elements from `nums1` mult... | null |
[C++|Java|Python3] gcd | check-if-point-is-reachable | 1 | 1 | Please pull this [commit](https://github.com/gaosanyong/leetcode/commit/7c339707e031611c80809107e7a667b2c6b6f7f0) for solutions of biweekly 96. \n\n**C++**\n```\nclass Solution {\npublic:\n bool isReachable(int targetX, int targetY) {\n int g = gcd(targetX, targetY); \n return (g & (g-1)) == 0; \n }... | 1 | There exists an infinitely large grid. You are currently at point `(1, 1)`, and you need to reach the point `(targetX, targetY)` using a finite number of steps.
In one **step**, you can move from point `(x, y)` to any one of the following points:
* `(x, y - x)`
* `(x - y, y)`
* `(2 * x, y)`
* `(x, 2 * y)`
Gi... | null |
One-liner Python | check-if-point-is-reachable | 0 | 1 | \n# Code\n```\nclass Solution:\n def isReachable(self, targetX: int, targetY: int) -> bool:\n return (1 << 32) % gcd(targetX, targetY) == 0\n \n``` | 1 | There exists an infinitely large grid. You are currently at point `(1, 1)`, and you need to reach the point `(targetX, targetY)` using a finite number of steps.
In one **step**, you can move from point `(x, y)` to any one of the following points:
* `(x, y - x)`
* `(x - y, y)`
* `(2 * x, y)`
* `(x, 2 * y)`
Gi... | null |
🔥Python3🔥only GCD | check-if-point-is-reachable | 0 | 1 | - Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n$$O(log(n))$$\n\n# Code\n```\nclass Solution:\n def isReachable(self, x: int, y: int) -> bool:\n a=gcd(x,y)\n while a%2==0:\n a//=2\n return a==1\n \n```\nPlease UPVOTE if it helps \u2764\uFE0F\uD83D\uDE0A\nTha... | 10 | There exists an infinitely large grid. You are currently at point `(1, 1)`, and you need to reach the point `(targetX, targetY)` using a finite number of steps.
In one **step**, you can move from point `(x, y)` to any one of the following points:
* `(x, y - x)`
* `(x - y, y)`
* `(2 * x, y)`
* `(x, 2 * y)`
Gi... | null |
[Java/Python 3] Check if the GCD has only factor 2 w/ explanation and analysis. | check-if-point-is-reachable | 1 | 1 | **Intuition**\n\nNotice there is double operations for either `x` or `y`- coordinates and the corresponding result must be even. Therefore, if the target coordinates is odd, we can only have `1` option: `+/-`. \n\nHence we can simplify the operation if we return from target to source.\n\nAlso the following operation hi... | 15 | There exists an infinitely large grid. You are currently at point `(1, 1)`, and you need to reach the point `(targetX, targetY)` using a finite number of steps.
In one **step**, you can move from point `(x, y)` to any one of the following points:
* `(x, y - x)`
* `(x - y, y)`
* `(2 * x, y)`
* `(x, 2 * y)`
Gi... | null |
1 line solution that beats 100% | check-if-point-is-reachable | 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(logn)\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(... | 1 | There exists an infinitely large grid. You are currently at point `(1, 1)`, and you need to reach the point `(targetX, targetY)` using a finite number of steps.
In one **step**, you can move from point `(x, y)` to any one of the following points:
* `(x, y - x)`
* `(x - y, y)`
* `(2 * x, y)`
* `(x, 2 * y)`
Gi... | null |
Simple recursive approach | check-if-point-is-reachable | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. --> The `isReachable` function uses a recursive approach to determine if it is possible to reach the target point `(targetX, targetY)` from the starting point `(1, 1)` using the given steps.\n\nThe function first checks if the current position... | 1 | There exists an infinitely large grid. You are currently at point `(1, 1)`, and you need to reach the point `(targetX, targetY)` using a finite number of steps.
In one **step**, you can move from point `(x, y)` to any one of the following points:
* `(x, y - x)`
* `(x - y, y)`
* `(2 * x, y)`
* `(x, 2 * y)`
Gi... | null |
🔥Python3🔥 math, number theory | check-if-point-is-reachable | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nIf x or y is a power of two, it means there is an exact solution. This is definitely a special case.\nIf the GCD of x and y is a power of two, then there is a solution. A very easy solution.\n\n\n- Time complexity:\n<!-- Add your time com... | 8 | There exists an infinitely large grid. You are currently at point `(1, 1)`, and you need to reach the point `(targetX, targetY)` using a finite number of steps.
In one **step**, you can move from point `(x, y)` to any one of the following points:
* `(x, y - x)`
* `(x - y, y)`
* `(2 * x, y)`
* `(x, 2 * y)`
Gi... | null |
Proof-based solution, now with correct proof | check-if-point-is-reachable | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe intuition is quite straightforward: a pair (a, b) is accessible if and only if the greatest common divisor of a and b, gcd(a, b), is a power of 2.\nThe difficulty is proving this, which fortunately was not required during the contest.... | 8 | There exists an infinitely large grid. You are currently at point `(1, 1)`, and you need to reach the point `(targetX, targetY)` using a finite number of steps.
In one **step**, you can move from point `(x, y)` to any one of the following points:
* `(x, y - x)`
* `(x - y, y)`
* `(2 * x, y)`
* `(x, 2 * y)`
Gi... | null |
[Python] One-liner Math, Now with Proof, The Best | check-if-point-is-reachable | 0 | 1 | # Intuition\nThe possible generalized transformations of $$(x, y)$$ into $$(x, y-kx)$$ and $$(x-ky, y)$$ are reminiscent of coefficients computation in Extended Euclidean Algorithm. The other two generalized transformations into $$(2^kx, y)$$ and $$(x, 2^ky)$$ suggest that powers-of-$$2$$ are also related.\n\nLooking a... | 2 | There exists an infinitely large grid. You are currently at point `(1, 1)`, and you need to reach the point `(targetX, targetY)` using a finite number of steps.
In one **step**, you can move from point `(x, y)` to any one of the following points:
* `(x, y - x)`
* `(x - y, y)`
* `(2 * x, y)`
* `(x, 2 * y)`
Gi... | null |
No GCD or other math magic! Simple intuition with explanation | check-if-point-is-reachable | 0 | 1 | # Intuition\n\nGo from the target to the start.\n\nIf `x` or `y` can reach `1`, then both coordinates can reach `1` (by subtracting `1` from the other coordinate).\n\nDecrease `x` and `y` greedily until any coordinate reaches `1`, or the process stucks in the same state.\n\n# Approach\n\nWhen you go backwards, there ar... | 9 | There exists an infinitely large grid. You are currently at point `(1, 1)`, and you need to reach the point `(targetX, targetY)` using a finite number of steps.
In one **step**, you can move from point `(x, y)` to any one of the following points:
* `(x, y - x)`
* `(x - y, y)`
* `(2 * x, y)`
* `(x, 2 * y)`
Gi... | null |
Countering Logic | alternating-digit-sum | 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)$$ --... | 2 | You are given a positive integer `n`. Each digit of `n` has a sign according to the following rules:
* The **most significant digit** is assigned a **positive** sign.
* Each other digit has an opposite sign to its adjacent digits.
Return _the sum of all digits with their corresponding sign_.
**Example 1:**
**In... | null |
Simple solution | alternating-digit-sum | 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)$$ --... | 1 | You are given a positive integer `n`. Each digit of `n` has a sign according to the following rules:
* The **most significant digit** is assigned a **positive** sign.
* Each other digit has an opposite sign to its adjacent digits.
Return _the sum of all digits with their corresponding sign_.
**Example 1:**
**In... | null |
Python 2 Approach Math + String || Simple Code | alternating-digit-sum | 0 | 1 | \n# Code\n> # Math Approach\n```\nclass Solution:\n def alternateDigitSum(self, n: int) -> int:\n nums = []\n while n > 0:\n nums.append(n%10)\n n = n//10\n\n nums.reverse()\n ans = 0\n\n for i in range(len(nums)):\n if i%2 == 0: #eve... | 1 | You are given a positive integer `n`. Each digit of `n` has a sign according to the following rules:
* The **most significant digit** is assigned a **positive** sign.
* Each other digit has an opposite sign to its adjacent digits.
Return _the sum of all digits with their corresponding sign_.
**Example 1:**
**In... | null |
simple approach wit python | alternating-digit-sum | 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)$$ --... | 1 | You are given a positive integer `n`. Each digit of `n` has a sign according to the following rules:
* The **most significant digit** is assigned a **positive** sign.
* Each other digit has an opposite sign to its adjacent digits.
Return _the sum of all digits with their corresponding sign_.
**Example 1:**
**In... | null |
EASY and in less time complexity | alternating-digit-sum | 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)$$ --... | 1 | You are given a positive integer `n`. Each digit of `n` has a sign according to the following rules:
* The **most significant digit** is assigned a **positive** sign.
* Each other digit has an opposite sign to its adjacent digits.
Return _the sum of all digits with their corresponding sign_.
**Example 1:**
**In... | null |
Easy Solution with best approach | alternating-digit-sum | 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. $$... | 1 | You are given a positive integer `n`. Each digit of `n` has a sign according to the following rules:
* The **most significant digit** is assigned a **positive** sign.
* Each other digit has an opposite sign to its adjacent digits.
Return _the sum of all digits with their corresponding sign_.
**Example 1:**
**In... | null |
Python Simple | alternating-digit-sum | 0 | 1 | \n\n\n# Code\n```\nclass Solution:\n def alternateDigitSum(self, n: int) -> int:\n a=str(n)\n ans=0\n k=0\n for i in a:\n if k&1==0:\n ans+=int(i)\n else:\n ans-=int(i)\n k+=1\n return ans\n``` | 1 | You are given a positive integer `n`. Each digit of `n` has a sign according to the following rules:
* The **most significant digit** is assigned a **positive** sign.
* Each other digit has an opposite sign to its adjacent digits.
Return _the sum of all digits with their corresponding sign_.
**Example 1:**
**In... | null |
Sweetest code this side of the Mississippi | alternating-digit-sum | 1 | 1 | # Java\n\n## Using a basic loop:\n\n```java\nclass Solution {\n public int alternateDigitSum(int n) {\n String[] digits = Integer.toString(n).split("");\n\n int res = 0;\n for (int i = 0; i < digits.length; ++i) {\n res += Integer.parseInt(digits[i]) * (i % 2 == 0 ? 1 : -1);\n }\n return res;\n }\... | 1 | You are given a positive integer `n`. Each digit of `n` has a sign according to the following rules:
* The **most significant digit** is assigned a **positive** sign.
* Each other digit has an opposite sign to its adjacent digits.
Return _the sum of all digits with their corresponding sign_.
**Example 1:**
**In... | null |
Amazing speed 100% | alternating-digit-sum | 0 | 1 | # Intuition\n\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 tim... | 2 | You are given a positive integer `n`. Each digit of `n` has a sign according to the following rules:
* The **most significant digit** is assigned a **positive** sign.
* Each other digit has an opposite sign to its adjacent digits.
Return _the sum of all digits with their corresponding sign_.
**Example 1:**
**In... | null |
Beats 96.19% || Alternating digit sum | alternating-digit-sum | 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)$$ --... | 1 | You are given a positive integer `n`. Each digit of `n` has a sign according to the following rules:
* The **most significant digit** is assigned a **positive** sign.
* Each other digit has an opposite sign to its adjacent digits.
Return _the sum of all digits with their corresponding sign_.
**Example 1:**
**In... | null |
Python Easy Solution || 100% || | alternating-digit-sum | 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)$$ --... | 1 | You are given a positive integer `n`. Each digit of `n` has a sign according to the following rules:
* The **most significant digit** is assigned a **positive** sign.
* Each other digit has an opposite sign to its adjacent digits.
Return _the sum of all digits with their corresponding sign_.
**Example 1:**
**In... | null |
✅ 91% || Python3 || 2 Lines || ⭐️ Sort and Lambda ⭐️ | sort-the-students-by-their-kth-score | 0 | 1 | # Intuition\n\n\n# Approach\nSort() funct iterate each list and sort according to the given specific index in lambda \n\n\n# Complexity\n- Time complexity:\n<!-- Add your time ... | 1 | There is a class with `m` students and `n` exams. You are given a **0-indexed** `m x n` integer matrix `score`, where each row represents one student and `score[i][j]` denotes the score the `ith` student got in the `jth` exam. The matrix `score` contains **distinct** integers only.
You are also given an integer `k`. S... | null |
Easy | Python Solution | Hashmap | sort-the-students-by-their-kth-score | 0 | 1 | # Code\n```\nclass Solution:\n def sortTheStudents(self, score: List[List[int]], k: int) -> List[List[int]]:\n hashmap = defaultdict(list)\n refer = {}\n ans = []\n for i in range(len(score)):\n hashmap[i].append(score[i])\n refer[i] = score[i][k]\n sorted_ans... | 1 | There is a class with `m` students and `n` exams. You are given a **0-indexed** `m x n` integer matrix `score`, where each row represents one student and `score[i][j]` denotes the score the `ith` student got in the `jth` exam. The matrix `score` contains **distinct** integers only.
You are also given an integer `k`. S... | null |
🔥Python3🔥 EASY Solution | sort-the-students-by-their-kth-score | 0 | 1 | \n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n$$O(n*log(n))$$\n# Python3\n```\nclass Solution:\n def sortTheStudents(self, a: List[List[int]], k: int) -> List[List[int]]:\n v=[]\n \n for i in range(len(a)):\n v+=[[a[i][k],a[i]]]\n print(v)\n ... | 14 | There is a class with `m` students and `n` exams. You are given a **0-indexed** `m x n` integer matrix `score`, where each row represents one student and `score[i][j]` denotes the score the `ith` student got in the `jth` exam. The matrix `score` contains **distinct** integers only.
You are also given an integer `k`. S... | null |
Simple solution with Sorting in Python3 / TypeScript | sort-the-students-by-their-kth-score | 0 | 1 | # Intuition\nHere we have:\n- `score` list of integers, and `k`\n- our goal is to sort `score` by `k` column\n\n# Approach\nJust simply sort by `k`-th column in **decreasing** order.\n\n# Complexity\n- Time complexity: **O(N log N)**\n\n- Space complexity: **O(1)**, **O(N)** for Python3 `sorted`, since it create **new*... | 1 | There is a class with `m` students and `n` exams. You are given a **0-indexed** `m x n` integer matrix `score`, where each row represents one student and `score[i][j]` denotes the score the `ith` student got in the `jth` exam. The matrix `score` contains **distinct** integers only.
You are also given an integer `k`. S... | null |
Very easy one linerb code | sort-the-students-by-their-kth-score | 0 | 1 | # One liner code\n\n# Code\n```\nclass Solution:\n def sortTheStudents(self, score: List[List[int]], k: int) -> List[List[int]]:\n return sorted(score,reverse=True, key=lambda x:x[k])\n``` | 1 | There is a class with `m` students and `n` exams. You are given a **0-indexed** `m x n` integer matrix `score`, where each row represents one student and `score[i][j]` denotes the score the `ith` student got in the `jth` exam. The matrix `score` contains **distinct** integers only.
You are also given an integer `k`. S... | null |
PYTHON3 || SORTING || DICTIONARY || BEGINNER-FRIENDLY | sort-the-students-by-their-kth-score | 0 | 1 | # PYTHON3 || SORTING || DICTIONARY || BEGINNER-FRIENDLY\n\n# Approach\n Used Simple Approach first storing the values of k position element in new array. Then used that array element parallelly with score array then created Key-Value Pair like: \n {11: [7,5,11,2], 9: [10,6,9,1],3: [4,8,3,15]}\nThen sorted reversely dic... | 2 | There is a class with `m` students and `n` exams. You are given a **0-indexed** `m x n` integer matrix `score`, where each row represents one student and `score[i][j]` denotes the score the `ith` student got in the `jth` exam. The matrix `score` contains **distinct** integers only.
You are also given an integer `k`. S... | null |
🔥🔥2 Linear Python Solution🔥🔥Up vote Please😊 | sort-the-students-by-their-kth-score | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->we can solve the problem through sorting.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nwe have to add the total row to the kth element in the dictionary and sort the dictionary then add the rows to the new list an... | 1 | There is a class with `m` students and `n` exams. You are given a **0-indexed** `m x n` integer matrix `score`, where each row represents one student and `score[i][j]` denotes the score the `ith` student got in the `jth` exam. The matrix `score` contains **distinct** integers only.
You are also given an integer `k`. S... | null |
One liner python solutions | using Lambda | sort-the-students-by-their-kth-score | 0 | 1 | \n# Code\n```\nclass Solution:\n def sortTheStudents(self, score: List[List[int]], k: int) -> List[List[int]]:\n return sorted(score, key=lambda x:x[k],reverse=True)\n``` | 2 | There is a class with `m` students and `n` exams. You are given a **0-indexed** `m x n` integer matrix `score`, where each row represents one student and `score[i][j]` denotes the score the `ith` student got in the `jth` exam. The matrix `score` contains **distinct** integers only.
You are also given an integer `k`. S... | null |
2 LINES PYTHON SOLUTION | apply-bitwise-operations-to-make-strings-equal | 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,... | 1 | You are given two **0-indexed binary** strings `s` and `target` of the same length `n`. You can do the following operation on `s` **any** number of times:
* Choose two **different** indices `i` and `j` where `0 <= i, j < n`.
* Simultaneously, replace `s[i]` with (`s[i]` **OR** `s[j]`) and `s[j]` with (`s[i]` **XOR... | null |
[Java/Python 3] Analysis results short codes. | apply-bitwise-operations-to-make-strings-equal | 1 | 1 | **If a string contains no `1`, then there is no way to change it any longer; If a string contains at least a `1`, there is no way to change it to an all-zero string, under the rules of the problem.**\n\nOtherwise, we can always change `s` to `target`.\n\n```java\n public boolean makeStringsEqual(String s, String ... | 12 | You are given two **0-indexed binary** strings `s` and `target` of the same length `n`. You can do the following operation on `s` **any** number of times:
* Choose two **different** indices `i` and `j` where `0 <= i, j < n`.
* Simultaneously, replace `s[i]` with (`s[i]` **OR** `s[j]`) and `s[j]` with (`s[i]` **XOR... | null |
Didn't realise that 1 has so much power 💪|| Easy Approach explained💡 || | apply-bitwise-operations-to-make-strings-equal | 0 | 1 | # Approach\uD83E\uDDE0\n<!-- Describe your approach to solving the problem. -->\n- Case 1 :\'1\' in s and \'0\' in target\n\n1.If we have \'1\' in s and \'0\' in target we can take help from another \'1\' in s to place \'0\' .\n```\ni.e (1^1=0) & (1|1=1) .\n```\n\n2.If there is no \'1\' available we can create an addit... | 1 | You are given two **0-indexed binary** strings `s` and `target` of the same length `n`. You can do the following operation on `s` **any** number of times:
* Choose two **different** indices `i` and `j` where `0 <= i, j < n`.
* Simultaneously, replace `s[i]` with (`s[i]` **OR** `s[j]`) and `s[j]` with (`s[i]` **XOR... | null |
Python 1 liner solution super easy to understand altho its an easy question :-) | apply-bitwise-operations-to-make-strings-equal | 0 | 1 | # what should i even say, all testcases have been passed using this simple code!\n# Code\n```\nclass Solution:\n def makeStringsEqual(self, s: str, target: str) -> bool:\n return max(s) == max(target)\n``` | 3 | You are given two **0-indexed binary** strings `s` and `target` of the same length `n`. You can do the following operation on `s` **any** number of times:
* Choose two **different** indices `i` and `j` where `0 <= i, j < n`.
* Simultaneously, replace `s[i]` with (`s[i]` **OR** `s[j]`) and `s[j]` with (`s[i]` **XOR... | null |
✅One Liner and Easy to Understand | apply-bitwise-operations-to-make-strings-equal | 0 | 1 | # Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n$$O(n)$$\n\n# Code\n```\nclass Solution:\n def makeStringsEqual(self, s: str, target: str) -> bool:\n return s==target or (int(target)>0 and int(s)>0)\n \n \n```\nPlease UPVOTE if it helps \u2764\uFE0F\uD83D... | 11 | You are given two **0-indexed binary** strings `s` and `target` of the same length `n`. You can do the following operation on `s` **any** number of times:
* Choose two **different** indices `i` and `j` where `0 <= i, j < n`.
* Simultaneously, replace `s[i]` with (`s[i]` **OR** `s[j]`) and `s[j]` with (`s[i]` **XOR... | null |
Python 3 || 2 lines, w/ explanation || T/M: 45 ms / 15 MB | apply-bitwise-operations-to-make-strings-equal | 0 | 1 | From the table below, one can see that:\n- If`s` has a `1`, then any other digit in`s`can be flipped, but there will remain at least one`1` in`s`, no matter how many oprations are performed.\n- If`s` has no `1`s, then no other digit in`s`can be flipped.\n\n\n and `s[j]` with (`s[i]` **XOR... | null |
[Python3/Golang/Rust] Count one | apply-bitwise-operations-to-make-strings-equal | 0 | 1 | We have to check if one of the strings contains 1 and the other does not, and vice versa. If both have it, then we can bring our string s equal to the target.\n\n**Python3**:\n```\nclass Solution:\n def makeStringsEqual(self, s: str, target: str) -> bool:\n return \'1\' in s and \'1\' in target or \'1\' not i... | 1 | You are given two **0-indexed binary** strings `s` and `target` of the same length `n`. You can do the following operation on `s` **any** number of times:
* Choose two **different** indices `i` and `j` where `0 <= i, j < n`.
* Simultaneously, replace `s[i]` with (`s[i]` **OR** `s[j]`) and `s[j]` with (`s[i]` **XOR... | null |
🔥Python3 || C++🔥 ✅ EASY Dynamic Programming with Dict(Map) | minimum-cost-to-split-an-array | 0 | 1 | \nAn initial value would be needed in this solution. \nTo that I added an element to the front of the array that is not in the array (nums=[-1]+nums) and since it is not in the array before, \ndp[0]=0 (it has no price).\nThen I started from the 1-index of the array because the 0-index has -1 and calculated the minimum ... | 23 | You are given an integer array `nums` and an integer `k`.
Split the array into some number of non-empty subarrays. The **cost** of a split is the sum of the **importance value** of each subarray in the split.
Let `trimmed(subarray)` be the version of the subarray where all numbers which appear only once are removed.
... | null |
✔ Python3 Solution | 100% faster | DP | minimum-cost-to-split-an-array | 0 | 1 | # Complexity\n- Time complexity: $$O(n^2)$$\n- Space complexity: $$O(n)$$\n\n# Code\n```\nclass Solution:\n def minCost(self, A, K):\n n = len(A)\n dp = [0] + [float(\'inf\')] * n\n for i in range(n):\n C = [0] * n\n val = K\n for j in range(i, -1, -1):\n ... | 1 | You are given an integer array `nums` and an integer `k`.
Split the array into some number of non-empty subarrays. The **cost** of a split is the sum of the **importance value** of each subarray in the split.
Let `trimmed(subarray)` be the version of the subarray where all numbers which appear only once are removed.
... | null |
SIMPLE PYTHON DP SOLUTION | minimum-cost-to-split-an-array | 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^2)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(N^2)$$\n<!-- Add your space complexity ... | 1 | You are given an integer array `nums` and an integer `k`.
Split the array into some number of non-empty subarrays. The **cost** of a split is the sum of the **importance value** of each subarray in the split.
Let `trimmed(subarray)` be the version of the subarray where all numbers which appear only once are removed.
... | null |
Python 3 || 11 lines, w/ example || T/M: 5373 ms / 20 MB | minimum-cost-to-split-an-array | 0 | 1 | ```\nclass Solution: # Example: nums = [1, 2, 1, 2] 5\n def minCost(self, nums: List[int], k: int) -> int: #\n # left right tmp ans nums[left,right+1]\n @lru_cache(None) ... | 4 | You are given an integer array `nums` and an integer `k`.
Split the array into some number of non-empty subarrays. The **cost** of a split is the sum of the **importance value** of each subarray in the split.
Let `trimmed(subarray)` be the version of the subarray where all numbers which appear only once are removed.
... | null |
[Python🐍] Simple DP with Dict (Hashmap) 15 Lines of code | minimum-cost-to-split-an-array | 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. -->\nDP Memorization Approach where `i` is the index of the current number and returning the minimum cost starting at index `i`.\nKeep a Hashmap called `hm` to remember th... | 14 | You are given an integer array `nums` and an integer `k`.
Split the array into some number of non-empty subarrays. The **cost** of a split is the sum of the **importance value** of each subarray in the split.
Let `trimmed(subarray)` be the version of the subarray where all numbers which appear only once are removed.
... | null |
python3 Solution | minimum-cost-to-split-an-array | 0 | 1 | \n```\nclass Solution:\n def minCost(self, nums: List[int], k: int) -> int:\n n = len(nums)\n dp = [inf]*(n+1)\n dp[-1] = 0 \n for i in range(n-1, -1, -1): \n val = 0 \n freq = Counter()\n for ii in range(i, n): \n freq[nums[ii]] += 1\n ... | 1 | You are given an integer array `nums` and an integer `k`.
Split the array into some number of non-empty subarrays. The **cost** of a split is the sum of the **importance value** of each subarray in the split.
Let `trimmed(subarray)` be the version of the subarray where all numbers which appear only once are removed.
... | null |
[C++ || Java || Python] Easy dp | minimum-cost-to-split-an-array | 1 | 1 | > **I know almost nothing about English, pointing out the mistakes in my article would be much appreciated.**\n\n> **In addition, I\'m too weak, please be critical of my ideas.**\n\n> **Vote welcome if this solution helped.**\n---\n\n# Intuition\n1. The value range of length is no more than 1000, so an $O(n^{2})$ algor... | 9 | You are given an integer array `nums` and an integer `k`.
Split the array into some number of non-empty subarrays. The **cost** of a split is the sum of the **importance value** of each subarray in the split.
Let `trimmed(subarray)` be the version of the subarray where all numbers which appear only once are removed.
... | null |
Python easy to read and understand | dp | minimum-cost-to-split-an-array | 0 | 1 | ```\nclass Solution:\n def solve(self, nums, index, dp, k):\n if index == len(nums):\n return 0\n if index in dp:\n return dp[index]\n mn = float("inf")\n cnt = 0\n d = collections.defaultdict(int)\n for i in range(index, len(nums)):\n d[nums... | 0 | You are given an integer array `nums` and an integer `k`.
Split the array into some number of non-empty subarrays. The **cost** of a split is the sum of the **importance value** of each subarray in the split.
Let `trimmed(subarray)` be the version of the subarray where all numbers which appear only once are removed.
... | null |
DP approach with Question Explaination in Simple Language | minimum-cost-to-split-an-array | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe Questions asks you to add any number of particians such that cost of each partition on both side k+ how many int comes more than once in currently operated array\nkey thinking aproach such that we can add any number of particians not ... | 0 | You are given an integer array `nums` and an integer `k`.
Split the array into some number of non-empty subarrays. The **cost** of a split is the sum of the **importance value** of each subarray in the split.
Let `trimmed(subarray)` be the version of the subarray where all numbers which appear only once are removed.
... | null |
Python3 | count-distinct-numbers-on-board | 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\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ ... | 1 | You are given a positive integer `n`, that is initially placed on a board. Every day, for `109` days, you perform the following procedure:
* For each number `x` present on the board, find all numbers `1 <= i <= n` such that `x % i == 1`.
* Then, place those numbers on the board.
Return _the number of **distinct**... | null |
Python3 || Oneliner | count-distinct-numbers-on-board | 0 | 1 | # Code\n```\nclass Solution:\n def distinctIntegers(self, n: int) -> int:\n return n-1 if n>1 else n\n```\n# Please do upvote if you like the solution | 2 | You are given a positive integer `n`, that is initially placed on a board. Every day, for `109` days, you perform the following procedure:
* For each number `x` present on the board, find all numbers `1 <= i <= n` such that `x % i == 1`.
* Then, place those numbers on the board.
Return _the number of **distinct**... | null |
ONE LINER | count-distinct-numbers-on-board | 0 | 1 | \n# Code\n```\nclass Solution:\n def distinctIntegers(self, n: int) -> int:\n if n == 1:\n return 1\n else:\n return n - 1\n \n``` | 2 | You are given a positive integer `n`, that is initially placed on a board. Every day, for `109` days, you perform the following procedure:
* For each number `x` present on the board, find all numbers `1 <= i <= n` such that `x % i == 1`.
* Then, place those numbers on the board.
Return _the number of **distinct**... | null |
Python solutoin beats 99% in time and space complexity | count-distinct-numbers-on-board | 0 | 1 | # Code\n```\nclass Solution:\n def distinctIntegers(self, n: int) -> int:\n return n - 1 or 1\n \n``` | 1 | You are given a positive integer `n`, that is initially placed on a board. Every day, for `109` days, you perform the following procedure:
* For each number `x` present on the board, find all numbers `1 <= i <= n` such that `x % i == 1`.
* Then, place those numbers on the board.
Return _the number of **distinct**... | null |
Easy to Understand Python3 Solution | count-distinct-numbers-on-board | 0 | 1 | \n\n\n# Complexity\n- Time complexity: O(1)\n\n\n- Space complexity: O(1)\n\n\n# Code\n```\nclass Solution:\n def distinctIntegers(self, n: int) -> int:\n if n==1:\n return 1\n return n... | 1 | You are given a positive integer `n`, that is initially placed on a board. Every day, for `109` days, you perform the following procedure:
* For each number `x` present on the board, find all numbers `1 <= i <= n` such that `x % i == 1`.
* Then, place those numbers on the board.
Return _the number of **distinct**... | null |
Python one-liner solution | count-distinct-numbers-on-board | 0 | 1 | \n\n# Code\n```\nclass Solution:\n def distinctIntegers(self, n: int) -> int:\n return [n - 1, 1][n == 1]\n``` | 4 | You are given a positive integer `n`, that is initially placed on a board. Every day, for `109` days, you perform the following procedure:
* For each number `x` present on the board, find all numbers `1 <= i <= n` such that `x % i == 1`.
* Then, place those numbers on the board.
Return _the number of **distinct**... | null |
Python | Easy Solution✅ | count-distinct-numbers-on-board | 0 | 1 | # Code\u2705\n```\nclass Solution:\n def distinctIntegers(self, n: int) -> int:\n return n if n<=1 else n-1\n``` | 5 | You are given a positive integer `n`, that is initially placed on a board. Every day, for `109` days, you perform the following procedure:
* For each number `x` present on the board, find all numbers `1 <= i <= n` such that `x % i == 1`.
* Then, place those numbers on the board.
Return _the number of **distinct**... | null |
Very clear explanation | Straightforward solution | Explanation case missed | count-collisions-of-monkeys-on-a-polygon | 0 | 1 | First of all, think that each monkey has two options to move. So this ends in them having `2^n` possible arrangements. \n\nThe only way the monkeys don\'t collide is if all of them go or clockwise or anticlockwise. In any other case there is at least one pair that ends in the same vertex. \n\nSo the raw solution would ... | 7 | There is a regular convex polygon with `n` vertices. The vertices are labeled from `0` to `n - 1` in a clockwise direction, and each vertex has **exactly one monkey**. The following figure shows a convex polygon of `6` vertices.
Each monkey moves simultaneously to a neighboring vertex. A neighboring vertex for a verte... | null |
✔ Python3 Solution | 1 linear | count-collisions-of-monkeys-on-a-polygon | 0 | 1 | # Intuition\nEach monkey can move to left or right, So there are 2 possible ways a single monkey can move. For `n` number of monkeys there are `2 ^ n` possibilities. Out of which only `2` possible ways where no monkey can collide when all of them move to either left or right.\nTherefore, `ans = 2 ^ n - 2`\n\n# Complexi... | 3 | There is a regular convex polygon with `n` vertices. The vertices are labeled from `0` to `n - 1` in a clockwise direction, and each vertex has **exactly one monkey**. The following figure shows a convex polygon of `6` vertices.
Each monkey moves simultaneously to a neighboring vertex. A neighboring vertex for a verte... | null |
Mod Pow | count-collisions-of-monkeys-on-a-polygon | 0 | 1 | There are only 2 moves when no monkey collides - everyone goes clockwise or counter-clockwise.\n\nAlso, a pair of monkeys could swap places, but LeetCode added "... or intersect on an edge" after the contest to clarify that it would also cause a collision.\n\nThe total number of moves is 2 ^ n, so the result is 2 ^ n -... | 2 | There is a regular convex polygon with `n` vertices. The vertices are labeled from `0` to `n - 1` in a clockwise direction, and each vertex has **exactly one monkey**. The following figure shows a convex polygon of `6` vertices.
Each monkey moves simultaneously to a neighboring vertex. A neighboring vertex for a verte... | null |
[Python] Just math; Explained | count-collisions-of-monkeys-on-a-polygon | 0 | 1 | This is a math problem. \nEach monkey can have two directions to move. Therefore, there are total `2 ** n` moving cases if there are n monkeys.\n\nAmong the 2 ** n cases, only 2 cases that no collision happens.\n\nTLE solutions\n```\nclass Solution: \n def monkeyMove(self, n: int) -> int:\n return (2 ** n ... | 1 | There is a regular convex polygon with `n` vertices. The vertices are labeled from `0` to `n - 1` in a clockwise direction, and each vertex has **exactly one monkey**. The following figure shows a convex polygon of `6` vertices.
Each monkey moves simultaneously to a neighboring vertex. A neighboring vertex for a verte... | null |
python3 Solution | count-collisions-of-monkeys-on-a-polygon | 0 | 1 | \n\n```\nclass Solution:\n def monkeyMove(self, n: int) -> int:\n return (pow(2,n,10**9+7)-2)%(10**9+7)\n``` | 1 | There is a regular convex polygon with `n` vertices. The vertices are labeled from `0` to `n - 1` in a clockwise direction, and each vertex has **exactly one monkey**. The following figure shows a convex polygon of `6` vertices.
Each monkey moves simultaneously to a neighboring vertex. A neighboring vertex for a verte... | null |
[JavaScript / Python] solutions | count-collisions-of-monkeys-on-a-polygon | 0 | 1 | ```javascript []\nconst monkeyMove = function (n) {\n const mod = BigInt(10 ** 9 + 7);\n let [base, res] = [2n, 1n];\n while (n > 0) {\n if (n % 2) res = (res * base) % mod;\n base = (base * base) % mod;\n n >>= 1;\n }\n return Number((res - 2n + mod) % mod);\n};\n```\n```python []\nclass Solution:\n def... | 2 | There is a regular convex polygon with `n` vertices. The vertices are labeled from `0` to `n - 1` in a clockwise direction, and each vertex has **exactly one monkey**. The following figure shows a convex polygon of `6` vertices.
Each monkey moves simultaneously to a neighboring vertex. A neighboring vertex for a verte... | null |
pow() Going on Lenthgs in Explanation and Experience | count-collisions-of-monkeys-on-a-polygon | 0 | 1 | ## Initial Thoughts\n\nI remember at the beginning of starting to confront LeetCode problems I made these judgments based on my ability that something was more difficult than it seemed. And problems with diagrams like this, I\'d go "Jesus Christ" a lot of times for. But once you get pass that and actually judge a probl... | 0 | There is a regular convex polygon with `n` vertices. The vertices are labeled from `0` to `n - 1` in a clockwise direction, and each vertex has **exactly one monkey**. The following figure shows a convex polygon of `6` vertices.
Each monkey moves simultaneously to a neighboring vertex. A neighboring vertex for a verte... | null |
Python 1-liner. Heap (PriorityQueue). Functional programming. | put-marbles-in-bags | 0 | 1 | # Approach\nTL;DR, Similar to [Editorial solution](https://leetcode.com/problems/put-marbles-in-bags/editorial/) but written functionally and using heaps instead of sorting.\n\n# Complexity\n- Time complexity: $$O(n)$$\n\n- Space complexity: $$O(n)$$\n\n# Code\n```python\nclass Solution:\n def putMarbles(self, weigh... | 1 | You have `k` bags. You are given a **0-indexed** integer array `weights` where `weights[i]` is the weight of the `ith` marble. You are also given the integer `k.`
Divide the marbles into the `k` bags according to the following rules:
* No bag is empty.
* If the `ith` marble and `jth` marble are in a bag, then all... | null |
Python Elegant & Short | Two Lines | put-marbles-in-bags | 0 | 1 | # Complexity\n- Time complexity: $$O(n * log_{2} n)$$\n- Space complexity: $$O(n)$$\n\n# Code\n```\nclass Solution:\n def putMarbles(self, weights: List[int], k: int) -> int:\n cost = [l + r for l, r in pairwise(weights)]\n return sum(nlargest(k - 1, cost)) - sum(nsmallest(k - 1, cost))\n```\n | 1 | You have `k` bags. You are given a **0-indexed** integer array `weights` where `weights[i]` is the weight of the `ith` marble. You are also given the integer `k.`
Divide the marbles into the `k` bags according to the following rules:
* No bag is empty.
* If the `ith` marble and `jth` marble are in a bag, then all... | null |
Explain Partition||C++/Python greedy||sort vs priority queue | put-marbles-in-bags | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n[Please turn on english subtitles if neccessary]\n[https://youtu.be/XMOqSMrbz_Q](https://youtu.be/XMOqSMrbz_Q)\n# What is the essential meaning for a partition?\n\nA partition refers to dividing something, such as a set or array, into sep... | 10 | You have `k` bags. You are given a **0-indexed** integer array `weights` where `weights[i]` is the weight of the `ith` marble. You are also given the integer `k.`
Divide the marbles into the `k` bags according to the following rules:
* No bag is empty.
* If the `ith` marble and `jth` marble are in a bag, then all... | null |
[Python3] SortedList/bisect.insort Solution Clean & Concise | count-increasing-quadruplets | 0 | 1 | # Approach\nWe break the quadruple into `(i, j)` and `(k, l)`, and use a `SortedList` data structure in Python to maintain the ongoing subarray up to `j`.\n\nFor each current element `nums[j]` (maintained using a for loop from left to right), we loop through the possible value of `nums[k]` from right to left, and count... | 7 | Given a **0-indexed** integer array `nums` of size `n` containing all numbers from `1` to `n`, return _the number of increasing quadruplets_.
A quadruplet `(i, j, k, l)` is increasing if:
* `0 <= i < j < k < l < n`, and
* `nums[i] < nums[k] < nums[j] < nums[l]`.
**Example 1:**
**Input:** nums = \[1,3,2,4,5\]
**... | null |
naive O(n^2 logn) solution python | count-increasing-quadruplets | 0 | 1 | the idea similar to 132 pattern\n\nbut now we have 1324 words\nwe keep the 3 as middle \n- first get the distribution of left hand side -> smaller\n- then check right hand side:\n - if bigger than 3 -> might be 4\n - if smaller than 3 -> count into 2\n\n\n```\nclass Solution:\n # Time: O(n^2 * logn)\n # Spa... | 1 | Given a **0-indexed** integer array `nums` of size `n` containing all numbers from `1` to `n`, return _the number of increasing quadruplets_.
A quadruplet `(i, j, k, l)` is increasing if:
* `0 <= i < j < k < l < n`, and
* `nums[i] < nums[k] < nums[j] < nums[l]`.
**Example 1:**
**Input:** nums = \[1,3,2,4,5\]
**... | null |
[C++|Java|Python3] Cleanest Code with Clarification O(n^2) | count-increasing-quadruplets | 1 | 1 | # Intuition\n\nThe crux of this problem is to identify and count increasing quadruplets. To simplify the problem, let\'s break it down to count the **132 triplets** first, then leverage them to count **1324 quadruplets**.\n\n1. **132 Triplet**: A triplet (i, j, k) that satisfies the condition `i < j < k` and `nums[i] <... | 165 | Given a **0-indexed** integer array `nums` of size `n` containing all numbers from `1` to `n`, return _the number of increasing quadruplets_.
A quadruplet `(i, j, k, l)` is increasing if:
* `0 <= i < j < k < l < n`, and
* `nums[i] < nums[k] < nums[j] < nums[l]`.
**Example 1:**
**Input:** nums = \[1,3,2,4,5\]
**... | null |
O(N^2) python code | count-increasing-quadruplets | 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)$$ --... | 1 | Given a **0-indexed** integer array `nums` of size `n` containing all numbers from `1` to `n`, return _the number of increasing quadruplets_.
A quadruplet `(i, j, k, l)` is increasing if:
* `0 <= i < j < k < l < n`, and
* `nums[i] < nums[k] < nums[j] < nums[l]`.
**Example 1:**
**Input:** nums = \[1,3,2,4,5\]
**... | null |
【C++||Java||Python】Enumerate All (j,k) Pairs, with O(n²) Complexity | count-increasing-quadruplets | 1 | 1 | > **I know almost nothing about English, pointing out the mistakes in my article would be much appreciated.**\n\n> **In addition, I\'m too weak, please be critical of my ideas.**\n---\n\nThis is an [Better answer](https://leetcode.com/problems/count-increasing-quadruplets/solutions/3111697/python3-clean-dp-with-clarifi... | 51 | Given a **0-indexed** integer array `nums` of size `n` containing all numbers from `1` to `n`, return _the number of increasing quadruplets_.
A quadruplet `(i, j, k, l)` is increasing if:
* `0 <= i < j < k < l < n`, and
* `nums[i] < nums[k] < nums[j] < nums[l]`.
**Example 1:**
**Input:** nums = \[1,3,2,4,5\]
**... | null |
2 Pass counting 132 nums and then using them to build 1324 nums | count-increasing-quadruplets | 0 | 1 | # Code\n```\nclass Solution:\n # T = O(N^2)\n # S = O(N)\n def countQuadruplets(self, nums: List[int]) -> int:\n # https://leetcode.com/problems/count-increasing-quadruplets/solutions/3111697/c-java-python3-cleanest-code-with-clarification-o-n-2/\n # This is an extension of 132 triplets \n ... | 0 | Given a **0-indexed** integer array `nums` of size `n` containing all numbers from `1` to `n`, return _the number of increasing quadruplets_.
A quadruplet `(i, j, k, l)` is increasing if:
* `0 <= i < j < k < l < n`, and
* `nums[i] < nums[k] < nums[j] < nums[l]`.
**Example 1:**
**Input:** nums = \[1,3,2,4,5\]
**... | null |
✅ Explained - Simple and Clear Python3 Code✅ | separate-the-digits-in-an-array | 0 | 1 | # Intuition\nThe given problem requires separating the digits of positive integers in an array and returning the digits in the same order they appear in the original numbers.\n\n\n# Approach\nThe provided solution uses a function named separateDigits within a class named Solution. The function takes an input parameter ... | 5 | Given an array of positive integers `nums`, return _an array_ `answer` _that consists of the digits of each integer in_ `nums` _after separating them in **the same order** they appear in_ `nums`.
To separate the digits of an integer is to get all the digits it has in the same order.
* For example, for the integer `... | null |
Python Solution Without Data Conv. || Easy to Understand | separate-the-digits-in-an-array | 0 | 1 | # Intuition\n\n---\n\n\n<!-- Describe your first thoughts on how to solve this problem. -->\nTo solve this problem, you can use the simple **digit extraction method** to get the required output without converting data type which makes the program runtime **slower**.\n\n# Approach\n\n---\n\n\n<!-- Describe your approach... | 1 | Given an array of positive integers `nums`, return _an array_ `answer` _that consists of the digits of each integer in_ `nums` _after separating them in **the same order** they appear in_ `nums`.
To separate the digits of an integer is to get all the digits it has in the same order.
* For example, for the integer `... | null |
Easy python for beginners | separate-the-digits-in-an-array | 0 | 1 | \n# Code\n```\nclass Solution:\n def separateDigits(self, nums: List[int]) -> List[int]:\n answer = []\n hash_map = {}\n i = 0\n for num in nums:\n x = [int(y) for y in str(num)]\n for number in x:\n hash_map[i] = number\n i += 1... | 1 | Given an array of positive integers `nums`, return _an array_ `answer` _that consists of the digits of each integer in_ `nums` _after separating them in **the same order** they appear in_ `nums`.
To separate the digits of an integer is to get all the digits it has in the same order.
* For example, for the integer `... | null |
Python 3 || Bit Operation || Reuse Input List | separate-the-digits-in-an-array | 0 | 1 | # Intuition\nMost solutions create a new list to return the result. This solution is based on reusing the input list by using bitwise operations.\n\n# Approach\nThe idea is to traverse the list and, if necessary, storing two values in one number. The maximum number is $$10^5$$, for which at most 17 bits are required. A... | 4 | Given an array of positive integers `nums`, return _an array_ `answer` _that consists of the digits of each integer in_ `nums` _after separating them in **the same order** they appear in_ `nums`.
To separate the digits of an integer is to get all the digits it has in the same order.
* For example, for the integer `... | null |
Python Easy Solution || 100% || | separate-the-digits-in-an-array | 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)$$ --... | 1 | Given an array of positive integers `nums`, return _an array_ `answer` _that consists of the digits of each integer in_ `nums` _after separating them in **the same order** they appear in_ `nums`.
To separate the digits of an integer is to get all the digits it has in the same order.
* For example, for the integer `... | null |
Easy | separate-the-digits-in-an-array | 0 | 1 | \n\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)$$ -->\n\n# Code\n```\nclass Solution:\n def separateDigits(self, nums: List[int... | 1 | Given an array of positive integers `nums`, return _an array_ `answer` _that consists of the digits of each integer in_ `nums` _after separating them in **the same order** they appear in_ `nums`.
To separate the digits of an integer is to get all the digits it has in the same order.
* For example, for the integer `... | null |
Easy to understand READABLE Python code | separate-the-digits-in-an-array | 0 | 1 | \n\n# Code\n```\nclass Solution:\n def separateDigits(self, nums: List[int]) -> List[int]:\n\n string_sep = []\n\n for num in nums:\n for s in str(num):\n string_sep.append(int(s))\n\n return string_sep\n \n```\nBy using List Comprehension:\n```\nclass Solution:\... | 2 | Given an array of positive integers `nums`, return _an array_ `answer` _that consists of the digits of each integer in_ `nums` _after separating them in **the same order** they appear in_ `nums`.
To separate the digits of an integer is to get all the digits it has in the same order.
* For example, for the integer `... | null |
[ Python ] ✅✅ Simple Python Solution Using Maths🥳✌👍 | separate-the-digits-in-an-array | 0 | 1 | # If You like the Solution, Don\'t Forget To UpVote Me, Please UpVote! \uD83D\uDD3C\uD83D\uDE4F\n# Runtime: 123 ms, faster than 6.15% of Python3 online submissions for Separate the Digits in an Array.\n# Memory Usage: 14.6 MB, less than 27.41% of Python3 online submissions for Separate the Digits in an Array.\n\n\tclas... | 3 | Given an array of positive integers `nums`, return _an array_ `answer` _that consists of the digits of each integer in_ `nums` _after separating them in **the same order** they appear in_ `nums`.
To separate the digits of an integer is to get all the digits it has in the same order.
* For example, for the integer `... | null |
Easy Python Solution - separateDigits | separate-the-digits-in-an-array | 0 | 1 | \n\n# Code\n```\nclass Solution:\n def separateDigits(self, nums: List[int]) -> List[int]:\n l = []\n for i in nums:\n s = str(i)\n for j in s:\n l.append(int(j))\n return l\n``` | 2 | Given an array of positive integers `nums`, return _an array_ `answer` _that consists of the digits of each integer in_ `nums` _after separating them in **the same order** they appear in_ `nums`.
To separate the digits of an integer is to get all the digits it has in the same order.
* For example, for the integer `... | null |
Beats 98.88%. Python solution | separate-the-digits-in-an-array | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->Here\'s a easier method to solve this.\nAll you have to do is iterate\n\n# Approach\n<!-- Describe your approach to solving the problem. -->We first iterate the list.\nThen we iterate the numbers in the list as a string and append them into... | 0 | Given an array of positive integers `nums`, return _an array_ `answer` _that consists of the digits of each integer in_ `nums` _after separating them in **the same order** they appear in_ `nums`.
To separate the digits of an integer is to get all the digits it has in the same order.
* For example, for the integer `... | null |
Python Solution || Easy to understand | separate-the-digits-in-an-array | 0 | 1 | ```\nclass Solution:\n def separateDigits(self, nums: List[int]) -> List[int]:\n ans = []\n\t\t\n\t\t# iterating numbers one by one\n for num in nums:\n\t\t\n\t\t\t# iterating digit of num via converting it to string\n for dig in str(num):\n\t\t\t\n\t\t\t\t# adding each digit to ans array\n ... | 1 | Given an array of positive integers `nums`, return _an array_ `answer` _that consists of the digits of each integer in_ `nums` _after separating them in **the same order** they appear in_ `nums`.
To separate the digits of an integer is to get all the digits it has in the same order.
* For example, for the integer `... | null |
[Python 3] Brute-force | maximum-number-of-integers-to-choose-from-a-range-i | 0 | 1 | ```python3 []\nclass Solution:\n def maxCount(self, banned: List[int], n: int, maxSum: int) -> int:\n res, s, b = 0, 0, set(banned)\n for i in range(1, n+1):\n if s + i > maxSum: break\n if i not in b:\n s += i\n res += 1\n\n return res\n```\n | 1 | You are given an integer array `banned` and two integers `n` and `maxSum`. You are choosing some number of integers following the below rules:
* The chosen integers have to be in the range `[1, n]`.
* Each integer can be chosen **at most once**.
* The chosen integers should not be in the array `banned`.
* The ... | null |
Python Easy to Understand Approach !! | maximum-number-of-integers-to-choose-from-a-range-i | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nIt is important to keep banned as set otherwise in PYTHON it gives TLE(Time Limit Exceeded)\n\n# Complexity\n- Time complexity: $$O(n)$$\n\n- Space complexity: $$O(n)$$\n\n# Code\n```\nclass Solution:\n def maxCount(self, banned: List[... | 1 | You are given an integer array `banned` and two integers `n` and `maxSum`. You are choosing some number of integers following the below rules:
* The chosen integers have to be in the range `[1, n]`.
* Each integer can be chosen **at most once**.
* The chosen integers should not be in the array `banned`.
* The ... | null |
Python 3 || 7 lines, brute force || T/M: 1142 ms / 16 MB | maximum-number-of-integers-to-choose-from-a-range-i | 0 | 1 | ```\nclass Solution:\n def maxCount(self, banned: List[int], n: int, maxSum: int) -> int:\n\n ans, banned = -1, set(banned)\n\n for i in range(1,n+1):\n if i not in banned:\n maxSum-= i\n ans+= 1\n\n if maxSum < 0: return ans\n\n return ans+1\n... | 4 | You are given an integer array `banned` and two integers `n` and `maxSum`. You are choosing some number of integers following the below rules:
* The chosen integers have to be in the range `[1, n]`.
* Each integer can be chosen **at most once**.
* The chosen integers should not be in the array `banned`.
* The ... | null |
Easy O(n) Solution using Set ✅ | maximum-number-of-integers-to-choose-from-a-range-i | 0 | 1 | \n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n O(n) , for traversing from 1 to n.\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n O(n) , where n is the number of elements in the banned list to make set for faster access.\n\n\n# Code\n... | 3 | You are given an integer array `banned` and two integers `n` and `maxSum`. You are choosing some number of integers following the below rules:
* The chosen integers have to be in the range `[1, n]`.
* Each integer can be chosen **at most once**.
* The chosen integers should not be in the array `banned`.
* The ... | null |
Python Solution || Easy to Understand for beginners | maximum-number-of-integers-to-choose-from-a-range-i | 0 | 1 | ```\nclass Solution:\n def maxCount(self, banned: List[int], n: int, maxSum: int) -> int:\n\t\t# making set of banned values because search in set is faster\n banned = set(banned)\n\t\t\n\t\t# cnt variable is use to store the count of minimum number required\n\t\t# ans stores the sum till current number\n ... | 1 | You are given an integer array `banned` and two integers `n` and `maxSum`. You are choosing some number of integers following the below rules:
* The chosen integers have to be in the range `[1, n]`.
* Each integer can be chosen **at most once**.
* The chosen integers should not be in the array `banned`.
* The ... | null |
Beats 100% by speed and memory, Python simple solution. | maximize-win-from-two-segments | 0 | 1 | # Intuition\nLet\'s iterate through the array and for each position, calculate the count of prizes in the interval if the interval ends at the current position and store the count and the position in the "intervals" list.\n```\nintervals = [(count of prizes, end pos), (count of prizes, end pos)]\n```\n\nLet\'s also sto... | 3 | There are some prizes on the **X-axis**. You are given an integer array `prizePositions` that is **sorted in non-decreasing order**, where `prizePositions[i]` is the position of the `ith` prize. There could be different prizes at the same position on the line. You are also given an integer `k`.
You are allowed to sele... | null |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.