task_id stringlengths 5 7 | question stringlengths 192 1.48k | test_list listlengths 2 5 | test_function stringlengths 54 236 | entry_point stringclasses 1
value | test_matching stringlengths 57 291 | test_match_function stringclasses 1
value |
|---|---|---|---|---|---|---|
OOP/400 | Question: Given a mountain array **mountainArr**, please return the smallest index **index** that makes mountainArr.get(index) equal to **target**. If there is no such index **index**, please return -1. What is a mountain array? If array **A** is a mountain array, then it satisfies the following conditions:
1. A.length... | [
"assert candidate([1,2,3,4,5,3,1],3)==2",
"assert candidate([0,1,2,4,2,1],3)==-1"
] | def test_run(content1,content2):
return SN_MAR(content1,content2).Mountain_array() | test_run | assert candidate([['class MAR', 'class SN_MAR(MAR)', 'super().__init__(array)', 'def Mountain_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]... |
OOP/401 | Question: Given a boolean expression **expression** in string form, return the result of the operation. A boolean expression is an expression whose result is either True or False. Valid expressions must follow the following conventions:
1. 't', the operation result is True; 2. 'f', the operation result is False; 3. '!(... | [
"assert candidate(\"&(|(f))\")==False",
"assert candidate(\"|(f,f,f,t)\")==True",
"assert candidate(\"!(&(f,t))\")==True"
] | def test_run(content1):
return SN_BLS(content1).Booleans() | test_run | assert candidate([['class BLS', 'class SN_BLS(BLS)', 'super().__init__(expression)', 'def Booleans']]) == 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]... |
OOP/402 | Question: Here we have **n** flights, numbered from 1 to **n**. There is a flight booking sheet **bookings**. The i-th booking record in the sheet, bookings[i]=[firsti,lasti,seatsi], means that **seatsi** seats have been booked on each flight from **firsti** to **lasti** (including **firsti** and **lasti**). Please ret... | [
"assert candidate([[1,2,10],[2,3,20],[2,5,25]],5)==[10,55,45,25,25]",
"assert candidate([[1,2,10],[2,2,15]],2)==[10,25]"
] | def test_run(content1,content2):
return SN_RSA(content1,content2).Reserved_seats() | test_run | assert candidate([['class RSA', 'class SN_RSA(RSA)', 'super().__init__(expression)', 'def Reserved_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]... |
OOP/403 | Question: Given a work schedule **hours**, which records the daily working hours of an employee. We consider that if the working hours of an employee in a day exceed 8 hours, then this day is a tiring day. The so-called good performance period means that during this period, the number of tiring days is strictly greater... | [
"assert candidate([9,9,6,0,6,6,9])==3",
"assert candidate([6,6,6])==0"
] | def test_run(content1):
return SN_PWL(content1).Performing_well() | test_run | assert candidate([['class PWL', 'class SN_PWL(PWL)', 'super().__init__(hours)', 'def Performing_well']]) == 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]... |
OOP/404 | Question: As a project manager, you have planned a list of required skills **req_skills**, and intend to select some people from the list of alternative personnel **people** to form a **necessary team** (the alternative personnel numbered **i**, people[i], has a list of skills that this alternative personnel masters). ... | [
"assert candidate([\"java\",\"nodejs\",\"reactjs\"],[[\"java\"],[\"nodejs\"],[\"nodejs\",\"reactjs\"]])==[0,2]",
"assert candidate([\"algorithms\",\"math\",\"java\",\"reactjs\",\"csharp\",\"aws\"],[[\"algorithms\",\"math\",\"java\"],[\"algorithms\",\"math\",\"reactjs\"],[\"java\",\"csharp\",\"aws\"],[\"reactjs\",... | def test_run(content1,content2):
return SN_NTM(content1,content2).Necessary_team() | test_run | assert candidate([['class NTM', 'class SN_NTM(NTM)', 'super().__init__(req_skills)', 'def Necessary_team']]) == 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]... |
OOP/405 | Question: Given an integer **n**, which is the number of nodes in a directed graph, where the nodes are labeled from 0 to n-1. Each edge in the graph is either red or blue, and there may be self-loops or parallel edges. Given two arrays **redEdges** and **blueEdges**, where:
1. redEdges[i]=[a_i,b_i] represents that the... | [
"assert candidate(3,[[0,1],[1,2]],[])==[0,1,-1]",
"assert candidate(3,[[0,1]],[[2,1]])==[0,1,-1]"
] | def test_run(content1,content2,content3):
return SN_AAR(content1,content2,content3).Alternating_appearance() | test_run | assert candidate([['class AAR', 'class SN_AAR(AAR)', 'super().__init__(n)', 'def 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]... |
OOP/406 | Question: Given two integer arrays of equal length, return the maximum value of the following expression: |arr1[i]-arr1[j]|+|arr2[i]-arr2[j]|+|i-j| where the indices **i**, **j** satisfy 0<=i,j<arr1.length;
Based on the above question, please create a class **MES** in Python, which has the attribute **arr1**. Then crea... | [
"assert candidate([1,2,3,4],[-1,4,5,6])==13",
"assert candidate([1,-2,-5,0,10],[0,-2,-1,-7,-4])==20"
] | def test_run(content1,content2):
return SN_MES(content1,content2).Maximum_expression() | test_run | assert candidate([['class MES', 'class SN_MES(MES)', 'super().__init__(arr1)', 'def Maximum_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]... |
OOP/407 | Question: Given a two-dimensional **grid** composed of several 0s and 1s, please find the largest square sub-grid whose boundaries are all composed of 1s, and return the number of elements in the sub-grid. If it does not exist, return 0;
Please create a class **SSR** with the property **grid** in Python based on the ab... | [
"assert candidate([[1,1,1],[1,0,1],[1,1,1]])==9",
"assert candidate([[1,1,0,0]])==1"
] | def test_run(content1):
return SN_GGG(content1).Square_subgrid() | test_run | assert candidate([['class SSR', 'class SN_GGG(GGG)', 'super().__init__(grid)', 'def Square_subgrid']]) == 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]... |
OOP/408 | Question: Alice and Bob continue their stone game. Many piles of stones are lined up, each pile has a positive integer number of stones piles[i]. The game is decided by who has the most stones in their hands. Alice and Bob take turns, with Alice starting first. Initially, M=1. In each player's turn, the player can take... | [
"assert candidate([2,7,9,4,4])==10",
"assert candidate([1,2,3,4,5,100])==104"
] | def test_run(content1):
return SN_SGA(content1).Stone_Game() | test_run | assert candidate([['class SGA', 'class SN_SGA(SGA)', 'super().__init__(piles)', 'def Stone_Game']]) == 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]... |
OOP/409 | Question: Given two strings **text1** and **text2**, return the length of the longest common subsequence of these two strings. If there is no common subsequence, return 0. A subsequence of a string is a new string that is formed by deleting some characters (or no characters) from the original string without changing th... | [
"assert candidate(\"abcde\",\"ace\")==3",
"assert candidate(\"abc\",\"abc\")==3",
"assert candidate(\"abc\",\"def\")==0"
] | def test_run(content1,content2):
return SN_SSN(content1,content2).Shared_subsequences() | test_run | assert candidate([['class SSN', 'class SN_SSN(SSN)', 'super().__init__(text1)', 'def Shared_subsequences']]) == 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]... |
OOP/410 | Question: Given an integer array **nums**, each operation will select an element and decrease its value by 1. If one of the following conditions is met, then array **A** is a zigzag array:
1. Each element corresponding to an even index is greater than its adjacent elements, i.e., A[0]>A[1]<A[2]>A[3]<A[4]>...;
2. Or, e... | [
"assert candidate([1,2,3])==2",
"assert candidate([9,6,1,6,2])==4"
] | def test_run(content1):
return SN_JAR(content1).Jagged_array() | test_run | assert candidate([['class JAR', 'class SN_JAR(JAR)', 'super().__init__(nums)', 'def Jagged_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]... |
OOP/411 | Question: You will be given a string **text**, which should be divided into **k** substrings (subtext1, subtext2,…,subtextk), with the following requirements:
1. Each **subtexti** is a non-empty string;
2. The concatenation of all substrings equals to **text** (i.e., subtext1+subtext2+...+subtextk==text);
3. For all ... | [
"assert candidate(\"ghiabcdefhelloadamhelloabcdefghi\")==7",
"assert candidate(\"merchant\")==1",
"assert candidate(\"antaprezatepzapreanta\")==11"
] | def test_run(content1):
return SN_ESI(content1).empty_string() | test_run | assert candidate([['class ESI', 'class SN_ESI(ESI)', 'super().__init__(text)', 'def empty_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]... |
OOP/412 | Question: Here we have **n** identical dice, each with **k** faces, numbered from 1 to **k**. Given three integers **n**, **k**, and **target**, return the number of possible ways (out of a total of k^n ways) to roll the dice so that the sum of the numbers facing up equals **target**;
Based on the above question, pleas... | [
"assert candidate(1,6,3)==1",
"assert candidate(2,6,7)==6",
"assert candidate(30,30,500)==222616187"
] | def test_run(content1,content2,content3):
return SN_FUP(content1,content2,content3).face_up() | test_run | assert candidate([['class FUP', 'class SN_FUP(FUP)', 'super().__init__(n)', 'def face_up']]) == 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]... |
OOP/413 | Question: If all characters in a string are the same, then the string is a single-character repeated string. Given a string **text**, you can only swap two characters once or do nothing, and then get some single-character repeated substrings. Return the length of the longest substring;
Please create a **DSN** class in ... | [
"assert candidate(\"ababa\")==3",
"assert candidate(\"aaabaaa\")==6",
"assert candidate(\"aaabbaaa\")==4",
"assert candidate(\"aaaaa\")==5",
"assert candidate(\"abcdef\")==1"
] | def test_run(content1):
return SN_DSN(content1).Duplicate_string() | test_run | assert candidate([['class DSN', 'class SN_DSN(DSN)', 'super().__init__(text)', 'def Duplicate_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]... |
OOP/414 | Question: You currently have a **grid** of size n x n in your hand, with each cell marked with 0 and 1. Here, 0 represents the ocean, and 1 represents the **land**. Please find an ocean cell where the distance to the nearest land cell is the maximum, and return this distance. If the grid only contains land or ocean, pl... | [
"assert candidate([[1,0,1],[0,0,0],[1,0,1]])==2",
"assert candidate([[1,0,0],[0,0,0],[0,0,0]])==4"
] | def test_run(content1):
return SN_OCL(content1).Ocean_Cell() | test_run | assert candidate([['class OCL', 'class SN_OCL(OCL)', 'super().__init__(grid)', 'def Ocean_Cell']]) == 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]... |
OOP/415 | Question: Given a string **s**, find all its substrings and sort them in lexicographical order, return the last substring;
Based on the above question, create a class **LAM** in Python language with the attribute **s**; then create another class **SN_LAM**, inheriting from the **LAM** class, and add a public function *... | [
"assert candidate(\"abab\")==\"bab\"",
"assert candidate(\"leetcode\")==\"tcode\""
] | def test_run(content1):
return SN_LAM(content1).Lexicographic_arrangement() | test_run | assert candidate([['class LAM', 'class SN_LAM(LAM)', 'super().__init__(s)', 'def Lexicographic_arrangement']]) == 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]... |
OOP/416 | Question: A transaction may be invalid under the following two circumstances:
1. The transaction amount exceeds $1000; 2. Or, it is not more than 60 minutes (including 60 minutes) apart from another transaction with the same name in another city; Given the string array transaction list **transactions**. Each transactio... | [
"assert candidate([\"alice,20,800,mtv\",\"alice,50,100,beijing\"])==[\"alice,20,800,mtv\",\"alice,50,100,beijing\"]",
"assert candidate([\"alice,20,800,mtv\",\"alice,50,1200,mtv\"])==[\"alice,50,1200,mtv\"]",
"assert candidate([\"alice,20,800,mtv\",\"bob,50,1200,mtv\"])==[\"bob,50,1200,mtv\"]"
] | def test_run(content1):
return SN_TLI(content1).Transaction_List() | test_run | assert candidate([['class TLI', 'class SN_TLI(TLI)', 'super().__init__(transactions)', 'def Transaction_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]... |
OOP/417 | Question: Given two integer arrays **arr1** and **arr2**, return the minimum number of operations required to make **arr1** strictly increasing (possibly 0). In each operation, you can select an index from both **arr1** and **arr2**, respectively **i** and **j**, where 0<=i<arr1.length and 0<=j<arr2.length, and then pe... | [
"assert candidate([1,5,3,6,7],[1,3,2,4])==1",
"assert candidate([1,5,3,6,7],[4,3,1])==2",
"assert candidate([1,5,3,6,7],[1,6,3,3])==-1"
] | def test_run(content1,content2):
return SN_SII(content1,content2).Strictly_Increasing() | test_run | assert candidate([['class SII', 'class SN_SII(SII)', 'super().__init__(arr1)', 'def Strictly_Increasing']]) == 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]... |
OOP/418 | Question: Given a string **s** (containing only lowercase English letters and parentheses), please reverse the string in each pair of matching parentheses from the inside out in order, and return the final result;
Based on the above question, please create a class **MBC** in Python language with the attribute **s**. Th... | [
"assert candidate(\"(abcd)\")==\"dcba\"",
"assert candidate(\"(u(love)i)\")==\"iloveu\"",
"assert candidate(\"(ed(et(oc))el)\")==\"leetcode\"",
"assert candidate(\"a(bcdefghijkl(mno)p)q\")==\"apmnolkjihgfedcbq\""
] | def test_run(content1):
return SN_MBC(content1).Match_Brace() | test_run | assert candidate([['class MBC', 'class SN_MBC(MBC)', 'super().__init__(s)', 'def Match_Brace']]) == 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]... |
OOP/419 | Question: Given an integer array **arr** and an integer **k**, modify the array by repeating **k** times. Return the sum of the largest subarray in the modified array;
Please create a class **SSA** in Python based on the above question, with the attribute **arr**. Then create a class **SN_SSA** that inherits from the *... | [
"assert candidate([1,2],3)==9",
"assert candidate([1,-2,1],5)==2",
"assert candidate([-1,-2],7)==0"
] | def test_run(content1,content2):
return SN_SSA(content1,content2).Sum_subarrays() | test_run | assert candidate([['class SSA', 'class SN_SSA(SSA)', 'super().__init__(k)', 'def Sum_subarrays']]) == 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]... |
OOP/420 | Question: Given four integers: **n**, **a**, **b**, **c**, please design an algorithm to find the n-th ugly number;
Based on the above question, create a class **UNB** in Python, with the attribute **n**; then create another class **SN_UNB**, inheriting from the **UNB** class, and add three attributes **a**, **b** and ... | [
"assert candidate(3,2,3,5)==4",
"assert candidate(4,2,3,4)==6",
"assert candidate(5,2,11,13)==10",
"assert candidate(1000000000,2,217983653,336916467)==1999999984"
] | def test_run(content1,content2,content3,content4):
return SN_UNB(content1,content2,content3,content4).Ugly_number() | test_run | assert candidate([['class UNB', 'class SN_UNB(UNB)', 'super().__init__(n)', 'def Ugly_number']]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]... |
OOP/421 | Question: Given a string **s** and some index pairs array **pairs** in the string, where pairs[i]=[a,b] represents two indexes in the string (numbered from 0). You can swap the characters at any pair of indexes in pairs any number of times. Return the lexicographically smallest string that **s** can become after severa... | [
"assert candidate(\"dcab\",[[0,3],[1,2]])==\"bacd\"",
"assert candidate(\"dcab\",[[0,3],[1,2],[0,2]])==\"abcd\"",
"assert candidate(\"cba\",[[0,1],[1,2]])==\"abc\""
] | def test_run(content1,content2):
return SN_DMM(content1,content2).Dictionary_minimum() | test_run | assert candidate([['class DMM', 'class SN_DMM(DMM)', 'super().__init__(s)', 'def Dictionary_minimum']]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]... |
OOP/422 | Question: Given two strings of equal length, **s** and **t**. Changing the i-th character in **s** to the i-th character in **t** requires a cost of |s[i]-t[i]| (the cost could be 0), which is the absolute difference of the ASCII values of the two characters. The maximum budget for changing the string is **maxCost**. D... | [
"assert candidate(\"abcd\",\"bcdf\",3)==3",
"assert candidate(\"abcd\",\"cdef\",3)==1",
"assert candidate(\"abcd\",\"acde\",0)==1"
] | def test_run(content1,content2,content3):
return SN_MBG(content1,content2,content3).Maximum_budget() | test_run | assert candidate([['class MBG', 'class SN_MBG(MBG)', 'super().__init__(s)', 'def Maximum_budget']]) == 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]... |
OOP/423 | Question: Given a string **s**, the **k** times repeated item deletion operation will select **k** adjacent and equal letters from **s** and delete them, connecting the left and right sides of the deleted string. You need to repeatedly perform such deletion operations on **s** indefinitely until it can no longer contin... | [
"assert candidate(\"abcd\",2)==\"abcd\"",
"assert candidate(\"deeedbbcccbdaa\",3)==\"aa\"",
"assert candidate(\"pbbcggttciiippooaais\",2)==\"ps\""
] | def test_run(content1,content2):
return SN_DOT(content1,content2).Delete_Operation() | test_run | assert candidate([['class DOT', 'class SN_DOT(DOT)', 'super().__init__(s)', 'def Delete_Operation']]) == 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]... |
OOP/424 | Question: Given an integer array **arr** and an integer **difference**, please find and return the length of the longest arithmetic subsequence in **arr**, where the difference between adjacent elements equals **difference**;
Based on the above question, please create a class **ESQ** in Python, which has the attribute ... | [
"assert candidate([1,2,3,4],1)==4",
"assert candidate([1,3,5,7],1)==1",
"assert candidate([1,5,7,8,5,3,4,2,1],-2)==4"
] | def test_run(content1,content2):
return SN_ESQ(content1,content2).Equidistant_subsequence() | test_run | assert candidate([['class ESQ', 'class SN_ESQ(ESQ)', 'super().__init__(arr)', 'def Equidistant_subsequence']]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]... |
OOP/425 | Question: You are to develop a gold mine. Geological surveyors have determined the resource distribution in the mine and marked it with an m*n grid. Each integer in a cell represents the amount of gold in that cell; if the cell is empty, it is 0. To maximize profits, miners need to mine gold according to the following ... | [
"assert candidate([[0,6,0],[5,8,7],[0,9,0]])==24",
"assert candidate([[1,0,7],[2,0,6],[3,4,5],[0,3,0],[9,0,20]])==28"
] | def test_run(content1):
return SN_RDB(content1).resource_distribution() | test_run | assert candidate([['class RDB', 'class SN_RDB(RDB)', 'super().__init__(grid)', 'def resource_distribution']]) == 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]... |
OOP/426 | Question: Given an integer **n**, please help to count how many strings of length **n** can be formed according to the following rules:
1. Each character in the string should be a lowercase vowel ('a', 'e', 'i', 'o', 'u'); 2. Each vowel 'a' can only be followed by 'e'; 3. Each vowel 'e' can only be followed by 'a' or '... | [
"assert candidate(1)==5",
"assert candidate(2)==10",
"assert candidate(5)==68"
] | def test_run(content1):
return SN_FSG(content1).Forming_String() | test_run | assert candidate([['class FSG', 'class SN_FSG(FSG)', 'super().__init__(n)', 'def Forming_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]... |
OOP/427 | Question: On an 8x8 chessboard, there are several black queens and one white king. Given an array of integer coordinates **queens**, representing the positions of the black queens; and a pair of coordinates **king**, representing the position of the white king, return the coordinates of all queens that can attack the k... | [
"assert candidate([[0,1],[1,0],[4,0],[0,4],[3,3],[2,4]],[0,0])==[[0,1],[1,0],[3,3]]",
"assert candidate([[0,0],[1,1],[2,2],[3,4],[3,5],[4,4],[4,5]],[3,3])==[[2,2],[3,4],[4,4]]",
"assert candidate([[5,6],[7,7],[2,1],[0,7],[1,6],[5,1],[3,7],[0,3],[4,0],[1,2],[6,3],[5,0],[0,4],[2,2],[1,1],[6,4],[5,4],[0,0],[2,6],[... | def test_run(content1,content2):
return SN_CKB(content1,content2).checkerboard() | test_run | assert candidate([['class CKB', 'class SN_CKB(CKB)', 'super().__init__(queens)', 'def checkerboard']]) == 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]... |
OOP/428 | Create a class named **SBFD** in Python, with properties **nums**, **left**, and **right**, as well as a public function named **find_subarray**. In the public function **find_subarray**, identify and return the count of contiguous, non-empty subarrays within **nums** where the maximum element falls within the range **... | [
"assert candidate([2,1,4,3],2,3,1,2)==True",
"assert candidate([2,9,2,5,6],2,8,1,4)==True"
] | def test_run(content1, content2, content3, res1, res2):
if SBFD(content1, content2, content3).find_subarray()==res1 and SN_FDSB(content1, content2, content3).find_subarray() == res2
return True
else:
return False | test_run | assert candidate([["class SBFD", "def __init__(self, nums, left, right)", "class SN_FDSB", "def find_subarray"]]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]... |
OOP/429 | First, write a class named **STR** in Python, which has an instance attribute, **s**, and a public function named **without_duplicates**. In the public function **without_duplicates**, based on the instance attribute **s**, find the length of the longest substring without duplicate characters. Next, create a class name... | [
"assert candidate(\"abcabcbb\", 3, 3)==True",
"assert candidate(\"abcabcccbb\", 3, 4)==True",
"assert candidate(\"pwwkeyow\", 5, 5)==True"
] | def test_run(content1, res1, res2):
if STR(content1).without_duplicates()==res1 and SUB_STR(content1).without_duplicates() == res2
return True
else:
return False | test_run | assert candidate([["class STR", "def __init__(self, s)", "class SUB_STR", "def without_duplicates"]]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]... |
OOP/430 | Using the Python language, start by creating a class named **PLDR** with an instance attribute **number** and a public function **PLind**. Within the **PLind** function, check if a given number is a palindrome; return **True** if it is, otherwise return **False**. Next, create a subclass named **SUBPLDR** that inherits... | [
"assert candidate(1211, \"abcabcbb\", False, False)==True",
"assert candidate(121, \"abcabcccbb\", True, False)==True",
"assert candidate(4576, \"level\", False, True)==True"
] | def test_run(content1, content2, res1, res2):
if PLDR(content1).PLind()==res1 and SUBPLDR(content2).PLind() == res2
return True
else:
return False | test_run | assert candidate([["class PLDR", "def __init__(self, number)", "class SUBPLDR", "def PLind"]]) == 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]... |
OOP/0 | 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. T... | [
"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 __init__(self, nums)", "def find_subarray", "def __init__(self, nums, left, right)", "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]... |
OOP/1 | 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 P... | [
"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 __init__(self, nums)", "class SN_FDSB(FDSB)", "def __init__(self, nums, left, right)", "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]... |
OOP/2 | 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** ... | [
"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", "def __init__(self, graph)", "class SN_PO(PO)", "super().__init__(graph)", "super().__init__(nums)", "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]... |
OOP/3 | 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 opera... | [
"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", "def __init__(self, nums1)", "class SN_EE(EE)", "def __init__(self, nums1, nums2)", "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]... |
OOP/4 | 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... | [
"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", "def __init__(self, graph)", "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]... |
OOP/5 | 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**,... | [
"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", "def __init__(self, grid)", "class SN_NBS(NBS)", "def __init__(self, grid, hits)", "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]... |
OOP/6 | 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 P... | [
"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", "def __init__(self, nums)", "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]... |
OOP/7 | 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 la... | [
"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", "def __init__(self, nums)", "class SN_MSE(MSE)", "def __init__(self, nums, k)", "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]... |
OOP/8 | 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** s... | [
"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", "def __init__(self, routes)", "class SN_TSN(TSN)", "def __init__(self, routes, source, target)", "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]... |
OOP/9 | 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.... | [
"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)\")==[(... | def test_run(content1):
return SN_AOR(content1).Any_order() | test_run | assert candidate([["class AOR", "def __init__(self, s)", "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]... |
OOP/10 | 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... | [
"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", "def __init__(self, words)", "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]... |
OOP/11 | 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** i... | [
"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", "def __init__(self, s)", "class SN_CDC(CDC)", "def __init__(self, s, c)", "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]... |
OOP/12 | 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 ... | [
"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", "def __init__(self, arr)", "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]... |
OOP/13 | 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 wi... | [
"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", "def __init__(self, difficulty)", "class SN_MPT(MPT)", "def __init__(self, difficulty, profit, worker)", "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]... |
OOP/14 | 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 ... | [
"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", "def __init__(self, grid)", "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]... |
OOP/15 | 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, ... | [
"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", "def __init__(self, s)", "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]... |
OOP/16 | 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**... | [
"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", "def __init__(self, n)", "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]... |
OOP/17 | 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 t... | [
"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", "def __init__(self, n)", "class SN_SDC(SDC)", "def __init__(self, n, edges)", "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]... |
OOP/18 | 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 o... | [
"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", "def __init__(self, img1)", "class SN_OQT(OQT)", "def __init__(self, img1, img2)", "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]... |
OOP/19 | 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 intersecti... | [
"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", "def __init__(self, rec1)", "class SN_ROP(ROP)", "def __init__(self, rec1, rec2)", "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]... |
OOP/20 | 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 ... | [
"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", "def __init__(self, n)", "class SN_ENS(ENS)", "def __init__(self, n, k, maxPts)", "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]... |
OOP/21 | 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 simi... | [
"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", "def __init__(self, strs)", "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]... |
OOP/22 | 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... | [
"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", "def __init__(self, grid)", "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]... |
OOP/23 | 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, indica... | [
"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", "def __init__(self, rooms)", "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]... |
OOP/24 | 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>... | [
"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", "def __init__(self, num)", "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]... |
OOP/25 | 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 su... | [
"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", "def __init__(self, arr)", "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]... |
OOP/26 | 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 ... | [
"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", "def __init__(self, hand)", "class SN_RRG(RRG)", "def __init__(self, hand, groupSize)", "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]... |
OOP/27 | 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 ... | [
"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", "def __init__(self, graph)", "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]... |
OOP/28 | 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**... | [
"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", "def __init__(self, s)", "class SN_SAN(SAN)", "def __init__(self, s, shifts)", "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]... |
OOP/29 | 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 dist... | [
"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", "def __init__(self, seats)", "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]... |
OOP/30 | 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 rectangl... | [
"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", "def __init__(self, rectangles)", "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]... |
OOP/31 | 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** betwee... | [
"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", "def __init__(self, s1)", "class SN_MVE(MVE)", "def __init__(self, s1, s2)", "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]... |
OOP/32 | 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, p... | [
"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", "def __init__(self, S)", "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]... |
OOP/33 | 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. Th... | [
"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", "def __init__(self, p)", "class SN_RNE(RNE)", "def __init__(self, p, q)", "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]... |
OOP/34 | 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 numb... | [
"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", "def __init__(self, grid)", "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]... |
OOP/35 | 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 **num... | [
"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", "def __init__(self, nums)", "class SN_SEY(SEY)", "def __init__(self, nums, k)", "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]... |
OOP/36 | 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 ... | [
"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", "def __init__(self, N)", "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]... |
OOP/37 | 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 attrib... | [
"assert candidate(1)==True",
"assert candidate(10)==False"
] | def test_run(content1):
return SN_NRG(content1).Number_Reordering() | test_run | assert candidate([["class NRG", "def __init__(self, n)", "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]... |
OOP/38 | 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... | [
"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", "def __init__(self, nums1)", "class SN_MAS(MAS)", "def __init__(self, nums1, nums2)", "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]... |
OOP/39 | 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**... | [
"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", "def __init__(self, arr)", "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]... |
OOP/40 | 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... | [
"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", "def __init__(self, piles)", "class SN_MSD(MSD)", "def __init__(self, piles, h)", "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]... |
OOP/41 | 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... | [
"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", "def __init__(self, n)", "class SN_MNS(MNS)", "def __init__(self, n, a, b)", "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]... |
OOP/42 | 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 generate... | [
"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", "def __init__(self, n)", "class SN_PPN(PPN)", "def __init__(self, n, minProfit, group, profit)", "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]... |
OOP/43 | 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 (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", "def __init__(self, S)", "class SN_DSG(DSG)", "def __init__(self, S, K)", "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]... |
OOP/44 | Question: Given an array **people**. people[i] represents the weight of the i-th person, the number of boats is unlimited, and each boat can carry a maximum weight of **limit**. Each boat can carry up to two people at the same time, but the condition is that the sum of these people's weights is at most **limit**. Retur... | [
"assert candidate([1,2],3)==1",
"assert candidate([3,2,2,1],3)==3",
"assert candidate([3,5,3,4],5)==4"
] | def test_run(content1,content2):
return SN_MSS(content1,content2).Minimum_ships() | test_run | assert candidate([["class MSS", "def __init__(self, people)", "class SN_MSS(MSS)", "def __init__(self, people, limit)", "super().__init__(people)", "def Minimum_ships"]]) == 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]... |
OOP/45 | Question: In an n x n **grid**, we place some 1 x 1 x 1 cubes aligned with the **x**, **y**, **z** axes. Each value v = grid[i][j] represents **v** cubes stacked on the cell (i, j). Now, we look at the projections of these cubes on the **xy**, **yz**, and **zx** planes. A projection is like a shadow, mapping a three-di... | [
"assert candidate([[1,2],[3,4]])==17",
"assert candidate([[2]])==5",
"assert candidate([[1,0],[0,2]])==8"
] | def test_run(content1):
return SN_TPD(content1).Total_projected() | test_run | assert candidate([["class TPD", "def __init__(self, grid)", "class SN_TPD(TPD)", "super().__init__(grid)", "def Total_projected"]]) == 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]... |
OOP/46 | Question: On a grid of rows x cols, you start from the cell (rStart, cStart) facing east. The northwest corner of the grid is at the first row and the first column, and the southeast corner is at the last row and the last column. You need to walk in a clockwise spiral, visiting every position in this grid. Whenever you... | [
"assert candidate(1,4,0,0)==[[0,0],[0,1],[0,2],[0,3]]",
"assert candidate(5,6,1,4)==[[1,4],[1,5],[2,5],[2,4],[2,3],[1,3],[0,3],[0,4],[0,5],[3,5],[3,4],[3,3],[3,2],[2,2],[1,2],[0,2],[4,5],[4,4],[4,3],[4,2],[4,1],[3,1],[2,1],[1,1],[0,1],[4,0],[3,0],[2,0],[1,0],[0,0]]"
] | def test_run(content1,content2,content3,content4):
return SN_CLT(content1,content2,content3,content4).Coordinate_List() | test_run | assert candidate([["class CLT", "def __init__(self, rows)", "class SN_CLT(CLT)", "def __init__(self, rows, cols, rStart, cStart)", "super().__init__(rows)", "def Coordinate_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]... |
OOP/47 | Question: Given a set of **n** people (numbered 1,2,...,n), we want to divide each person into two groups of any size. Each person may not like others, so they should not belong to the same group. Given the integer **n** and the array **dislikes**, where dislikes[i]=[a_i,b_i], it is not allowed to put the people number... | [
"assert candidate(4,[[1,2],[1,3],[2,4]])==True",
"assert candidate(3,[[1,2],[1,3],[2,3]])==False",
"assert candidate(5,[[1,2],[2,3],[3,4],[4,5],[1,5]])==False"
] | def test_run(content1,content2):
return SN_GPG(content1,content2).grouping() | test_run | assert candidate([["class GPG", "def __init__(self, n)", "class SN_GPG(GPG)", "def __init__(self, n, dislikes)", "super().__init__(n)", "def grouping"]]) == 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]... |
OOP/48 | Question: You are given **k** identical eggs and you have access to a building with **n** floors from the 1st floor to the n-th floor. It is known that there exists a floor **f**, satisfying 0<=f<=n, any eggs dropped from a floor higher than **f** will break, and those dropped from the **f** floor or lower will not bre... | [
"assert candidate(1,2)==2",
"assert candidate(2,6)==3",
"assert candidate(3,14)==4"
] | def test_run(content1,content2):
return SN_NOS(content1,content2).number_operations() | test_run | assert candidate([["class NOS", "def __init__(self, k)", "class SN_NOS(NOS)", "def __init__(self, k, n)", "super().__init__(k)", "def number_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]... |
OOP/49 | Question: The width of a sequence is defined as the difference between the maximum and minimum elements in the sequence. Given an integer array **nums**, return the sum of the widths of all non-empty subsequences of **nums**. A subsequence is defined as an array obtained by deleting some (or not deleting) elements from... | [
"assert candidate([2,1,3])==6",
"assert candidate([2])==0"
] | def test_run(content1):
return SN_SWS(content1).Sum_widths() | test_run | assert candidate([["class SWS", "def __init__(self, nums)", "class SN_SWS(SWS)", "super().__init__(nums)", "def Sum_widths"]]) == 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]... |
OOP/50 | Question: We have a non-negative integer array **arr**. For each (continuous) subarray sub=[arr[i],arr[i+1],...,arr[j]] (i<=j), we perform a bitwise OR operation on each element in **sub**, obtaining the result arr[i]|arr[i+1]|...|arr[j]. Return the number of possible results. Multiple occurrences of the result are onl... | [
"assert candidate([0])==1",
"assert candidate([1,1,2])==3",
"assert candidate([1,2,4])==6"
] | def test_run(content1):
return SN_FAR(content1).Final_Answer() | test_run | assert candidate([["class FAR", "def __init__(self, arr)", "class SN_FAR(FAR)", "super().__init__(arr)", "def Final_Answer"]]) == 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]... |
OOP/51 | Question: Given a string **s** and an integer **k**. You can choose one from the first **k** letters of **s** and add it to the end of the string. Return the lexicographically smallest string after any number of moves applying the above steps;
Please create a class **SSG** with the attribute **s** in Python based on th... | [
"assert candidate(\"cba\",1)==\"acb\"",
"assert candidate(\"baaca\",3)==\"aaabc\""
] | def test_run(content1,content2):
return SN_SSG(content1,content2).Smallest_string() | test_run | assert candidate([["class SSG", "def __init__(self, s)", "class SN_SSG(SSG)", "def __init__(self, s, k)", "super().__init__(s)", "def Smallest_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]... |
OOP/52 | Question: Given a numerical array **digits** sorted in non-decreasing order. You can write numbers using digits[i] any number of times. For example, if digits = ['1','3','5'], we can write numbers like '13', '551', and '1351315'. Return the number of positive integers that can be generated that are less than or equal t... | [
"assert candidate([\"1\",\"3\",\"5\",\"7\"],100)==20",
"assert candidate([\"1\",\"4\",\"9\"],1000000000)==29523",
"assert candidate([\"7\"],8)==1"
] | def test_run(content1,content2):
return SN_NDG(content1,content2).Non_decreasing() | test_run | assert candidate([["class NDG", "def __init__(self, digits)", "class SN_NDG(NDG)", "def __init__(self, digits, n)", "super().__init__(digits)", "def Non_decreasing"]]) == 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]... |
OOP/53 | Question: Given a string **s** of length **n**, where s[i] is:
1. **D** means decrease; 2. **I** means increase; A valid arrangement is a permutation **perm** of n+1 integers within the range [0, n], so that for all **i**:
1. If s[i] == 'D', then perm[i] > perm[i+1]; 2. If s[i] == 'I', then perm[i] < perm[i+1]. Return ... | [
"assert candidate(\"DID\")==5",
"assert candidate(\"D\")==1"
] | def test_run(content1):
return SN_EAT(content1).Effective_arrangement() | test_run | assert candidate([["class EAT", "def __init__(self, s)", "class SN_EAT(EAT)", "super().__init__(s)", "def Effective_arrangement"]]) == 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]... |
OOP/54 | Question: Given an integer array **arr**, find the sum of min(b), where **b** ranges over each (continuous) subarray of **arr**.
Please create a class **IAY** in Python language based on the above question, with the attribute **arr**; then create a class **SN_IAY** that inherits from the **IAY** class, and add a public... | [
"assert candidate([3,1,2,4])==17",
"assert candidate([11,81,94,43,3])==444"
] | def test_run(content1):
return SN_IAY(content1).Integer_array() | test_run | assert candidate([["class IAY", "def __init__(self, arr)", "class SN_IAY(IAY)", "super().__init__(arr)", "def Integer_array"]]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]... |
OOP/55 | Question: Given an integer array **nums** and an integer **k**. For each index **i** (0<=i<nums.length), change nums[i] to nums[i]+k or nums[i]-k. The score of **nums** is the difference between the maximum and minimum elements in **nums**. After changing the value corresponding to each index, return the minimum score ... | [
"assert candidate([1],0)==0",
"assert candidate([0,10],2)==6",
"assert candidate([1,3,6],3)==3"
] | def test_run(content1,content2):
return SN_MSE(content1,content2).Minimum_score() | test_run | assert candidate([["class MSE", "def __init__(self, nums)", "class SN_MSE(MSE)", "def __init__(self, nums, k)", "super().__init__(nums)", "def 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]... |
OOP/56 | Question: Given an integer array **nums**, please sort this array in ascending order;
Based on the above question, please create a class **AOR** using Python language, with the attribute **nums**; then create another class **SN_AOR** that inherits from the **AOR** class, and add a public function **ascend_order** to so... | [
"assert candidate([5,2,3,1])==[1,2,3,5]",
"assert candidate([5,1,1,2,0,0])==[0,0,1,1,2,5]"
] | def test_run(content1):
return SN_AOR(content1).ascend_order() | test_run | assert candidate([["class AOR", "def __init__(self, nums)", "class SN_AOR(AOR)", "super().__init__(nums)", "def ascend_order"]]) == True | def matching_function(content):
def run_match(text):
for task in text:
if task not in str_content:
return False
return True
len_cont = len(content)
if len_cont==1 and run_match(content[0]) == True:
return True
elif (len_cont==2 and run_match(content[0]... |
OOP/57 | Question: Two players play the roles of a cat and a mouse respectively, and they play a game on an undirected graph, taking turns to move. The form of the graph is: graph[a] is a list, consisting of all nodes **b** that satisfy that **ab** is an edge in the graph. The **mouse** starts from node 1 and moves first; the *... | [
"assert candidate([[2,5],[3],[0,4,5],[1,4,5],[2,3],[0,2,3]])==0",
"assert candidate([[1,3],[0],[3],[0,2]])==1"
] | def test_run(content1):
return SN_CGS(content1).Cat_games() | test_run | assert candidate([["class CGS", "def __init__(self, graph)", "class SN_CGS(CGS)", "super().__init__(graph)", "def Cat_games"]]) == 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]... |
OOP/58 | Question: Given a deck of cards, each card has an integer written on it. At this point, you need to select a number **X**, so that we can divide the deck into one or more groups according to the following rules: each group has **X** cards. All the cards in the group have the same integer written on them. Return True on... | [
"assert candidate([1,2,3,4,4,3,2,1])==True",
"assert candidate([1,1,1,2,2,2,3,3])==False"
] | def test_run(content1):
return SN_SIR(content1).Same_integer() | test_run | assert candidate([["class SIR", "def __init__(self, deck)", "class SN_SIR(SIR)", "super().__init__(deck)", "def Same_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]... |
OOP/59 | Question: Given an array **nums**, divide it into two consecutive sub-arrays **left** and **right** so that:
1. Each element in **left** is less than or equal to each element in **right**. 2. Both **left** and **right** are non-empty. 3. The length of **left** should be as small as possible. After completing such group... | [
"assert candidate([5,0,3,8,6])==3",
"assert candidate([1,1,1,0,6,12])==4"
] | def test_run(content1):
return SN_PLH(content1).Packet_Length() | test_run | assert candidate([["class PLH", "def __init__(self, nums)", "class SN_PLH(PLH)", "super().__init__(nums)", "def Packet_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]... |
OOP/60 | Question: Given two string arrays **words1** and **words2**. Now, if every letter in **b** appears in **a**, including the repeated letters, then we say that string **b** is a subset of string **a**. If for every word **b** in **words2**, **b** is a subset of **a**, then we say that the word **a** in **words1** is a un... | [
"assert candidate([\"amazon\",\"apple\",\"facebook\",\"google\",\"leetcode\"],[\"e\",\"o\"])==[\"facebook\",\"google\",\"leetcode\"]",
"assert candidate([\"amazon\",\"apple\",\"facebook\",\"google\",\"leetcode\"],[\"l\",\"e\"])==[\"apple\",\"google\",\"leetcode\"]",
"assert candidate([\"amazon\",\"apple\",\"fac... | def test_run(content1,content2):
return SN_CWS(content1,content2).Common_Words() | test_run | assert candidate([["class CWS", "def __init__(self, words1)", "class SN_CWS(CWS)", "def __init__(self, words1, words2)", "super().__init__(words1)", "def Common_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]... |
OOP/61 | Question: Given a circular integer array **nums** of length **n**, return the maximum possible sum of non-empty subarrays in **nums**.
Please create a class **CAY** in Python based on the above question, with the attribute **nums**. Then create another class **SN_CAY**, inheriting from the **CAY** class, and add a pub... | [
"assert candidate([1,-2,3,-2])==3",
"assert candidate([5,-3,5])==10",
"assert candidate([3,-2,2,-3])==3"
] | def test_run(content1):
return SN_CAY(content1).Circular_array() | test_run | assert candidate([["class CAY", "def __init__(self, nums)", "class SN_CAY(CAY)", "super().__init__(nums)", "def Circular_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]... |
OOP/62 | Question: You have **n** different songs in your music player. During your journey, you plan to listen to **goal** songs (not necessarily different, i.e., song repetition is allowed). You will create a playlist according to the following rules:
1. Each song is played at least once. 2. A song can only be played again af... | [
"assert candidate(3,3,1)==6",
"assert candidate(2,3,0)==6",
"assert candidate(2,3,1)==2"
] | def test_run(content1,content2,content3):
return SN_PAL(content1,content2,content3).PlayList() | test_run | assert candidate([["class PAL", "def __init__(self, n)", "class SN_PAL(PAL)", "def __init__(self, n, goal, k)", "super().__init__(n)", "def PlayList"]]) == 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]... |
OOP/63 | Question: A parenthesis string is valid only if one of the following conditions is met:
1. It is an empty string; 2. It can be written as AB (A connected with B), where both A and B are valid strings; 3. It can be written as (A), where A is a valid string. Given a parenthesis string **s**, in each operation, you can in... | [
"assert candidate(\"())\")==1",
"assert candidate(\"(((\")==3"
] | def test_run(content1):
return SN_MPS(content1).Minimum_parentheses() | test_run | assert candidate([["class MPS", "def __init__(self, s)", "class SN_MPS(MPS)", "super().__init__(s)", "def Minimum_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]... |
OOP/64 | Question: Given a non-negative integer array **nums**, half of the integers in **nums** are odd, and half are even. Sort the array so that when nums[i] is odd, **i** is also odd; when nums[i] is even, **i** is also even. You can return any array that meets the above conditions as the answer;
Based on the above question... | [
"assert candidate([4,2,5,7])==[4,5,2,7]",
"assert candidate([2,3])==[2,3]"
] | def test_run(content1):
return SN_ASG(content1).Array_sorting() | test_run | assert candidate([["class ASG", "def __init__(self, nums)", "class SN_ASG(ASG)", "super().__init__(nums)", "def Array_sorting"]]) == 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]... |
OOP/65 | Question: Given an integer array **arr**, and an integer **target** as the target value, return the number of tuples **i**, **j**, **k** that satisfy i<j<k and arr[i]+arr[j]+arr[k]==target;
Please create a class **NTS** in Python language based on the above question, with **arr** as an attribute; then create another cl... | [
"assert candidate([1,1,2,2,3,3,4,4,5,5],8)==20",
"assert candidate([1,1,2,2,2,2],5)==12"
] | def test_run(content1,content2):
return SN_NTS(content1,content2).Number_tuples() | test_run | assert candidate([["class NTS", "def __init__(self, arr)", "class SN_NTS(NTS)", "def __init__(self, arr, target)", "super().__init__(arr)", "def Number_tuples"]]) == 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]... |
OOP/66 | Question: Given a binary string **s**, you can flip any 0 to 1 or flip 1 to 0. Return the minimum number of flips to make **s** monotonically increasing;
Please create a class **FTM** in Python based on the above question, with the attribute **s**. Then create another class **SN_FTM** that inherits from the **FTM** cla... | [
"assert candidate(\"00110\")==1",
"assert candidate(\"010110\")==2",
"assert candidate(\"00011000\")==2"
] | def test_run(content1):
return SN_FTM(content1).Flip_Times() | test_run | assert candidate([["class FTM", "def __init__(self, s)", "class SN_FTM(FTM)", "super().__init__(s)", "def Flip_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]... |
OOP/67 | Question: Given an array **arr** composed of 0s and 1s, divide the array into three non-empty parts so that all these parts represent the same binary value. If it can be done, please return any [i, j], where i+1<j, so that:
1. arr[0], arr[1], ..., arr[i] is the first part; 2. arr[i+1], arr[i+2], ..., arr[j-1] is the se... | [
"assert candidate([1,0,1,0,1])==[0,3]",
"assert candidate([1,1,0,1,1])==[-1,-1]",
"assert candidate([1,1,0,0,1])==[0,2]"
] | def test_run(content1):
return SN_BVE(content1).Binary_values() | test_run | assert candidate([["class BVE", "def __init__(self, arr)", "class SN_BVE(BVE)", "super().__init__(arr)", "def Binary_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]... |
OOP/68 | Question: Given a binary array **nums** and an integer **goal**, please count and return how many non-empty subarrays have a sum equal to **goal**.
Please create a class **NSY** in Python based on the above question, with the attribute **nums**. Then create another class **SN_NSY**, inheriting from the **NSY** class, ... | [
"assert candidate([1,0,1,0,1],2)==4",
"assert candidate([0,0,0,0,0],0)==15"
] | def test_run(content1,content2):
return SN_NSY(content1,content2).Non_subarray() | test_run | assert candidate([["class NSY", "def __init__(self, nums)", "class SN_NSY(NSY)", "def __init__(self, nums, goal)", "super().__init__(nums)", "def Non_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]... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.