question_title stringlengths 10 64 | question_content stringlengths 115 1.23k | question_id stringdate 2727-01-01 00:00:00 3347-01-01 00:00:00 | contest_id stringlengths 18 20 | test_id int64 0 0 | contest_date timestamp[us]date 2023-05-07 00:00:00 2024-03-02 00:00:00 | starter_code stringlengths 44 122 | function_name stringlengths 5 30 | difficulty stringclasses 3
values | test stringlengths 117 353 | generated_code sequencelengths 8 8 | gt_rewards sequencelengths 8 8 |
|---|---|---|---|---|---|---|---|---|---|---|---|
number-of-senior-citizens | You are given a 0-indexed array of strings details. Each element of details provides information about a given passenger compressed into a string of length 15. The system is such that:
The first ten characters consist of the phone number of passengers.
The next character denotes the gender of the person.
The following... | 2727 | biweekly-contest-104 | 0 | 2023-05-13T00:00:00 | def countSeniors(self, details: List[str]) -> int:
pass | countSeniors | easy | [{'input': '["7868190130M7522", "5303914400F9211", "9273338290F4010"]', 'output': '2', 'testtype': 'functional'}, {'input': '["1313579440F2036", "2921522980M5644"]', 'output': '0', 'testtype': 'functional'}] | [
"Here is the Python solution for the problem:\n\n```python\nfrom typing import List\n\ndef countSeniors(details: List[str]) -> int:\n count = 0\n for detail in details:\n age = int(detail[11:13])\n if age > 60:\n count += 1\n return count\n```\n\nThis function iterates over each st... | [
1,
1,
1,
1,
1,
1,
1,
1
] |
sum-in-a-matrix | You are given a 0-indexed 2D integer array nums. Initially, your score is 0. Perform the following operations until the matrix becomes empty:
From each row in the matrix, select the largest number and remove it. In the case of a tie, it does not matter which number is chosen.
Identify the highest number amongst all th... | 2728 | biweekly-contest-104 | 0 | 2023-05-13T00:00:00 | def matrixSum(self, nums: List[List[int]]) -> int:
pass | matrixSum | medium | [{'input': '[[7, 2, 1], [6, 4, 2], [6, 5, 3], [3, 2, 1]]', 'output': '15', 'testtype': 'functional'}, {'input': '[[1]]', 'output': '1', 'testtype': 'functional'}] | [
"Here is the Python code to solve the problem:\n\n```python\nfrom typing import List\n\ndef matrixSum(nums: List[List[int]]) -> int:\n score = 0\n while nums:\n # Find the maximum number in each row\n max_num = max(row) for row in nums\n # Add the maximum number to the score\n scor... | [
0,
0,
0,
0,
0,
0,
0,
0
] |
maximum-or | You are given a 0-indexed integer array nums of length n and an integer k. In an operation, you can choose an element and multiply it by 2.
Return the maximum possible value of nums[0] | nums[1] | ... | nums[n - 1] that can be obtained after applying the operation on nums at most k times.
Note that a | b denotes the bi... | 2730 | biweekly-contest-104 | 0 | 2023-05-13T00:00:00 | def maximumOr(self, nums: List[int], k: int) -> int:
pass | maximumOr | medium | [{'input': '[12, 9]\n1', 'output': '30', 'testtype': 'functional'}, {'input': '[8, 1, 2]\n2', 'output': '35', 'testtype': 'functional'}] | [
"Here is a Python solution for the problem:\n\n```python\nfrom typing import List\n\ndef maximumOr(nums: List[int], k: int) -> int:\n # Initialize the maximum value to 0\n max_val = 0\n \n # Iterate over each number in the array\n for num in nums:\n # Calculate the maximum value by applying th... | [
0,
0,
0,
0,
0,
0,
0,
0
] |
maximum-strength-of-a-group | You are given a 0-indexed integer array nums representing the score of students in an exam. The teacher would like to form one non-empty group of students with maximal strength, where the strength of a group of students of indices i_0, i_1, i_2, ... , i_k is defined as nums[i_0] * nums[i_1] * nums[i_2] * ... * nums[i_k... | 2754 | biweekly-contest-105 | 0 | 2023-05-27T00:00:00 | def maxStrength(self, nums: List[int]) -> int:
pass | maxStrength | medium | [{'input': '[3, -1, -5, 2, 5, -9]', 'output': '1350', 'testtype': 'functional'}, {'input': '[-4, -5, -4]', 'output': '20', 'testtype': 'functional'}] | [
"Here is the Python code to solve the problem:\n\n```python\nfrom typing import List\n\ndef maxStrength(nums: List[int]) -> int:\n nums.sort()\n n = len(nums)\n if n == 1:\n return nums[0]\n if n == 2:\n return max(nums[0], nums[1])\n if n == 3:\n return max(nums[0], nums[1] * nu... | [
0,
0,
0,
0,
0,
0,
0,
0
] |
extra-characters-in-a-string | You are given a 0-indexed string s and a dictionary of words dictionary. You have to break s into one or more non-overlapping substrings such that each substring is present in dictionary. There may be some extra characters in s which are not present in any of the substrings.
Return the minimum number of extra character... | 2755 | biweekly-contest-105 | 0 | 2023-05-27T00:00:00 | def minExtraChar(self, s: str, dictionary: List[str]) -> int:
pass | minExtraChar | medium | [{'input': '"leetscode"\n["leet", "code", "leetcode"]', 'output': '1', 'testtype': 'functional'}, {'input': '"sayhelloworld"\n["hello", "world"]', 'output': '3', 'testtype': 'functional'}] | [
"Here is a Python solution for the problem:\n\n```python\nfrom typing import List\n\ndef minExtraChar(s: str, dictionary: List[str]) -> int:\n n = len(s)\n dp = [0] * (n + 1)\n \n for i in range(1, n + 1):\n dp[i] = dp[i - 1] + 1\n for word in dictionary:\n if s[i - len(word):i]... | [
1,
1,
1,
1,
1,
1,
1,
1
] |
buy-two-chocolates | You are given an integer array prices representing the prices of various chocolates in a store. You are also given a single integer money, which represents your initial amount of money.
You must buy exactly two chocolates in such a way that you still have some non-negative leftover money. You would like to minimize the... | 2756 | biweekly-contest-105 | 0 | 2023-05-27T00:00:00 | def buyChoco(self, prices: List[int], money: int) -> int:
pass | buyChoco | easy | [{'input': '[1, 2, 2]\n3', 'output': '0', 'testtype': 'functional'}, {'input': '[3, 2, 3]\n3', 'output': '3', 'testtype': 'functional'}] | [
"Here is the Python code to solve the problem:\n\n```python\nfrom typing import List\n\ndef buyChoco(prices: List[int], money: int) -> int:\n prices.sort()\n return money - (prices[0] + prices[1])\n```\n\nThis function first sorts the list of prices in ascending order. Then it subtracts the sum of the first t... | [
0,
0,
1,
1,
0,
1,
1,
1
] |
count-of-integers | You are given two numeric strings num1 and num2 and two integers max_sum and min_sum. We denote an integer x to be good if:
num1 <= x <= num2
min_sum <= digit_sum(x) <= max_sum.
Return the number of good integers. Since the answer may be large, return it modulo 10^9 + 7.
Note that digit_sum(x) denotes the sum of the ... | 2757 | weekly-contest-348 | 0 | 2023-06-04T00:00:00 | def count(self, num1: str, num2: str, min_sum: int, max_sum: int) -> int:
pass | count | hard | [{'input': '"1"\n"12"\n1\n8', 'output': '11', 'testtype': 'functional'}, {'input': '"1"\n"5"\n1\n5', 'output': '5', 'testtype': 'functional'}] | [
"Here is a Python solution for the problem:\n\n```python\ndef count(num1: str, num2: str, min_sum: int, max_sum: int) -> int:\n mod = 10**9 + 7\n n1 = len(num1)\n n2 = len(num2)\n \n # Initialize a 2D array to store the number of good integers\n dp = [[0] * (max_sum + 1) for _ in range(n1 + 1)]\n ... | [
0,
0,
0,
0,
0,
0,
0,
0
] |
find-the-distinct-difference-array | You are given a 0-indexed array nums of length n.
The distinct difference array of nums is an array diff of length n such that diff[i] is equal to the number of distinct elements in the suffix nums[i + 1, ..., n - 1] subtracted from the number of distinct elements in the prefix nums[0, ..., i].
Return the distinct diff... | 2777 | weekly-contest-344 | 0 | 2023-05-07T00:00:00 | def distinctDifferenceArray(self, nums: List[int]) -> List[int]:
pass | distinctDifferenceArray | easy | [{'input': '[1, 2, 3, 4, 5]', 'output': '[-3, -1, 1, 3, 5]', 'testtype': 'functional'}, {'input': '[3, 2, 3, 4, 2]', 'output': '[-2, -1, 0, 2, 3]', 'testtype': 'functional'}] | [
"Here is the Python code to solve the problem:\n\n```python\nfrom typing import List\n\ndef distinctDifferenceArray(nums: List[int]) -> List[int]:\n n = len(nums)\n prefix = [0] * n\n suffix = [0] * n\n distinct = set()\n \n # Calculate prefix array\n for i in range(n):\n distinct.add(nu... | [
0,
0,
0,
0,
0,
0,
0,
0
] |
number-of-adjacent-elements-with-the-same-color | There is a 0-indexed array nums of length n. Initially, all elements are uncolored (has a value of 0).
You are given a 2D integer array queries where queries[i] = [index_i, color_i].
For each query, you color the index index_i with the color color_i in the array nums.
Return an array answer of the same length as querie... | 2779 | weekly-contest-344 | 0 | 2023-05-07T00:00:00 | def colorTheArray(self, n: int, queries: List[List[int]]) -> List[int]:
pass | colorTheArray | medium | [{'input': '4\n[[0, 2], [1, 2], [3, 1], [1, 1], [2, 1]]', 'output': '[0, 1, 1, 0, 2]', 'testtype': 'functional'}, {'input': '1\n[[0, 100000]]', 'output': '[0]', 'testtype': 'functional'}] | [
"Here is the Python code to solve the problem:\n\n```python\nfrom typing import List\n\ndef colorTheArray(n: int, queries: List[List[int]]) -> List[int]:\n color = [0] * n\n count = [0] * n\n result = [0] * len(queries)\n \n for i, query in enumerate(queries):\n index, color_i = query\n ... | [
0,
0,
0,
0,
0,
0,
0,
0
] |
power-of-heroes | You are given a 0-indexed integer array nums representing the strength of some heroes. The power of a group of heroes is defined as follows:
Let i_0, i_1, ... ,i_k be the indices of the heroes in a group. Then, the power of this group is max(nums[i_0], nums[i_1], ... ,nums[i_k])^2 * min(nums[i_0], nums[i_1], ... ,nums... | 2784 | biweekly-contest-104 | 0 | 2023-05-13T00:00:00 | def sumOfPower(self, nums: List[int]) -> int:
pass | sumOfPower | hard | [{'input': '[2, 1, 4]', 'output': '141', 'testtype': 'functional'}, {'input': '[1, 1, 1]', 'output': '7', 'testtype': 'functional'}] | [
"Here is the Python code to solve the problem:\n\n```python\nfrom typing import List\n\ndef sumOfPower(nums: List[int]) -> int:\n MOD = 10**9 + 7\n n = len(nums)\n nums.sort()\n ans = 0\n \n for i in range(n):\n ans = (ans + (nums[i]**2) * (n - i)) % MOD\n \n return ans\n```\n\nThis c... | [
0,
0,
0,
0,
0,
0,
0,
0
] |
semi-ordered-permutation | You are given a 0-indexed permutation of n integers nums.
A permutation is called semi-ordered if the first number equals 1 and the last number equals n. You can perform the below operation as many times as you want until you make nums a semi-ordered permutation:
Pick two adjacent elements in nums, then swap them.
Re... | 2785 | weekly-contest-348 | 0 | 2023-06-04T00:00:00 | def semiOrderedPermutation(self, nums: List[int]) -> int:
pass | semiOrderedPermutation | easy | [{'input': '[2, 1, 4, 3]', 'output': '2', 'testtype': 'functional'}, {'input': '[2, 4, 1, 3]', 'output': '3', 'testtype': 'functional'}, {'input': '[1, 3, 4, 2, 5]', 'output': '0', 'testtype': 'functional'}] | [
"Here is the Python code to solve the problem:\n\n```python\nfrom typing import List\n\ndef semiOrderedPermutation(nums: List[int]) -> int:\n n = len(nums)\n first_index = nums.index(1)\n last_index = nums.index(n)\n \n if first_index == 0 and last_index == n-1:\n return 0\n \n if first_... | [
0,
0,
0,
0,
0,
0,
0,
0
] |
find-the-longest-semi-repetitive-substring | You are given a 0-indexed string s that consists of digits from 0 to 9.
A string t is called a semi-repetitive if there is at most one consecutive pair of the same digits inside t. For example, 0010, 002020, 0123, 2002, and 54944 are semi-repetitive while 00101022, and 1101234883 are not.
Return the length of the longe... | 2786 | biweekly-contest-106 | 0 | 2023-06-10T00:00:00 | def longestSemiRepetitiveSubstring(self, s: str) -> int:
pass | longestSemiRepetitiveSubstring | medium | [{'input': '"52233"', 'output': '4', 'testtype': 'functional'}, {'input': '"5494"', 'output': '4', 'testtype': 'functional'}, {'input': '"1111111"', 'output': '2', 'testtype': 'functional'}] | [
"Here is a Python solution for the problem:\n\n```python\ndef longestSemiRepetitiveSubstring(s: str) -> int:\n max_length = 0\n current_length = 0\n last_digit = None\n\n for digit in s:\n if digit == last_digit:\n current_length += 1\n else:\n current_length = 2\n ... | [
0,
0,
0,
0,
0,
0,
0,
0
] |
find-the-losers-of-the-circular-game | There are n friends that are playing a game. The friends are sitting in a circle and are numbered from 1 to n in clockwise order. More formally, moving clockwise from the i^th friend brings you to the (i+1)^th friend for 1 <= i < n, and moving clockwise from the n^th friend brings you to the 1^st friend.
The rules of t... | 2791 | weekly-contest-345 | 0 | 2023-05-14T00:00:00 | def circularGameLosers(self, n: int, k: int) -> List[int]:
pass | circularGameLosers | easy | [{'input': '5\n2', 'output': '[4, 5]', 'testtype': 'functional'}, {'input': '4\n4', 'output': '[2, 3, 4]', 'testtype': 'functional'}] | [
"Here is the Python code to solve the problem:\n\n```python\nfrom typing import List\n\ndef circularGameLosers(n: int, k: int) -> List[int]:\n # Initialize the position of the ball\n position = 0\n \n # Initialize the set of friends who have received the ball\n received = set()\n \n # Loop unti... | [
0,
0,
0,
0,
0,
0,
0,
0
] |
neighboring-bitwise-xor | A 0-indexed array derived with length n is derived by computing the bitwise XOR (⊕) of adjacent values in a binary array original of length n.
Specifically, for each index i in the range [0, n - 1]:
If i = n - 1, then derived[i] = original[i] ⊕ original[0].
Otherwise, derived[i] = original[i] ⊕ original[i + 1].
Given... | 2792 | weekly-contest-345 | 0 | 2023-05-14T00:00:00 | def doesValidArrayExist(self, derived: List[int]) -> bool:
pass | doesValidArrayExist | medium | [{'input': '[1, 1, 0]', 'output': 'true', 'testtype': 'functional'}, {'input': '[1, 1]', 'output': 'true', 'testtype': 'functional'}, {'input': '[1, 0]', 'output': 'false', 'testtype': 'functional'}] | [
"To solve this problem, we need to determine if there exists a binary array `original` that, when processed through the bitwise XOR operation, results in the given `derived` array. Here's a step-by-step approach to solve this problem:\n\n1. **Understand the Problem**: The `derived` array is formed by XORing adjacen... | [
0,
0,
0,
0,
0,
0,
0,
0
] |
minimum-string-length-after-removing-substrings | You are given a string s consisting only of uppercase English letters.
You can apply some operations to this string where, in one operation, you can remove any occurrence of one of the substrings "AB" or "CD" from s.
Return the minimum possible length of the resulting string that you can obtain.
Note that the string co... | 2800 | weekly-contest-346 | 0 | 2023-05-21T00:00:00 | def minLength(self, s: str) -> int:
pass | minLength | easy | [{'input': '"ABFCACDB"', 'output': '2', 'testtype': 'functional'}, {'input': '"ACBBD"', 'output': '5', 'testtype': 'functional'}] | [
"Here is a Python solution for the problem:\n\n```python\ndef minLength(s: str) -> int:\n while \"AB\" in s or \"CD\" in s:\n s = s.replace(\"AB\", \"\").replace(\"CD\", \"\")\n return len(s)\n```\n\nThis solution works by repeatedly removing all occurrences of \"AB\" and \"CD\" from the string until n... | [
1,
1,
1,
1,
1,
1,
1,
1
] |
find-the-punishment-number-of-an-integer | Given a positive integer n, return the punishment number of n.
The punishment number of n is defined as the sum of the squares of all integers i such that:
1 <= i <= n
The decimal representation of i * i can be partitioned into contiguous substrings such that the sum of the integer values of these substrings equals i.... | 2802 | weekly-contest-346 | 0 | 2023-05-21T00:00:00 | def punishmentNumber(self, n: int) -> int:
pass | punishmentNumber | medium | [{'input': '10', 'output': '182', 'testtype': 'functional'}, {'input': '37', 'output': '1478', 'testtype': 'functional'}] | [
"Here is a Python solution for the problem:\n\n```python\ndef punishmentNumber(n: int) -> int:\n def is_punishment_number(num):\n for i in range(1, int(num**0.5) + 1):\n if num % i == 0:\n if sum(int(c) for c in str(i * i)) == i:\n return True\n return F... | [
0,
0,
0,
0,
0,
0,
0,
0
] |
painting-the-walls | You are given two 0-indexed integer arrays, cost and time, of size n representing the costs and the time taken to paint n different walls respectively. There are two painters available:
A paid painter that paints the i^th wall in time[i] units of time and takes cost[i] units of money.
A free painter that paints any wa... | 2808 | weekly-contest-350 | 0 | 2023-06-18T00:00:00 | def paintWalls(self, cost: List[int], time: List[int]) -> int:
pass | paintWalls | hard | [{'input': '[1, 2, 3, 2]\n[1, 2, 3, 2]', 'output': '3', 'testtype': 'functional'}, {'input': '[2, 3, 4, 2]\n[1, 1, 1, 1]', 'output': '4', 'testtype': 'functional'}] | [
"Here is the Python code to solve the problem:\n\n```python\nfrom typing import List\n\ndef paintWalls(cost: List[int], time: List[int]) -> int:\n n = len(cost)\n dp = [[0] * (n + 1) for _ in range(n + 1)]\n \n for i in range(1, n + 1):\n for j in range(1, n + 1):\n if j >= time[i - 1]... | [
0,
0,
0,
0,
0,
0,
0,
0
] |
collecting-chocolates | You are given a 0-indexed integer array nums of size n representing the cost of collecting different chocolates. The cost of collecting the chocolate at the index i is nums[i]. Each chocolate is of a different type, and initially, the chocolate at the index i is of i^th type.
In one operation, you can do the following ... | 2810 | weekly-contest-349 | 0 | 2023-06-11T00:00:00 | def minCost(self, nums: List[int], x: int) -> int:
pass | minCost | medium | [{'input': '[20, 1, 15]\n5', 'output': '13', 'testtype': 'functional'}, {'input': '[1, 2, 3]\n4', 'output': '6', 'testtype': 'functional'}] | [
"Here is the Python code to solve the problem:\n\n```python\nfrom typing import List\n\ndef minCost(nums: List[int], x: int) -> int:\n n = len(nums)\n total_cost = 0\n for i in range(n):\n total_cost += nums[i]\n for i in range(n):\n total_cost += x\n return total_cost\n```\n\nThis code... | [
0,
0,
0,
0,
0,
0,
0,
0
] |
determine-the-minimum-sum-of-a-k-avoiding-array | You are given two integers, n and k.
An array of distinct positive integers is called a k-avoiding array if there does not exist any pair of distinct elements that sum to k.
Return the minimum possible sum of a k-avoiding array of length n.
| 2811 | weekly-contest-359 | 0 | 2023-08-20T00:00:00 | def minimumSum(self, n: int, k: int) -> int:
pass | minimumSum | medium | [{'input': '5\n4', 'output': '18', 'testtype': 'functional'}, {'input': '2\n6', 'output': '3', 'testtype': 'functional'}] | [
"Here is a Python solution for the problem:\n\n```python\ndef minimumSum(n: int, k: int) -> int:\n # Initialize the sum to 0\n sum = 0\n \n # Iterate through the first n/2 numbers\n for i in range(1, n//2 + 1):\n # Add the current number to the sum\n sum += i\n \n # If the... | [
0,
0,
0,
0,
0,
0,
0,
0
] |
find-the-maximum-achievable-number | You are given two integers, num and t.
An integer x is called achievable if it can become equal to num after applying the following operation no more than t times:
Increase or decrease x by 1, and simultaneously increase or decrease num by 1.
Return the maximum possible achievable number. It can be proven that there ... | 2812 | weekly-contest-353 | 0 | 2023-07-09T00:00:00 | def theMaximumAchievableX(self, num: int, t: int) -> int:
pass | theMaximumAchievableX | easy | [{'input': '4\n1', 'output': '6', 'testtype': 'functional'}, {'input': '3\n2', 'output': '7', 'testtype': 'functional'}] | [
"Here is the Python code to solve the problem:\n\n```python\ndef theMaximumAchievableX(num: int, t: int) -> int:\n return num + 2 * t\n```\n\nThis function simply returns the sum of `num` and `2 * t`. This is because each operation increases or decreases `x` by 1, and `num` is increased or decreased by 1 simulta... | [
1,
1,
1,
1,
1,
1,
1,
1
] |
lexicographically-smallest-palindrome | You are given a string s consisting of lowercase English letters, and you are allowed to perform operations on it. In one operation, you can replace a character in s with another lowercase English letter.
Your task is to make s a palindrome with the minimum number of operations possible. If there are multiple palindrom... | 2816 | weekly-contest-346 | 0 | 2023-05-21T00:00:00 | def makeSmallestPalindrome(self, s: str) -> str:
pass | makeSmallestPalindrome | easy | [{'input': '"egcfe"', 'output': '"efcfe"', 'testtype': 'functional'}, {'input': '"abcd"', 'output': '"abba"', 'testtype': 'functional'}, {'input': '"seven"', 'output': '"neven"', 'testtype': 'functional'}] | [
"Here is the Python code to solve the problem:\n\n```python\ndef makeSmallestPalindrome(s: str) -> str:\n left, right = 0, len(s) - 1\n while left < right:\n if s[left] != s[right]:\n s[left] = s[right]\n left += 1\n right -= 1\n return s\n```\n\nThis function works by compa... | [
0,
0,
0,
0,
0,
0,
0,
0
] |
minimum-cost-to-make-all-characters-equal | You are given a 0-indexed binary string s of length n on which you can apply two types of operations:
Choose an index i and invert all characters from index 0 to index i (both inclusive), with a cost of i + 1
Choose an index i and invert all characters from index i to index n - 1 (both inclusive), with a cost of n - i... | 2817 | weekly-contest-347 | 0 | 2023-05-28T00:00:00 | def minimumCost(self, s: str) -> int:
pass | minimumCost | medium | [{'input': '"0011"', 'output': '2', 'testtype': 'functional'}, {'input': '"010101"', 'output': '9', 'testtype': 'functional'}] | [
"Here is the Python code to solve the problem:\n\n```python\ndef minimumCost(s: str) -> int:\n n = len(s)\n cost = 0\n for i in range(n):\n if s[i] == '0':\n cost += i + 1\n else:\n cost += n - i\n return cost\n```\n\nThis function works by iterating through the strin... | [
0,
0,
0,
0,
0,
0,
0,
0
] |
remove-trailing-zeros-from-a-string | Given a positive integer num represented as a string, return the integer num without trailing zeros as a string.
| 2819 | weekly-contest-347 | 0 | 2023-05-28T00:00:00 | def removeTrailingZeros(self, num: str) -> str:
pass | removeTrailingZeros | easy | [{'input': '"51230100"', 'output': '"512301"', 'testtype': 'functional'}, {'input': '"123"', 'output': '"123"', 'testtype': 'functional'}] | [
"Here is the Python code to solve the problem:\n\n```python\ndef removeTrailingZeros(num: str) -> str:\n return num.rstrip('0')\n```\n\nThe `rstrip` method in Python is used to remove trailing characters from a string. In this case, we are removing the trailing zeros from the string `num`.",
"Here is the Pytho... | [
1,
1,
1,
1,
1,
1,
1,
1
] |
End of preview. Expand in Data Studio
README.md exists but content is empty.
- Downloads last month
- 7