content
stringlengths
250
2.36k
labels
dict
test
stringlengths
42
359
id
int64
1
140
Write a Python function according to the function name and the problem description in the docstring below. from typing import List def is_new_year(numbers: List[int]): """ Given a list containing four numbers. First, calculate the square of the first number. For the second number, check if it is divisible by 3. If it is, add it to the result, otherwise subtract it. Multiply the resulting value by the third number three times. For the fourth number, calculate the sum of its digits and compare it with the first number. If the sum is greater, add the fourth number to the result, otherwise keep the result unchanged. If the final result equals 2024, return the string "Happy New Year", otherwise return "Whoops"."""
{ "difficulty_type": "Complex" }
assert is_new_year([2, 0, 2, 4]) == "Whoops" assert is_new_year([3, 5, 6, 1160]) == "Happy New Year"
101
Write a Python function according to the function name and the problem description in the docstring below. from typing import List def second_smaller_number(nums: List[int]) -> List[int]: """Given a non-negative number array, for each number in it, find the second number smaller than it that appears after it. If none exists, represent it as -1."""
{ "difficulty_type": "Complex" }
assert second_smaller_number([1,1,1]) == [-1,-1,-1] assert second_smaller_number([6,5,4,3,2,1,0,3]) == [4, 3, 2, 1, 0, -1, -1, -1]
102
Write a Python function according to the function name and the problem description in the docstring below. from typing import List def stock_scheme(n: int, total_profit: int, cost: List[int], profit: List[int]): """You have n dollars and plan to purchase goods from a wholesale market. For the i-th item, the cost price is cost[i] dollars, and selling it generates a profit of profit[i] dollars. If your target total profit is total_profit, how many purchasing schemes do you have? Note that you are not obligated to use all of your money. The answer can be large, return it modulo 10**9+7"""
{ "difficulty_type": "Complex" }
assert stock_scheme(5, 1, [1, 2], [4, 3]) == 3 assert stock_scheme(5, 3, [2, 2], [2, 3]) == 2
103
Write a Python function according to the function name and the problem description in the docstring below. from typing import List import heapq def time_passing_door(arrival: List[int], state: List[int]) -> List[int]: """There are n people, numbered from 0 to n - 1. There is a door that each person can only pass through once, either to enter or to leave, which takes one second. You are given a non-decreasing integer array `arrival` of length n, where `arrival[i]` is the time when the i-th person arrives at the door. You are also given an array `state` of length n, where `state[i]` is 0 if the i-th person wishes to enter through the door, and 1 if they wish to leave. If two or more people want to use the door at the same time, the following rules must be followed: - If the door was not used in the previous second, the person who wants to leave will leave first. - If the door was used to enter in the previous second, the person who wants to enter will enter first. - If the door was used to leave in the previous second, the person who wants to leave will leave first. - If multiple people want to go in the same direction (either all enter or all leave), the person with the smallest number will pass through the door first. Return an array `answer` of length n, where `answer[i]` is the time (in seconds) when the i-th person passes through the door. Note: - Only one person can pass through the door each second. - To follow the above rules, a person may wait near the door without passing through to enter or leave."""
{ "difficulty_type": "Complex" }
assert time_pass_door([0,0,0], [1,0,1]) == [0,2,1] assert time_pass_door([0,0,1,1,2,7,8,8,9,10,10,11,13], [1,1,1,1,1,1,1,1,1,1,1,1,1]) == [0,1,2,3,4,7,8,9,10,11,12,13,14]
104
Write a Python function according to the function name and the problem description in the docstring below. from typing import List def space_with_most_talks(n: int, talks: List[List[int]]) -> int: """You are an organizer of an international conference, now you have n rooms numbered from 0 to n - 1 and some talks represented by a 2D array `talks` where `talks[i] = [start_i, end_i]` represents a scheduled presentation during the half-closed interval `[start_i, end_i)` (including a and not including b), you need to assign talks to spaces according to the following rules: - Assign each talk to the available space with the lowest number. - If no spaces are available, delay the presentation until space is freed, its duration stays unchanged. - When a space becomes available, prioritize presentations with earlier start times for assignment. Identify and return the number of the space that hosts the most presentations. In case of a tie, return the space with the lowest number. Note that all the values of start_i are unique."""
{ "difficulty_type": "Complex" }
assert space_with_most_talks(2, [[0,6],[1,7],[2,9],[3,5]]) == 0 assert space_with_most_talks(3, [[1,15],[2,10],[3,7],[5,8],[6,9]]) == 1
105
Write a Python function according to the function name and the problem description in the docstring below. from typing import List def candy_probability(candy: List[int]) -> float: """ Given 2n candies of k different flavors. You will be given an integer array candies of size k where candies[i] is the number of candies of flavor i. All the candies will be mixed uniformly at random, then we will allocate the first n candies to the first bowl and the remaining n candies to the second bowl (Please read the explanation of the second sample carefully). Please be aware that the two bowls are viewed as distinct. For example, if we have two candies of flavors a and b, and two bowls [] and (), then the allocation [a] (b) is viewed differently than the allocation [b] (a) (Please read the explanation of the first sample carefully). Return the likelihood of the two bowls containing the same quantity of distinct candies. Answers with a 10-5 deviation from the actual value will be considered correct. Example 1:"""
{ "difficulty_type": "Complex" }
assert candy_probability([1,1]) == 1.00000 assert candy_probability([2,1,1]) == 0.66667
106
Write a Python function according to the function name and the problem description in the docstring below. from typing import List def mini_operations(shells: str) -> int: """ Dylan embarked on a spring journey to the beach, where he gathered a mix of blue and green seashells along the shore. Upon returning, he organized these seashells into a beginning set he named "shells," which exclusively includes the lowercase letters 'b' for blue shells and 'g' for green shells. The letter 'b' signifies a blue shell, while 'g' stands for a green shell. Dylan aspired to reorganize the shells in his set into three segments: "blue, green, blue." While each segment might vary in quantity, they must all contain at least one shell. Dylan can switch out a blue shell for a green one or vice versa whenever he rearranges the set. What is the minimum number of switches Dylan must perform to achieve his desired sorting?"""
{ "difficulty_type": "Complex" }
assert mini_operations("bbbgggbbbgggbb") == 2 assert mini_operations("bgb") == 0
107
Write a Python function according to the function name and the problem description in the docstring below. from collections import defaultdict from typing import List def find_word_on_board(board: List[List[str]], words: List[str]) -> List[str]: """Given an alphabet 'board' of m*n, please use the letters on the alphabet board to form words. Words can only be connected horizontally and vertically, and cannot be reused in a word. Please output the words that can be formed with the letters on the alphabet board and exist in the list 'words'. m == board.length n == board[i].length 1 <= m, n <= 12 board[i][j] is a lowercase English letter. 1 <= words.length <= 3 * 104 1 <= words[i].length <= 10 words[i] consists of lowercase English letters. All the strings of words are unique."""
{ "difficulty_type": "Complex" }
assert find_word_on_board([["o","a","a","n"],["e","t","a","e"],["i","h","k","r"],["i","f","l","v"]], ["oath","pea","eat","rain"]) == ["eat","oath"] assert find_word_on_board([["a","b"],["c","d"]], ["abcb"]) == []
108
Write a Python function according to the function name and the problem description in the docstring below. from functools import lru_cache from typing import List def clean_up_fallen_leaves(grid: List[List[int]]) -> int: """There are two robots sweeping fallen leaves in an m*n matrix grid. The number in each grid represents the number of fallen leaves in the area. Robot 1 starts from the upper left corner grid (0,0), and robot 2 starts from the upper right corner grid (0, n-1). Please follow the rules below to return the maximum number of fallen leaves that robots can collect. 1. Starting from grid (i,j), the robot can move to grid (i+1, j-1), (i+1, j) or (i+1, j+1). 2. The robot collects all fallen leaves wherever it passes. 3. When robots arrive at the same grid at the same time, only one of them will work. 4. The robot cannot move outside of the grid at any time. 5. The robot must finally reach the bottom row of the grid. m == grid.length n == grid[i].length 2 <= m, n <= 70 0 <= grid[i][j] <= 100"""
{ "difficulty_type": "Complex" }
assert clean_up_fallen_leaves([[1,0,0,0,0,0,1],[2,0,0,0,0,3,0],[2,0,9,0,0,0,0],[0,3,0,5,4,0,0],[1,0,2,3,0,0,6]]) == 28 assert clean_up_fallen_leaves([[1,1],[1,1]]) == 4
109
Write a Python function according to the function name and the problem description in the docstring below. from typing import List def max_perimeter(grid:List[List[int]])->int: """Given a row x col two-dimensional grid map grid, where grid[i][j] = 1 indicates land and grid[i][j] = 0 indicates water. Islands are always surrounded by water, and each island can only be formed by adjacent land connections in a horizontal and/or vertical direction. There is no `` lake'' in the island. ("Lake" means that the waters are within the island and are not connected to the waters around the island). The grid is a square with a side length of 1. There are several islands in this body of water. Find the longest perimeter of all the islands and return its perimeter."""
{ "difficulty_type": "Complex" }
assert max_perimeter([[1,1,0,0,0],[1,1,0,0,0],[0,0,1,0,0],[0,0,0,1,1]]) == 8 assert max_perimeter([[1,1,1,1,0],[1,1,0,1,0],[1,1,0,0,0],[0,0,0,0,0]]) == 16
110
Write a Python function according to the function name and the problem description in the docstring below. from typing import List def make_two_equivalent(a: List[int], b: List[int]) -> str: """ Define an operation as follows 1. choose range [l, r] such that 0 <= l <= r <= len(a), 2 . for i in range(l, r), set a[i] = max(a[l], a[l+1],..,a[r]). Suppose we can do any times of above operations (maybe zero), determin if we can make list a equal to list b. Output "YES" if we can, otherwise "No""""
{ "difficulty_type": "Complex" }
assert make_two_equivalent([1, 2, 3, 2, 4], [1, 3, 3, 2, 4]) == "YES" assert make_two_equivalent([1, 1, 2], [2, 1, 2]) == "NO"
111
Write a Python function according to the function name and the problem description in the docstring below. def magic_equal(x: int, y: int) -> int: """ You are given two positive integers x and y. In one operation, you can choose to do one of the following: If x is a multiple of 11, divide x by 11. If x is a multiple of 5, divide x by 5. Decrement x by 1. Increment x by 1. Return the minimum number of operations needed to make x and y equal."""
{ "difficulty_type": "Complex" }
assert magic_equal(26,1) == 3 assert magic_equal(25,30) == 5
112
Write a Python function according to the function name and the problem description in the docstring below. from typing import List def maximum_num_of_blocks(area: List[int], mass: List[int]) -> int: """When playing with building blocks, we usually place small and light building blocks on top of larger and heavier building blocks. Given the mass and area of ​​the building blocks, please calculate the maximum number of building blocks that can be stacked? height.length == weight.length <= 10000"""
{ "difficulty_type": "Complex" }
assert maximum_num_of_blocks([65,70,56,75,60,68], [100,150,90,190,95,110]) == 6 assert maximum_num_of_blocks([6, 7, 8], [2, 1, 6]) == 2
113
Write a Python function according to the function name and the problem description in the docstring below. from typing import List def maximal_rectangle(matrix: List[List[str]]) -> int: """There is an open space in Alice's backyard. She divided the open space into m*n parts, and each part can choose to grow wheat or not. Alice's strategy for using m*n pieces of land is now given, represented by a binary matrix called matrix. 0 means not planting wheat, and 1 means planting wheat.What is the largest rectangular area for growing wheat in Alice's backyard? Return its area. rows == matrix.length cols == matrix[0].length 1 <= row, cols <= 200 matrix[i][j] is 0 or 1."""
{ "difficulty_type": "Complex" }
assert maximal_rectangle([[1,1,1]]) == 3 assert maximal_rectangle([[1,0,1],[1,1,0],[1,1,0]]) == 4
114
Write a Python function according to the function name and the problem description in the docstring below. from typing import Optional, List def lexical_order(n: int) -> Optional[List[int]]: """ Given an integer n, return all numbers in the range [1, n] according to the following requirements: If n is odd, odd numbers should come before even numbers, and both odd and even numbers should be sorted in lexicographical order. If n is even, even numbers should come before odd numbers, and both even and odd numbers should be sorted in lexicographical order. If n is less than or equal to zero, return empty list."""
{ "difficulty_type": "Complex" }
assert lexical_order(13) == [1, 11, 13, 3, 5, 7, 9, 10, 12, 2, 4, 6, 8] assert lexical_order(0) == []
115
Write a Python function according to the function name and the problem description in the docstring below. from typing import List def find_days(pencils: List[int], k: int) -> int: """ There are n pencils arranged in a row, each with a unique number, and initially, all of them are unused. Every day, an employee will take away one pencil, until after n days, all the pencils are taken. Given an array of pencils of length n, where pencils[i] = x indicates that on the (i+1)th day, the employee will take the pencil at position x, with i starting from 0 and x starting from 1. Now, given an integer k, please calculate the number of days needed to reach the situation where exactly two pencils are taken, and there are k untouched pencils between them. If this situation cannot be reached, return -1. Hints: + n == pencils.length + 1 <= n <= 2 * 10^4 + 1 <= pencils[i] <= n + pencils is a permutation of numbers from 1 to n + 0 <= k <= 2 * 10^4"""
{ "difficulty_type": "Complex" }
assert find_days([1,3,2], 1) == 2 assert find_days([1,2,3], 1) == -1
116
Write a Python function according to the function name and the problem description in the docstring below. from typing import List def milk_deliver(scores: List[int]) -> int: """You're a milk delivery man, there are n families on a street, they order milk from you all year round and each family gets a milk credit. Now it's an annual reward, the milk company gives gifts to these families based on their credit, you need to distribute the gifts according to the following rules: -Each family is allocated at least one gift. -Neighboring families with higher points will get more gifts. -Prepare the least number of gifts Please calculate how many gifts these families need."""
{ "difficulty_type": "Complex" }
assert milk_deliver([1,1,2]) == 4 assert milk_deliver([3,1,2]) == 5
117
Write a Python function according to the function name and the problem description in the docstring below. from typing import List def get_treasure(labyrinth: List[List[str]], clues: str) -> int: """There is a treasure in an M*N labyrinth that is marked with a sign at each location, which is a letter or a number. You inadvertently get a clue to the treasure. This clue does not necessarily lead to the final treasure, but you can only move forward according to this clue. At the same time, the hint has some invalid information, such as non-numbers and characters. There's also a rule that you can't go through a grid again after you've gone through it. If you can execute all the valid parts of the hint, the hint is correct and you return True, if the hint breaks in the middle, you return False!"""
{ "difficulty_type": "Complex" }
assert get_treasure([["A","B","C","5"],["11","6","C","S"],["A","D","E","2"]], "#AB%CCED") == True assert get_treasure(["A","B","C","E"],["S","F","C","S"],["A","D","E","E"], "ABCB") == False
118
Write a Python function according to the function name and the problem description in the docstring below. from typing import List def extract_numbers(s:str)->List[int]: """Given a sentence which contain multiple numbers. The numbers are not next to each other and they are represented in English format. For example, 123 is represented as "One Hundred Twenty Three". Return the numbers in the sentence in a list."""
{ "difficulty_type": "Complex" }
assert extract_numbers("One hundred twenty three") == [123] assert extract_numbers("One hundred and one thousand") == [100,1000]
119
Write a Python function according to the function name and the problem description in the docstring below. from typing import List def rectangular_land(mat: List[List[int]]) -> int: """There is an open space in Alice's backyard. She divided the open space into m*n parts, and each part can choose to grow wheat or not. Alice's strategy for using m*n pieces of land is now given, represented by a binary matrix called mat. 0 means not planting wheat, and 1 means planting wheat. How many different rectangular plots of land are there in Alice's backyard that are all planted with wheat? m == grid.length n == grid[i].length 1 <= m, n <= 150 grid[i][j] is 0 or 1."""
{ "difficulty_type": "Complex" }
assert rectangular_land([[1,1,1]]) == 6 assert rectangular_land([[1,0,1],[1,1,0],[1,1,0]])276 == 13
120
Write a Python function according to the function name and the problem description in the docstring below. def custom_sort(dictionary): """Given a dictionary with non-negative integers as keys, sort the key-value pairs in the dictionary where the values are strings. Arrange these key-value pairs in descending order based on the count of ones in the ternary representation of the keys. In case of equal counts of ones, arrange them in ascending order based on the alphabetical order of the values. Return the sorted list."""
{ "difficulty_type": "Codesense" }
assert custom_sort({1: '"apple"', 2: 123, 3: 'banana', 4: 'orange', 5: 456, 6: 'cherry'}) == [(4, 'orange'), (1, '"apple"'), (3, 'banana'), (6, 'cherry')]
121
Write a Python function according to the function name and the problem description in the docstring below. import re def find_float(data: str): """Find the unique floating-point number in the given string, with priority given to those represented in scientific notation."""
{ "difficulty_type": "Codesense" }
assert find_float("Its height is 1e6 kilometer") == "1e6" assert find_float("Its weight is 123. gram") == "123."
122
Write a Python function according to the function name and the problem description in the docstring below. from typing import List def replace_non_coprime_number(nums: List[int]) -> List[int]: """You are given an array of integers nums. Perform the following steps: Find any two adjacent numbers in nums that are non-coprime. If no such numbers are found, stop the process. Otherwise, delete the two numbers and replace them with their LCM (Least Common Multiple). Repeat this process as long as you keep finding two adjacent non-coprime numbers. Return the final modified array. It can be shown that replacing adjacent non-coprime numbers in any arbitrary order will lead to the same result. The test cases are generated such that the values in the final array are less than or equal to 108. Two values x and y are non-coprime if GCD(x, y) > 1 where GCD(x, y) is the Greatest Common Divisor of x and y."""
{ "difficulty_type": "Codesense" }
assert replace_non_coprime_number([6,4,3,2,7,6,2]) == [12,7,6] assert replace_non_coprime_number([5,5,4,3,8,7,3]) == [5,4,3,8,7,3]
123
Write a Python function according to the function name and the problem description in the docstring below. def get_specific_permutation(N: int, M: int) -> str: """Given a integer N (1 <= N <= 9), there are n! different permutations that can be formed using digits less than or equal to N. If we arrange these permutations in ascending order, for example, when n=3, the 1st result is 123, and the 6th result is 321. Please find the Mth permutation when given the values of N and the positive integer M."""
{ "difficulty_type": "Codesense" }
assert get_specific_permutation(3, 6) == "321" assert get_specific_permutation(4, 9) == "2314"
124
Write a Python function according to the function name and the problem description in the docstring below. from typing import List def generate_string_permutation(raw_data: List[str], replaced_str: str) -> int: """Generate all permutations of raw_data elements, excluding one element per permutation. Replace up to three occurrences of replaced_str in each permutation with an empty string. Return the number of unique strings."""
{ "difficulty_type": "Codesense" }
assert generate_string_permutation(["a", "b", "c"], "a") == 4 assert generate_string_permutation(["hello", "world", "rock", "great"], "or") == 24
125
Write a Python function according to the function name and the problem description in the docstring below. from typing import List def string_count(s: str, queries: List[List[int]]) -> List[int]: """ Given a string 's' that is indexed starting at 0, and a two-dimensional array 'queries' consisting of pairs [li, ri], which defines a substring in 's' from the index 'li' to 'ri' inclusive, determine the number of substrings for each query that have matching starting and ending characters. Provide the results as an array 'ans', where 'ans[i]' corresponds to the query 'queries[i]'. A substring is considered to have matching ends if the first and last characters are identical."""
{ "difficulty_type": "Codesense" }
assert string_count("abcaab", [[0,0],[1,4],[2,5],[0,5]]) == [1,5,5,10] assert string_count("abcd", [[0,3]]) == [4]
126
Write a Python function according to the function name and the problem description in the docstring below. from typing import List def max_score(prices: List[int]) -> int: """ Given a 1-indexed integer array, 'prices', where each element represents the price of a certain stock on the corresponding day, you are required to linearly select some elements from the array. A subsequence selection is termed 'indexes', a 1-indexed integer sub-array of length k. This selection is considered 'linear' if the difference between the price of the 'j-th' stock and the price of the '(j - 1)'-th stock is equal to the difference between their indexes in each case, where 1 < j <= k. The total achievable score from a given selection is the sum of all prices corresponding to the selected indexes. What is the maximum score attainable through linear selection?"""
{ "difficulty_type": "Codesense" }
assert max_score([1,5,3,7,8]) == 20 assert max_score([5,6,7,8,9]) == 35
127
Write a Python function according to the function name and the problem description in the docstring below. from typing import List def list_identifier(ids: List[int], parentIds: List[int], target: int) -> List[int]: """ In a digital family tree, there are n individuals each assigned a unique identifier. The connections between them are tracked with two arrays, ids and parentIds, with ids[i] representing each individual's unique identifier, and parentIds[i] representing the identifier of their immediate ancestor. Every individual in this tree is a descendant with exactly one ancestor, except for the founding ancestor who has no predecessor, indicated by a parentIds[i] value of 0. When a lineage is set to be discontinued, both the target ancestor and all of their descendants are to be included in the discontinuation. You are to determine the set of identifiers for those who are discontinued when an individual with a specific identifier is targeted. List all identifiers of the individuals in this lineage. The order of the list is not important."""
{ "difficulty_type": "Codesense" }
assert list_identifier([1,3,10,5], [3,0,5,3], 5) == [5,10] assert list_identifier([1], [0], 1) == [1]
128
Write a Python function according to the function name and the problem description in the docstring below. def divide_string(s: str) -> bool: """ A string composed entirely of repetitive characters is known as a uniform string. For example, "1111" and "33" are uniform strings. By contrast, "123" is not a uniform string. Rule: Given a numeric string s, divide the string into some uniform substrings, such that there is exactly one uniform substring of length 2 and all other uniform substrings have a length of 3. If the string s can be divided according to the rule mentioned above, return true; otherwise, return false. Substrings are sequences of contiguous characters within the original string."""
{ "difficulty_type": "Codesense" }
assert divide_string("000111000") == False assert divide_string("00011111222") == True
129
Write a Python function according to the function name and the problem description in the docstring below. from typing import List def count_subs(s: str, count: int) -> int: """ Given a string `s` that starts with an index of 0 and only includes lowercase English letters, along with an integer `count`, your task is to find and return the number of substrings within `s` where each type of letter appears exactly `count` times. This would make it an equal-count substring. Note that a substring is a contiguous sequence of non-empty characters within the string."""
{ "difficulty_type": "Codesense" }
assert count_subs("aaabcbbcc", 3) == 3 assert count_subs("abcd", 2) == 0
130
Write a Python function according to the function name and the problem description in the docstring below. from typing import List def remove_add_game(nums: List[int]) -> List[int]: """ Given a 1-indexed integer array `prices`, where `prices[i]` is the price of a certain stock on day `i`, your task is to linearly select some elements from `prices`. A selection `indexes`, where `indexes` is a 1-indexed integer array of length `k` and is a subsequence of the array `[1, 2, ..., n]`, is considered linear if the following condition holds: For each `1 < j <= k`, `prices[indexes[j]] - prices[indexes[j - 1]] == indexes[j] - indexes[j - 1]`. A subsequence of an array is a new array generated from the original array by deleting some elements (possibly none), without changing the relative order of the remaining elements. The score of selecting `indexes` is equal to the sum of the following array: `[prices[indexes[1]], prices[indexes[2]], ..., prices[indexes[k]]`. Return the maximum score of a linear selection."""
{ "difficulty_type": "Codesense" }
assert remove_add_game([1,2,3,4]) == [2,1,4,3] assert remove_add_game([10,1]) == [10,1]
131
Write a Python function according to the function name and the problem description in the docstring below. from typing import List def minimum_coins(prices: List[int]) -> int: """ You're in a fruit market where each fruit has a price in gold coins, listed in prices. (index start from 1) The market offers a special deal: when you buy a fruit for its price, you get the next few fruits for free. The number of free fruits you get is equal to the number of the fruit you bought. For example, if you buy the 3rd fruit, you get the next 3 fruits for free. You can also choose to buy a fruit that's available for free to get its corresponding number of free fruits. Your goal is to find out the least amount of gold coins needed to buy all the fruits."""
{ "difficulty_type": "Codesense" }
assert minimum_coins([1,2,3,4]) == 3 assert minimum_coins([2, 1]) == 2
132
Write a Python function according to the function name and the problem description in the docstring below. from typing import List def find_words(words: List[str], x: str) -> List[int]: """ Given an array of strings called 'words' and a character 'x', return an array of indexes. These indexes should correspond to the words in 'words' that contain the character 'x'. The order of indexes in the return array does not matter."""
{ "difficulty_type": "Codesense" }
assert find_words(["bo","god"], "o") == [0,1] assert find_words(["guo","god"], "g") == [0,1]
133
Write a Python function according to the function name and the problem description in the docstring below. from typing import List def split_to_digits(nums: List[int]) -> List[int]: """ You are given a positive integer array nums. You need to return an array answer, where you split each integer in nums into its digits and place them in answer in the same order as they appeared in nums. To split an integer into digits means to arrange the digits of the integer in the original order they appeared in to form an array."""
{ "difficulty_type": "Codesense" }
assert split_to_digits([1,2,3,4]) == [1,2,3,4] assert split_to_digits([22,13,45]) == [2,2,1,3,4,5]
134
Write a Python function according to the function name and the problem description in the docstring below. from typing import List def combine_items_by_value(items1: List[List[int]], items2: List[List[int]]) -> List[List[int]]: """ You are given two 2D integer arrays items1 and items2 representing two sets of items. Each array items has the following properties: - items[i] = [valuei, weighti] where valuei is the value of the ith item and weighti is the weight of the ith item. - The values of the items in items are unique. Return a 2D array ret where ret[i] = [valuei, weighti] such that weighti is the sum of the weights of all items with value equal to valuei."""
{ "difficulty_type": "Codesense" }
assert combine_items_by_value([[1,1]],[[2,1]]) == [[1,1],[2,1]] assert combine_items_by_value([[1,3],[2,2]][[1,2]]) == [[1,5],[2,2]]
135
Write a Python function according to the function name and the problem description in the docstring below. def count_full_weeks(year: int, month: int) -> int: """ Given a specific year 'year' and month 'month', return the number of complete weeks in that month. Note: + 1583 <= year <= 2100 + 1 <= month <= 12"""
{ "difficulty_type": "Codesense" }
assert count_full_weeks(2024, 1) == 4 assert count_full_weeks(2000, 2) == 3
136
Write a Python function according to the function name and the problem description in the docstring below. def work_or_rest(day: str) -> str: """There is a Chinese saying called "go fishing for three days and dry the nets for two days", it means work by fits and starts. Someone has been working this way since January 1, 2000. I want to know if this person is working or resting on a certain day, please help me solve it. Given a day, the format is yyyy-mm-dd, retrun his state "work" or "rest". if the input date does not exist or early than January 1, 2000, return "illegal input""""
{ "difficulty_type": "Codesense" }
assert work_or_rest("2000-1-2") == "work" assert work_or_rest("2000-1-5") == "rest" assert work_or_rest("2000-2-30") == "illegal input"
137
Write a Python function according to the function name and the problem description in the docstring below. from typing import List def k_closest(points: List[List[int]], target_point:List[int], k: int) -> List[int]: """Given an array called points, where points[i]=[xi, yi, zi] denotes a point in X-Y-Z space, and xi, yi, zi are integers. Also given a target point, return the k closest points to the target point, where distance is defined as euclidean distance. The returned k points should be sorted in ascending order by distance, and if there are points with equal distances, the one with smaller dictionary order by xiyizi is prioritized."""
{ "difficulty_type": "Codesense" }
assert k_closest([[1,3,1],[-2,2,1]], [1,2,1], 1) == [[1,3,1]] assert k_closest([[3,3,3],[4,4,4],[-5,-5,-5]], [0,0,0], 2) == [[3,3,3], [4,4,4]]
138
Write a Python function according to the function name and the problem description in the docstring below. def restore_message_order(message: str) -> str: """In an encrypted communication system, messages are encoded by reversing the order of words. However, these messages may be distorted by leading, trailing, or excessive spaces during transmission. Your task is to develop an algorithm to clean and restore these messages, ensuring that words appear in the correct order and are separated by only a single space between them."""
{ "difficulty_type": "Codesense" }
assert restore_message_order(" "apple" ") == "apple" assert restore_message_order(" world hello") == "hello world"
139
Write a Python function according to the function name and the problem description in the docstring below. from typing import List def hamming_distance_sum(integers: List[int]) -> int: """Given an integer array nums, calculate the total number of positions at which the corresponding bits differ amongst all possible pairs of the numbers within the array. Note that every integer is smaller than 1000000000."""
{ "difficulty_type": "Codesense" }
assert hamming_distance_sum([1, 2, 3]) == 4 assert hamming_distance_sum([20, 4, 2]) == 6
140