task_id
stringlengths 5
7
| question
stringlengths 192
1.48k
| test_list
sequencelengths 2
5
| test_function
stringlengths 54
236
| entry_point
stringclasses 1
value | test_matching
stringlengths 57
291
| test_match_function
stringclasses 1
value |
---|---|---|---|---|---|---|
OOP/0 | First, write a **WDS** class using the Python language. Then, within the WDS class, create a public function called **without_duplicates** to implement finding the length of the longest substring in a given string **s** that does not contain any duplicate characters. | [
"assert candidate(\"abcabcbb\")==3",
"assert candidate(\"bbbbb\")==1",
"assert candidate(\"pwwkew\")==3"
] | def test_run(content1):
return WDS().without_duplicates(content1) | test_run | assert candidate([["class WDS", "def without_duplicates"]]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/1 | First, design a class called **MNS** in Python, which has an instance attribute called **machines**, a private function called **private_Ministeps**, and a public function called **public_Ministeps**. Then, implement the following problem in the private function **private_Ministeps**. Finally, call the private function private_Ministeps in the public function **public_Ministeps** and return the result.
Problem: There are **n** super washing machines placed in a row, and it is unknown whether there are clothes inside each machine. You can choose any **m** machines and move one piece of clothing from each selected machine to an adjacent machine. Return the minimum number of steps required to make the number of clothes remaining in each machine equal. | [
"assert candidate([1,0,5])==3",
"assert candidate([0,3,0])==2",
"assert candidate([0,2,0])==-1"
] | def test_run(content1):
return MNS(content1).public_Minimum_number_steps() | test_run | assert candidate([["class MNS", "def public_Ministeps", "def __private_Ministeps"],["class MNS", "def public_Ministeps", "def _private_Ministeps"]]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/3 | First, write a class called **FTM** using the Python language. Then, within the **FTM** class, create a public function called **find_the_median** that returns the median of two sorted arrays, **nums1** and **nums2**. | [
"assert candidate([1,3], [2])==2.00000",
"assert candidate([1,2], [3,4])==2.50000"
] | def test_run(content1,content2):
return FTM().find_the_median(content1,content2) | test_run | assert candidate([["class FTM", "def find_the_median"]]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/4 | First, write a **PDSB** class using the Python language. Then, within the **PDSB** class, implement a public **pa_substring** function to find the longest palindrome substring in string **s**. | [
"assert candidate(\"babad\")==\"bab\"",
"assert candidate(\"cbbd\")==\"bb\""
] | def test_run(content1):
return PDSB().pa_substring(content1) | test_run | assert candidate([["class PDSB", "def pa_substring"]]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/5 | First, write a **ZZPTN** class using the Python language, then write a public **Zigzag_pattern** function in the **ZZPTN** class to solve the following problem.
Problem: Given a string **s** and an integer **numRows**, arrange the string **s** from top to bottom and from left to right in a Z shape according to the given **numRows**. | [
"assert candidate(\"PAYPALISHIRING\", 3)==\"PAHNAPLSIIGYIR\"",
"assert candidate(\"PAYPALISHIRING\", 4)==\"PINALSIGYAHRPI\"",
"assert candidate(\"A\", 1)==\"A\""
] | def test_run(content1,content2):
return ZZPTN().Zigzag_pattern(content1,content2) | test_run | assert candidate([["class ZZPTN", "def Zigzag_pattern"]]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/6 | First, write an **ITOC** class using the Python language. Then, within the **ITOC** class, create a public function called **Invert_outcome** that takes a 32-bit signed integer **x** as input and returns the result of reversing the numerical part of **x**. | [
"assert candidate(123)==321",
"assert candidate(-123)==-321",
"assert candidate(120)==21",
"assert candidate(0)==0"
] | def test_run(content1):
return ITOC().Invert_outcome(content1) | test_run | assert candidate([["class ITOC", "def Invert_outcome"]]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/7 | First, write a **PDIT** class using Python language. Then, within the **PDIT** class, write a public function named **Palindromic_integer**. This function should determine whether a given integer **x** is a palindromic integer. If it is, the function should return True; otherwise, it should return False. | [
"assert candidate(121)==True",
"assert candidate(-121)==False",
"assert candidate(10)==False"
] | def test_run(content1):
return PDIT().Palindromic_integer(content1) | test_run | assert candidate([["class PDIT", "def Palindromic_integer"]]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/8 | First, write a **RLMH** class using the Python language. Then, within the **RLMH** class, create a public **rule_matching** function that implements a regular expression matching for a given string **s** and a character pattern **p**, using the following rules: 1. '.' matches any single character; 2. '*' matches zero or more occurrences of the preceding element. | [
"assert candidate(\"aa\", \"a\")==False",
"assert candidate(\"aa\", \"a*\")==True",
"assert candidate(\"ab\", \".*\")==True"
] | def test_run(content1,content2):
return RLMH().rule_matching(content1,content2) | test_run | assert candidate([["class RLMH", "def rule_matching"]]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/9 | First, write a **LCMP** class using the Python language. Then, within the **LCMP** class, create a public function called **longest_common_prefix** to find the longest common prefix among an array of strings. If no common prefix exists, return an empty string "". | [
"assert candidate([\"flower\",\"flow\",\"flight\"])==\"fl\"",
"assert candidate([\"dog\",\"racecar\",\"car\"])==\"\""
] | def test_run(content1,content2,content3):
return LCMP().longest_common_prefix(content1,content2,content3) | test_run | assert candidate([["class LCMP", "def longest_common_prefix"]]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/10 | First, write a **TSOTN** class using the Python language. Then, within the **TSOTN** class, create a public function called **sum_three_numbers**. This function takes in an integer array called **nums** with a length of **n**, and a target value called **target**. The function selects three integers from **nums** in such a way that their sum is closest to the target value. Finally, the function returns the sum of these three numbers. | [
"assert candidate([-1,2,1,-4], 1)==2",
"assert candidate([0,0,0], 1)==0"
] | def test_run(content1,content2):
return TSOTN().sum_three_numbers(content1,content2) | test_run | assert candidate([["class TSOTN", "def sum_three_numbers"]]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/11 | Firstly, write a class **VLD_ST** using the Python language, then write a public function **valid_string** within the **VLD_ST** class to judge whether a given string **s**, which only includes '(',')','{','}','[',']', is valid or not.
A valid string must meet the following conditions:
1. The left bracket must be closed by the right bracket of the same type;
2. The left brackets must be closed in the correct order;
3. Each right bracket has a corresponding left bracket of the same type. | [
"assert candidate(\"()\")==True",
"assert candidate(\"()[]{}\")==True",
"assert candidate(\"(]\")==False"
] | def test_run(content1):
return VLD_ST().valid_string(content1) | test_run | assert candidate([["class VLD_ST", "def valid_string"]]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/12 | First, write a **VDPT** class using the Python language. Then, within the **VDPT** class, create a public **valid_parentheses** function. This function should take an integer **n** as input, representing the number of pairs of parentheses to generate. The function should then print out all possible and valid combinations of parentheses. | [
"assert candidate(3)==[\"((()))\",\"(()())\",\"(())()\",\"()(())\",\"()()()==[\"((()))\",\"(()())\",\"(())()\",\"()(())\",\"()()()\"]",
"assert candidate(1)==[\"()==[\"()\"]",
"assert candidate(\"(]\")==False"
] | def test_run(content1):
return VDPT().valid_parentheses(content1) | test_run | assert candidate([["class VDPT", "def valid_parentheses"]]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/13 | First, write a **NLAR** class using the Python language. Then, within the **NLAR** class, create a public function called **new_length_removal**. This function should take an array called **nums** and a value called **val** as input. The function should remove all elements in the array that are equal to **val**, and return the new length of the array after removal. | [
"assert candidate([3,2,2,3], 3)==2",
"assert candidate([0,1,2,2,3,0,4,2], 2)==5"
] | def test_run(content1,content2):
return NLAR().new_length_removal(content1,content2) | test_run | assert candidate([["class NLAR", "def new_length_removal"]]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/14 | First, write a class **FMIS** using the Python language. Then, within the **FMIS** class, write a public function **find_matching_items** that, given two strings **haystack** and **needle**, finds the index of the first matching item of the **needle** string in the **haystack** string (index starts from 0). If the **needle** is not part of the **haystack**, return -1. | [
"assert candidate(\"sadbutsad\", \"sad\")==0",
"assert candidate(\"leetcode\", \"leeto\")==-1"
] | def test_run(content1,content2):
return FMIS().find_matching_items(content1,content2) | test_run | assert candidate([["class FMIS", "def find_matching_items"]]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/15 | First, write an **LVPSS** class using the Python language. Then, within the **LVPSS** class, write a public function named **long_valid_substring**. This function should find the length of the longest valid (correctly formatted and continuous) parenthesis substring in a given string that only contains '(' and ')'. | [
"assert candidate(\"(()\")==2",
"assert candidate(\"\")==0",
"assert candidate(\")()())\")==4"
] | def test_run(content1):
return LVPSS().long_valid_substring(content1) | test_run | assert candidate([["class LVPSS", "def long_valid_substring"]]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/16 | First, write a class named **FTGV** using the Python language. Then, within the **FTGV** class, write a public function called **find_target_value** that, given a sorted array and a target value, finds the target value in the array and returns its index. If the target value does not exist in the array, it returns the position where it would be inserted in order. | [
"assert candidate([1,3,5,6], 5)==2",
"assert candidate([1,3,5,6], 2)==1",
"assert candidate([1,3,5,6], 7)==4"
] | def test_run(content1,content2):
return FTGV().find_target_value(content1,content2) | test_run | assert candidate([["class FTGV", "def find_target_value"]]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/17 | First, write a class **FSAEP** using the Python language, then write a public function **finding_positions** in the **LVPSS** class. Given an integer array **nums** sorted in non-decreasing order and a target value **target**, this function finds the starting and ending positions of the given target value in the array. If the target value **target** does not exist in the array, return [-1, -1]. | [
"assert candidate([5,7,7,8,8,10], 8)==[3,4]",
"assert candidate([5,7,7,8,8,10], 6)==[-1,-1]",
"assert candidate([], 0)==[-1,-1]"
] | def test_run(content1,content2):
return LVPSS().long_valid_substring(content1,content2) | test_run | assert candidate([["class FSAEP", "def finding_positions"]]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/18 | Firstly, write an **NCBT** class using the Python language. Then, within the **NCBT** class, write a public function named **numeric_combination**. Given a set of candidate numbers **candidates** and a target number **target**, this function should find all combinations in **candidates** that can sum up to the **target** and return them in the form of a list. | [
"assert candidate([10,1,2,7,6,1,5], 8)==[[1,1,6],[1,2,5],[1,7],[2,6]]",
"assert candidate([2,5,2,1,2], 5)==[[1,2,2],[5]]"
] | def test_run(content1,content2):
return NCBT().numeric_combination(content1,content2) | test_run | assert candidate([["class NCBT", "def numeric_combination"]]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/19 | First, create a class called **TSPI** using the Python language. Then, within the **TSPI** class, write a public function called **smallest_positive_integer**. This function should take an unsorted array of integers called **nums** as input and find the smallest positive integer that is not present in the array. | [
"assert candidate([1,2,0])==3",
"assert candidate([3,4,-1,1])==2",
"assert candidate([7,8,9,11,12])==1"
] | def test_run(content1):
return TSPI().smallest_positive_integer(content1) | test_run | assert candidate([["class TSPI", "def smallest_positive_integer"]]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/20 | First, write an **HTRW** class using the Python language, then write a public function named **harvest_rainwater** within the **HTRW** class to solve the following problem.
Problem: Given **n** non-negative integers representing the height of each pillar of width 1 in the diagram, calculate how much rainwater can be collected after it rains with the pillars arranged in this way. | [
"assert candidate([0,1,0,2,1,0,1,3,2,1,2,1])==6",
"assert candidate([4,2,0,3,2,5])==9"
] | def test_run(content1):
return HTRW().harvest_rainwater(content1) | test_run | assert candidate([["class HTRW", "def harvest_rainwater"]]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/21 | First, write a class called **STFM** using the Python language. Then, within the **STFM** class, create a public function called **string_form**. This function should take two non-negative integers, **num1** and **num2**, represented as strings, and return their product as a string. | [
"assert candidate(\"123\", \"456\")==\"56088\"",
"assert candidate(\"2\", \"3\")==\"6\""
] | def test_run(content1,content2):
return HTRW().harvest_rainwater(content1,content2) | test_run | assert candidate([["class STFM", "def string_form"]]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/22 | First, write a **PMTTN** class using the Python language. Then, within the **PMTTN** class, create a public **permutation** function that takes an array **nums** without duplicate numbers as input and returns all possible permutations. | [
"assert candidate([1,2,3])==[[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]",
"assert candidate([0,1])==[[0,1],[1,0]]",
"assert candidate([1])==[[1]]"
] | def test_run(content1):
return PMTTN().permutation(content1) | test_run | assert candidate([["class PMTTN", "def permutation"]]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/23 | First, write a **UQPTT** class using the Python language, then write a public **unique_permutations** function within the **UQPTT** class to solve the following problem.
Problem: Given a sequence of **nums** containing duplicate numbers, return all unique permutations. | [
"assert candidate([1,1,2])==[[1,1,2],[1,2,1],[2,1,1]]",
"assert candidate([1,2,3])==[[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]"
] | def test_run(content1):
return UQPTT().unique_permutations(content1) | test_run | assert candidate([["class UQPTT", "def unique_permutations"]]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/24 | First, write a class called **RTICW** using the Python language. Then, within the **RTICW** class, create a public function called **rotate_image_clockwise**. This function should take a 2D matrix, represented by the variable matrix, with dimensions n × n, which represents an image. The function should rotate the image clockwise by 90 degrees. | [
"assert candidate([[1,2,3],[4,5,6],[7,8,9]])==[[7,4,1],[8,5,2],[9,6,3]]",
"assert candidate([[5,1,9,11],[2,4,8,10],[13,3,6,7],[15,14,12,16]])==[[15,13,2,5],[14,3,4,1],[12,6,8,9],[16,7,10,11]]"
] | def test_run(content1):
return RTICW().rotate_image_clockwise(content1) | test_run | assert candidate([["class RTICW", "def rotate_image_clockwise"]]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/25 | First, write a class called **AAGM** using the Python language. Then, within the **AAGM** class, create a public function called **anagram** that takes an array of strings as input. This function should group together anagrams and return the result as a list. | [
"assert candidate([\"eat\", \"tea\", \"tan\", \"ate\", \"nat\", \"bat\"])==[[\"bat\"],[\"nat\",\"tan\"],[\"ate\",\"eat\",\"tea\"]]",
"assert candidate([\"\"])==[[\"\"]]",
"assert candidate([\"a\"])==[[\"a\"]]"
] | def test_run(content1):
return AAGM().anagram(content1) | test_run | assert candidate([["class AAGM", "def anagram"]]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/26 | First, write a **PFTN** class using the Python language. Then, within the **PFTN** class, create a public **power_function** function that calculates the integer power of **x** to the n-th degree. | [
"assert candidate(2.00000, 10)==1024.00000",
"assert candidate(2.10000, 3)==9.26100",
"assert candidate(2.00000, -2)==0.25000"
] | def test_run(content1,content2):
return PFTN().power_function(content1,content2) | test_run | assert candidate([["class PFTN", "def power_function"]]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/27 | First, write a class called **FDSB** using the Python language. Then, within the **FDSB** class, write a public function called **find_subarray** that takes an integer array called **nums** as input. This function will find a contiguous subarray within **nums** that has the maximum sum. | [
"assert candidate([-2,1,-3,4,-1,2,1,-5,4])==6",
"assert candidate([1])==1",
"assert candidate([5,4,-1,7,8])==23"
] | def test_run(content1):
return FDSB().find_subarray(content1) | test_run | assert candidate([["class FDSB", "def find_subarray"]]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/28 | First, write a class called **CWSO** using the Python language. Then, within the **CWSO** class, create a public function called **clockwise_spiral_order**. This function takes a matrix with **m** rows and **n** columns as input and returns all the elements in the matrix in a clockwise spiral order. | [
"assert candidate([[1,2,3],[4,5,6],[7,8,9]])==[1,2,3,6,9,8,7,4,5]",
"assert candidate([[1,2,3,4],[5,6,7,8],[9,10,11,12]])==[1,2,3,4,8,12,11,10,9,5,6,7]"
] | def test_run(content1):
return CWSO().clockwise_spiral_order(content1) | test_run | assert candidate([["class CWSO", "def clockwise_spiral_order"]]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/29 | First, write a class called **MMJL** using the Python language. Then, within the **MMJL** class, write a public function called **maximum_jump_length**. Given a non-negative integer array called **nums**, this function should determine whether it is possible to reach the last index based on the following rules: 1. Initially, start at the first index of the array. 2. Each element in the array represents the maximum length that can be jumped from that position. If it is possible to reach the last index, the function should return True; otherwise, it should return False. | [
"assert candidate([2,3,1,1,4])==True",
"assert candidate([3,2,1,0,4])==False"
] | def test_run(content1):
return MMJL().maximum_jump_length(content1) | test_run | assert candidate([["class MMJL", "def maximum_jump_length"]]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/30 | Firstly, write a class named **MOLI** using Python language. Then, in the **MOLI** class, write a public function called **merge_overlapping_intervals** that takes an array **intervals** representing a collection of ranges, where each individual range is represented as intervals[i] = [start_i, end_i]. This function should merge all overlapping ranges and return an array of non-overlapping ranges that exactly cover all the ranges in the input. | [
"assert candidate([[1,3],[2,6],[8,10],[15,18]])==[[1,6],[8,10],[15,18]]",
"assert candidate([[1,4],[4,5]])==[[1,5]]"
] | def test_run(content1):
return MOLI().merge_overlapping_intervals(content1) | test_run | assert candidate([["class MOLI", "def merge_overlapping_intervals"]]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/31 | First, write a **STANOL** class using the Python language. Then, within the **STANOL** class, create a public function called **sorted_non_overlapping** that inserts a new interval into a sorted list of non-overlapping intervals, sorted by the starting points of each interval. This function should ensure that the intervals in the list remain sorted and non-overlapping. | [
"assert candidate([[1,3],[6,9]], [2,5])==[[1,5],[6,9]]",
"assert candidate([[1,2],[3,5],[6,7],[8,10],[12,16]], [4,8])==[[1,2],[3,10],[12,16]]",
"assert candidate([], [5,7])==[[5,7]]",
"assert candidate([[1,5]], [2,3])==[[1,5]]",
"assert candidate([[1,5]], [2,7])==[[1,7]]"
] | def test_run(content1,content2):
return STANOL().sorted_non_overlapping(content1,content2) | test_run | assert candidate([["class STANOL", "def sorted_non_overlapping"]]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/32 | First, write a **WDLH** class using the Python language, then write a public **word_length** function in the **WDLH** class to solve the following problem.
Problem: Given a string **s**, the string **s** is composed of several words, separated by some space characters before and after the word, return the length of the last word in the string. | [
"assert candidate(\"Hello World\")==5",
"assert candidate(\" fly me to the moon \")==4",
"assert candidate(\"luffy is still joyboy\")==6"
] | def test_run(content1):
return WDLH().word_length(content1) | test_run | assert candidate([["class WDLH", "def word_length"]]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/33 | First, write an **STP** class using the Python language. Then, in the **STP** class, write a public function named **shortest_path**. Given a m x n grid containing non-negative integers, this function should find a path from the top left corner to the bottom right corner that minimizes the sum of the numbers along the path. | [
"assert candidate([[1,3,1],[1,5,1],[4,2,1]])==7",
"assert candidate([[1,2,3],[4,5,6]])==12"
] | def test_run(content1):
return STP().shortest_path(content1) | test_run | assert candidate([["class STP", "def shortest_path"]]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/34 | First, write a **NNTI** class using the Python language, then write a public **non_negative_integer** function in the **NNTI** class to solve the following problem.
Problem: Given a non-empty array composed of integers representing a non-negative integer, add one to this number, and return the result with the highest digit stored at the beginning of the array.
Note:Each element in the array only stores a single digit (except for the integer 0, this integer will not start with zero). | [
"assert candidate([1,2,3])==[1,2,4]",
"assert candidate([4,3,2,1])==[4,3,2,2]",
"assert candidate([0])==[1]"
] | def test_run(content1):
return NNTI().non_negative_integer(content1) | test_run | assert candidate([["class NNTI", "def non_negative_integer"]]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/35 | First, write a class called **BASTI** using the Python language. Then, within the **BASTI** class, create a public function called **binary_string**. This function should take two binary strings, **a** and **b**, as input and return their sum in the form of a binary string. | [
"assert candidate(\"11\", \"1\")==\"100\"",
"assert candidate(\"1010\", \"1011\")==\"10101\""
] | def test_run(content1,content2):
return BASTI().binary_string(content1,content2) | test_run | assert candidate([["class BASTI", "def binary_string"]]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/36 | First, write a **CRTP** class using the Python language. Then, within the **CRTP** class, implement a public function called **climb_rooftop** to solve the following problem: Suppose you are climbing a staircase and it takes **n** steps to reach the top. At each step, you can either climb 1 or 2 steps. How many distinct ways are there to climb to the top? | [
"assert candidate(2)==2",
"assert candidate(3)==3"
] | def test_run(content1):
return CRTP().climb_rooftop(content1) | test_run | assert candidate([["class CRTP", "def climb_rooftop"]]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/37 | First, write a **TAFER** class using the Python language. Then, within the **TAFER** class, create a public **trans_fomer** function. This function takes two words, **word1** and **word2**, as input and returns the minimum number of operations required to transform **word1** into **word2**. There are three possible operations that can be performed on a word: 1. Inserting a character, 2. Deleting a character, and 3. Replacing a character. | [
"assert candidate(\"horse\", \"ros\")==3",
"assert candidate(\"intention\", \"execution\")==5"
] | def test_run(content1,content2):
return TAFER().trans_fomer(content1,content2) | test_run | assert candidate([["class TAFER", "def trans_fomer"]]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/38 | First, write a class called **STEZ** using the Python language. Then, within the **STEZ** class, create a public function called **element_setting_zero**. This function should take in an m x n matrix as input. If an element in the matrix is 0, it should set all the elements in its corresponding row and column to 0. | [
"assert candidate([[1,1,1],[1,0,1],[1,1,1]])==[[1,0,1],[0,0,0],[1,0,1]]",
"assert candidate([[0,1,2,0],[3,4,5,2],[1,3,1,5]])==[[0,0,0,0],[0,4,5,0],[0,3,1,0]]"
] | def test_run(content1):
return STEZ().element_setting_zero(content1) | test_run | assert candidate([["class STEZ", "def element_setting_zero"]]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/39 | First, implement the **GYHT** class using the Python language. Then, write a public function called **YangHui_Triangle** within the **GYHT** class. This function should take a non-negative integer **numRows** as input and generate the first **numRows** rows of the Yang Hui triangle. | [
"assert candidate(5)==[[1],[1,1],[1,2,1],[1,3,3,1],[1,4,6,4,1]]",
"assert candidate(1)==[[1]]"
] | def test_run(content1):
return GYHT().Generate_Yang_Hui_Triangle(content1) | test_run | assert candidate([["class GYHT", "def YangHui_Triangle"]]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/40 | First, implement the **FTMPA** class using the Python language. Then, write a public function called **Minimum_Path** in the **FTMPA** class. This function should aim to find the minimum path sum from top to bottom in a given **triangle**. | [
"assert candidate([[2],[3,4],[6,5,7],[4,1,8,3]])==11",
"assert candidate([[-10]])==-10"
] | def test_run(content1):
return FTMPA().Find_The_Minimum_Path_And(content1) | test_run | assert candidate([["class FTMPA", "def Minimum_Path"]]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/41 | First, implement the **CMP** class using the Python language. Then, within the **CMP** class, write a public function called **Calculate_Maximum_Profit**. This function should take an array as input and calculate the maximum profit that can be obtained. Each element in the array represents the price of a given stock on the i-th day. It is allowed to complete a maximum of two transactions. | [
"assert candidate([3,3,5,0,0,3,1,4])==6",
"assert candidate([1,2,3,4,5])==4",
"assert candidate([7,6,4,3,1])==0",
"assert candidate([1])==0"
] | def test_run(content1):
return CMP().Calculate_Maximum_Profit(content1) | test_run | assert candidate([["class CMP", "def Calculate_Maximum_Profit"]]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/42 | First, implement the **FTLOTLS** class using the Python language. Then, write a public function called **Longest_Sequence** within the **FTLOTLS** class. This function should take an unsorted integer array called **nums** as input and find the length of the longest sequence of consecutive numbers (the sequence elements do not need to be consecutive in the original array). | [
"assert candidate([100,4,200,1,3,2])==4",
"assert candidate([0,3,7,2,5,8,4,6,0,1])==9"
] | def test_run(content1):
return FTLOTLS().Find_The_Length_Of_The_Longest_Sequence(content1) | test_run | assert candidate([["class FTLOTLS", "def Longest_Sequence"]]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/43 | First, implement the **AF** class using the Python language. Then, within the **AF** class, write a public function called **Area_Fill** that takes a given m x n matrix called **board**, which is composed of characters 'X' and 'O'. The function should find all the regions surrounded by 'X' and fill all the 'O' within these regions with 'X'. | [
"assert candidate([[\"X\",\"X\",\"X\",\"X\"],[\"X\",\"O\",\"O\",\"X\"],[\"X\",\"X\",\"O\",\"X\"],[\"X\",\"O\",\"X\",\"X\"]])==[[\"X\",\"X\",\"X\",\"X\"],[\"X\",\"X\",\"X\",\"X\"],[\"X\",\"X\",\"X\",\"X\"],[\"X\",\"O\",\"X\",\"X\"]]",
"assert candidate([[\"X\"]])==[[\"X\"]]"
] | def test_run(content1):
return AF().Area_Fill(content1) | test_run | assert candidate([["class AF", "def Area_Fill"]]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/44 | First, implement the **SS** class using the Python language. Then, within the **SS** class, write a public function called **Split_String** that takes a string **s** as input and returns all possible partition schemes of **s**, where each substring in the partition is a palindrome. | [
"assert candidate(\"aab\")==[[\"a\",\"a\",\"b\"],[\"aa\",\"b\"]]",
"assert candidate(\"a\")==[[\"a\"]]"
] | def test_run(content1):
return SS().Split_String(content1) | test_run | assert candidate([["class SS", "def Split_String"]]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/45 | First, implement the **MNOD** class using the Python language. Then, within the **MNOD** class, write a public function called **Minimum_Divisions** that takes a string **s** as input. This function should split the string **s** into substrings, where each substring is a palindrome, and return the minimum number of divisions required to satisfy this condition. | [
"assert candidate(\"aab\")==1",
"assert candidate(\"a\")==0",
"assert candidate(\"ab\")==1"
] | def test_run(content1):
return MNOD().Minimum_Number_Of_Divisions(content1) | test_run | assert candidate([["class MNOD", "def Minimum_Divisions"]]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/46 | Firstly, implement the **DSBCD** class using Python language. Then, write a public **distribute_candie** function in the **DSBCD** class to solve the following problem.
Problem: **n** children are standing in a line, and an integer array **ratings** is given to represent the ratings of each child. Candies need to be distributed to these children according to the following requirements:
1. Each child should be allocated at least one candy;
2. The child with a higher rating among two adjacent children will get more candies.
For distributing candies to each child, calculate and return the minimum number of candies that need to be prepared. | [
"assert candidate([1,0,2])==5",
"assert candidate([1,2,2])==4"
] | def test_run(content1):
return DSBCD().distribute_candie(content1) | test_run | assert candidate([["class DSBCD", "def distribute_candie"]]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/47 | First, implement the **ITETAO** class using the Python language. Then, write a public function called **Appeared_Once** in the **ITETAO** class. This function should take a non-empty integer array called **nums** as input. The function should find the element that appears only once in the array, while all other elements appear twice. | [
"assert candidate([2,2,1])==1",
"assert candidate([4,1,2,1,2])==4",
"assert candidate([1])==1"
] | def test_run(content1):
return ITETAO().Identify_The_Element_That_Appeared_Once(content1) | test_run | assert candidate([["class ITETAO", "def Appeared_Once"]]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/48 | Firstly, implement a **JS** class using Python language. Then, in the **JS** class, write a public function named **Judgment_Splicing**. This function should take a string **s** and a list of strings **wordDict** as a dictionary, and determine whether the string **s** can be spliced together using the words that appear in the dictionary. If it can, return True; otherwise, return False. | [
"assert candidate(\"leetcode\", [\"leet\", \"code\"])==True",
"assert candidate(\"applepenapple\", [\"apple\", \"pen\"])==True",
"assert candidate(\"catsandog\", [\"cats\", \"dog\", \"sand\", \"and\", \"cat\"])==False"
] | def test_run(content1,content2):
return JS().Judgment_Splicing(content1,content2) | test_run | assert candidate([["class JS", "def Judgment_Splicing"]]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/49 | First, implement the **CS** class using the Python language. Then, write a public **Constructing_Sentences** function in the **CS** class to create a sentence by adding spaces in a given string **s**, using words from the wordDict string dictionary. The function should return all possible sentences that can be constructed. | [
"assert candidate(\"catsanddog\", [\"cat\",\"cats\",\"and\",\"sand\",\"dog\"])==[\"cats and dog\",\"cat sand dog\"]",
"assert candidate(\"pineapplepenapple\", [\"apple\",\"pen\",\"applepen\",\"pine\",\"pineapple\"])==[\"pine apple pen apple\",\"pineapple pen apple\",\"pine applepen apple\"]",
"assert candidate(\"catsandog\", [\"cats\",\"dog\",\"sand\",\"and\",\"cat\"])==[]"
] | def test_run(content1,content2):
return CS().Constructing_Sentences(content1,content2) | test_run | assert candidate([["class CS", "def Constructing_Sentences"]]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/50 | Firstly, implement the **FTMP** class using Python language. Then, in the **FTMP** class, write a public function named **Most_Points**. This function should take an array of **points** as input, where points[i]=[x_i,y_i] represents a point on the X-Y plane. The function should return how many points can be on the same line at most. | [
"assert candidate([[1,1],[2,2],[3,3]])==3",
"assert candidate([[1,1],[3,2],[5,3],[4,1],[2,3],[1,4]])==4"
] | def test_run(content1):
return FTMP().Find_The_Most_Points(content1) | test_run | assert candidate([["class FTMP", "def Most_Points"]]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/51 | First, implement the **CE** class using the Python language. Then, write a public function called **Calculating_Expressions** in the **CE** class to calculate the arithmetic expression represented by a given string array called **tokens**, which represents the expression in Reverse Polish Notation. The function should calculate the expression and return an integer representing the value of the expression. | [
"assert candidate([\"2\",\"1\",\"+\",\"3\",\"*\"])==9",
"assert candidate([\"4\",\"13\",\"5\",\"/\",\"+\"])==6",
"assert candidate([\"10\",\"6\",\"9\",\"3\",\"+\",\"-11\",\"*\",\"/\",\"*\",\"17\",\"+\",\"5\",\"+\"])==22"
] | def test_run(content1):
return CE().Calculating_Expressions(content1) | test_run | assert candidate([["class CE", "def Calculating_Expressions"]]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/52 | First, implement the **RWO** class using the Python language. Then, write a public function called **Reverse_Word_Order** in the **RWO** class to solve the following problem.
Problem: Given a string **s**, return the order of the words in the reversed string. | [
"assert candidate(\"the sky is blue\")==\"blue is sky the\"",
"assert candidate(\" hello world \")==\"world hello\"",
"assert candidate(\"a good example\")==\"example good a\""
] | def test_run(content1):
return RWO().Reverse_Word_Order(content1) | test_run | assert candidate([["class RWO", "def Reverse_Word_Order"]]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/53 | First, implement the **NCS** class using the Python language. Then, write a public **non_empty_subarray** function in the **NCS** class to solve the following problem:
Problem: Given an integer array **nums**, find the contiguous subarray with the maximum product (the subarray must contain at least one number) and return the product of that subarray. | [
"assert candidate([2,3,-2,4])==6",
"assert candidate([-2,0,-1])==0"
] | def test_run(content1):
return NCS().non_empty_contiguous_subarray(content1) | test_run | assert candidate([["class NCS", "def non_empty_subarray"]]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/54 | First, implement the **PE** class using the Python language. Then, write a public function called **Peak_elements** in the **PE** class to solve the following problem:
Problem: Given an integer array **nums**, find a peak element and return its index.
A peak element is defined as an element that is strictly greater than its adjacent elements on the left and right. | [
"assert candidate([1,2,3,1])==2",
"assert candidate([1,2,1,3,5,6,4])==1",
"assert candidate([1,2,1,3,5,6,4])==5"
] | def test_run(content1):
return PE().Peak_elementes(content1) | test_run | assert candidate([["class PE", "def Peak_elements"]]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/55 | First, implement the **TMDBAE** class using the Python language. Then, write a public function called **adjacent_elements** in the **TMDBAE** class to solve the following problem:
Problem: Given an unordered array **nums**, return the maximum difference between adjacent elements after sorting the array. If the number of elements in the array is less than 2, return 0. | [
"assert candidate([3,6,9,1])==3",
"assert candidate([10])==0"
] | def test_run(content1):
return TMDBAE().The_maximum_difference_between_adjacent_elements(content1) | test_run | assert candidate([["class TMDBAE", "def adjacent_elements"]]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/56 | First, implement the **GME** class using the Python language. Then, write a public function called **get_most_elements** in the **GME** class to solve the following problem:
Problem: Given an array **nums** of size **n**, return the majority element.
The majority element is the element that appears more than ⌊n/2⌋ times in the array. | [
"assert candidate([3,2,3])==3",
"assert candidate([2,2,1,1,1,2,2])==2"
] | def test_run(content1):
return GME().get_most_elements(content1) | test_run | assert candidate([["class GME", "def get_most_elements"]]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/57 | First, implement the **GTNOTZ** class using the Python language. Then, write a public function called **get_trailing** within the **GTNOTZ** class to solve the following problem:
Problem: Given an integer **n**, return the number of trailing zeros in the result of **n!**. | [
"assert candidate(3)==3",
"assert candidate(5)==1"
] | def test_run(content1):
return GTNOTZ().get_the_number_of_trailing_zeros(content1) | test_run | assert candidate([["class GTNOTZ", "def get_trailing"]]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/58 | First, implement the **NNI** class using the Python language. Then, write a public function called **Non_negative_integers** in the **NNI** class to solve the following problem:
Problem: Given a set of non-negative integers **nums**, rearrange the order of each number (without splitting any number) to form the largest possible integer.
Note: The output result may be very large, so you need to return a string instead of an integer. | [
"assert candidate([10,2])==210",
"assert candidate([3,30,34,5,9])==9534330"
] | def test_run(content1):
return NNI().Non_negative_integers(content1) | test_run | assert candidate([["class NNI", "def Non_negative_integers"]]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/59 | First, implement the **IRSID** class using the Python language. Then, write a public function named **sequences_DNA** in the **IRSID** class to solve the following problem:
Problem: DNA sequences are composed of a series of nucleotides abbreviated as 'A', 'C', 'G', and 'T'. When studying DNA, it is useful to identify repetitive sequences in the DNA.
Given a string **s** representing a DNA sequence, return all the 10-letter sequences (substrings) that appear more than once in the DNA molecule. | [
"assert candidate([\"AAAAACCCCCAAAAACCCCCCAAAAAGGGTTT\"])==[\"AAAAACCCCC\",\"CCCCCAAAAA\"]",
"assert candidate(\"AAAAAAAAAAAAA\")==[\"AAAAAAAAAA\"]"
] | def test_run(content1):
return IRSID().Identify_repetitive_sequences_in_DNA(content1) | test_run | assert candidate([["class IRSID", "def sequences_DNA"]]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/60 | First, implement the **ERTTR** class using the Python language. Then, write a public function called **element_rotates** in the **ERTTR** class to solve the following problem:
Problem: Given an integer array **nums**, rotate the elements in the array to the right by **k** positions and return the result. | [
"assert candidate([1,2,3,4,5,6,7],3)==[5,6,7,1,2,3,4]",
"assert candidate([-1,-100,3,99],2)==[3,99,-1,-100]"
] | def test_run(content1,content2):
return ERTTR().element_rotates_to_the_right(content1,content2) | test_run | assert candidate([["class ERTTR", "def element_rotates"]]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/61 | First, implement the **ITBB** class using the Python language. Then, write a public function called **Invert_the_binary_bits** in the **ITBB** class to solve the following problem:
Problem: Reverse the binary bits of a given 32-bit unsigned integer and return the unsigned integer result. | [
"assert candidate(00000010100101000001111010011100)==964176192",
"assert candidate(11111111111111111111111111111101)==3221225471"
] | def test_run(content1):
return ITBB().Invert_the_binary_bits(content1) | test_run | assert candidate([["class ITBB", "def Invert_the_binary_bits"]]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/62 | First, implement the **RTN** class using the Python language. Then, write a public function called **Hamming_weight** in the **RTN** class to solve the following problem:
Problem: Write a function that takes an unsigned integer as input (in the form of a binary string) and returns the number of '1' digits in its binary representation (also known as the Hamming weight). | [
"assert candidate(00000000000000000000000000001011)==3",
"assert candidate(00000000000000000000000010000000)==1",
"assert candidate(11111111111111111111111111111101)==31"
] | def test_run(content1):
return RTN().Returns_the_number(content1) | test_run | assert candidate([["class RTN", "def Hamming_weight"]]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/63 | First, implement the **CTNOI** class using the Python language. Then, write a public function called **number_islands** in the **CTNOI** class to solve the following problem:
Problem: Given a 2D grid consisting of '1' (land) and '0' (water), calculate the number of islands in the grid.
An island is surrounded by water and is formed by connecting adjacent lands horizontally and/or vertically. | [
"assert candidate([[\"1\",\"1\",\"1\",\"1\",\"0\"],[\"1\",\"1\",\"0\",\"1\",\"0\"],[\"1\",\"1\",\"0\",\"0\",\"0\"],[\"0\",\"0\",\"0\",\"0\",\"0\"]])==1",
"assert candidate([[\"1\",\"1\",\"0\",\"0\",\"0\"],[\"1\",\"1\",\"0\",\"0\",\"0\"],[\"0\",\"0\",\"1\",\"0\",\"0\"],[\"0\",\"0\",\"0\",\"1\",\"1\"]])==3"
] | def test_run(content1):
return CTNOI().Calculate_the_number_of_islands(content1) | test_run | assert candidate([["class CTNOI", "def number_islands"]]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/64 | First, implement the **DABA** class using the Python language. Then, write a public function called **Digits_bitwise** in the **DABA** class to solve the following problem:
Problem: Given two integers, **left** and **right**, representing the range [left, right], return the bitwise AND of all numbers in this range (including the endpoints **left** and **right**). | [
"assert candidate(5,7)==4",
"assert candidate(0,0)==0",
"assert candidate(1,2147483647)==0"
] | def test_run(content1,content2):
return DABA().Digits_are_bitwise_and(content1,content2) | test_run | assert candidate([["class DABA", "def Digits_bitwise"]]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/65 | First, implement the **RV** class using the Python language. Then, write a public **Return_value** function in the **RV** class to solve the following problem:
Problem: Given an integer **n**, return the count of prime numbers less than the non-negative integer **n**. | [
"assert candidate(10)==4",
"assert candidate(0)==0",
"assert candidate(1)==0"
] | def test_run(content1):
return RV().Return_value(content1) | test_run | assert candidate([["class RV", "def Return_value"]]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/66 | First, implement the **DIIII** class using Python language, then write a public function called **isomorphic** in the **DIIII** class to solve the following problem.
Problem: Given two strings **s** and **t**, determine whether they are isomorphic. If the characters in **s** can be replaced by some mapping relationship to get **t**, then these two strings are isomorphic. | [
"assert candidate(\"egg\",\"add\")==True",
"assert candidate(\"foo\", \"bar\")==False",
"assert candidate(\"paper\",\"title\")==True"
] | def test_run(content1,content2):
return DIIII().Determine_if_it_is_isomorphic(content1,content2) | test_run | assert candidate([["class DIIII", "def isomorphic"]]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/67 | First, implement the **FTA** class using the Python language. Then, write a public function called **Find_the_array** in the **FTA** class to solve the following problem:
Problem: Given an array of **n** positive integers and a positive integer **target**, find the length of the smallest contiguous subarray [numsl, numsl+1, ..., numsr-1, numsr] whose sum is greater than or equal to the target. If no such subarray exists, return 0. | [
"assert candidate(7, [2,3,1,2,4,3])==2",
"assert candidate(4, [1,4,4])==1",
"assert candidate(11, [1,1,1,1,1,1,1,1])==0"
] | def test_run(content1,content2):
return FTA().Find_the_array(content1,content2) | test_run | assert candidate([["class FTA", "def Find_the_array"]]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/68 | First, implement the **STPD** class using the Python language. Then, write a public function called **Shortest_Palindrome** in the **STPD** class to solve the following problem:
Problem: Given a string **s**, convert it into a palindrome by adding characters at the beginning of the string. Find and return the shortest palindrome that can be obtained using this method. | [
"assert candidate(\"aacecaaa\")==\"aaacecaaa\"",
"assert candidate(\"abcd\")==\"dcbabcd\""
] | def test_run(content1):
return STPD().Shortest_Palindrome(content1) | test_run | assert candidate([["class STPD", "def Shortest_Palindrome"]]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/69 | First, implement the **RTLE** class using the Python language. Then, write a public function **largest_element** in the **RTLE** class to solve the following problem:
Problem: Given an integer array **nums** and an integer **k**, return the k-th largest element in the array. | [
"assert candidate([3,2,1,5,6,4],2)==5",
"assert candidate([3,2,3,1,2,4,5,5,6],4)==4"
] | def test_run(content1,content2):
return RTLE().Returns_the_largest_element(content1,content2) | test_run | assert candidate([["class RTLE", "def largest_element"]]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/70 | First, implement the **GTAC** class using the Python language. Then, write a public function called **additive_combination** in the **GTAC** class to solve the following problem:
Problem: Find all combinations of **k** numbers that add up to **n**, satisfying the following conditions:
1. Only use numbers from 1 to 9.
2. Each number can only be used once.
Return a list of all possible valid combinations. | [
"assert candidate(3,7)==[[1,2,4]]",
"assert candidate(3,9)==[[1,2,6], [1,3,5], [2,3,4]]",
"assert candidate(4,1)==[]"
] | def test_run(content1,content2):
return GTAC().Get_the_additive_combination(content1,content2) | test_run | assert candidate([["class GTAC", "def additive_combination"]]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/71 | First, implement the **JTA** class using the Python language. Then, write a public function called **judging_the_array** in the **JTA** class to solve the following problem:
Problem: Given an integer array **nums**, return True if any value appears at least twice in the array, and False if every element in the array is distinct. | [
"assert candidate([1,2,3,1])==True",
"assert candidate([1,2,3,4])==False",
"assert candidate([1,1,1,3,3,4,3,2,4,2])==True"
] | def test_run(content1):
return JTA().Judging_the_array(content1) | test_run | assert candidate([["class JTA", "def Judging_the_array"]]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/72 | First, implement the **JI** class using the Python language. Then, write a public function called **Judgment_Index** in the **JI** class to solve the following problem:
Problem: Given an integer array **nums** and an integer **k**, determine if there are two distinct indices **i** and **j** in the array such that nums[i] == nums[j] and abs(i - j) <= k. If such indices exist, return True; otherwise, return False. | [
"assert candidate([1,2,3,1])==3",
"assert candidate([1,0,1,1])==1",
"assert candidate([1,2,3,1,2,3])==2"
] | def test_run(content1):
return JI().Judgment_Index(content1) | test_run | assert candidate([["class JI", "def Judgment_Index"]]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/73 | First, implement the **AC** class using the Python language. Then, write a public function called **Array_conditions** in the **AC** class to solve the following problem:
Problem: Given an integer array **nums** and two integers **indexDiff** and **valueDiff**, find the index pair (i, j) that satisfies the following conditions:
1. i != j;
2. abs(i - j) <= indexDiff;
3. abs(nums[i] - nums[j]) <= valueDiff.
If such a pair exists, return True; otherwise, return False. | [
"assert candidate([1,2,3,1],3,0)==True",
"assert candidate([1,5,9,1,5,9],2,3)==False"
] | def test_run(content1,content2,content3):
return AC().Array_conditions(content1,content2,content3) | test_run | assert candidate([["class AC", "def Array_conditions"]]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/74 | First, implement the **FTLS** class using the Python language. Then, write a public function called **largest_square** in the **FTLS** class to solve the following problem:
Problem: Given a 2D matrix consisting of '0' and '1', find the largest square that contains only '1' and return its area. | [
"assert candidate([[\"1\",\"0\",\"1\",\"0\",\"0\"],[\"1\",\"0\",\"1\",\"1\",\"1\"],[\"1\",\"1\",\"1\",\"1\",\"1\"],[\"1\",\"0\",\"0\",\"1\",\"0\"]])==4",
"assert candidate([[\"0\",\"1\"],[\"1\",\"0\"]])==1",
"assert candidate([[\"0\"]])==0"
] | def test_run(content1):
return FTLS().Find_the_largest_square(content1) | test_run | assert candidate([["class FTLS", "def largest_square"]]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/75 | First, implement the **CTMA** class using the Python language. Then, write a public function called **matrix_area** in the **CTMA** class to solve the following problem:
Problem: Given two rectangles on a two-dimensional plane, each formed by lines parallel/vertical to the coordinate axes, calculate and return the total area covered by the two rectangles. Each rectangle is defined by the coordinates of its bottom-left vertex and top-right vertex:
1. The first rectangle is defined by its bottom-left vertex (ax1, ay1) and top-right vertex (ax2, ay2).
2. The second rectangle is defined by its bottom-left vertex (bx1, by1) and top-right vertex (bx2, by2). | [
"assert candidate(-3,0,3,4,0,-1,9,2)==45",
"assert candidate(-2,-2,2,2,-2,-2,2,2)==16"
] | def test_run(content1,content2,content3,content4,content5,content6,content7,content8):
return CTMA().Calculate_the_matrix_area(content1,content2,content3,content4,content5,content6,content7,content8) | test_run | assert candidate([["class CTMA", "def matrix_area"]]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/76 | First, implement the **TAC** class using the Python language. Then, write a public function named **The_array_contains** in the **TAC** class to solve the following problem:
Problem: Given a sorted integer array **nums** with no duplicate elements, return a list of the smallest sorted range intervals that exactly cover all the numbers in the array. In other words, each element in **nums** should be covered by exactly one range interval, and there should be no number **x** that belongs to a range interval but not to **nums**. Each range interval [a, b] in the list should be output in the following format:
1. **a->b** if a != b;
2. **a** if a == b. | [
"assert candidate([0,1,2,4,5,7])==[\"0->2\",\"4->5\",\"7\"]",
"assert candidate([0,2,3,4,6,8,9])==[\"0\",\"2->4\",\"6\",\"8->9\"]"
] | def test_run(content1):
return TAC().The_array_contains(content1) | test_run | assert candidate([["class TAC", "def The_array_contains"]]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/77 | First, implement the **GTAC** class using the Python language. Then, write a public function called **array_count** in the **GTAC** class to solve the following problem:
Problem: Given an integer array of size **n**, find all elements that appear more than ⌊n/3⌋ times. | [
"assert candidate([3,2,3])==[3]",
"assert candidate([1])==[1]",
"assert candidate([1,2])==[1,2]"
] | def test_run(content1):
return GTAC().Get_the_array_count(content1) | test_run | assert candidate([["class GTAC", "def array_count"]]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/78 | Question: Given an integer **n**, please find and return the n-th ugly number.
Please design a **ULYNB** class in Python language based on the above question. The class should have an instance attribute **n**, a private function **private_ugly_number**, and a public function **public_ugly_number**. In the private function **private_ugly_number**, find the n-th ugly number based on the instance attribute **n**. Finally, in the public function **public_ugly_number**, call the private function **private_ugly_number** and return the result. | [
"assert candidate(10)==12",
"assert candidate(1)==1"
] | def test_run(content1):
return ULYNB(content1).public_ugly_number() | test_run | assert candidate([['class ULYNB', 'def _private_ugly_number', 'def public_ugly_number'], ['class ULYNB', 'def __private_ugly_number', 'def public_ugly_number']]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/79 | First, design a **NAR** class using Python language, which has instance attributes **nums**, a private function **private_Number_array**, and a public function **public_Number_array**. Then, in the private function **private_Number_array**, return the numbers in the range [0, n] that do not appear in the array **nums**. Finally, in the public function **public_Number_array**, call the private function **private_Number_array** to return the result. | [
"assert candidate([3,0,1])==2",
"assert candidate([0,1])==2",
"assert candidate([9,6,4,2,3,5,7,0,1])==8",
"assert candidate([0])==1"
] | def test_run(content1):
return NAR(content1).public_Number_array() | test_run | assert candidate([['class NAR', 'def _private_Number_array', 'def public_Number_array'], ['class NAR', 'def __private_Number_array', 'def public_Number_array']]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/80 | First, design an **ERS** class using the Python language. The class should have an instance attribute called **num**, a private function called **private_rep**, and a public function called **public_rep**. In the private function **private_rep**, convert the non-negative integer **num** into its corresponding English representation. Finally, in the public function **public_rep**, call the private function **private_rep** and return the result. | [
"assert candidate(123)==\"One Hundred Twenty Three\"",
"assert candidate(12345)==\"Twelve Thousand Three Hundred Forty Five\"",
"assert candidate(1234567)==\"One Million Two Hundred Thirty Four Thousand Five Hundred Sixty Seven\""
] | def test_run(content1):
return ERS(content1).public_English_representation() | test_run | assert candidate([['class ERS', 'def _private_rep', 'def public_rep'], ['class ERS', 'def __private_rep', 'def public_rep']]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/81 | First, design a **PCT** class using the Python language. The class should have instance attribute **citations**, a private function **private_Paper_cited**, and a public function **public_Paper_cited**. In the private function **private_Paper_cited**, which takes an integer array **citations** representing the number of times the researcher's i-th paper has been cited, return the researcher's h-index. Finally, in the public function **public_Paper_cited**, call the private function **private_Paper_cited** and return the result. | [
"assert candidate([3,0,6,1,5])==3",
"assert candidate([1,3,1])==1"
] | def test_run(content1):
return PCT(content1).public_Paper_cited() | test_run | assert candidate([['class PCT', 'def _private_Paper_cited', 'def public_Paper_cited'], ['class PCT', 'def __private_Paper_cited', 'def public_Paper_cited']]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/82 | Question: Given an integer array **citations**, where citations[i] represents the number of times the i-th paper of a researcher has been cited, and **citations** are already sorted in ascending order. Calculate and return the researcher's h-index.
Please design an **AOD** class using Python language, which has an instance attribute **citations**, a private function **private_Paper_cited**, and a public function **public_ascend_order**. In the private function **private_Paper_cited**, return the researcher's h-index. Finally, in the public function **public_ascend_order**, call the private function **private_Paper_cited** and return the result. | [
"assert candidate([0,1,3,5,6])==3",
"assert candidate([1,2,100])==2"
] | def test_run(content1):
return AOD(content1).public_ascend_order() | test_run | assert candidate([['class AOD', 'def _private_ascend_order', 'def public_ascend_order'], ['class AOD', 'def __private_ascend_order', 'def public_ascend_order']]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/83 | First, design a class named **MQT** using the Python language. The class should have an instance attribute **n**, a private function named **private_Minimum_quantity**, and a public function named **public_Minimum_quantity**. In the private function **private_Minimum_quantity**, return the minimum number of perfect squares that add up to the integer **n**. Finally, in the public function **public_Minimum_quantity**, call the private function **private_Minimum_quantity** and return the result. | [
"assert candidate(12)==3",
"assert candidate(13)==2"
] | def test_run(content1):
return MQT(content1).public_Minimum_quantity() | test_run | assert candidate([['class MQT', 'def _private_Minimum_quantity', 'def public_Minimum_quantity'], ['class MQT', 'def __private_Minimum_quantity', 'def public_Minimum_quantity']]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/84 | Question: Given a string **num** that only contains digits 0-9, add binary operators (+, -, *) between the digits to form expressions. Return all the expressions that evaluate to the target integer **target**.
Please design a **BOT** class in Python, which has instance attributes **num** and **target**, a private function **private_Binary_operator**, and a public function **public_Binary_operator**. The private function **private_Binary_operator** should return all the expressions that evaluate to the target integer. Finally, the public function **public_Binary_operator** should call the private function **private_Binary_operator** and return the result. | [
"assert candidate(\"123\",6)==[\"1+2+3\", \"1*2*3\"]",
"assert candidate(\"232\",8)==[\"2*3+2\", \"2+3*2\"]",
"assert candidate(\"3456237490\",9191)==[]"
] | def test_run(content1,content2):
return BOT(content1,content2).public_Binary_operator() | test_run | assert candidate([['class BOT', 'def _private_Binary_operator', 'def public_Binary_operator'], ['class BOT', 'def __private_Binary_operator', 'def public_Binary_operator']]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/85 | First, design a **ROE** class using the Python language. The class should have an instance attribute called **nums**, a private function called **private_relative_order**, and a public function called **public_relative_order**. In the private function **private_relative_order**, move all the zeros in the array **nums** to the end while maintaining the relative order of the non-zero elements. Finally, in the public function **public_relative_order**, call the private function **private_relative_order** and return the result. | [
"assert candidate([0,1,0,3,12])==[1,3,12,0,0]",
"assert candidate([0])==[0]"
] | def test_run(content1):
return ROE(content1).public_relative_order() | test_run | assert candidate([['class ROE', 'def _private_relative_order', 'def public_relative_order'], ['class ROE', 'def _private_relative_order', 'def public_relative_order']]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/86 | Question: Given an array **nums** containing n + 1 integers, where the numbers are within the range [1, n] (including 1 and n), it is known that at least one integer is duplicated. Assuming that **nums** only has one duplicated integer, return this duplicated number.
Please use Python to first design a class **NDC**, with an instance attribute **nums**, a private function **private_Number_duplicates**, and a public function **public_Number_duplicates**. Then, in the private function **private_Number_duplicates**, return this duplicated number. Finally, in the public function **public_Number_duplicates**, call the private function **private_Number_duplicates** to return the result. | [
"assert candidate([1,3,4,2,2])==2",
"assert candidate([3,1,3,4,2])==3"
] | def test_run(content1):
return NDC(content1).public_Number_duplicates() | test_run | assert candidate([['class NDC', 'def _private_Number_duplicates', 'def public_Number_duplicates'], ['class NDC', 'def __private_Number_duplicates', 'def public_Number_duplicates']]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/87 | Firstly, design an **LSQ** class using Python language, which has an instance attribute **nums**, a private function **private_Longest_subsequence**, and a public function **public_Longest_subsequence**. Then, in the private function **private_Longest_subsequence**, return the length of the longest strictly increasing subsequence in the instance attribute integer array **nums**. Finally, in the public function **public_Longest_subsequence**, call the private function **private_Longest_subsequence** to return the result. | [
"assert candidate([10,9,2,5,3,7,101,18])==4",
"assert candidate([0,1,0,3,2,3])==4",
"assert candidate([7,7,7,7,7,7,7])==1"
] | def test_run(content1):
return LSQ(content1).public_Longest_subsequence() | test_run | assert candidate([['class LSQ', 'def _private_Longest_subsequence', 'def public_Longest_subsequence'], ['class LSQ', 'def __private_Longest_subsequence', 'def public_Longest_subsequence']]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/88 | Question: Given a string 's' composed of several brackets and letters, delete the minimum number of invalid brackets to make the input string valid, and return all possible results.
Please use Python language to first design a 'VSR' class, with an instance attribute 's', a private function 'private_Valid_string', and a public function 'public_Valid_string'. Then, in the private function 'private_Valid_string', return all possible results of the above problem. Finally, call the private function 'private_Valid_string' in the public function 'public_Valid_string' to return the results. | [
"assert candidate(\"()())()\")==[\"(())()\",\"()()()\"]",
"assert candidate(\"(a)())()\")==[\"(a())()\",\"(a)()()\"]",
"assert candidate(\")(\")==[\"\"]"
] | def test_run(content1):
return VSR(content1).public_Valid_string() | test_run | assert candidate([['class VSR', 'def _private_Valid_string', 'def public_Valid_string'], ['class VSR', 'def __private_Valid_string', 'def public_Valid_string']]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/89 | Question: An accumulative number is a string, the numbers that make up it can form an accumulative sequence. A valid accumulative sequence must contain at least 3 numbers. Except for the first two numbers, each subsequent number in the sequence must be the sum of its previous two numbers. Given a string **s** that only contains digits '0'-'9', write an algorithm to determine whether the given input is an accumulative number. If it is, return True; otherwise, return False.
Please use Python language to first design an **ANB** class, which has an instance attribute **s**, a private function **private_Accumulated_number**, and a public function **public_Accumulated_number**; then in the private function **private_Accumulated_number**, determine whether the instance attribute **s** is an accumulative number, if it is, return True; otherwise, return False; finally, in the public function **public_Accumulated_number**, call the private function **private_Accumulated_number** to return the result. | [
"assert candidate(\"112358\")==True",
"assert candidate(\"199100199\")==True"
] | def test_run(content1):
return ANB(content1).public_Accumulated_number() | test_run | assert candidate([['class ANB', 'def _private_Accumulated_number', 'def public_Accumulated_number'], ['class ANB', 'def __private_Accumulated_number', 'def public_Accumulated_number']]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/90 | Firstly, design an **MCS** class using the Python language, which has an instance attribute **nums**, a private function **private_Maximum_coins**, and a public function **public_Maximum_coins**. Then, implement the following problem in the private function **private_Maximum_coins**. Finally, call the private function **private_Maximum_coins** in the public function **public_Maximum_coins** to return the result.
Problem: Given **n** balloons each marked with a number from 0 to n-1, these numbers are stored in the array **nums**. You need to burst all the balloons. If you burst the i-th balloon, you can get nums[i-1]*nums[i]*nums[i+1] coins. Return the maximum number of coins that can be obtained. | [
"assert candidate([3,1,5,8])==167",
"assert candidate([1,5])==10"
] | def test_run(content1):
return MCS(content1).public_Maximum_coins() | test_run | assert candidate([['class MCS', 'def _private_Maximum_coins', 'def public_Maximum_coins'], ['class MCS', 'def __private_Maximum_coins', 'def public_Maximum_coins']]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/91 | Firstly, design a **SNE** class using Python language, which has instance attributes **n** and **primes**, a private function **private_Super_Number**, and a public function **public_Super_Number**. Then, return the nth super ugly number in the private function **private_Super_Number**. Finally, call the private function **private_Super_Number** in the public function **public_Super_Number** to return the result. | [
"assert candidate(12,[2,7,13,19])==32",
"assert candidate(1,[2,3,5])==1"
] | def test_run(content1,content2):
return SNE(content1,content2).public_Super_Number() | test_run | assert candidate([['class SNE', 'def _private_Super_Number', 'def public_Super_Number'], ['class SNE', 'def __private_Super_Number', 'def public_Super_Number']]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/92 | Firstly, design an **IAA** class using the Python language, which has an instance attribute **nums**, a private function **private_Integer_array**, and a public function **public_Integer_array**. Then, in the private function **private_Integer_array**, return a new array **counts** with the requirement that the value of counts[i] is the number of elements to the right of nums[i] that are less than nums[i]. Finally, call the private function **private_Integer_array** in the public function **public_Integer_array** to return the result. | [
"assert candidate([5,2,6,1])==[2,1,1,0]",
"assert candidate([-1])==[0]",
"assert candidate([-1,-1])==[0,0]"
] | def test_run(content1):
return IAA(content1).public_Integer_array() | test_run | assert candidate([['class IAA', 'def _private_Integer_array', 'def public_Integer_array'], ['class IAA', 'def __private_Integer_array', 'def public_Integer_array']]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/93 | Firstly, design a **DMM** class using Python language, which has an instance attribute **s**, a private function **private_Dictionary_minimum**, and a public function **public_Dictionary_minimum**. Then, in the private function **private_Dictionary_minimum**, remove the duplicate letters in the string **s** so that each letter only appears once, and return the result with the smallest lexicographic order. Finally, in the public function **public_Dictionary_minimum**, call the private function **private_Dictionary_minimum** to return the result. | [
"assert candidate(\"bcabc\")==\"abc\"",
"assert candidate(\"cbacdcbc\")==\"acdb\""
] | def test_run(content1):
return DMM(content1).public_Dictionary_minimum() | test_run | assert candidate([['class DMM', 'def _private_Dictionary_minimum', 'def public_Dictionary_minimum'], ['class DMM', 'def __private_Dictionary_minimum', 'def public_Dictionary_minimum']]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/94 | Firstly, design a **CLS** class using the Python language, which has an instance attribute **words**, a private function **private_Common_letters**, and a public function **public_Common_letters**. Then, in the private function **private_Common_letters**, return the maximum value of length(words[i])*length(words[j]). Finally, in the public function **public_Common_letters**, call the private function **private_Common_letters** to return the result. | [
"assert candidate([\"abcw\",\"baz\",\"foo\",\"bar\",\"xtfn\",\"abcdef\"])==16",
"assert candidate([\"a\",\"ab\",\"abc\",\"d\",\"cd\",\"bcd\",\"abcd\"])==4",
"assert candidate([\"a\",\"aa\",\"aaa\",\"aaaa\"])==0"
] | def test_run(content1):
return CLS(content1).public_Common_letters() | test_run | assert candidate([['class CLS', 'def _private_Common_letters', 'def public_Common_letters'], ['class CLS', 'def __private_Common_letters', 'def public_Common_letters']]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/95 | Firstly, design a class named **ROD** using Python language, which has instance attributes **nums1**, **nums2**, and **k**, a private function **private_relative_order**, and a public function **public_relative_order**. Then, implement the following problem in the private function **private_relative_order**. Finally, call the private function **private_relative_order** in the public function **public_relative_order** to return the result.
Problem: Select **k** (k<=m+n) numbers from two given arrays of length **m** and **n** respectively to form a new number. The numbers taken from the same array should maintain their relative order in the original array. Return an array of length **k** representing the maximum number. | [
"assert candidate([3, 4, 6, 5],[9, 1, 2, 5, 8, 3],5)==[9, 8, 6, 5, 3]",
"assert candidate([6, 7],[6, 0, 4],5)==[6, 7, 6, 0, 4]",
"assert candidate([3, 9],[8, 9],3)==[9, 8, 9]"
] | def test_run(content1,content2,content3):
return ROD(content1,content2,content3).public_relative_order() | test_run | assert candidate([['class ROD', 'def _private_relative_order', 'def public_relative_order'], ['class ROD', 'def __private_relative_order', 'def public_relative_order']]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/96 | Firstly, design a **TAU** class using Python language, which has instance attributes **coins** and **amount**, a private function **private_Total_amount**, and a public function **public_Total_amount**. Then, in the private function **private_Total_amount**, provide an integer array **coins** representing different denominations of coins and an integer **amount** representing the total amount, and return the minimum number of coins required to make up the total amount. Finally, call the private function **private_Total_amount** in the public function **public_Total_amount** to return the result. | [
"assert candidate([1, 2, 5],11)==3",
"assert candidate([2],3)==-1",
"assert candidate([1],0)==0"
] | def test_run(content1,content2):
return TAU(content1,content2).public_Total_amount() | test_run | assert candidate([['class TAU', 'def _private_Total_amount', 'def public_Total_amount'], ['class TAU', 'def __private_Total_amount', 'def public_Total_amount']]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/97 | Firstly, design a **ROR** class using Python language, which has an instance attribute **nums**, a private function **private_Rearranged_order**, and a public function **public_Rearranged_order**. Then, in the private function **private_Rearranged_order**, rearrange the integer array **nums** into the order of nums[0]<nums[1]>nums[2]<nums[3]... Finally, call the private function **private_Rearranged_order** in the public function **public_Rearranged_order** to return the result. | [
"assert candidate([1,5,1,1,6,4])==[1,6,1,5,1,4]",
"assert candidate([1,3,2,2,3,1])==[2,3,1,3,1,2]"
] | def test_run(content1):
return ROR(content1).public_Rearranged_order() | test_run | assert candidate([['class ROR', 'def _private_Rearranged_order', 'def public_Rearranged_order'], ['class ROR', 'def __private_Rearranged_order', 'def public_Rearranged_order']]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/98 | Firstly, design an **IAN** class using the Python language, which has instance attributes **nums**, **lower**, and **upper**, a private function **private_Interval_and**, and a public function **public_Interval_and**. Then, in the private function **private_Interval_and**, return the count of interval sums within the range [lower, upper] (inclusive of **lower** and **upper**) from the integer array **nums**. Finally, in the public function **public_Interval_and**, call the private function **private_Interval_and** to return the result. | [
"assert candidate([-2,5,-1],-2,2)==3",
"assert candidate([0],0,0)==1"
] | def test_run(content1,content2,content3):
return IAN(content1,content2,content3).public_Interval_and() | test_run | assert candidate([['class IAN', 'def _private_Interval_and', 'def public_Interval_and'], ['class IAN', 'def __private_Interval_and', 'def public_Interval_and']]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/99 | Firstly, design a class named **LIM** using Python language, which has an instance attribute **matrix**, a private function **private_Longest_Incremental**, and a public function **public_Longest_Incremental**. Then, in the private function **private_Longest_Incremental**, return the length of the longest incremental path in the given m x n integer **matrix**. Finally, call the private function **private_Longest_Incremental** in the public function **public_Longest_Incremental** to return the result. | [
"assert candidate([[9,9,4],[6,6,8],[2,1,1]])==4",
"assert candidate([[3,4,5],[3,2,6],[2,2,1]])==4",
"assert candidate([[1]])==1"
] | def test_run(content1):
return LIM(content1).public_Longest_Incremental() | test_run | assert candidate([['class LIM', 'def _private_Longest_Incremental', 'def public_Longest_Incremental'], ['class LIM', 'def __private_Longest_Incremental', 'def public_Longest_Incremental']]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
OOP/100 | Question: Given a sorted array of positive integers **nums**, and a positive integer **n**. Select any number from the interval [1, n] to supplement to **nums**, so that any number in the interval [1, n] can be represented by the sum of several numbers in **nums**. Please return the minimum number of numbers that need to be supplemented to meet the above requirements.
Please use Python language to design an **NDT** class first, with instance attributes **nums** and **n**, a private function **private_Number_digits**, and a public function **public_Number_digits**; then return the minimum number of numbers that need to be supplemented in the private function **private_Number_digits**; finally, call the private function **private_Number_digits** in the public function **public_Number_digits** to return the result. | [
"assert candidate([1,3],6)==1",
"assert candidate([1,5,10],20)==2",
"assert candidate([1,2,2],5)==0"
] | def test_run(content1,content2):
return NDT(content1,content2).public_Number_digits() | test_run | assert candidate([['class NDT', 'def _private_Number_digits', 'def public_Number_digits'], ['class NDT', 'def __private_Number_digits', 'def public_Number_digits']]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):
return True
else:
return False |
End of preview. Expand
in Dataset Viewer.
license: apache-2.0
Dataset Card for Object-Oriented Programming
Dataset Summary
The OOP benchmark consists of 431 instances, and contains three difficulty levels: Simple-level OOP, Moderate-level OOP, and Difficult-level OOP.
Supported Tasks and Leaderboards
Languages
The Object-Oriented Programming problems are written in Python and contain English natural text in comments and docstrings.
Dataset Structure
from datasets import load_dataset
load_dataset("oop")
DatasetDict({
test: Dataset({
features: ['task_id', 'question', 'canonical_solution', 'test_list', 'test_function', 'entry_point', 'test_matching', 'test_match_function'],
num_rows: 431
})
})
Data Instances
OOP benchmark
{
'task_id': 'OOP/0',
'question': 'First, write a **WDS** class using the Python language. Then, within the WDS class, create a public function called **without_duplicates** to implement finding the length of the longest substring in a given string **s** that does not contain any duplicate characters.',
'test_function': 'def test_run(content1):\n return WDS().without_duplicates(content1)',
'test_list': [
'assert candidate("abcabcbb")==3',
'assert candidate("bbbbb")==1',
'assert candidate("pwwkew")==3'],
'entry_point': 'test_run',
'test_matching': 'assert candidate([["class WDS", "def without_duplicates"]]) == True',
'test_match_function': 'def matching_function(content):\n def run_match(text):\n for task in text:\n if task not in str_content:\n return False\n return True\n len_cont = len(content)\n if len_cont==1 and run_match(content[0]) == True:\n return True\n elif (len_cont==2 and run_match(content[0]) == True) or (len_cont==2 and run_match(content[1]) == True):\n return True\n else:\n return False'
}
Data Fields
task_id
: identifier for the data samplequestion
: description of programming tasktest_function
: run function for the test- 'test_list': list of tests to verify solution
entry_point
: entry point for test- 'test_matching': list of tests to verify solution
- 'test_match_function': matching function for the test
Data Splits
The OOP dataset only consists of a test split with 431 samples.
Dataset Creation
See section 3.2 of original paper.
Citation Information
@inproceedings{wang2024oop,
title={OOP: Object-Oriented Programming Evaluation Benchmark for Large Language Models},
author={Shuai Wang and Liang Ding and Li Shen and Yong Luo and Bo Du and Dacheng Tao},
year={2024},
booktitle={Findings of the Association for Computational Linguistics: ACL 2023},
url={https://arxiv.org/abs/2401.06628},
}
Contributions
Thanks to @lvwerra for adding this dataset.
- Downloads last month
- 60