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/201
Firstly, design an **LPC** class using Python language, which has an instance attribute **pairs**, a private function **private_Longest_pair_chain**, and a public function **public_Longest_pair_chain**. Then, implement the following problem in the private function **private_Longest_pair_chain**. Finally, call the private function **private_Longest_pair_chain** in the public function **public_Longest_pair_chain** to return the result. Problem: Given an array of pairs **pairs** composed of n pairs, where pairs[i] = [left_i, right_i] and left_i < right_i. Now, define a following relationship, where pair p2 = [c, d] can only follow p1 = [a, b] if and only if b < c. Use this form to construct a pair chain, find and return the length of the longest pair chain that can be formed.
[ "assert candidate([[1,2], [2,3], [3,4]])==2", "assert candidate([[1,2],[7,8],[4,5]])==3" ]
def test_run(content1): return LPC(content1).public_Longest_pair_chain()
test_run
assert candidate([['class LPC', 'def _private_Longest_pair_chain', 'def public_Longest_pair_chain'], ['class LPC', 'def __private_Longest_pair_chain', 'def public_Longest_pair_chain']]) == 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/202
Firstly, design a **PS** class using Python language, which has an instance attribute **s**, a private function **private_Palindrome_substring**, and a public function **public_Palindrome_substring**. Then, return the number of palindrome substrings in the string **s** within the private function **private_Palindrome_substring**. Finally, call the private function **private_Palindrome_substring** to return the result within the public function **public_Palindrome_substring**.
[ "assert candidate(\"abc\")==3", "assert candidate(\"aaa\")==6" ]
def test_run(content1): return PS(content1).public_Palindrome_substring()
test_run
assert candidate([['class PS', 'def _private_Palindrome_substring', 'def public_Palindrome_substring'], ['class PS', 'def __private_Palindrome_substring', 'def public_Palindrome_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/203
Firstly, design an **RS** class using the Python language, which has instance attributes **dictionary** and **sentence**, a private function **private_Root_substitution**, and a public function **public_Root_substitution**. Then, implement the following problem in the private function **private_Root_substitution**. Finally, call the private function **private_Root_substitution** in the public function **public_Root_substitution** to return the result. Problem: In English, there is a concept called **root**, where you can add other words after the root to form a longer word, which is called a **successor** word. For example, the root **an**, followed by the word **other**, can form a new word **another**. Now, given a **dictionary** composed of many roots and a **sentence** formed by words separated by spaces. You need to replace all the successor words in the sentence with the root. If there are many roots that can form the successor word, replace it with the shortest root. You need to output the sentence after the replacement.
[ "assert candidate([\"cat\",\"bat\",\"rat\"],\"the cattle was rattled by the battery\")==\"the cat was rat by the bat\"", "assert candidate([\"a\",\"b\",\"c\"],\"aadsfasf absbs bbab cadsfafs\")==\"a a b c\"" ]
def test_run(content1,content2): return RS(content1,content2).public_Root_substitution()
test_run
assert candidate([['class RS', 'def _private_Root_substitution', 'def public_Root_substitution'], ['class RS', 'def __private_Root_substitution', 'def public_Root_substitution']]) == 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/204
Firstly, design an **MNO** class using Python language, which has an instance attribute **n**, a private function **Minimum_operations**, and a public function **public_Minimum_operations**. Then, implement the following problem in the private function **Minimum_operations**. Finally, call the private function **Minimum_operations** in the public function **public_Minimum_operations** to return the result. Problem: Initially, there is only one character 'A' on the notepad. You can perform two types of operations on this notepad each time: 1. Copy All: Copy all characters in this notepad (partial copying is not allowed); 2. Paste: Paste the characters copied last time. Given a number **n**, you need to use the minimum number of operations to output exactly **n** 'A's on the notepad. Return the minimum number of operations that can print out **n** 'A's.
[ "assert candidate(3)==3", "assert candidate(1)==0" ]
def test_run(content1): return MNO(content1).public_Minimum_operations()
test_run
assert candidate([['class MNO', 'def _Minimum_operations', 'def public_Minimum_operations'], ['class MNO', 'def __Minimum_operations', 'def public_Minimum_operations']]) == 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/205
Firstly, design an **FPV** class using Python language, which has instance attributes **arr**, **k**, and **x**, a private function **private_Find_Proximity_Values**, and a public function **public_Find_Proximity_Values**. Then, implement the following problem in the private function **private_Find_Proximity_Values**. Finally, call the private function **private_Find_Proximity_Values** in the public function **public_Find_Proximity_Values** to return the result. Problem: Given a sorted array **arr**, two integers **k** and **x**, find the **k** numbers closest to **x** (the difference between the two numbers is the smallest) from the array. The returned result must be sorted in ascending order. An integer **a** is closer to **x** than an integer **b** if: |a-x| < |b-x| or |a-x| == |b-x| and a < b.
[ "assert candidate([1,2,3,4,5],4,3)==[1,2,3,4]", "assert candidate([1,2,3,4,5],4,-1)==[1,2,3,4]" ]
def test_run(content1,content2,content3): return FPV(content1,content2,content3).public_Find_Proximity_Values()
test_run
assert candidate([['class FPV', 'def _private_Find_Proximity_Values', 'def public_Find_Proximity_Values'], ['class FPV', 'def __private_Find_Proximity_Values', 'def public_Find_Proximity_Values']]) == 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/206
Firstly, design a **JS** class using the Python language, which has an instance attribute **nums**, a private function **private_Judgment_segmentation**, and a public function **public_Judgment_segmentation**. Then, implement the following problem in the private function **private_Judgment_segmentation**. Finally, call the private function **private_Judgment_segmentation** in the public function **public_Judgment_segmentation** to return the result. Problem: Given an integer array **nums** sorted in non-decreasing order. Please judge whether it is possible to satisfy the following two conditions while dividing **nums** into one or more sub-sequences: each sub-sequence is a continuous increasing sequence (that is, each integer is exactly one larger than the previous one); the length of all sub-sequences is at least 3. If **nums** can be divided and meet the above conditions, return True; otherwise, return False.
[ "assert candidate([1,2,3,3,4,5])==True", "assert candidate([1,2,3,3,4,4,5,5])==True", "assert candidate([1,2,3,4,4,5])==False" ]
def test_run(content1): return JS(content1).public_Judgment_segmentation()
test_run
assert candidate([['class JS', 'def _private_Judgment_segmentation', 'def public_Judgment_segmentation'], ['class JS', 'def _private_Judgment_segmentation', 'def public_Judgment_segmentation']]) == 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/207
Firstly, design an **MPT** class using Python language, which has an instance attribute **s**, a private function **Minimum_Times**, and a public function **public_Minimum_Times**. Then, implement the following problem in the private function **Minimum_Times**. Finally, call the private function **Minimum_Times** in the public function **public_Minimum_Times** to return the result. Problem: There is a strange printer with the following two special requirements: 1. The printer can only print a sequence composed of the same character each time; 2. It can print a new character at any position from the beginning to the end each time, and it will overwrite the original characters. Given a string **s**, your task is to calculate the minimum number of times this printer needs to print it.
[ "assert candidate(\"aaabbb\")==2", "assert candidate(\"aba\")==2" ]
def test_run(content1): return MPT(content1).public_Minimum_Times()
test_run
assert candidate([['class MPT', 'def _Minimum_Times', 'def public_Minimum_Times'], ['class MPT', 'def __Minimum_Times', 'def public_Minimum_Times']]) == 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/208
Firstly, design an **NDC** class using Python language, which has an instance attribute **nums**, a private function **private_Non_decreasing_column**, and a public function **public_Non_decreasing_column**. Then, implement the following problem in the private function **private_Non_decreasing_column**. Finally, call the private function **private_Non_decreasing_column** in the public function **public_Non_decreasing_column** to return the result. Problem: Given an integer array **nums** of length **n**, please determine whether this array can become a non-decreasing sequence by changing at most one element. Definition of non-decreasing sequence: For any **i** (0 <= i <= n-2) in the array, it always satisfies that nums[i]<= nums[i + 1].
[ "assert candidate([4,2,3])==True", "assert candidate([4,2,1])==False" ]
def test_run(content1): return NDC(content1).public_Non_decreasing_column()
test_run
assert candidate([['class NDC', 'def _private_Non_decreasing_column', 'def public_Non_decreasing_column'], ['class NDC', 'def __private_Non_decreasing_column', 'def public_Non_decreasing_column']]) == 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/209
Firstly, design an **AL** class using Python language, which has instance attributes **n** and **k**, a private function **private_Answer_List**, and a public function **public_Answer_List**. Then, return the constructed answer list **answer** in the private function **private_Answer_List**. Finally, call the private function **private_Answer_List** in the public function **public_Answer_List** to return the result. Problem: Given two integers **n** and **k**, please construct an answer list **answer**. This list should contain **n** different positive integers from 1 to **n**, and at the same time meet the following condition: Assuming the list is answer=[a1, a2, a3, ... , an], then the list [|a1 - a2|,|a2 - a3|,|a3 - a4|,...,|an-1 - an|] should have exactly **k** different integers. Return the list **answer**.
[ "assert candidate(3,1)==[1, 2, 3]", "assert candidate(3,2)==[1, 3, 2]" ]
def test_run(content1,content2): return AL(content1,content2).public_Answer_List()
test_run
assert candidate([['class AL', 'def _private_Answer_List', 'def public_Answer_List'], ['class AL', 'def _private_Answer_List', 'def public_Answer_List']]) == 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/210
Firstly, design a class named **LIS** using Python language, which has instance attribute **nums**, a private function **lo_in_sub**, and a public function **public_lo_in_sub**. Then, in the private function **lo_in_sub**, return the count of the longest increasing subsequence from the unsorted integer array **nums**. Finally, in the public function **public_lo_in_sub**, call the private function **lo_in_sub** to return the result.
[ "assert candidate([1,3,5,4,7])==2", "assert candidate([2,2,2,2,2])==5" ]
def test_run(content1): return LIS(content1).public_lo_in_sub()
test_run
assert candidate([['class LIS', 'def _lo_in_sub', 'def public_lo_in_sub'], ['class LIS', 'def __lo_in_sub', 'def public_lo_in_sub']]) == 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/211
Firstly, design a **CDT** class using Python language, which has an instance attribute **forest**, a private function **private_Chop_down_trees**, and a public function **public_Chop_down_trees**. Then, implement the following problem in the private function **private_Chop_down_trees**. Finally, call the private function **private_Chop_down_trees** in the public function **public_Chop_down_trees** to return the result. Problem: The forest is represented by an m x n matrix. In this matrix, 0 represents an obstacle that cannot be touched; 1 represents the ground where you can walk. Numbers larger than 1 represent cells with trees, which can be walked on, and the number represents the height of the tree. At each step, you can move one unit in one of the four directions: up, down, left, or right. If there is a tree where you stand, you can decide whether to cut it down. You need to cut down all the trees from low to high according to the height of the trees. After cutting down a tree, the value of the cell becomes **1** (i.e., it becomes the ground). You will start working from the point (0, 0), and return the minimum number of steps you need to take to cut down all the trees. If you cannot cut down all the trees, return -1.
[ "assert candidate([[1,2,3],[0,0,4],[7,6,5]])==6", "assert candidate([[1,2,3],[0,0,0],[7,6,5]])==-1", "assert candidate([[2,3,4],[0,0,5],[8,7,6]])==6" ]
def test_run(content1): return CDT(content1).public_Chop_down_trees()
test_run
assert candidate([['class CDT', 'def _private_Chop_down_trees', 'def public_Chop_down_trees'], ['class CDT', 'def __private_Chop_down_trees', 'def public_Chop_down_trees']]) == 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/212
Firstly, design a **VS** class using Python language, which has an instance attribute **s**, a private function **private_Valid_String**, and a public function **public_Valid_String**. Then, implement the following problem in the private function **private_Valid_String**. Finally, call the private function **private_Valid_String** in the public function **public_Valid_String** and return the result. Problem: Given a string that only contains three types of characters, the supported character types are '(', ')', and '*'. Please check whether this string is a valid string. If it is a valid string, return True; otherwise, return False.
[ "assert candidate(\"()\")==True", "assert candidate(\"(*)\")==True", "assert candidate(\"(*))\")==True" ]
def test_run(content1): return VS(content1).public_Valid_String()
test_run
assert candidate([['class VS', 'def _private_Valid_String', 'def public_Valid_String'], ['class VS', '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/213
Firstly, design a class **ME** using the Python language, which has an instance attribute **cards**, a private function **private_mathematical_expression**, and a public function **public_mathematical_expression**. Then, implement the following problem in the private function **private_mathematical_expression**. Finally, call the private function **private_mathematical_expression** in the public function **public_mathematical_expression** to return the result. Problem: Given an integer array **cards** of length 4. Assume there are 4 cards, each containing a number ranging from [1,9]. You should arrange the numbers on these cards into a mathematical expression using the operators ['+', '-', '*', '/'] and parentheses '(' and ')' to achieve the value 24. You must follow these rules: 1. The division operator '/' represents real number division, not integer division; 2. Each operation is between two numbers. Specifically, you cannot use "-" as a unary operator. For example, if cards = [1,1,1,1], the expression "-1 -1 -1 -1" is not allowed; 3. You cannot string numbers together. If cards = [1,2,1,2], the expression "12 + 12" is invalid. If such an expression can be obtained and its calculation result is 24, return True, otherwise return False.
[ "assert candidate([4, 1, 8, 7])==True", "assert candidate([1, 2, 1, 2])==False" ]
def test_run(content1): return ME(content1).public_mathematical_expression()
test_run
assert candidate([['class ME', 'def _private_mathematical_expression', 'def public_mathematical_expression'], ['class ME', 'def __private_mathematical_expression', 'def public_mathematical_expression']]) == 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/214
Firstly, design an **OS** class using Python language, which has instance attributes **a** and **b**, a private function **private_Overlay_substring**, and a public function **public_Overlay_substring**. Then, implement the following problem in the private function **private_Overlay_substring**. Finally, call the private function **private_Overlay_substring** in the public function **public_Overlay_substring** to return the result. Problem: Given two strings **a** and **b**, find the minimum number of times string **a** needs to be repeatedly overlaid so that string **b** becomes a substring of the overlaid string **a**. If it does not exist, return -1.
[ "assert candidate(\"abcd\",\"cdabcdab\")==3", "assert candidate(\"a\",\"aa\")==2", "assert candidate(\"a\",\"a\")==1", "assert candidate(\"abc\",\"wxyz\")==-1" ]
def test_run(content1,content2): return OS(content1,content2).public_Overlay_substring()
test_run
assert candidate([['class OS', 'def _private_Overlay_substring', 'def public_Overlay_substring'], ['class OS', 'def __private_Overlay_substring', 'def public_Overlay_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/215
Firstly, design a **KC** class using Python language, which has instance attributes **n**, **k**, **row**, and **column**, a private function **private_Knight_Chessboard**, and a public function **public_Knight_Chessboard**. Then, implement the following problem in the private function **private_Knight_Chessboard**. Finally, call the private function **private_Knight_Chessboard** in the public function **public_Knight_Chessboard** to return the result. Problem: On an n x n international chessboard, a knight starts from the cell (row, column) and tries to make **k** moves. Rows and columns start from 0, so the top-left cell is (0,0), and the bottom-right cell is (n - 1, n - 1). The chess knight has 8 possible moves, each move is two cells in the basic direction, then one cell in the orthogonal direction. Each time the knight is to move, it randomly selects one from the 8 possible moves (even if the piece will leave the board), and then moves there. The knight continues to move until it has taken **k** steps or has left the board. Return the probability that the knight still remains on the board after it stops moving.
[ "assert candidate(3,2,0,0)==0.0625", "assert candidate(1,0,0,0)==1.00000" ]
def test_run(content1,content2,content3,content4): return KC(content1,content2,content3,content4).public_Knight_Chessboard()
test_run
assert candidate([['class KC', 'def _private_Knight_Chessboard', 'def public_Knight_Chessboard'], ['class KC', 'def __private_Knight_Chessboard', 'def public_Knight_Chessboard']]) == 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/216
Firstly, design an **MS** class using Python language, which has instance attributes **nums** and **k**, a private function **private_Maximum_subarray**, and a public function **public_Maximum_subarray**. Then, implement the following problem in the private function **private_Maximum_subarray**. Finally, call the private function **private_Maximum_subarray** in the public function **public_Maximum_subarray** to return the result. Problem: Given an integer array **nums** and an integer **k**, find three non-overlapping subarrays of length **k** with the maximum sum of all numbers (3*k items) and return these three subarrays.
[ "assert candidate([1,2,1,2,6,7,5,1],2)==[0,3,5]", "assert candidate([1,2,1,2,1,2,1,2,1],2)==[0,2,4]" ]
def test_run(content1,content2): return MS(content1,content2).public_Maximum_subarray()
test_run
assert candidate([['class MS', 'def _private_Maximum_subarray', 'def public_Maximum_subarray'], ['class MS', 'def __private_Maximum_subarray', 'def public_Maximum_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/217
Firstly, design a class named **SW** using Python language, which has instance attributes **stickers** and **target**, a private function **private_Sticker_Words**, and a public function **public_Sticker_Words**. Then, implement the following problem in the private function **private_Sticker_Words**. Finally, call the private function **private_Sticker_Words** in the public function **public_Sticker_Words** to return the result. Problem: There are **n** different types of stickers, each with a lowercase English word on it. You want to spell out a given string **target** by cutting individual letters from the collected stickers and rearranging them. If you wish, you can use each sticker multiple times, and the quantity of each sticker is unlimited. Return the minimum number of stickers required to spell out the **target**. If the task is impossible, return -1.
[ "assert candidate([\"with\",\"example\",\"science\"],\"thehat\")==3", "assert candidate([\"notice\",\"possible\"],\"basicbasic\")==-1" ]
def test_run(content1,content2): return SW(content1,content2).public_Sticker_Words()
test_run
assert candidate([['class SW', 'def _private_Sticker_Words', 'def public_Sticker_Words'], ['class SW', 'def __private_Sticker_Words', 'def public_Sticker_Words']]) == 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/218
Firstly, design an **MT** class using the Python language, which has instance attributes **words** and **k**, a private function **private_Most_times**, and a public function **public_Most_times**. Then, in the private function **private_Most_times**, return the top **k** most frequently occurring words from a given word list **words** and an integer **k**. Finally, call the private function **private_Most_times** in the public function **public_Most_times** to return the result.
[ "assert candidate([\"i\", \"love\", \"leetcode\", \"i\", \"love\", \"coding\"],2)==[\"i\", \"love\"]", "assert candidate([\"the\", \"day\", \"is\", \"sunny\", \"the\", \"the\", \"the\", \"sunny\", \"is\", \"is\"],4)==[\"the\", \"is\", \"sunny\", \"day\"]" ]
def test_run(content1,content2): return MT(content1,content2).public_Most_times()
test_run
assert candidate([['class MT', 'def _private_Most_times', 'def public_Most_times'], ['class MT', 'def __private_Most_times', 'def public_Most_times']]) == 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/219
Firstly, design an **AA** class using the Python language, which has an instance attribute **n**, a private function **private_Alternating_appearance**, and a public function **public_Alternating_appearance**. Then, implement the following problem in the private function **private_Alternating_appearance**. Finally, call the private function **private_Alternating_appearance** in the public function **public_Alternating_appearance** to return the result. Problem: Given a positive integer, check whether its binary representation always alternates between 0 and 1. In other words, the adjacent digits in the binary representation are never the same. If 0 and 1 alternate, return True; otherwise, return False.
[ "assert candidate(5)==True", "assert candidate(7)==False", "assert candidate(11)==False" ]
def test_run(content1): return AA(content1).public_Alternating_appearance()
test_run
assert candidate([['class AA', 'def _private_Alternating_appearance', 'def public_Alternating_appearance'], ['class AA', 'def __private_Alternating_appearance', 'def public_Alternating_appearance']]) == 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/220
Firstly, design an **IA** class using Python language, which has an instance attribute **grid**, a private function **private_Island_area**, and a public function **public_Island_area**. Then, implement the following problem in the private function **private_Island_area**. Finally, call the private function **private_Island_area** in the public function **public_Island_area** to return the result. Problem: Given a binary matrix **grid** of size m x n. An island is a combination of some adjacent 1s (representing land), where adjacency requires that two 1s must be adjacent in the horizontal or vertical four directions. It can be assumed that the four edges of the **grid** are surrounded by 0s (representing water). The area of the island is the number of cells on the island with a value of 1. Calculate and return the largest island area in the **grid**. If there is no island, return an area of 0.
[ "assert candidate([[0,0,1,0,0,0,0,1,0,0,0,0,0],[0,0,0,0,0,0,0,1,1,1,0,0,0],[0,1,1,0,1,0,0,0,0,0,0,0,0],[0,1,0,0,1,1,0,0,1,0,1,0,0],[0,1,0,0,1,1,0,0,1,1,1,0,0],[0,0,0,0,0,0,0,0,0,0,1,0,0],[0,0,0,0,0,0,0,1,1,1,0,0,0],[0,0,0,0,0,0,0,1,1,0,0,0,0]])==6", "assert candidate([[0,0,0,0,0,0,0,0]])==0" ]
def test_run(content1): return IA(content1).public_Island_area()
test_run
assert candidate([['class IA', 'def _private_Island_area', 'def public_Island_area'], ['class IA', 'def __private_Island_area', 'def public_Island_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/221
Firstly, design an **ES** class using Python language, which has instance attributes **nums** and **k**, a private function **private_Equal_sum**, and a public function **public_Equal_sum**. Then, in the private function **private_Equal_sum**, determine whether it is possible to divide this array into **k** non-empty subsets with equal sums, based on a given integer array **nums** and a positive integer **k**. Finally, call the private function **private_Equal_sum** in the public function **public_Equal_sum** to return the result.
[ "assert candidate([4, 3, 2, 3, 5, 2, 1],4)==True", "assert candidate([1,2,3,4],3)==False" ]
def test_run(content1,content2): return ES(content1,content2).public_Equal_sum()
test_run
assert candidate([['class ES', 'def _private_Equal_sum', 'def public_Equal_sum'], ['class ES', 'def __private_Equal_sum', 'def public_Equal_sum']]) == 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/222
Firstly, design a **BS** class using Python language, which has an instance attribute **positions**, a private function **private_Block_stacking**, and a public function **public_Block_stacking**. Then, implement the following problem in the private function **private_Block_stacking**. Finally, call the private function **private_Block_stacking** in the public function **public_Block_stacking** to return the result. Problem: Given a two-dimensional integer array **positions**, where positions[i] = [left_i, sideLength_i] indicates: the side length of the i-th block is **sideLength_i**, and its left side aligns with the coordinate point **left_i** on the x-axis. Each block falls from a height higher than all the currently landed blocks. The block falls in the negative direction of the y-axis until it lands on the top edge of another square or on the x-axis. A block merely brushing past the left or right side of another block does not count as landing. Once landed, it will be fixed in place and cannot move. After each block falls, you must record the highest height of the currently stable stacked blocks.
[ "assert candidate([[1,2],[2,3],[6,1]])==[2,5,5]", "assert candidate([[100,100],[200,100]])==[100,100]" ]
def test_run(content1): return BS(content1).public_Block_stacking()
test_run
assert candidate([['class BS', 'def _private_Block_stacking', 'def public_Block_stacking'], ['class BS', 'def __private_Block_stacking', 'def public_Block_stacking']]) == 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/223
Firstly, design a **DC** class using the Python language, which has instance attributes **s1** and **s2**, a private function **private_Delete_Characters**, and a public function **public_Delete_Characters**. Then, in the private function **private_Delete_Characters**, return the minimum sum of the ASCII values of the characters that need to be deleted to make the two given strings **s1** and **s2** equal. Finally, call the private function **private_Delete_Characters** in the public function **public_Delete_Characters** to return the result.
[ "assert candidate(\"sea\",\"eat\")==231", "assert candidate(\"delete\",\"leet\")==403" ]
def test_run(content1,content2): return DC(content1,content2).public_Delete_Characters()
test_run
assert candidate([['class DC', 'def _private_Delete_Characters', 'def public_Delete_Characters'], ['class DC', 'def __private_Delete_Characters', 'def public_Delete_Characters']]) == 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/224
Firstly, design a **POE** class using Python language, which has instance attributes **nums** and **k**, a private function **private_Product_of_elements**, and a public function **public_Product_of_elements**. Then, in the private function **private_Product_of_elements**, return the number of continuous subarrays where the product of all elements in the subarray is strictly less than **k**, given an integer array **nums** and an integer **k**. Finally, in the public function **public_Product_of_elements**, call the private function **private_Product_of_elements** to return the result.
[ "assert candidate([10,5,2,6],100)==8", "assert candidate([1,2,3],0)==0" ]
def test_run(content1,content2): return POE(content1,content2).public_Product_of_elements()
test_run
assert candidate([['class POE', 'def _private_Product_of_elements', 'def public_Product_of_elements'], ['class POE', 'def __private_Product_of_elements', 'def public_Product_of_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/225
Firstly, design a **BS** class using Python language, which has instance attributes **prices** and **fee**, a private function **private_buy_share**, and a public function **public_buy_share**. Then, implement the following problem in the private function **private_buy_share**. Finally, call the private function **private_buy_share** in the public function **public_buy_share** to return the result. Problem: Given an integer array **prices**, where prices[i] represents the stock price on the i-th day; the integer **fee** represents the transaction fee for trading stocks. You can complete transactions unlimited times, but you need to pay a fee for each transaction. If you have already purchased a stock, you cannot continue to buy stocks before selling it. Return the maximum profit that can be obtained.
[ "assert candidate([1, 3, 2, 8, 4, 9],2)==8", "assert candidate([1,3,7,5,10,3],3)==6" ]
def test_run(content1,content2): return BS(content1,content2).public_buy_share()
test_run
assert candidate([['class BS', 'def _private_buy_share', 'def public_buy_share'], ['class BS', 'def __private_buy_share', 'def public_buy_share']]) == 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/226
Firstly, design a **BC** class using the Python language, which has an instance attribute **bits**, a private function **private_Bit_character**, and a public function **public_Bit_character**. Then, implement the following problem in the private function **private_Bit_character**. Finally, call the private function **private_Bit_character** in the public function **public_Bit_character** to return the result. Problem: There are two special characters: the first type of character can be represented by a one-bit 0; the second type of character can be represented by two bits (10 or 11). Given a binary array **bits** ending with 0, if the last character must be a one-bit character, return True; otherwise, return False.
[ "assert candidate([1, 0, 0])==True", "assert candidate([1,1,1,0])==False" ]
def test_run(content1): return BC(content1).public_Bit_character()
test_run
assert candidate([['class BC', 'def _private_Bit_character', 'def public_Bit_character'], ['class BC', 'def __private_Bit_character', 'def public_Bit_character']]) == 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/227
Firstly, design a **BL** class using Python language, which has instance attributes **nums1** and **nums2**, a private function **private_BLongest_length**, and a public function **public_BLongest_length**. Then, in the private function **private_BLongest_length**, return the length of the longest common subarray from the two given integer arrays **nums1** and **nums2**. Finally, call the private function **private_BLongest_length** in the public function **public_BLongest_length** to return the result.
[ "assert candidate([1,2,3,2,1],[3,2,1,4,7])==3", "assert candidate([0,0,0,0,0],[0,0,0,0,0])==5" ]
def test_run(content1,content2): return BL(content1,content2).public_BLongest_length()
test_run
assert candidate([['class BL', 'def _private_BLongest_length', 'def public_BLongest_length'], ['class BL', 'def __private_BLongest_length', 'def public_BLongest_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/228
Firstly, design an **AD** class using Python language, which has instance attributes **nums** and **k**, a private function **private_absolute_difference**, and a public function **public_absolute_difference**. Then, implement the following problem in the private function **private_absolute_difference**. Finally, call the private function **private_absolute_difference** in the public function **public_absolute_difference** to return the result. Problem: A pair of numbers (a, b) is composed of integers **a** and **b**, and the distance of the pair is defined as the absolute difference between **a** and **b**. Given an integer array **nums** and an integer **k**, the pair is composed of nums[i] and nums[j] and satisfies 0<= i<j<nums.length. Return the k-th smallest pair distance among all pair distances.
[ "assert candidate([1,3,1],1)==0", "assert candidate([1,1,1],2)==0", "assert candidate([1,6,1],3)==5" ]
def test_run(content1,content2): return AD(content1,content2).public_absolute_difference()
test_run
assert candidate([['class AD', 'def _private_absolute_difference', 'def public_absolute_difference'], ['class AD', 'def __private_absolute_difference', 'def public_absolute_difference']]) == 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/229
Firstly, design an **ED** class using the Python language, which has an instance attribute **words**, a private function **private_English_Dictionary**, and a public function **public_English_Dictionary**. Then, implement the following problem in the private function **private_English_Dictionary**. Finally, call the private function **private_English_Dictionary** in the public function **public_English_Dictionary** to return the result. Problem: Given a string array **words** that forms an English dictionary, return the longest word in **words**. This word is formed by gradually adding one letter from other words in the **words** dictionary. If there are multiple feasible answers, return the word with the smallest lexicographical order among the answers. If there is no answer, return an empty string.
[ "assert candidate([\"w\",\"wo\",\"wor\",\"worl\", \"world\"])==\"world\"", "assert candidate([\"a\", \"banana\", \"app\", \"appl\", \"ap\", \"apply\", \"apple\"])==\"apple\"" ]
def test_run(content1): return ED(content1).public_English_Dictionary()
test_run
assert candidate([['class ED', 'def _private_English_Dictionary', 'def public_English_Dictionary'], ['class ED', 'def __private_English_Dictionary', 'def public_English_Dictionary']]) == 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/230
Firstly, design an **LS** class using Python language, which has instance attributes **head** and **k**, a private function **private_List_separation**, and a public function **public_List_separation**. Then, implement the following problem in the private function **private_List_separation**. Finally, call the private function **private_List_separation** in the public function **public_List_separation** to return the result. Problem: Given a singly linked list with a head node **head** and an integer **k**, please design an algorithm to divide the linked list into **k** consecutive parts. The length of each part should be as equal as possible: the difference in length between any two parts cannot exceed 1. This may cause some parts to be null. These **k** parts should be arranged in the order they appear in the linked list, and the length of the parts in the front should be greater than or equal to the length of the parts in the back. Return an array composed of the above **k** parts.
[ "assert candidate([1,2,3],5)==[[1],[2],[3],[],[]]", "assert candidate([1,2,3,4,5,6,7,8,9,10],3)==[[1,2,3,4],[5,6,7],[8,9,10]]" ]
def test_run(content1,content2): return LS(content1,content2).public_public_List_separation()
test_run
assert candidate([['class LS', 'def _private_List_separation', 'def public_List_separation'], ['class LS', 'def __private_List_separation', 'def public_List_separation']]) == 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/231
Firstly, design a **NOS** class using the Python language, which has an instance attribute **s**, a private function **private_Number_of_sequences**, and a public function **public_Number_of_sequences**. Then, in the private function **private_Number_of_sequences**, return the number of different non-empty palindrome sub-sequences in a given string **s**. Finally, in the public function **public_Number_of_sequences**, call the private function **private_Number_of_sequences** to return the result.
[ "assert candidate('bccb')==6", "assert candidate('abcdabcdabcdabcdabcdabcdabcdabcddcbadcbadcbadcbadcbadcbadcbadcba')==104860361" ]
def test_run(content1): return NOS(content1).public_Number_of_sequences()
test_run
assert candidate([['class NOS', 'def _private_Number_of_sequences', 'def public_Number_of_sequences'], ['class NOS', 'def __private_Number_of_sequences', 'def public_Number_of_sequences']]) == 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/232
Firstly, design an **MI** class using Python language, which has an instance attribute **n**, a private function **private_monotonic_increase**, and a public function **public_monotonic_increase**. Then, implement the following problem in the private function **private_monotonic_increase**. Finally, call the private function **private_monotonic_increase** in the public function **public_monotonic_increase** to return the result. Problem: An integer is said to be monotonically increasing if and only if each pair of adjacent digits **x** and **y** satisfy x <= y. Given an integer **n**, return the largest number less than or equal to **n** that is monotonically increasing.
[ "assert candidate(10)==9", "assert candidate(1234)==1234", "assert candidate(332)==299" ]
def test_run(content1): return MI(content1).public_monotonic_increase()
test_run
assert candidate([['class MI', 'def _private_monotonic_increase', 'def public_monotonic_increase'], ['class MI', 'def __private_monotonic_increase', 'def public_monotonic_increase']]) == 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/233
Firstly, design a class **TR** using the Python language, which has an instance attribute **temperatures**, a private function **private_Temperature_rise**, and a public function **public_Temperature_rise**. Then, implement the following problem in the private function **private_Temperature_rise**. Finally, call the private function **private_Temperature_rise** in the public function **public_Temperature_rise** to return the result. Problem: Given an integer array **temperatures** representing the temperature of each day, return an array **answer**, where answer[i] refers to the number of days until the next higher temperature for the i-th day. If the temperature will not rise after this, please replace it with 0 at this position.
[ "assert candidate([73,74,75,71,69,72,76,73])==[1,1,4,2,1,1,0,0]", "assert candidate([30,40,50,60])==[1,1,1,0]", "assert candidate([30,60,90])==[1,1,0]" ]
def test_run(content1): return TR(content1).public_Temperature_rise()
test_run
assert candidate([['class TR', 'def _private_Temperature_rise', 'def public_Temperature_rise'], ['class TR', 'def __private_Temperature_rise', 'def public_Temperature_rise']]) == 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/234
Firstly, design a class **MN** using the Python language, which has an instance attribute **nums**, a private function **private_Maximum_number**, and a public function **public_Maximum_number**. Then, implement the following problem in the private function **private_Maximum_number**. Finally, call the private function **private_Maximum_number** in the public function **public_Maximum_number** to return the result. Problem: Given an integer array **nums**, you can perform some operations on it. In each operation, choose any nums[i], delete it and get the points of nums[i]. After that, you must delete all elements equal to nums[i]-1 and nums[i]+1. Initially, you have 0 points. Return the maximum points that can be obtained through these operations.
[ "assert candidate([3,4,2])==6", "assert candidate([2,2,3,3,3,4])==9" ]
def test_run(content1): return MN(content1).public_Maximum_number()
test_run
assert candidate([['class MN', 'def _private_Maximum_number', 'def public_Maximum_number'], ['class MN', 'def __private_Maximum_number', 'def public_Maximum_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/235
Firstly, design a class **NN** using the Python language, which has instance attributes **times**, **n** and **k**, a private function **private_network_node**, and a public function **public_network_node**. Then, implement the following problem in the private function **private_network_node**. Finally, call the private function **private_network_node** in the public function **public_network_node** to return the result. Problem: There are **n** network nodes, labeled from 1 to n. Given a list **times**, which represents the transmission time of signals passing through directed edges. times[i] = (u_i, v_i, w_i), where **u_i** is the source node, **v_i** is the target node, and **w_i** is the time it takes for a signal to pass from the source node to the target node. Now, a signal is sent from a certain node **K**, how long will it take for all nodes to receive the signal? If not all nodes can receive the signal, return -1.
[ "assert candidate([[2,1,1],[2,3,1],[3,4,1]],4,2)==2", "assert candidate([[1,2,1]],2,1)==1", "assert candidate([[1,2,1]],2,2)==-1" ]
def test_run(content1,content2,content3): return NN(content1,content2,content3).public_network_node()
test_run
assert candidate([['class NN', 'def _private_network_node', 'def public_network_node'], ['class NN', 'def __private_network_node', 'def public_network_node']]) == 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/236
Firstly, design an **INA** class using Python language, which has an instance attribute **target**, a private function **private_Infinite_number_axis**, and a public function **public_Infinite_number_axis**. Then, implement the following problem in the private function **private_Infinite_number_axis**. Finally, call the private function **private_Infinite_number_axis** in the public function **public_Infinite_number_axis** to return the result. Problem: On an infinitely long number axis, you stand at position 0, and the endpoint is at the **target** position. You can make a certain number of moves **numMoves**: each time you can choose to move left or right, and for the i-th move (from i==1 to i==numMoves), you walk **i** steps in the chosen direction. Given an integer **target**, return the minimum number of moves required to reach the target (i.e., the minimum **numMoves**).
[ "assert candidate(2)==3", "assert candidate(3)==2" ]
def test_run(content1): return INA(content1).public_Infinite_number_axis()
test_run
assert candidate([['class INA', 'def _private_Infinite_number_axis', 'def public_Infinite_number_axis'], ['class INA', 'def __private_Infinite_number_axis', 'def public_Infinite_number_axis']]) == 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/237
Firstly, design an **IC** class using Python language, which has an instance attribute **intervals**, a private function **private_Include_Collection**, and a public function **public_Include_Collection**. Then, implement the following problem in the private function **private_Include_Collection**. Finally, call the private function **private_Include_Collection** in the public function **public_Include_Collection** to return the result. Problem: Given a two-dimensional integer array **intervals**, where intervals[i] = [start_i, end_i] represents all integers from **start_i** to **end_i**, including **start_i** and **end_i**. The inclusion set is an array named **nums**, and it satisfies that each interval in **intervals** has at least two integers in **nums**. Return the possible minimum size of the inclusion set.
[ "assert candidate([[1,3],[3,7],[8,9]])==5", "assert candidate([[1,3],[1,4],[2,5],[3,5]])==3", "assert candidate([[1,2],[2,3],[2,4],[4,5]])==5" ]
def test_run(content1): return IC(content1).public_Include_Collection()
test_run
assert candidate([['class IC', 'def _private_Include_Collection', 'def public_Include_Collection'], ['class IC', 'def __private_Include_Collection', 'def public_Include_Collection']]) == 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/238
Firstly, design a class **SP** using Python language, which has an instance attribute **s**, a private function **private_String_partitioning**, and a public function **public_String_partitioning**. Then, implement the following problem in the private function **private_String_partitioning**. Finally, call the private function **private_String_partitioning** in the public function **public_String_partitioning** to return the result. Problem: Given a string **s**, partition this string into as many segments as possible, with the same letter appearing at most once in a segment, and return a list representing the length of each string segment. The partition result needs to satisfy: concatenating all partition results in order, the string obtained is still **s**.
[ "assert candidate(\"ababcbacadefegdehijhklij\")==[9,7,8]", "assert candidate(\"eccbbbbdec\")==[10]" ]
def test_run(content1): return SP(content1).public_String_partitioning()
test_run
assert candidate([['class SP', 'def _private_String_partitioning', 'def public_String_partitioning'], ['class SP', 'def __private_String_partitioning', 'def public_String_partitioning']]) == 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/239
Firstly, design a **PS** class using Python language, which has instance attributes **n** and **mines**, a private function **private_Plus_sign**, and a public function **public_Plus_sign**. Then, implement the following problem in the private function **private_Plus_sign**. Finally, call the private function **private_Plus_sign** in the public function **public_Plus_sign** to return the result. Problem: In an n x n matrix **grid**, every element is 1 except for the elements given as 0 in the array **mines**. mines[i]=[x_i,y_i] indicates grid[x_i][y_i]==0. Return the order of the largest axis-aligned plus sign of 1s in **grid**. If no plus sign is found, return 0.
[ "assert candidate(5,[[4, 2]])==2", "assert candidate(1,[[0, 0]])==0" ]
def test_run(content1,content2): return PS(content1,content2).public_Plus_sign()
test_run
assert candidate([['class PS', 'def _private_Plus_sign', 'def public_Plus_sign'], ['class PS', 'def __private_Plus_sign', 'def public_Plus_sign']]) == 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/240
Firstly, design an **ES** class using Python language, which has an instance attribute **row**, a private function **private_Exchange_seats**, and a public function **public_Exchange_seats**. Then, implement the following problem in the private function **private_Exchange_seats**. Finally, call the private function **private_Exchange_seats** in the public function **public_Exchange_seats** to return the result. Problem: There are **n** pairs of couples sitting on **2n** seats arranged in a row, and they want to hold each other's hands. People and seats are represented by an integer array **row**, where row[i] is the ID of the person sitting in the i-th seat. The couples are numbered in order, the first pair is (0, 1), the second pair is (2, 3), and so on, the last pair is (2n-2, 2n-1). Return the minimum number of seat swaps so that each couple can sit together side by side. You can choose any two people for each swap, and have them stand up and exchange seats.
[ "assert candidate([0,2,1,3])==1", "assert candidate([3,2,0,1])==0" ]
def test_run(content1): return ES(content1).public_Exchange_seats()
test_run
assert candidate([['class ES', 'def _private_Exchange_seats', 'def public_Exchange_seats'], ['class ES', 'def __private_Exchange_seats', 'def public_Exchange_seats']]) == 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/241
Firstly, design a **JM** class using Python language, which has an instance attribute **matrix**, a private function **private_judgment_matrix**, and a public function **public_judgment_matrix**. Then, in the private function **private_judgment_matrix**, determine whether a given m x n **matrix** is a Toeplitz matrix. If it is, return True; otherwise, return False. Finally, call the private function **private_judgment_matrix** in the public function **public_judgment_matrix** to return the result.
[ "assert candidate([[1,2,3,4],[5,1,2,3],[9,5,1,2]])==True", "assert candidate([[1,2],[2,2]])==False" ]
def test_run(content1): return JM(content1).public_judgment_matrix()
test_run
assert candidate([['class JM', 'def _private_judgment_matrix', 'def public_judgment_matrix'], ['class JM', 'def _private_judgment_matrix', 'def public_judgment_matrix']]) == 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/242
First, design an **RL** class using the Python language, which has an instance attribute **s**, a private function **private_Rearrange_letters**, and a public function **public_Rearrange_letters**. Then, implement the following problem in the private function **private_Rearrange_letters**. Finally, call the private function **private_Rearrange_letters** in the public function **public_Rearrange_letters** to return the result. Problem: Given a string **s**, check if it is possible to rearrange its letters so that no two adjacent characters are the same. Return any possible rearrangement of **s**. If it is not feasible, return an empty string "".
[ "assert candidate(\"aab\")==\"aba\"", "assert candidate(\"aaab\")==\"\"" ]
def test_run(content1): return RL(content1).public_Rearrange_letters()
test_run
assert candidate([['class RL', 'def _private_Rearrange_letters', 'def public_Rearrange_letters'], ['class RL', 'def _private_Rearrange_letters', 'def public_Rearrange_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/243
Firstly, design an **MNB** class using the Python language, which has an instance attribute **arr**, a private function **private_Maximum_number_blocks**, and a public function **public_Maximum_number_blocks**. Then, implement the following problem in the private function **private_Maximum_number_blocks**. Finally, call the private function **private_Maximum_number_blocks** in the public function **public_Maximum_number_blocks** to return the result. Problem: Given an integer array **arr**, split **arr** into several chunks, and sort these chunks separately. Then connect them together so that the result of the connection is the same as the original array sorted in ascending order. Return the maximum number of chunks that the array can be divided into.
[ "assert candidate([5,4,3,2,1])==1", "assert candidate([2,1,3,4,4])==4" ]
def test_run(content1): return MNB(content1).public_Maximum_number_blocks()
test_run
assert candidate([['class MNB', 'def _private_Maximum_number_blocks', 'def public_Maximum_number_blocks'], ['class MNB', 'def __private_Maximum_number_blocks', 'def public_Maximum_number_blocks']]) == 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/244
Firstly, design a class named **SS** using Python language, which includes an instance attribute **arr**, a private function **private_Sort_separately**, and a public function **public_Sort_separately**. Then, implement the following problem in the private function **private_Sort_separately**. Finally, call the private function **private_Sort_separately** in the public function **public_Sort_separately** and return the result. Problem: Given an integer array **arr** of length **n**, which represents the permutation of integers in the range [0, n - 1], divide **arr** into several blocks (i.e., partitions) and sort each block separately. After connecting them, make the result of the connection the same as the original array sorted in ascending order, and return the maximum number of blocks that the array can be divided into.
[ "assert candidate([4,3,2,1,0])==1", "assert candidate([1,0,2,3,4])==4" ]
def test_run(content1): return SS(content1).public_Sort_separately()
test_run
assert candidate([['class SS', 'def _private_Sort_separately', 'def public_Sort_separately'], ['class SS', 'def __private_Sort_separately', 'def public_Sort_separately']]) == 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/245
Firstly, design a class **SPB** using Python language, which has an instance attribute **board**, a private function **private_Solving_puzzle_board**, and a public function **public_Solving_puzzle_board**. Then, implement the following problem in the private function **private_Solving_puzzle_board**. Finally, call the private function **private_Solving_puzzle_board** in the public function **public_Solving_puzzle_board** to return the result. Problem: On a 2 x 3 **board**, there are 5 tiles represented by numbers 1~5, and an empty space represented by 0. A move is defined as swapping 0 with an adjacent number (up, down, left, or right). The puzzle is solved when the **board** result is [[1,2,3],[4,5,0]]. Given an initial state of the puzzle **board**, return the minimum number of moves to solve the puzzle. If the puzzle cannot be solved, return -1.
[ "assert candidate([[1,2,3],[4,0,5]])==1", "assert candidate([[1,2,3],[5,4,0]])==-1", "assert candidate([[4,1,2],[5,0,3]])==5" ]
def test_run(content1): return SPB(content1).public_Solving_puzzle_board()
test_run
assert candidate([['class SPB', 'def _private_Solving_puzzle_board', 'def public_Solving_puzzle_board'], ['class SPB', 'def __private_Solving_puzzle_board', 'def public_Solving_puzzle_board']]) == 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/246
Firstly, design a class **LI** using Python language, which has an instance attribute **nums**, a private function **private_Local_inversion**, and a public function **public_Local_inversion**. Then, implement the following problem in the private function **private_Local_inversion**. Finally, call the private function **private_Local_inversion** in the public function **public_Local_inversion** and return the result. Problem: Given an integer array **nums** of length **n**, representing a permutation composed of all integers within the range [0, n - 1]. The number of global inversions is equal to the number of different index pairs (i, j) that satisfy the following conditions: 1. 0 <= i < j < n; 2. nums[i] > nums[j]; The number of local inversions is equal to the number of indexes **i** that satisfy the following conditions: 1. 0 <= i < n - 1; 2. nums[i] > nums[i + 1]; When the number of global inversions in the array **nums** equals the number of local inversions, return True; otherwise, return False.
[ "assert candidate([1,0,2])==True", "assert candidate([1,2,0])==False" ]
def test_run(content1): return LI(content1).public_Local_inversion()
test_run
assert candidate([['class LI', 'def _private_Local_inversion', 'def public_Local_inversion'], ['class LI', 'def __private_Local_inversion', 'def public_Local_inversion']]) == 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/247
Firstly, design a class **GS** using the Python language, which has an instance attribute **grid**, a private function **private_Grid_swimming**, and a public function **public_Grid_swimming**. Then, implement the following problem in the private function **private_Grid_swimming**. Finally, call the private function **private_Grid_swimming** in the public function **public_Grid_swimming** to return the result. Problem: In an n x n integer matrix **grid**, each cell's value grid[i][j] represents the platform height at position (i, j). When it starts to rain, the water level in the pool is **t** at time **t**. You can swim to any adjacent platform, but the prerequisite is that the water level must submerge these two platforms at the same time. Assuming you can move an infinite distance instantly, that is, it is assumed that swimming within the grid does not consume time. Of course, you must stay within the coordinate grid while swimming. You start from the top-left platform (0,0) of the coordinate grid, and return the minimum time required to reach the bottom-right platform (n-1, n-1) of the coordinate grid.
[ "assert candidate([[0,2],[1,3]])==3", "assert candidate([[0,1,2,3,4],[24,23,22,21,5],[12,13,14,15,16],[11,17,18,19,20],[10,9,8,7,6]])==16" ]
def test_run(content1): return GS(content1).public_Grid_swimming()
test_run
assert candidate([['class GS', 'def _private_Grid_swimming', 'def public_Grid_swimming'], ['class GS', 'def __private_Grid_swimming', 'def public_Grid_swimming']]) == 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/248
Firstly, design a **GNR** class using Python language, which has instance attributes **n** and **k**, a private function **private_Given_number_rows**, and a public function **public_Given_number_rows**. Then, implement the following problem in the private function **private_Given_number_rows**. Finally, call the private function **private_Given_number_rows** in the public function **public_Given_number_rows** to return the result. Problem: We have constructed a table with **n** rows (indexed from 1). Initially, we write a 0 on the first row. For each subsequent row, we replace 0 with 01 and 1 with 10 in the previous row. Given the row number **n** and the ordinal **k**, return the k-th character (k indexed from 1) in the n-th row.
[ "assert candidate(1,1)==0", "assert candidate(2,1)==0", "assert candidate(2,2)==1" ]
def test_run(content1,content2): return GNR(content1,content2).public_Given_number_rows()
test_run
assert candidate([['class GNR', 'def _private_Given_number_rows', 'def public_Given_number_rows'], ['class GNR', 'def __private_Given_number_rows', 'def public_Given_number_rows']]) == 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/249
Firstly, design a **CN** class using Python language, which has instance attributes **sx**, **sy**, **tx**, and **ty**, a private function **private_Convert_numbers**, and a public function **public_Convert_numbers**. Then, implement the following problem in the private function **private_Convert_numbers**. Finally, call the private function **private_Convert_numbers** in the public function **public_Convert_numbers** to return the result. Problem: Given four integers **sx**, **sy**, **tx**, and **ty**. If it is possible to reach the endpoint (tx, ty) from the starting point (sx, sy) through a series of transformations, return True, otherwise return False. From point (x, y), it can be transformed to either (x, x+y) or (x+y, y).
[ "assert candidate(1,1,3,5)==True", "assert candidate(1,1,2,2)==False", "assert candidate(1,1,1,1)==True" ]
def test_run(content1,content2,content3,content4): return CN(content1,content2,content3,content4).public_Convert_numbers()
test_run
assert candidate([['class CN', 'def _private_Convert_numbers', 'def public_Convert_numbers'], ['class CN', 'def __private_Convert_numbers', 'def public_Convert_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/250
First, design a class **FR** using the Python language, which has an instance attribute **answers**, a private function **private_Forest_Rabbit**, and a public function **public_Forest_Rabbit**. Then, implement the following problem in the private function **private_Forest_Rabbit**. Finally, call the private function **private_Forest_Rabbit** in the public function **public_Forest_Rabbit** to return the result. Problem: There is an unknown number of rabbits in the forest. Ask some of the rabbits **how many other rabbits have the same color as you (referring to the rabbit being asked)**, and collect the answers into an integer array **answers**, where answers[i] is the answer of the i-th rabbit. Given the array **answers**, return the minimum number of rabbits in the forest.
[ "assert candidate([1,1,2])==5", "assert candidate([10,10,10])==11" ]
def test_run(content1): return FR(content1).public_Forest_Rabbit()
test_run
assert candidate([['class FR', 'def _private_Forest_Rabbit', 'def public_Forest_Rabbit'], ['class FR', 'def __private_Forest_Rabbit', 'def public_Forest_Rabbit']]) == 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/251
Firstly, design a class **NM** using the Python language, which has an instance attribute **board**, a private function **private_Network_Matrix**, and a public function **public_Network_Matrix**. Then, implement the following problem in the private function **private_Network_Matrix**. Finally, call the private function **private_Network_Matrix** in the public function **public_Network_Matrix** to return the result. Problem: A n x n two-dimensional network **board** is composed only of 0 and 1. In each move, you can freely swap the positions of two columns or two rows. Return the minimum number of moves required to transform this matrix into a **chessboard**. If there is no feasible transformation, output -1.
[ "assert candidate([[0,1,1,0],[0,1,1,0],[1,0,0,1],[1,0,0,1]])==2", "assert candidate([[0,1],[1,0]])==0", "assert candidate([[1,0],[1,0]])==-1" ]
def test_run(content1): return NM(content1).public_Network_Matrix()
test_run
assert candidate([['class NM', 'def _private_Network_Matrix', 'def public_Network_Matrix'], ['class NM', 'def __private_Network_Matrix', 'def public_Network_Matrix']]) == 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/252
Firstly, design a class **CC** using Python language, which has an instance attribute **s**, a private function **private_Change_Case**, and a public function **public_Change_Case**. Then, implement the following problem in the private function **private_Change_Case**. Finally, call the private function **private_Change_Case** in the public function **public_Change_Case** to return the result. Problem: Given a string **s**, by changing the case of each letter in the string **s**, we can obtain a new string. Return the set of all possible strings that can be obtained.
[ "assert candidate(\"a1b2\")==[\"a1b2\", \"a1B2\", \"A1b2\", \"A1B2\"]", "assert candidate(\"3z4\")==[\"3z4\",\"3Z4\"]" ]
def test_run(content1): return CC(content1).public_Change_Case()
test_run
assert candidate([['class CC', 'def _private_Change_Case', 'def public_Change_Case'], ['class CC', 'def __private_Change_Case', 'def public_Change_Case']]) == 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/253
Firstly, design a class **MS** using the Python language, which has instance attributes **arr** and **k**, a private function **private_Minimum_score**, and a public function **public_Minimum_score**. Then, implement the following problem in the private function **private_Minimum_score**. Finally, call the private function **private_Minimum_score** in the public function **public_Minimum_score** to return the result. Problem: Given an array **arr** sorted in ascending order and an integer **k**. The array **arr** is composed of 1 and several prime numbers, and all integers in it are different from each other. For each pair of **i** and **j** satisfying 0 <= i < j < arr.length, a score can be obtained as arr[i]/arr[j]. So, what is the k-th smallest score?
[ "assert candidate([1,2,3,5],3)==[2,5]", "assert candidate([1,7],1)==[1,7]" ]
def test_run(content1,content2): return MS(content1,content2).public_Minimum_score()
test_run
assert candidate([['class MS', 'def _private_Minimum_score', 'def public_Minimum_score'], ['class MS', 'def __private_Minimum_score', 'def public_Minimum_score']]) == 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/254
Firstly, design a **PM** class using Python language, which has instance attributes **order** and **s**, a private function **private_Permutation_matching**, and a public function **public_Permutation_matching**. Then, implement the following problem in the private function **private_Permutation_matching**. Finally, call the private function **private_Permutation_matching** in the public function **public_Permutation_matching** to return the result. Problem: Given two strings, **order** and **s**, all the letters in **order** are unique and have been sorted in some custom order. Permute the characters of **s** to match the sorted **order**. More specifically, if character **x** appears before character **y** in **order**, then in the permuted string, **x** should also appear before **y**. Return any permutation of **s** that satisfies this property.
[ "assert candidate(\"cba\",\"abcd\")==\"cbad\"", "assert candidate(\"cbafg\",\"abcd\")==\"cbad\"" ]
def test_run(content1,content2): return PM(content1,content2).public_Permutation_matching()
test_run
assert candidate([['class PM', 'def _private_Permutation_matching', 'def public_Permutation_matching'], ['class PM', 'def _private_Permutation_matching', 'def public_Permutation_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/255
Firstly, design a class **NW** using the Python language, which has instance attributes **s** and **words**, a private function **private_Number_words**, and a public function **public_Number_words**. Then, in the private function **private_Number_words**, return the number of words in words[i] that are subsequences of the given string **s** based on the given string **s** and the number of strings **words**. Finally, in the public function **public_Number_words**, call the private function **private_Number_words** to return the result.
[ "assert candidate(\"abcde\",[\"a\",\"bb\",\"acd\",\"ace\"])==3", "assert candidate(\"dsahjpjauf\",[\"ahjpjau\",\"ja\",\"ahbwzgqnuk\",\"tnmlanowax\"])==2" ]
def test_run(content1,content2): return NW(content1,content2).public_Number_words()
test_run
assert candidate([['class NW', 'def _private_Number_words', 'def public_Number_words'], ['class NW', 'def __private_Number_words', 'def public_Number_words']]) == 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/256
Firstly, design a class **NI** using Python language, which has an instance attribute **k**, a private function **private_nonnegative_integer**, and a public function **public_nonnegative_integer**. Then, implement the following problem in the private function **private_nonnegative_integer**. Finally, call the private function **private_nonnegative_integer** in the public function **public_nonnegative_integer** to return the result. Problem: f(x) is the number of zeros at the end of x!, recall that x! = 1*2*3*...*x, and 0! = 1. Given **k**, find the number of non-negative integers **x** that can satisfy f(x) = k.
[ "assert candidate(0)==5", "assert candidate(5)==0", "assert candidate(3)==5" ]
def test_run(content1): return NI(content1).public_nonnegative_integer()
test_run
assert candidate([['class NI', 'def _private_nonnegative_integer', 'def public_nonnegative_integer'], ['class NI', 'def __private_nonnegative_integer', 'def public_nonnegative_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/2
Question: Given an integer array **nums** and two integers **left** and **right**. Find the number of subarrays in **nums** that are continuous, non-empty, and have the maximum element within the range [left, right]. Please create a class called FDSB in Python based on the above problem, with the **nums** attribute. Then create a class called **SN_FDSB** that inherits from the **FDSB** class, and add two attributes **left** and **right**, as well as a public function called **find_subarray** that checks and returns the number of subarrays in **nums** that are continuous, non-empty, and have the maximum element within the range [left, right].
[ "assert candidate([2,1,4,3],2,3)==3", "assert candidate([2,9,2,5,6],2,8)==7" ]
def test_run(content1,content2,content3): return SN_FDSB(content1,content2,content3).find_subarray()
test_run
assert candidate([['class FDSB', 'def find_subarray', 'super().__init__(nums)', '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/257
Question: Given an integer array **nums** and two integers: **left** and **right**. Find the continuous, non-empty subarrays in **nums** where the maximum element is within the range [left, right] and return the number of such subarrays that meet the conditions. Based on the above question, create a class **FDSB** in Python language with the attribute **nums**; then create another class **SN_FDSB** that inherits from the **FDSB** class, and add two attributes **left** and **right**, as well as a public function **find_subarray** to determine and return the number of continuous, non-empty subarrays in **nums** where the maximum element is within the range [left, right].
[ "assert candidate([2,1,4,3],2,3)==3", "assert candidate([2,9,2,5,6],2,8)==7" ]
def test_run(content1,content2,content3): return SN_FDSB(content1,content2,content3).find_subarray()
test_run
assert candidate([['class FDSB', 'class SN_FDSB(FDSB)', 'super().__init__(nums)', '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/258
Question: Given a directed acyclic graph (DAG) with **n** nodes, find and output all paths from node 0 to node n-1; Based on the above question, create a class **PO** in Python with the attribute **graph**; then create another class **SN_PO**, inheriting from the **PO** class, and add a public function **Path_output** to return all paths from node 0 to node n-1 in the **n** nodes.
[ "assert candidate([[1,2],[3],[3],[]])==[[0,1,3],[0,2,3]]", "assert candidate([[4,3,1],[3,2,4],[3],[4],[]])==[[0,4],[0,3,4],[0,1,3,4],[0,1,2,3,4],[0,1,4]]" ]
def test_run(content1): return SN_PO(content1).Path_output()
test_run
assert candidate([['class PO', 'class SN_PO(PO)', 'super().__init__(graph)', 'def Path_output']]) == 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/259
Question: Given two integer arrays **nums1** and **nums2** of equal length and not empty. In one operation, you can swap the elements of nums1[i] and nums2[i]. For example, if nums1=[1,2,3,8], nums2=[5,6,7,4], you can swap the element at i=3 to get nums1=[1,2,3,4] and nums2=[5,6,7,8]. Return the minimum number of operations required to make **nums1** and **nums2** strictly increasing; Based on the above question, create a class **EE** in Python language with the attribute **nums1**; then create a class **SN_EE** that inherits the **EE** class, and add the attribute **nums2**, as well as a public function **Exchange_Elements** to return the minimum number of operations required to make **nums1** and **nums2** strictly increasing.
[ "assert candidate([1,3,5,4],[1,2,3,7])==1", "assert candidate([0,3,5,8,9],[2,1,4,6,9])==1" ]
def test_run(content1,content2): return SN_EE(content1,content2).Exchange_Elements()
test_run
assert candidate([['class EE', 'class SN_EE(EE)', 'super().__init__(nums1)', 'def Exchange_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/260
Question: Given a directed graph with **n** nodes numbered from 0 to n-1, the graph is represented by a 2D integer array **graph** indexed from 0, where graph[i] is an integer array of nodes adjacent to node **i**, meaning there is an edge from node **i** to each node in **graph[i]**. If a node has no outgoing directed edges, it is a **terminal node**. If all possible paths starting from this node lead to a terminal node, then this node is a **safe node**. Return an array consisting of all the safe nodes in the graph as the answer. The elements in the answer array should be sorted in ascending order; Based on the above question, please create a class **SND** in Python with the property **graph**; then create a class **SN_SND** that inherits from the **SND** class, and add a public function **secure_node** to return an array of all the safe nodes in the graph sorted in ascending order.
[ "assert candidate([[1,2],[2,3],[5],[0],[5],[],[]])==[2,4,5,6]", "assert candidate([[1,2,3,4],[1,2],[3,4],[0,4],[]])==[4]" ]
def test_run(content1): return SN_SND(content1).secure_node()
test_run
assert candidate([['class SND', 'class SN_SND(SND)', 'super().__init__(graph)', 'def secure_node']]) == 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/261
Question: There is an m x n binary **grid**, where 1 represents a brick and 0 represents a blank. The premise for a brick to be stable (not falling) is: a brick is directly connected to the top of the grid, or at least one adjacent (one of the four directions) brick is stable and will not fall. Given an array **hits**, this is the position where the bricks need to be eliminated in order. Whenever the brick at the position hits[i]=(row_i, col_i) is eliminated, the corresponding brick (if it exists) will disappear, and then other bricks may fall due to this elimination operation. Once the brick falls, it will immediately disappear from the grid (it will not fall on other stable bricks). Return an array **result**, where result[i] represents the number of bricks falling corresponding to the i-th elimination operation; Based on the above question, please create a class **NBS** in Python language with the property **grid**; then create a class **SN_NBS** that inherits the **NBS** class, and add the property **hits**, and a public function **Number_bricks** to return the array **result** representing the number of bricks falling corresponding to the elimination operation.
[ "assert candidate([[1,0,0,0],[1,1,1,0]],[[1,0]])==[2]", "assert candidate([[1,0,0,0],[1,1,0,0]],[[1,1],[1,0]])==[0,0]" ]
def test_run(content1,content2): return SN_NBS(content1,content2).Number_bricks()
test_run
assert candidate([['class NBS', 'class SN_NBS(NBS)', 'super().__init__(grid)', 'def Number_bricks']]) == 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/262
Question: Given an integer array **nums**. Move each element in the **nums** array to array **A** or array **B**, ensuring that arrays **A** and **B** are not empty, and average(A) == average(B). If it can be completed, return True, otherwise return False; Based on the above question, please create a class **EMT** in Python, with the attribute **nums**; then create another class **SN_EMT** that inherits from the **EMT** class, and add a public function **Element_Movement** to determine whether it can be completed.
[ "assert candidate([1,2,3,4,5,6,7,8])==True", "assert candidate([3,1])==False" ]
def test_run(content1): return SN_EMT(content1).Element_Movement()
test_run
assert candidate([['class EMT', 'class SN_EMT(EMT)', 'super().__init__(nums)', 'def Element_Movement']]) == 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/263
Question: Given an array **nums** and an integer **k**. We divide the given array **nums** into at most **k** non-empty subarrays, and the array is continuous. The score is composed of the sum of the averages within each subarray. Return the maximum score that can be obtained; Based on the above question, use Python language to create a class **MSE** with the attribute **nums**; then create a class **SN_MSE**, inheriting from the **MSE** class, and add the attribute **k**, as well as a public function **Maximum_score** to return the maximum score that can be obtained.
[ "assert candidate([9,1,2,3,9],3)==20.00000", "assert candidate([1,2,3,4,5,6,7],4)==20.50000" ]
def test_run(content1,content2): return SN_MSE(content1,content2).Maximum_score()
test_run
assert candidate([['class MSE', 'class SN_MSE(MSE)', 'super().__init__(nums)', 'def Maximum_score']]) == 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/264
Question: Given an array **routes**, representing a series of bus routes, where each routes[i] represents a bus route, the i-th bus will circulate on it. For example, the route routes[0]=[1,5,7] indicates that the 0-th bus will always travel in the sequence of 1->5->7->1->5->7->1->... Now starting from the **source** station (not initially on the bus), you want to go to the **target** station. During this period, you can only take the bus. Find the minimum number of buses to take. If it is impossible to reach the terminal station, return -1; Based on the above question, please use Python to create a class **TSN** with the attribute **routes**; then create a class **SN_TSN** that inherits from the **TSN** class, and add two attributes **source** and **target**, as well as a public function **Terminal_Station** to return the minimum number of buses to take.
[ "assert candidate([[1,2,7],[3,6,7]],1,6)==2", "assert candidate([[7,12],[4,5,15],[6],[15,19],[9,12,13]],15,12)==-1" ]
def test_run(content1,content2,content3): return SN_TSN(content1,content2,content3).Terminal_Station()
test_run
assert candidate([['class TSN', 'class SN_TSN(TSN)', 'super().__init__(routes)', 'def Terminal_Station']]) == 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/265
Question: There are some two-dimensional coordinates, such as (1,3) or (2,0.5), and then we remove all commas, decimal points, and spaces to get a string **S**. Return all possible original strings to a list. The original coordinate notation will not have extra zeros, so there will be no **00**, **0.0**, **0.00**, **1.0**, **001**, **00.01** or some other smaller numbers to represent coordinates. In addition, there is at least one number before a decimal point, so there will be no **.1** form of numbers. Note that there is a space between the two returned numbers (after the comma); Please create a class **AOR** based on the above problem using Python language, with the attribute **s**; then create a class **SN_AOR** that inherits the **AOR** class, and add a public function **Any_order** to return all possible original strings in any order to a list after removing all commas, decimal points, and spaces from the string **S**.
[ "assert candidate(\"(123)\")==[\"(1, 23)\", \"(12, 3)\", \"(1.2, 3)\", \"(1, 2.3)\"]", "assert candidate(\"(00011)\")==[\"(0.001, 1)\", \"(0, 0.011)\"]", "assert candidate(\"(0123)\")==[\"(0, 123)\", \"(0, 12.3)\", \"(0, 1.23)\", \"(0.1, 23)\", \"(0.1, 2.3)\", \"(0.12, 3)\"]", "assert candidate(\"(100)\")==[(10, 0)]" ]
def test_run(content1): return SN_AOR(content1).Any_order()
test_run
assert candidate([['class AOR', 'class SN_AOR(AOR)', 'super().__init__(s)', 'def Any_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/266
Question: The valid encoding of the word array **words** consists of any mnemonic string **s** and index array **indices**, and meets the following requirements: 1. words.length == indices.length 2. The mnemonic string **s** ends with the character '#' 3. For each index indices[i], a substring of **s** that starts from indices[i] and ends at the next '#' character (but does not include '#') exactly equals to words[i]. Given a word array **words**, return the length of the smallest mnemonic string **s** that successfully encodes **words**; Based on the above question, please create a class **ECG** in Python with the attribute **words**; then create a class **SN_ECG** that inherits the **ECG** class, and add a public function **efficient_coding** to return the length of the smallest mnemonic string **s** that successfully encodes **words**.
[ "assert candidate([\"time\", \"me\", \"bell\"])==10", "assert candidate([\"t\"])==2" ]
def test_run(content1): return SN_ECG(content1).efficient_coding()
test_run
assert candidate([['class ECG', 'class SN_ECG(ECG)', 'super().__init__(words)', 'def efficient_coding']]) == 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/267
Question: Given a string **s** and a character **c**, where **c** is a character that appears in **s**. Return an integer array **answer**, where answer.length == s.length and answer[i] is the distance from index **i** in **s** to the nearest character **c**; Based on the above question, please create a class **CDC** in Python, with the attribute **s**; then create another class **SN_CDC**, inheriting from the **CDC** class, and add the attribute **c**, as well as a public function **Character_distance** to return an integer array **answer**.
[ "assert candidate(\"loveleetcode\",\"e\")==[3,2,1,0,1,0,0,1,2,2,1,0]", "assert candidate(\"aaab\",\"b\")==[3,2,1,0]" ]
def test_run(content1,content2): return SN_CDC(content1,content2).Character_distance()
test_run
assert candidate([['class CDC', 'class SN_CDC(CDC)', 'super().__init__(s)', 'def Character_distance']]) == 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/268
Question: Given an array **arr** containing non-repeating integer elements, each integer arr[i] is greater than 1. Use these integers to construct a binary tree, each integer can be used any number of times. Where: the value of each non-leaf node should be equal to the product of the values of its two child nodes. How many binary trees are there that meet the conditions; Based on the above question, please use Python language to create a class **RIR** with the attribute **arr**; then create a class **SN_RIR** that inherits the **RIR** class, and add a public function **repeating_integer** to return the number of binary trees that meet the conditions.
[ "assert candidate([2, 4])==3", "assert candidate([2, 4, 5, 10])==7" ]
def test_run(content1): return SN_RIR(content1).repeating_integer()
test_run
assert candidate([['class RIR', 'class SN_RIR(RIR)', 'super().__init__(arr)', 'def repeating_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/269
Question: You have **n** jobs and **m** workers. Given three arrays: **difficulty**, **profit**, and **worker**, where: difficulty[i] represents the difficulty of the i-th job, profit[i] represents the profit of the i-th job. **worker[i]** is the ability of the i-th worker, that is, the worker can only complete jobs with difficulty less than or equal to worker[i]. Each worker can only be assigned one job at most, but one job can be completed multiple times. For example, if three workers all try to complete the same job with a reward of $1, then the total profit is $3. If a worker cannot complete any job, his profit is $0. Return the maximum profit we can get after assigning workers to jobs; Please create a class **MPT** in Python based on the above question, with the attribute **difficulty**; then create a class **SN_MPT** that inherits the **MPT** class, and add two attributes **profit** and **worker**, as well as a public function **Maximum_profit** to return the maximum profit we can get after assigning **m** workers to **n** jobs.
[ "assert candidate([2,4,6,8,10],[10,20,30,40,50],[4,5,6,7])==100", "assert candidate([85,47,57],[24,66,99],[40,25,25])==0" ]
def test_run(content1,content2,content3): return SN_MPT(content1,content2,content3).Maximum_profit()
test_run
assert candidate([['class MPT', 'class SN_MPT(MPT)', 'super().__init__(difficulty)', 'def 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/270
Question: Given a binary matrix **grid** of size n x n. You are allowed to change at most one 0 to 1. Return the maximum area of an island in the **grid** after this operation; Please create a class **IAA** in Python based on the above question, with the attribute **grid**. Then create a class **SN_IAA** that inherits from the **IAA** class, and add a public function **Island_area** to return the maximum area of an island in the **grid** after changing one 0 to 1 in the binary matrix **grid**.
[ "assert candidate([[1, 0], [0, 1]])==3", "assert candidate([[1, 1], [1, 0]])==4", "assert candidate([[1, 1], [1, 1]])==4" ]
def test_run(content1): return SN_IAA(content1).Island_area()
test_run
assert candidate([['class IAA', 'class SN_IAA(IAA)', 'super().__init__(grid)', 'def Island_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/271
Question: Define a function **countUniqueChars** to count the unique characters in string **s**, and return the number of unique characters; Based on the above question, please create a class **UCR** in Python language with the attribute **s**; then create another class **SN_UCR** that inherits from the **UCR** class, and add a public function **Unique_character** to return the number of unique characters in string **s**.
[ "assert candidate(\"ABC\")==10", "assert candidate(\"ABA\")==8", "assert candidate(\"LEETCODE\")==92" ]
def test_run(content1): return SN_UCR(content1).Unique_character()
test_run
assert candidate([['class UCR', 'class SN_UCR(UCR)', 'super().__init__(s)', 'def Unique_character']]) == 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/272
Question: Given a positive integer **n**, return the number of groups of consecutive positive integers that satisfy the sum of all numbers equals **n**; Based on the above question, please create a class **SNS** in Python, which has an attribute **n**. Then create another class **SN_SNS** that inherits from the **SNS** class, and add a public function **Sum_Numbers** to return the number of groups of consecutive positive integers that satisfy the sum of all numbers equals **n**.
[ "assert candidate(5)==2", "assert candidate(9)==3", "assert candidate(15)==5" ]
def test_run(content1): return SN_SNS(content1).Sum_Numbers()
test_run
assert candidate([['class SNS', 'class SN_SNS(SNS)', 'super().__init__(n)', 'def Sum_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/273
Question: Given an undirected, connected tree. The tree has **n** nodes labeled from 0 to n-1 and n-1 edges. Given an integer **n** and an array **edges**, edges[i] = [a_i, b_i] indicates that there is an edge between nodes a_i and b_i in the tree. Return an array answer of length **n**, where answer[i] is the sum of the distances between the i-th node and all other nodes in the tree; Based on the above question, please create a class **SDC** in Python language with the attribute **n**; then create a class **SN_SDC** that inherits from the **SDC** class, and add the attribute **edges**, as well as a public function **Sum_distances** to return an array **answer** of length **n**.
[ "assert candidate(6,[[0,1],[0,2],[2,3],[2,4],[2,5]])==[8,12,6,10,10,10]", "assert candidate(1,[])==[0]", "assert candidate(2,[[1,0]])==[1,1]" ]
def test_run(content1,content2): return SN_SDC(content1,content2).Sum_distances()
test_run
assert candidate([['class SDC', 'class SN_SDC(SDC)', 'super().__init__(n)', 'def Sum_distances']]) == 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/274
Question: Given two images **img1** and **img2**, both of which are n x n in size and represented by binary square matrices of the same size. The binary matrix is composed only of several 0s and 1s. Transform one of the images by sliding all the 1s to the left, right, up, or down by any number of units; then place it on top of the other image. The overlap of this transformation refers to the number of positions where both images have 1s. Please note that the transformation does not include rotation in any direction. Any 1s that cross the matrix boundary will be cleared. What is the maximum possible number of overlaps? Based on the above question, please create a class **OQT** in Python with the attribute **img1**; then create another class **SN_OQT** that inherits from the **OQT** class, and add the attribute **img2**, as well as a public function **Overlap_quantity** to return the maximum possible number of overlaps.
[ "assert candidate([[1,1,0],[0,1,0],[0,1,0]],[[0,0,0],[0,1,1],[0,0,1]])==3", "assert candidate([[1]],[[1]])==1", "assert candidate([[0]],[[0]])==0" ]
def test_run(content1,content2): return SN_OQT(content1,content2).Overlap_quantity()
test_run
assert candidate([['class OQT', 'class SN_OQT(OQT)', 'super().__init__(img1)', 'def Overlap_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/275
Question: A rectangle is represented as a list [x1,y1,x2,y2], where (x1,y1) is the coordinate of the bottom left corner, and (x2,y2) is the coordinate of the top right corner. The top and bottom edges of the rectangle are parallel to the x-axis, and the left and right edges are parallel to the y-axis. If the intersecting area is positive, then the two rectangles are considered to be **overlapping**. It should be clarified that two rectangles that only touch at the corner or edge do not constitute an overlap. Given two rectangles **rec1** and **rec2**. If they overlap, return True; otherwise, return False. Based on the above question, please create a class **ROP** in Python language with the attribute **rec1**; then create a class **SN_ROP** that inherits from the **ROP** class, and add the attribute **rec2**, as well as a public function **Rectangle_overlap** to determine whether the intersecting area of the two rectangles **rec1** and **rec2** is positive. If it is, return True; otherwise, return False.
[ "assert candidate([0,0,2,2],[1,1,3,3])==True", "assert candidate([0,0,1,1],[1,0,2,1])==False", "assert candidate([0,0,1,1],[2,2,3,3])==False" ]
def test_run(content1,content2): return SN_ROP(content1,content2).Rectangle_overlap()
test_run
assert candidate([['class ROP', 'class SN_ROP(ROP)', 'super().__init__(rec1)', 'def Rectangle_overlap']]) == 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/276
Question: Alice participates in a game roughly based on the rules of the card game **Blackjack**, described as follows: Alice starts with 0 points, and draws numbers when her score is less than k points. When drawing, she randomly gets an integer from the range [1, maxPts] to accumulate as a score, where **maxPts** is an integer. Each draw is independent, and the results have the same probability. When Alice gets **k** points or more, she stops drawing numbers. What is the probability that Alice's score does not exceed **n**; Please create a class **ENS** in python language based on the above question, with the attribute **n**; then create a class **SN_ENS**, inheriting from the **ENS** class, and add two attributes **k** and **maxPts**, as well as a public **Extract_Numbers** function to return the probability that Alice's score does not exceed **n**.
[ "assert candidate(10,1,10)==1.00000", "assert candidate(6,1,10)==0.60000", "assert candidate(21,17,10)==0.73278" ]
def test_run(content1,content2,content3): return SN_ENS(content1,content2,content3).Extract_Numbers()
test_run
assert candidate([['class ENS', 'class SN_ENS(ENS)', 'super().__init__(n)', 'def Extract_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/277
Question: If two different positions in string **X** are swapped to make it equal to string **Y**, then **X** and **Y** are considered similar. If the two strings are identical, they are also similar. Given a list of strings **strs**, each string in the list is an anagram of all other strings in **strs**. How many similar string groups are there in **strs**; Based on the above question, create a class **SST** in Python with the attribute **strs**; then create a class **SN_SST** that inherits from the **SST** class, and add a public function **Similar_Strings** to return the number of similar string groups in the string list **strs**.
[ "assert candidate([\"tars\",\"rats\",\"arts\",\"star\"])==2", "assert candidate([\"omv\",\"ovm\"])==1" ]
def test_run(content1): return SN_SST(content1).Similar_Strings()
test_run
assert candidate([['class SST', 'class SN_SST(SST)', 'super().__init__(strs)', 'def Similar_Strings']]) == 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/278
Question: A 3x3 magic square is a 3x3 matrix filled with distinct numbers from 1 to 9, where the sum of each row, each column, and the two diagonals are equal. Given a grid of row x col composed of integers, how many 3x3 **magic square** submatrices are there? (Each submatrix is continuous); Based on the above question, please create a **SAX** class in Python with a **grid** attribute; then create a **SN_SAX** class that inherits from the **SAX** class, and add a public **submatrix** function to return the number of 3x3 magic square submatrices.
[ "assert candidate([[4,3,8,4],[9,5,1,9],[2,7,6,2]])==1", "assert candidate([[8]])==0" ]
def test_run(content1): return SN_SAX(content1).submatrix()
test_run
assert candidate([['class SAX', 'class SN_SAX(SAX)', 'super().__init__(grid)', 'def submatrix']]) == 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/279
Question: There are **n** rooms, numbered from 0 to n-1. Initially, all rooms except room 0 are locked. Your goal is to enter all rooms. However, you cannot enter a locked room without obtaining the key. When you enter a room, you may find a set of different keys inside, each key has a corresponding room number, indicating the room that the key can open. You can take all the keys to unlock other rooms. You are given an array **rooms**, where rooms[i] is the set of keys you can get when you enter room **i**. If you can enter all rooms, return True, otherwise return False. Please create a class **ARS** in Python based on the above question, with the property **rooms**. Then create a class **SN_ARS** that inherits the **ARS** class, and add a public function **All_rooms** to determine whether you can enter all **n** rooms numbered from 0 to n-1. If you can, return True, otherwise return False.
[ "assert candidate([[1],[2],[3],[]])==True", "assert candidate([[1,3],[3,0,1],[2],[0]])==False" ]
def test_run(content1): return SN_ARS(content1).All_rooms()
test_run
assert candidate([['class ARS', 'class SN_ARS(ARS)', 'super().__init__(rooms)', 'def All_rooms']]) == 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/280
Question: Given a string of digits **num**, such as "123456579", we can split it into a Fibonacci-like sequence [123,456,579]. Formally, a Fibonacci-like sequence is a list of non-negative integers **f**, satisfying: 1. 0<=f[i]<231, (in other words, each integer conforms to the 32-bit signed integer type). 2. f.length>=3. 3. For all 0<=i<f.length-2, f[i]+f[i+1]=f[i+2]. Also, please note that when splitting the string into chunks, each chunk's number must not start with zero, unless the chunk is the number 0 itself. Return any Fibonacci-like sequence chunks split from num, if it cannot be split, return []. Based on the above question, please create a class **FEQ** in Python, with the attribute **num**; then create another class **SN_FEQ**, inheriting from the **FEQ** class, and add a public function **Fibonacci_equation** to return any Fibonacci-like sequence chunks split from **num**, if it cannot be split, return [].
[ "assert candidate(\"1101111\")==[11,0,11,11]", "assert candidate(\"112358130\")==[]", "assert candidate(\"0123\")==[]" ]
def test_run(content1): return SN_FEQ(content1).Fibonacci_equation()
test_run
assert candidate([['class FEQ', 'class SN_FEQ(FEQ)', 'super().__init__(num)', 'def Fibonacci_equation']]) == 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/281
Question: An array arr is called a mountain array if it meets the following properties: 1. arr.length>=3. 2. There exists an index **i** (0<i<arr.length-1), such that arr[0]<arr[1]<...<arr[i-1]<arr[i] and arr[i]>arr[i+1]>...>arr[arr.length-1]. Given an integer array **arr**, return the length of the longest mountain subarray. If there is no mountain subarray, return 0; Based on the above question, please create a class **LMN** in Python, which has the property **arr**; then create a class **SN_LMN** that inherits the **LMN** class, and add a public function **Longest_mountain** to return the length of the longest **mountain subarray** in the integer array **arr**. If there is no mountain subarray, return 0.
[ "assert candidate([2,1,4,7,3,2,5])==5", "assert candidate([2,2,2])==0" ]
def test_run(content1): return SN_LMN(content1).Longest_mountain()
test_run
assert candidate([['class LMN', 'class SN_LMN(LMN)', 'super().__init__(arr)', 'def Longest_mountain']]) == 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/282
Question: Alice has a deck of cards in her hand. She wants to rearrange these cards into several groups, each with a group size of **groupSize**, and each group consists of **groupSize** consecutive cards. You are given an integer array **hand** where hand[i] is the value written on the i-th card. If she can rearrange these cards, return True; otherwise, return False. Based on the above question, please create a class **RRG** in Python, which has the attribute **hand**; then create a class **SN_RRG** that inherits the **RRG** class, and add the attribute **groupSize**, as well as a public function **rearrange** to determine whether Alice can rearrange the deck of cards in her hand into several groups, each with a group size of **groupSize**, and each group consists of **groupSize** consecutive cards.
[ "assert candidate([1,2,3,6,2,3,4,7,8],3)==True", "assert candidate([1,2,3,4,5],4)==False" ]
def test_run(content1,content2): return SN_RRG(content1,content2).rearrange()
test_run
assert candidate([['class RRG', 'class SN_RRG(RRG)', 'super().__init__(hand)', 'def rearrange']]) == 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/283
Question: There exists an undirected connected graph composed of **n** nodes, with the nodes numbered from 0 to n-1. A given array **graph** represents this graph. In it, graph[i] is a list, composed of all nodes directly connected to node **i**. Return the length of the shortest path that can visit all nodes. You can start and stop at any node, revisit nodes multiple times, and reuse edges; Based on the above question, create a class **TTH** using Python, with the property **graph**; then create another class **SN_TTH** that inherits from the **TTH** class, and add a public function **The_length** to return the length of the shortest path that can visit all nodes.
[ "assert candidate([[1,2,3],[0],[0],[0]])==4", "assert candidate([[1],[0,2,4],[1,3,4],[2],[1,2]])==4" ]
def test_run(content1): return SN_TTH(content1).The_length()
test_run
assert candidate([['class TTH', 'class SN_TTH(TTH)', 'super().__init__(graph)', 'def The_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/284
Question: There is a string **s** composed of lowercase letters, and an integer array **shifts** of the same length. We call the next letter in the alphabet a **shift** of the original letter (since the alphabet is circular, 'z' will become 'a'). Return the final string obtained after applying all these shifts to **s**; Based on the above question, please create a class **SAN** in Python language with the attribute **s**; then create a class **SN_SAN** that inherits the **SAN** class, and add the attribute **shifts**, as well as a public function **Shift_application** to return the final string obtained after applying all these shifts to **s**.
[ "assert candidate(\"abc\",[3,5,9])==\"rpl\"", "assert candidate(\"aaa\",[1,2,3])==\"gfd\"" ]
def test_run(content1,content2): return SN_SAN(content1,content2).Shift_application()
test_run
assert candidate([['class SAN', 'class SN_SAN(SAN)', 'super().__init__(s)', 'def Shift_application']]) == 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/285
Question: Given an array **seats** representing a row of seats, where seats[i]=1 means someone is sitting in the i-th seat, and seats[i]=0 means the i-th seat is empty (index starts from 0). There is at least one empty seat, and at least one person is already sitting. Alex wants to sit in a seat that maximizes the distance to the nearest person; Based on the above question, use Python to create a class **ASG** with the attribute **seats**. Then create a class **SN_ASG** that inherits the **ASG** class, and add a public function **Maximized_seating** that returns the maximum distance from Alex to the nearest person.
[ "assert candidate([1,0,0,0,1,0,1])==2", "assert candidate([1,0,0,0])==3", "assert candidate([0,1])==1" ]
def test_run(content1): return SN_ASG(content1).Maximized_seating()
test_run
assert candidate([['class ASG', 'class SN_ASG(ASG)', 'super().__init__(seats)', 'def Maximized_seating']]) == 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/286
Question: Given an axis-aligned 2D array **rectangles**. For rectangle[i]=[x1,y1,x2,y2], where (x1,y1) are the coordinates of the bottom left corner of rectangle **i**, (x_i1,y_i1) are the coordinates of the bottom left corner of the rectangle, and (x_i2,y_i2) are the coordinates of the top right corner of the rectangle. Calculate the total area covered by all rectangles in the plane. Any area covered by two or more rectangles should only be counted once, return the total area. Based on the above question, please create a class **TAR** in Python language with the attribute **rectangles**; then create a class **SN_TAR** that inherits the **TAR** class, and add a public function **total_area** to return the total area covered by all axis-aligned 2D array rectangles in the plane.
[ "assert candidate([[0,0,2,2],[1,0,2,3],[1,0,3,1]])==6", "assert candidate([[0,0,1000000000,1000000000]])==49" ]
def test_run(content1): return SN_TAR(content1).total_area()
test_run
assert candidate([['class TAR', 'class SN_TAR(TAR)', 'super().__init__(rectangles)', 'def total_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/287
Question: For some non-negative integers **k**, if swapping the positions of two letters in **s1** exactly **k** times can result in a string equal to **s2**, then the similarity of strings **s1** and **s2** is considered to be **k**. Given two anagrams s1 and s2, return the minimum value of the similarity **k** between **s1** and **s2**; Based on the above question, please create a class named **MVE** using Python, which has an attribute **s1**. Then create another class named **SN_MVE**, inheriting from the **MVE** class, and add an attribute **s2**, as well as a public function **Minimum_value** to return the minimum value of the similarity **k** between the given two anagrams **s1** and **s2**.
[ "assert candidate(\"ab\",\"ba\")==1", "assert candidate(\"abc\",\"bca\")==2" ]
def test_run(content1,content2): return SN_MVE(content1,content2).Minimum_value()
test_run
assert candidate([['class MVE', 'class SN_MVE(MVE)', 'super().__init__(s1)', 'def Minimum_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/288
Question: Given a balanced parentheses string **S**, calculate the score of the string according to the following rules: 1. **()** gets 1 point. 2. **AB** gets A+B points, where A and B are balanced parentheses strings. 3. **(A)** gets 2*A points, where A is a balanced parentheses string. Based on the above question, please create a class **BPS** in Python, with the attribute **S**. Then create another class **SN_BPS** that inherits from the **BPS** class, and add a public function **Balanced_parentheses** to return the score of a given balanced parentheses string **S** calculated according to the rules.
[ "assert candidate(\"()\")==1", "assert candidate(\"(())\")==2", "assert candidate(\"()()\")==2", "assert candidate(\"(()(()))\")==6" ]
def test_run(content1): return SN_BPS(content1).Balanced_parentheses()
test_run
assert candidate([['class BPS', 'class SN_BPS(BPS)', 'super().__init__(S)', 'def Balanced_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/289
Question: There is a special **square room**, each wall of which has a mirror. Except for the **southwest corner**, there is a receiver in each corner, numbered as 0, 1, and 2. The length of the wall of the square room is **p**, a laser beam is emitted from the southwest corner, and it will first meet the east wall. The distance from the point of incidence to receiver 0 is **q**. Return the number of the receiver that the returned light first encounters (ensure that the light will eventually encounter a receiver); Based on the above question, please use Python language to create a class **RNE** with the attribute **p**; then create a class **SN_RNE** that inherits the **RNE** class, and add the attribute **q** and a public function **Receiver_number** to return the number of the receiver that the light first encounters.
[ "assert candidate(2,1)==2", "assert candidate(3,1)==1" ]
def test_run(content1,content2): return SN_RNE(content1,content2).Receiver_number()
test_run
assert candidate([['class RNE', 'class SN_RNE(RNE)', 'super().__init__(p)', 'def Receiver_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/290
Question: Given a binary matrix **grid** of size m x n, where each element in the matrix is either 0 or 1. A move is defined as choosing any row or column and flipping the values in that row or column: change all 0s to 1s and all 1s to 0s. After making any number of moves, the score of the matrix is the sum of the numbers obtained by interpreting each row as a binary number. After making any number of moves (including 0), return the possible highest score; Based on the above question, please create a class **HSE** in Python with the attribute **grid**. Then create a class **SN_HSE** that inherits from the **HSE** class, and add a public function **Highest_Score** to return the possible highest score.
[ "assert candidate([[0,0,1,1],[1,0,1,0],[1,1,0,0]])==39", "assert candidate([[0]])==1" ]
def test_run(content1): return SN_HSE(content1).Highest_Score()
test_run
assert candidate([['class HSE', 'class SN_HSE(HSE)', 'super().__init__(grid)', 'def Highest_Score']]) == 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/291
Question: Given an integer array **nums** and an integer **k**, find the shortest non-empty subarray in **nums** whose sum is at least **k**, and return the length of this subarray. If such a subarray does not exist, return -1; Based on the above question, create a class **SEY** in Python, which has the attribute **nums**; then create another class **SN_SEY** that inherits from the **SEY** class, and add the attribute **k**, as well as a public function **Shortest_empty** to return the length of the shortest non-empty subarray in **nums** whose sum is at least **k**.
[ "assert candidate([1],1)==1", "assert candidate([1,2],4)==-1", "assert candidate([2,-1,2],3)==3" ]
def test_run(content1,content2): return SN_SEY(content1,content2).Shortest_empty()
test_run
assert candidate([['class SEY', 'class SN_SEY(SEY)', 'super().__init__(nums)', 'def Shortest_empty']]) == 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/292
Question: Find the smallest palindrome prime number that is greater than or equal to **N**; Based on the above question, please create a class **PPM** in Python with an attribute **N**. Then, create another class **SN_PPM** that inherits from the **PPM** class, and add a public function **prime_palindromes** to return the smallest palindrome prime number that is greater than or equal to **N**.
[ "assert candidate(6)==7", "assert candidate(8)==11", "assert candidate(13)==101" ]
def test_run(content1): return SN_PPM(content1).prime_palindromes()
test_run
assert candidate([['class PPM', 'class SN_PPM(PPM)', 'super().__init__(N)', 'def prime_palindromes']]) == 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/293
Question: Given a positive integer **n**, we reorder the digits in any order (including the original order), noting that the leading digit cannot be zero. If we can obtain a power of 2 in this way, return True; otherwise, return False; Based on the above question, please create a class **NRG** in Python with the attribute **n**; then create a class **SN_NRG** that inherits from the **NRG** class, and add a public function **Number_Reordering** to determine whether reordering the positive integer **n** in any order (including the original order) can result in a power of 2. If it can, return True; otherwise, return False.
[ "assert candidate(1)==True", "assert candidate(10)==False" ]
def test_run(content1): return SN_NRG(content1).Number_Reordering()
test_run
assert candidate([['class NRG', 'class SN_NRG(NRG)', 'super().__init__(n)', 'def Number_Reordering']]) == 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/294
Question: Given two arrays of equal length, **nums1** and **nums2**, the advantage of **nums1** over **nums2** can be described by the number of indices **i** for which nums1[i] > nums2[i]. Return any permutation of **nums1** that maximizes its advantage over **nums2**; Based on the above question, create a class **MAS** in Python with the attribute **nums1**. Then create a class **SN_MAS** that inherits from the **MAS** class, and add the attribute **nums2**, as well as a public function **Maximizing_Advantages** that returns any permutation of **nums1** that maximizes its **advantage** over **nums2**.
[ "assert candidate([2,7,11,15],[1,10,4,11])==[2,11,7,15]", "assert candidate([12,24,8,32],[13,25,32,11])==[24,32,8,12]" ]
def test_run(content1,content2): return SN_MAS(content1,content2).Maximizing_Advantages()
test_run
assert candidate([['class MAS', 'class SN_MAS(MAS)', 'super().__init__(nums1)', 'def Maximizing_Advantages']]) == 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/295
Question: If a sequence X_1, X_2, ..., X_n satisfies the following conditions, it is said to be **Fibonacci-like**: 1. n>=3. 2. For all i+2<=n, we have X_i+X_{i+1}=X_{i+2}. Given a strictly increasing positive integer array forming a sequence **arr**, find the length of the longest Fibonacci-like subsequence in **arr**. If one does not exist, return 0; Based on the above question, please create a class **PAY** in Python, which has the attribute **arr**; then create a class **SN_PAY** that inherits the **PAY** class, and add a public function **Positive_array** to return the length of the longest Fibonacci-like subsequence in the strictly increasing positive integer array forming the sequence **arr**.
[ "assert candidate([1,2,3,4,5,6,7,8])==5", "assert candidate([1,3,7,11,12,14,18])==3" ]
def test_run(content1): return SN_PAY(content1).Positive_array()
test_run
assert candidate([['class PAY', 'class SN_PAY(PAY)', 'super().__init__(arr)', 'def Positive_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/296
Question: Koko loves to eat bananas. There are **n** piles of bananas here, and the i-th pile has piles[i] bananas. The guard has already left and will return in **h** hours. Koko can decide her eating speed **k** (unit: bananas/hour). Every hour, she will choose a pile of bananas and eat **k** bananas from it. If this pile has fewer than **k** bananas, she will eat all the bananas in this pile, and will not eat any more bananas within this hour. Koko likes to eat slowly, but still wants to eat all the bananas before the guard comes back. Return the minimum speed **k** (k is an integer) at which she can eat all the bananas within **h** hours; Based on the above question, please create a class **MSD** in Python language with the attribute **piles**; then create a class **SN_MSD** that inherits the **MSD** class, and add the attribute **h**, as well as a public function **Minimum_Speed** to return the minimum speed **k** at which Koko can eat all the bananas within **h** hours.
[ "assert candidate([3,6,7,11],8)==4", "assert candidate([30,11,23,4,20],5)==30", "assert candidate([30,11,23,4,20],6)==23" ]
def test_run(content1,content2): return SN_MSD(content1,content2).Minimum_Speed()
test_run
assert candidate([['class MSD', 'class SN_MSD(MSD)', 'super().__init__(piles)', 'def Minimum_Speed']]) == 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/297
Question: A positive integer is magical if it can be divided by **a** or **b**. Given three integers **n**, **a**, **b**, return the n-th magical number; Based on the above question, create a class **MNS** in Python with the attribute **n**; then create another class **SN_MNS** that inherits from the **MNS** class, and add two attributes **a** and **b**, as well as a public function **Magical_Numbers** to return the n-th magical number.
[ "assert candidate(1,2,3)==2", "assert candidate(4,2,3)==6" ]
def test_run(content1,content2,content3): return SN_MNS(content1,content2,content3).Magical_Numbers()
test_run
assert candidate([['class MNS', 'class SN_MNS(MNS)', 'super().__init__(n)', 'def Magical_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/298
Question: There are **n** employees in the group, who can complete various jobs to generate profits. The i-th job will generate a profit of profit[i], and it requires group[i] members to participate together. If a member participates in one job, he/she cannot participate in another job. Any subset of jobs that generates at least **minProfit** profit is called a profitable plan. And the total number of job members is up to **n**. How many plans can be chosen; Based on the above question, please create a class called **PPN** in Python, which has an attribute **n**; then create another class **SN_PPN** that inherits from the **PPN** class, and add three attributes **minProfit**, **group**, and **profit**, as well as a public function **Profit_Plan** that returns the number of profitable plans.
[ "assert candidate(5,3,[2,2],[2,3])==2", "assert candidate(10,5,[2,3,5],[6,7,8])==7" ]
def test_run(content1,content2,content3,content4): return SN_PPN(content1,content2,content3,content4).Profit_Plan()
test_run
assert candidate([['class PPN', 'class SN_PPN(PPN)', 'super().__init__(n)', 'def Profit_Plan']]) == 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/299
Question: Given an encoded string **S**. You are asked to find the decoded string and write it onto a tape. During the decoding process, read one character from the encoded string at a time, and take the following steps: 1. If the character read is a letter, write it on the tape. 2. If the character read is a number (such as **d**), the entire current tape will be written repeatedly **d-1** times. Now, for the given encoded string **S** and index **K**, find and return the K-th letter in the decoded string; You are required to create a class **DSG** in Python, which has the attribute **S**; then create another class **SN_DSG** that inherits from the **DSG** class, and add the attribute **K**, as well as a public function **Decode_String** to find and return the K-th letter in the given encoded string **S**.
[ "assert candidate(\"leet2code3\",10)==\"o\"", "assert candidate(\"ha22\",5)==\"h\"", "assert candidate(\"a2345678999999999999999\",1)==\"a\"" ]
def test_run(content1,content2): return SN_DSG(content1,content2).Decode_String()
test_run
assert candidate([['class DSG', 'class SN_DSG(DSG)', 'super().__init__(S)', 'def Decode_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