task_id stringlengths 3 79 | prompt stringlengths 255 3.9k |
|---|---|
find-the-minimum-area-to-cover-all-ones-i | def minimumArea(grid: List[List[int]]) -> int:
"""
You are given a 2D binary array grid. Find a rectangle with horizontal and vertical sides with the smallest area, such that all the 1's in grid lie inside this rectangle.
Return the minimum possible area of the rectangle.
Example 1:
>>> mi... |
maximize-total-cost-of-alternating-subarrays | def maximumTotalCost(nums: List[int]) -> int:
"""
You are given an integer array nums with length n.
The cost of a subarray nums[l..r], where 0 <= l <= r < n, is defined as:
cost(l, r) = nums[l] - nums[l + 1] + ... + nums[r] * (−1)r − l
Your task is to split nums into subarrays such that the total c... |
find-the-minimum-area-to-cover-all-ones-ii | def minimumSum(grid: List[List[int]]) -> int:
"""
You are given a 2D binary array grid. You need to find 3 non-overlapping rectangles having non-zero areas with horizontal and vertical sides such that all the 1's in grid lie inside these rectangles.
Return the minimum possible sum of the area of these recta... |
count-triplets-with-even-xor-set-bits-i | def tripletCount(a: List[int], b: List[int], c: List[int]) -> int:
"""
Given three integer arrays a, b, and c, return the number of triplets (a[i], b[j], c[k]), such that the bitwise XOR of the elements of each triplet has an even number of set bits.
Example 1:
>>> tripletCount(a = [1], b = [2... |
maximum-height-of-a-triangle | def maxHeightOfTriangle(red: int, blue: int) -> int:
"""
You are given two integers red and blue representing the count of red and blue colored balls. You have to arrange these balls to form a triangle such that the 1st row will have 1 ball, the 2nd row will have 2 balls, the 3rd row will have 3 balls, and so o... |
find-the-maximum-length-of-valid-subsequence-i | def maximumLength(nums: List[int]) -> int:
"""
You are given an integer array nums.
A subsequence sub of nums with length x is called valid if it satisfies:
(sub[0] + sub[1]) % 2 == (sub[1] + sub[2]) % 2 == ... == (sub[x - 2] + sub[x - 1]) % 2.
Return the length of the longest valid subseq... |
find-the-maximum-length-of-valid-subsequence-ii | def maximumLength(nums: List[int], k: int) -> int:
"""
You are given an integer array nums and a positive integer k.
A subsequence sub of nums with length x is called valid if it satisfies:
(sub[0] + sub[1]) % k == (sub[1] + sub[2]) % k == ... == (sub[x - 2] + sub[x - 1]) % k.
Return the l... |
find-minimum-diameter-after-merging-two-trees | def minimumDiameterAfterMerge(edges1: List[List[int]], edges2: List[List[int]]) -> int:
"""
There exist two undirected trees with n and m nodes, numbered from 0 to n - 1 and from 0 to m - 1, respectively. You are given two 2D integer arrays edges1 and edges2 of lengths n - 1 and m - 1, respectively, where edges... |
maximum-array-hopping-score-i | def maxScore(nums: List[int]) -> int:
"""
Given an array nums, you have to get the maximum score starting from index 0 and hopping until you reach the last element of the array.
In each hop, you can jump from index i to an index j > i, and you get a score of (j - i) * nums[j].
Return the maximum score y... |
alternating-groups-i | def numberOfAlternatingGroups(colors: List[int]) -> int:
"""
There is a circle of red and blue tiles. You are given an array of integers colors. The color of tile i is represented by colors[i]:
colors[i] == 0 means that tile i is red.
colors[i] == 1 means that tile i is blue.
Every 3 conti... |
maximum-points-after-enemy-battles | def maximumPoints(enemyEnergies: List[int], currentEnergy: int) -> int:
"""
You are given an integer array enemyEnergies denoting the energy values of various enemies.
You are also given an integer currentEnergy denoting the amount of energy you have initially.
You start with 0 points, and all the enemi... |
alternating-groups-ii | def numberOfAlternatingGroups(colors: List[int], k: int) -> int:
"""
There is a circle of red and blue tiles. You are given an array of integers colors and an integer k. The color of tile i is represented by colors[i]:
colors[i] == 0 means that tile i is red.
colors[i] == 1 means that tile i is blu... |
number-of-subarrays-with-and-value-of-k | def countSubarrays(nums: List[int], k: int) -> int:
"""
Given an array of integers nums and an integer k, return the number of subarrays of nums where the bitwise AND of the elements of the subarray equals k.
Example 1:
>>> countSubarrays(nums = [1,1,1], k = 1)
>>> 6
Explanation:
A... |
find-the-encrypted-string | def getEncryptedString(s: str, k: int) -> str:
"""
You are given a string s and an integer k. Encrypt the string using the following algorithm:
For each character c in s, replace c with the kth character after c in the string (in a cyclic manner).
Return the encrypted string.
Example ... |
generate-binary-strings-without-adjacent-zeros | def validStrings(n: int) -> List[str]:
"""
You are given a positive integer n.
A binary string x is valid if all substrings of x of length 2 contain at least one "1".
Return all valid strings with length n, in any order.
Example 1:
>>> validStrings(n = 3)
>>> ["010","011","101","11... |
count-submatrices-with-equal-frequency-of-x-and-y | def numberOfSubmatrices(grid: List[List[str]]) -> int:
"""
Given a 2D character matrix grid, where grid[i][j] is either 'X', 'Y', or '.', return the number of submatrices that contain:
grid[0][0]
an equal frequency of 'X' and 'Y'.
at least one 'X'.
Example 1:
>>> numberOf... |
construct-string-with-minimum-cost | def minimumCost(target: str, words: List[str], costs: List[int]) -> int:
"""
You are given a string target, an array of strings words, and an integer array costs, both arrays of the same length.
Imagine an empty string s.
You can perform the following operation any number of times (including zero):
... |
count-triplets-with-even-xor-set-bits-ii | def tripletCount(a: List[int], b: List[int], c: List[int]) -> int:
"""
Given three integer arrays a, b, and c, return the number of triplets (a[i], b[j], c[k]), such that the bitwise XOR between the elements of each triplet has an even number of set bits.
Example 1:
>>> tripletCount(a = [1], b... |
lexicographically-smallest-string-after-a-swap | def getSmallestString(s: str) -> str:
"""
Given a string s containing only digits, return the lexicographically smallest string that can be obtained after swapping adjacent digits in s with the same parity at most once.
Digits have the same parity if both are odd or both are even. For example, 5 and 9, as w... |
delete-nodes-from-linked-list-present-in-array | # class ListNode:
# def __init__(val=0, next=None):
# self.val = val
# self.next = next
class Solution:
def modifiedList(nums: List[int], head: Optional[ListNode]) -> Optional[ListNode]:
"""
You are given an array of integers nums and the head of a linked list. Return the head of the mod... |
minimum-cost-for-cutting-cake-i | def minimumCost(m: int, n: int, horizontalCut: List[int], verticalCut: List[int]) -> int:
"""
There is an m x n cake that needs to be cut into 1 x 1 pieces.
You are given integers m, n, and two arrays:
horizontalCut of size m - 1, where horizontalCut[i] represents the cost to cut along the horizont... |
minimum-cost-for-cutting-cake-ii | def minimumCost(m: int, n: int, horizontalCut: List[int], verticalCut: List[int]) -> int:
"""
There is an m x n cake that needs to be cut into 1 x 1 pieces.
You are given integers m, n, and two arrays:
horizontalCut of size m - 1, where horizontalCut[i] represents the cost to cut along the horizont... |
maximum-array-hopping-score-ii | def maxScore(nums: List[int]) -> int:
"""
Given an array nums, you have to get the maximum score starting from index 0 and hopping until you reach the last element of the array.
In each hop, you can jump from index i to an index j > i, and you get a score of (j - i) * nums[j].
Return the maximum score y... |
find-the-winning-player-in-coin-game | def winningPlayer(x: int, y: int) -> str:
"""
You are given two positive integers x and y, denoting the number of coins with values 75 and 10 respectively.
Alice and Bob are playing a game. Each turn, starting with Alice, the player must pick up coins with a total value 115. If the player is unable to do so... |
minimum-length-of-string-after-operations | def minimumLength(s: str) -> int:
"""
You are given a string s.
You can perform the following process on s any number of times:
Choose an index i in the string such that there is at least one character to the left of index i that is equal to s[i], and at least one character to the right that is als... |
minimum-array-changes-to-make-differences-equal | def minChanges(nums: List[int], k: int) -> int:
"""
You are given an integer array nums of size n where n is even, and an integer k.
You can perform some changes on the array, where in one change you can replace any element in the array with any integer in the range from 0 to k.
You need to perform some... |
maximum-score-from-grid-operations | def maximumScore(grid: List[List[int]]) -> int:
"""
You are given a 2D matrix grid of size n x n. Initially, all cells of the grid are colored white. In one operation, you can select any cell of indices (i, j), and color black all the cells of the jth column starting from the top row down to the ith row.
Th... |
number-of-bit-changes-to-make-two-integers-equal | def minChanges(n: int, k: int) -> int:
"""
You are given two positive integers n and k.
You can choose any bit in the binary representation of n that is equal to 1 and change it to 0.
Return the number of changes needed to make n equal to k. If it is impossible, return -1.
Example 1:
>... |
vowels-game-in-a-string | def doesAliceWin(s: str) -> bool:
"""
Alice and Bob are playing a game on a string.
You are given a string s, Alice and Bob will take turns playing the following game where Alice starts first:
On Alice's turn, she has to remove any non-empty substring from s that contains an odd number of vowels.
... |
maximum-number-of-operations-to-move-ones-to-the-end | def maxOperations(s: str) -> int:
"""
You are given a binary string s.
You can perform the following operation on the string any number of times:
Choose any index i from the string where i + 1 < s.length such that s[i] == '1' and s[i + 1] == '0'.
Move the character s[i] to the right until it re... |
minimum-operations-to-make-array-equal-to-target | def minimumOperations(nums: List[int], target: List[int]) -> int:
"""
You are given two positive integer arrays nums and target, of the same length.
In a single operation, you can select any subarray of nums and increment each element within that subarray by 1 or decrement each element within that subarray ... |
minimum-number-of-increasing-subsequence-to-be-removed | def minOperations(nums: List[int]) -> int:
"""
Given an array of integers nums, you are allowed to perform the following operation any number of times:
Remove a strictly increasing subsequence from the array.
Your task is to find the minimum number of operations required to make the array empt... |
find-if-digit-game-can-be-won | def canAliceWin(nums: List[int]) -> bool:
"""
You are given an array of positive integers nums.
Alice and Bob are playing a game. In the game, Alice can choose either all single-digit numbers or all double-digit numbers from nums, and the rest of the numbers are given to Bob. Alice wins if the sum of her nu... |
find-the-count-of-numbers-which-are-not-special | def nonSpecialCount(l: int, r: int) -> int:
"""
You are given 2 positive integers l and r. For any number x, all positive divisors of x except x are called the proper divisors of x.
A number is called special if it has exactly 2 proper divisors. For example:
The number 4 is special because it has p... |
count-the-number-of-substrings-with-dominant-ones | def numberOfSubstrings(s: str) -> int:
"""
You are given a binary string s.
Return the number of substrings with dominant ones.
A string has dominant ones if the number of ones in the string is greater than or equal to the square of the number of zeros in the string.
Example 1:
>>> num... |
check-if-the-rectangle-corner-is-reachable | def canReachCorner(xCorner: int, yCorner: int, circles: List[List[int]]) -> bool:
"""
You are given two positive integers xCorner and yCorner, and a 2D array circles, where circles[i] = [xi, yi, ri] denotes a circle with center at (xi, yi) and radius ri.
There is a rectangle in the coordinate plane with its... |
alt-and-tab-simulation | def simulationResult(windows: List[int], queries: List[int]) -> List[int]:
"""
There are n windows open numbered from 1 to n, we want to simulate using alt + tab to navigate between the windows.
You are given an array windows which contains the initial order of the windows (the first element is at the top a... |
find-the-number-of-winning-players | def winningPlayerCount(n: int, pick: List[List[int]]) -> int:
"""
You are given an integer n representing the number of players in a game and a 2D array pick where pick[i] = [xi, yi] represents that the player xi picked a ball of color yi.
Player i wins the game if they pick strictly more than i balls of th... |
minimum-number-of-flips-to-make-binary-grid-palindromic-i | def minFlips(grid: List[List[int]]) -> int:
"""
You are given an m x n binary matrix grid.
A row or column is considered palindromic if its values read the same forward and backward.
You can flip any number of cells in grid from 0 to 1, or from 1 to 0.
Return the minimum number of cells that need to... |
minimum-number-of-flips-to-make-binary-grid-palindromic-ii | def minFlips(grid: List[List[int]]) -> int:
"""
You are given an m x n binary matrix grid.
A row or column is considered palindromic if its values read the same forward and backward.
You can flip any number of cells in grid from 0 to 1, or from 1 to 0.
Return the minimum number of cells that need to... |
time-taken-to-mark-all-nodes | def timeTaken(edges: List[List[int]]) -> List[int]:
"""
There exists an undirected tree with n nodes numbered 0 to n - 1. You are given a 2D integer array edges of length n - 1, where edges[i] = [ui, vi] indicates that there is an edge between nodes ui and vi in the tree.
Initially, all nodes are unmarked. ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.