task_name
stringclasses 1
value | src_lang
stringclasses 1
value | tgt_lang
stringclasses 1
value | data_id
stringlengths 10
12
| demos
listlengths 0
0
| compare_func
listlengths 0
0
| dataset_name
stringclasses 1
value | suffix
stringlengths 0
672
| test_cases
listlengths 0
5
| entry_func
stringlengths 3
31
| import_str
listlengths 0
1
| doc_string
stringlengths 39
252
| prefix
stringlengths 80
786
| solution
stringlengths 11
142
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
code_infilling
|
python
|
python
|
MBPP/228/L1
|
[] |
[] |
MBPP_Infilling
|
new_num = n & num
if new_num == 0:
return True
return False
|
[
[
"4,1,2",
"True"
],
[
"17,2,4",
"True"
],
[
"39,4,6",
"False"
]
] |
all_Bits_Set_In_The_Given_Range
|
[] |
Write a python function to check whether all the bits are unset in the given range or not.
|
def all_Bits_Set_In_The_Given_Range(n, l, r):
"""Write a python function to check whether all the bits are unset in the given range or not. """
|
num = (1 << r) - 1 ^ (1 << l - 1) - 1
|
code_infilling
|
python
|
python
|
MBPP/228/L2
|
[] |
[] |
MBPP_Infilling
|
if new_num == 0:
return True
return False
|
[
[
"4,1,2",
"True"
],
[
"17,2,4",
"True"
],
[
"39,4,6",
"False"
]
] |
all_Bits_Set_In_The_Given_Range
|
[] |
Write a python function to check whether all the bits are unset in the given range or not.
|
def all_Bits_Set_In_The_Given_Range(n, l, r):
"""Write a python function to check whether all the bits are unset in the given range or not. """
num = (1 << r) - 1 ^ (1 << l - 1) - 1
|
new_num = n & num
|
code_infilling
|
python
|
python
|
MBPP/228/L3
|
[] |
[] |
MBPP_Infilling
|
return True
return False
|
[
[
"4,1,2",
"True"
],
[
"17,2,4",
"True"
],
[
"39,4,6",
"False"
]
] |
all_Bits_Set_In_The_Given_Range
|
[] |
Write a python function to check whether all the bits are unset in the given range or not.
|
def all_Bits_Set_In_The_Given_Range(n, l, r):
"""Write a python function to check whether all the bits are unset in the given range or not. """
num = (1 << r) - 1 ^ (1 << l - 1) - 1
new_num = n & num
|
if new_num == 0:
|
code_infilling
|
python
|
python
|
MBPP/228/L4
|
[] |
[] |
MBPP_Infilling
|
return False
|
[
[
"4,1,2",
"True"
],
[
"17,2,4",
"True"
],
[
"39,4,6",
"False"
]
] |
all_Bits_Set_In_The_Given_Range
|
[] |
Write a python function to check whether all the bits are unset in the given range or not.
|
def all_Bits_Set_In_The_Given_Range(n, l, r):
"""Write a python function to check whether all the bits are unset in the given range or not. """
num = (1 << r) - 1 ^ (1 << l - 1) - 1
new_num = n & num
if new_num == 0:
|
return True
|
code_infilling
|
python
|
python
|
MBPP/228/L5
|
[] |
[] |
MBPP_Infilling
|
[
[
"4,1,2",
"True"
],
[
"17,2,4",
"True"
],
[
"39,4,6",
"False"
]
] |
all_Bits_Set_In_The_Given_Range
|
[] |
Write a python function to check whether all the bits are unset in the given range or not.
|
def all_Bits_Set_In_The_Given_Range(n, l, r):
"""Write a python function to check whether all the bits are unset in the given range or not. """
num = (1 << r) - 1 ^ (1 << l - 1) - 1
new_num = n & num
if new_num == 0:
return True
|
return False
|
|
code_infilling
|
python
|
python
|
MBPP/229/L1
|
[] |
[] |
MBPP_Infilling
|
for i in range(0, n):
if arr[i] < 0:
temp = arr[i]
arr[i] = arr[j]
arr[j] = temp
j = j + 1
return arr
|
[
[
"[-1, 2, -3, 4, 5, 6, -7, 8, 9], 9",
"[-1, -3, -7, 4, 5, 6, 2, 8, 9]"
],
[
"[12, -14, -26, 13, 15], 5",
"[-14, -26, 12, 13, 15]"
],
[
"[10, 24, 36, -42, -39, -78, 85], 7",
"[-42, -39, -78, 10, 24, 36, 85]"
]
] |
re_arrange_array
|
[] |
Write a function that takes in an array and an integer n, and re-arranges the first n elements of the given array so that all negative elements appear before positive ones, and where the relative order among negative and positive elements is preserved.
|
def re_arrange_array(arr, n):
"""Write a function that takes in an array and an integer n, and re-arranges the first n elements of the given array so that all negative elements appear before positive ones, and where the relative order among negative and positive elements is preserved. """
|
j = 0
|
code_infilling
|
python
|
python
|
MBPP/229/L2
|
[] |
[] |
MBPP_Infilling
|
if arr[i] < 0:
temp = arr[i]
arr[i] = arr[j]
arr[j] = temp
j = j + 1
return arr
|
[
[
"[-1, 2, -3, 4, 5, 6, -7, 8, 9], 9",
"[-1, -3, -7, 4, 5, 6, 2, 8, 9]"
],
[
"[12, -14, -26, 13, 15], 5",
"[-14, -26, 12, 13, 15]"
],
[
"[10, 24, 36, -42, -39, -78, 85], 7",
"[-42, -39, -78, 10, 24, 36, 85]"
]
] |
re_arrange_array
|
[] |
Write a function that takes in an array and an integer n, and re-arranges the first n elements of the given array so that all negative elements appear before positive ones, and where the relative order among negative and positive elements is preserved.
|
def re_arrange_array(arr, n):
"""Write a function that takes in an array and an integer n, and re-arranges the first n elements of the given array so that all negative elements appear before positive ones, and where the relative order among negative and positive elements is preserved. """
j = 0
|
for i in range(0, n):
|
code_infilling
|
python
|
python
|
MBPP/229/L3
|
[] |
[] |
MBPP_Infilling
|
temp = arr[i]
arr[i] = arr[j]
arr[j] = temp
j = j + 1
return arr
|
[
[
"[-1, 2, -3, 4, 5, 6, -7, 8, 9], 9",
"[-1, -3, -7, 4, 5, 6, 2, 8, 9]"
],
[
"[12, -14, -26, 13, 15], 5",
"[-14, -26, 12, 13, 15]"
],
[
"[10, 24, 36, -42, -39, -78, 85], 7",
"[-42, -39, -78, 10, 24, 36, 85]"
]
] |
re_arrange_array
|
[] |
Write a function that takes in an array and an integer n, and re-arranges the first n elements of the given array so that all negative elements appear before positive ones, and where the relative order among negative and positive elements is preserved.
|
def re_arrange_array(arr, n):
"""Write a function that takes in an array and an integer n, and re-arranges the first n elements of the given array so that all negative elements appear before positive ones, and where the relative order among negative and positive elements is preserved. """
j = 0
for i in range(0, n):
|
if arr[i] < 0:
|
code_infilling
|
python
|
python
|
MBPP/229/L4
|
[] |
[] |
MBPP_Infilling
|
arr[i] = arr[j]
arr[j] = temp
j = j + 1
return arr
|
[
[
"[-1, 2, -3, 4, 5, 6, -7, 8, 9], 9",
"[-1, -3, -7, 4, 5, 6, 2, 8, 9]"
],
[
"[12, -14, -26, 13, 15], 5",
"[-14, -26, 12, 13, 15]"
],
[
"[10, 24, 36, -42, -39, -78, 85], 7",
"[-42, -39, -78, 10, 24, 36, 85]"
]
] |
re_arrange_array
|
[] |
Write a function that takes in an array and an integer n, and re-arranges the first n elements of the given array so that all negative elements appear before positive ones, and where the relative order among negative and positive elements is preserved.
|
def re_arrange_array(arr, n):
"""Write a function that takes in an array and an integer n, and re-arranges the first n elements of the given array so that all negative elements appear before positive ones, and where the relative order among negative and positive elements is preserved. """
j = 0
for i in range(0, n):
if arr[i] < 0:
|
temp = arr[i]
|
code_infilling
|
python
|
python
|
MBPP/229/L5
|
[] |
[] |
MBPP_Infilling
|
arr[j] = temp
j = j + 1
return arr
|
[
[
"[-1, 2, -3, 4, 5, 6, -7, 8, 9], 9",
"[-1, -3, -7, 4, 5, 6, 2, 8, 9]"
],
[
"[12, -14, -26, 13, 15], 5",
"[-14, -26, 12, 13, 15]"
],
[
"[10, 24, 36, -42, -39, -78, 85], 7",
"[-42, -39, -78, 10, 24, 36, 85]"
]
] |
re_arrange_array
|
[] |
Write a function that takes in an array and an integer n, and re-arranges the first n elements of the given array so that all negative elements appear before positive ones, and where the relative order among negative and positive elements is preserved.
|
def re_arrange_array(arr, n):
"""Write a function that takes in an array and an integer n, and re-arranges the first n elements of the given array so that all negative elements appear before positive ones, and where the relative order among negative and positive elements is preserved. """
j = 0
for i in range(0, n):
if arr[i] < 0:
temp = arr[i]
|
arr[i] = arr[j]
|
code_infilling
|
python
|
python
|
MBPP/229/L6
|
[] |
[] |
MBPP_Infilling
|
j = j + 1
return arr
|
[
[
"[-1, 2, -3, 4, 5, 6, -7, 8, 9], 9",
"[-1, -3, -7, 4, 5, 6, 2, 8, 9]"
],
[
"[12, -14, -26, 13, 15], 5",
"[-14, -26, 12, 13, 15]"
],
[
"[10, 24, 36, -42, -39, -78, 85], 7",
"[-42, -39, -78, 10, 24, 36, 85]"
]
] |
re_arrange_array
|
[] |
Write a function that takes in an array and an integer n, and re-arranges the first n elements of the given array so that all negative elements appear before positive ones, and where the relative order among negative and positive elements is preserved.
|
def re_arrange_array(arr, n):
"""Write a function that takes in an array and an integer n, and re-arranges the first n elements of the given array so that all negative elements appear before positive ones, and where the relative order among negative and positive elements is preserved. """
j = 0
for i in range(0, n):
if arr[i] < 0:
temp = arr[i]
arr[i] = arr[j]
|
arr[j] = temp
|
code_infilling
|
python
|
python
|
MBPP/229/L7
|
[] |
[] |
MBPP_Infilling
|
return arr
|
[
[
"[-1, 2, -3, 4, 5, 6, -7, 8, 9], 9",
"[-1, -3, -7, 4, 5, 6, 2, 8, 9]"
],
[
"[12, -14, -26, 13, 15], 5",
"[-14, -26, 12, 13, 15]"
],
[
"[10, 24, 36, -42, -39, -78, 85], 7",
"[-42, -39, -78, 10, 24, 36, 85]"
]
] |
re_arrange_array
|
[] |
Write a function that takes in an array and an integer n, and re-arranges the first n elements of the given array so that all negative elements appear before positive ones, and where the relative order among negative and positive elements is preserved.
|
def re_arrange_array(arr, n):
"""Write a function that takes in an array and an integer n, and re-arranges the first n elements of the given array so that all negative elements appear before positive ones, and where the relative order among negative and positive elements is preserved. """
j = 0
for i in range(0, n):
if arr[i] < 0:
temp = arr[i]
arr[i] = arr[j]
arr[j] = temp
|
j = j + 1
|
code_infilling
|
python
|
python
|
MBPP/229/L8
|
[] |
[] |
MBPP_Infilling
|
[
[
"[-1, 2, -3, 4, 5, 6, -7, 8, 9], 9",
"[-1, -3, -7, 4, 5, 6, 2, 8, 9]"
],
[
"[12, -14, -26, 13, 15], 5",
"[-14, -26, 12, 13, 15]"
],
[
"[10, 24, 36, -42, -39, -78, 85], 7",
"[-42, -39, -78, 10, 24, 36, 85]"
]
] |
re_arrange_array
|
[] |
Write a function that takes in an array and an integer n, and re-arranges the first n elements of the given array so that all negative elements appear before positive ones, and where the relative order among negative and positive elements is preserved.
|
def re_arrange_array(arr, n):
"""Write a function that takes in an array and an integer n, and re-arranges the first n elements of the given array so that all negative elements appear before positive ones, and where the relative order among negative and positive elements is preserved. """
j = 0
for i in range(0, n):
if arr[i] < 0:
temp = arr[i]
arr[i] = arr[j]
arr[j] = temp
j = j + 1
|
return arr
|
|
code_infilling
|
python
|
python
|
MBPP/230/L1
|
[] |
[] |
MBPP_Infilling
|
return str2
|
[
[
"\"hello people\",'@'",
"(\"hello@people\")"
],
[
"\"python program language\",'$'",
"(\"python$program$language\")"
],
[
"\"blank space\",\"-\"",
"(\"blank-space\")"
]
] |
replace_blank
|
[] |
Write a function that takes in a string and character, replaces blank spaces in the string with the character, and returns the string.
|
def replace_blank(str1, char):
"""Write a function that takes in a string and character, replaces blank spaces in the string with the character, and returns the string. """
|
str2 = str1.replace(' ', char)
|
code_infilling
|
python
|
python
|
MBPP/230/L2
|
[] |
[] |
MBPP_Infilling
|
[
[
"\"hello people\",'@'",
"(\"hello@people\")"
],
[
"\"python program language\",'$'",
"(\"python$program$language\")"
],
[
"\"blank space\",\"-\"",
"(\"blank-space\")"
]
] |
replace_blank
|
[] |
Write a function that takes in a string and character, replaces blank spaces in the string with the character, and returns the string.
|
def replace_blank(str1, char):
"""Write a function that takes in a string and character, replaces blank spaces in the string with the character, and returns the string. """
str2 = str1.replace(' ', char)
|
return str2
|
|
code_infilling
|
python
|
python
|
MBPP/232/L3
|
[] |
[] |
MBPP_Infilling
|
return largest
|
[
[
"[10, 20, 50, 70, 90, 20, 50, 40, 60, 80, 100],2",
"set([100,90])"
],
[
"[10, 20, 50, 70, 90, 20, 50, 40, 60, 80, 100],5",
"set([100,90,80,70,60])"
],
[
"[10, 20, 50, 70, 90, 20, 50, 40, 60, 80, 100],3",
"set([100,90,80])"
]
] |
larg_nnum
|
[
"import heapq"
] |
Write a function that takes in a list and an integer n and returns a list containing the n largest items from the list.
|
import heapq
def larg_nnum(list1, n):
"""Write a function that takes in a list and an integer n and returns a list containing the n largest items from the list. """
|
largest = heapq.nlargest(n, list1)
|
code_infilling
|
python
|
python
|
MBPP/232/L4
|
[] |
[] |
MBPP_Infilling
|
[
[
"[10, 20, 50, 70, 90, 20, 50, 40, 60, 80, 100],2",
"set([100,90])"
],
[
"[10, 20, 50, 70, 90, 20, 50, 40, 60, 80, 100],5",
"set([100,90,80,70,60])"
],
[
"[10, 20, 50, 70, 90, 20, 50, 40, 60, 80, 100],3",
"set([100,90,80])"
]
] |
larg_nnum
|
[
"import heapq"
] |
Write a function that takes in a list and an integer n and returns a list containing the n largest items from the list.
|
import heapq
def larg_nnum(list1, n):
"""Write a function that takes in a list and an integer n and returns a list containing the n largest items from the list. """
largest = heapq.nlargest(n, list1)
|
return largest
|
|
code_infilling
|
python
|
python
|
MBPP/233/L1
|
[] |
[] |
MBPP_Infilling
|
return lateralsurface
|
[] |
lateralsuface_cylinder
|
[] |
Write a function to find the lateral surface area of a cylinder.
|
def lateralsuface_cylinder(r, h):
"""Write a function to find the lateral surface area of a cylinder. """
|
lateralsurface = 2 * 3.1415 * r * h
|
code_infilling
|
python
|
python
|
MBPP/233/L2
|
[] |
[] |
MBPP_Infilling
|
[] |
lateralsuface_cylinder
|
[] |
Write a function to find the lateral surface area of a cylinder.
|
def lateralsuface_cylinder(r, h):
"""Write a function to find the lateral surface area of a cylinder. """
lateralsurface = 2 * 3.1415 * r * h
|
return lateralsurface
|
|
code_infilling
|
python
|
python
|
MBPP/234/L1
|
[] |
[] |
MBPP_Infilling
|
return volume
|
[
[
"3",
"27"
],
[
"2",
"8"
],
[
"5",
"125"
]
] |
volume_cube
|
[] |
Write a function to find the volume of a cube given its side length.
|
def volume_cube(l):
"""Write a function to find the volume of a cube given its side length. """
|
volume = l * l * l
|
code_infilling
|
python
|
python
|
MBPP/234/L2
|
[] |
[] |
MBPP_Infilling
|
[
[
"3",
"27"
],
[
"2",
"8"
],
[
"5",
"125"
]
] |
volume_cube
|
[] |
Write a function to find the volume of a cube given its side length.
|
def volume_cube(l):
"""Write a function to find the volume of a cube given its side length. """
volume = l * l * l
|
return volume
|
|
code_infilling
|
python
|
python
|
MBPP/235/L1
|
[] |
[] |
MBPP_Infilling
|
res = 0
temp = n
while temp > 0:
if count % 2 == 1:
res |= 1 << count
count += 1
temp >>= 1
return n | res
|
[
[
"10",
"10"
],
[
"20",
"30"
],
[
"30",
"30"
]
] |
even_bit_set_number
|
[] |
Write a python function to set all even bits of a given number.
|
def even_bit_set_number(n):
"""Write a python function to set all even bits of a given number. """
|
count = 0
|
code_infilling
|
python
|
python
|
MBPP/235/L2
|
[] |
[] |
MBPP_Infilling
|
temp = n
while temp > 0:
if count % 2 == 1:
res |= 1 << count
count += 1
temp >>= 1
return n | res
|
[
[
"10",
"10"
],
[
"20",
"30"
],
[
"30",
"30"
]
] |
even_bit_set_number
|
[] |
Write a python function to set all even bits of a given number.
|
def even_bit_set_number(n):
"""Write a python function to set all even bits of a given number. """
count = 0
|
res = 0
|
code_infilling
|
python
|
python
|
MBPP/235/L3
|
[] |
[] |
MBPP_Infilling
|
while temp > 0:
if count % 2 == 1:
res |= 1 << count
count += 1
temp >>= 1
return n | res
|
[
[
"10",
"10"
],
[
"20",
"30"
],
[
"30",
"30"
]
] |
even_bit_set_number
|
[] |
Write a python function to set all even bits of a given number.
|
def even_bit_set_number(n):
"""Write a python function to set all even bits of a given number. """
count = 0
res = 0
|
temp = n
|
code_infilling
|
python
|
python
|
MBPP/235/L4
|
[] |
[] |
MBPP_Infilling
|
if count % 2 == 1:
res |= 1 << count
count += 1
temp >>= 1
return n | res
|
[
[
"10",
"10"
],
[
"20",
"30"
],
[
"30",
"30"
]
] |
even_bit_set_number
|
[] |
Write a python function to set all even bits of a given number.
|
def even_bit_set_number(n):
"""Write a python function to set all even bits of a given number. """
count = 0
res = 0
temp = n
|
while temp > 0:
|
code_infilling
|
python
|
python
|
MBPP/235/L5
|
[] |
[] |
MBPP_Infilling
|
res |= 1 << count
count += 1
temp >>= 1
return n | res
|
[
[
"10",
"10"
],
[
"20",
"30"
],
[
"30",
"30"
]
] |
even_bit_set_number
|
[] |
Write a python function to set all even bits of a given number.
|
def even_bit_set_number(n):
"""Write a python function to set all even bits of a given number. """
count = 0
res = 0
temp = n
while temp > 0:
|
if count % 2 == 1:
|
code_infilling
|
python
|
python
|
MBPP/235/L6
|
[] |
[] |
MBPP_Infilling
|
count += 1
temp >>= 1
return n | res
|
[
[
"10",
"10"
],
[
"20",
"30"
],
[
"30",
"30"
]
] |
even_bit_set_number
|
[] |
Write a python function to set all even bits of a given number.
|
def even_bit_set_number(n):
"""Write a python function to set all even bits of a given number. """
count = 0
res = 0
temp = n
while temp > 0:
if count % 2 == 1:
|
res |= 1 << count
|
code_infilling
|
python
|
python
|
MBPP/235/L7
|
[] |
[] |
MBPP_Infilling
|
temp >>= 1
return n | res
|
[
[
"10",
"10"
],
[
"20",
"30"
],
[
"30",
"30"
]
] |
even_bit_set_number
|
[] |
Write a python function to set all even bits of a given number.
|
def even_bit_set_number(n):
"""Write a python function to set all even bits of a given number. """
count = 0
res = 0
temp = n
while temp > 0:
if count % 2 == 1:
res |= 1 << count
|
count += 1
|
code_infilling
|
python
|
python
|
MBPP/235/L8
|
[] |
[] |
MBPP_Infilling
|
return n | res
|
[
[
"10",
"10"
],
[
"20",
"30"
],
[
"30",
"30"
]
] |
even_bit_set_number
|
[] |
Write a python function to set all even bits of a given number.
|
def even_bit_set_number(n):
"""Write a python function to set all even bits of a given number. """
count = 0
res = 0
temp = n
while temp > 0:
if count % 2 == 1:
res |= 1 << count
count += 1
|
temp >>= 1
|
code_infilling
|
python
|
python
|
MBPP/235/L9
|
[] |
[] |
MBPP_Infilling
|
[
[
"10",
"10"
],
[
"20",
"30"
],
[
"30",
"30"
]
] |
even_bit_set_number
|
[] |
Write a python function to set all even bits of a given number.
|
def even_bit_set_number(n):
"""Write a python function to set all even bits of a given number. """
count = 0
res = 0
temp = n
while temp > 0:
if count % 2 == 1:
res |= 1 << count
count += 1
temp >>= 1
|
return n | res
|
|
code_infilling
|
python
|
python
|
MBPP/237/L3
|
[] |
[] |
MBPP_Infilling
|
return res
|
[
[
"[(3, 1), (1, 3), (2, 5), (5, 2), (6, 3)] ",
"{(1, 3): 2, (2, 5): 2, (3, 6): 1}"
],
[
"[(4, 2), (2, 4), (3, 6), (6, 3), (7, 4)] ",
"{(2, 4): 2, (3, 6): 2, (4, 7): 1}"
],
[
"[(13, 2), (11, 23), (12, 25), (25, 12), (16, 23)] ",
"{(2, 13): 1, (11, 23): 1, (12, 25): 2, (16, 23): 1}"
]
] |
check_occurences
|
[
"from collections import Counter "
] |
Write a function that takes in a list of tuples and returns a dictionary mapping each unique tuple to the number of times it occurs in the list.
|
from collections import Counter
def check_occurences(test_list):
"""Write a function that takes in a list of tuples and returns a dictionary mapping each unique tuple to the number of times it occurs in the list. """
|
res = dict(Counter((tuple(ele) for ele in map(sorted, test_list))))
|
code_infilling
|
python
|
python
|
MBPP/237/L4
|
[] |
[] |
MBPP_Infilling
|
[
[
"[(3, 1), (1, 3), (2, 5), (5, 2), (6, 3)] ",
"{(1, 3): 2, (2, 5): 2, (3, 6): 1}"
],
[
"[(4, 2), (2, 4), (3, 6), (6, 3), (7, 4)] ",
"{(2, 4): 2, (3, 6): 2, (4, 7): 1}"
],
[
"[(13, 2), (11, 23), (12, 25), (25, 12), (16, 23)] ",
"{(2, 13): 1, (11, 23): 1, (12, 25): 2, (16, 23): 1}"
]
] |
check_occurences
|
[
"from collections import Counter "
] |
Write a function that takes in a list of tuples and returns a dictionary mapping each unique tuple to the number of times it occurs in the list.
|
from collections import Counter
def check_occurences(test_list):
"""Write a function that takes in a list of tuples and returns a dictionary mapping each unique tuple to the number of times it occurs in the list. """
res = dict(Counter((tuple(ele) for ele in map(sorted, test_list))))
|
return res
|
|
code_infilling
|
python
|
python
|
MBPP/238/L1
|
[] |
[] |
MBPP_Infilling
|
return int(str_len * (str_len + 1) / 2)
|
[
[
"\"abc\"",
"6"
],
[
"\"abcd\"",
"10"
],
[
"\"abcde\"",
"15"
]
] |
number_of_substrings
|
[] |
Write a python function to count the number of non-empty substrings of a given string.
|
def number_of_substrings(str):
"""Write a python function to count the number of non-empty substrings of a given string. """
|
str_len = len(str)
|
code_infilling
|
python
|
python
|
MBPP/238/L2
|
[] |
[] |
MBPP_Infilling
|
[
[
"\"abc\"",
"6"
],
[
"\"abcd\"",
"10"
],
[
"\"abcde\"",
"15"
]
] |
number_of_substrings
|
[] |
Write a python function to count the number of non-empty substrings of a given string.
|
def number_of_substrings(str):
"""Write a python function to count the number of non-empty substrings of a given string. """
str_len = len(str)
|
return int(str_len * (str_len + 1) / 2)
|
|
code_infilling
|
python
|
python
|
MBPP/239/L1
|
[] |
[] |
MBPP_Infilling
|
for i in range(m + 1):
for j in range(n + 1):
if i == 0 or j == 0:
T[i][j] = 0
elif i < j:
T[i][j] = 0
elif j == 1:
T[i][j] = i
else:
T[i][j] = T[i - 1][j] + T[i // 2][j - 1]
return T[m][n]
|
[
[
"10, 4",
"4"
],
[
"5, 2",
"6"
],
[
"16, 3",
"84"
]
] |
get_total_number_of_sequences
|
[] |
Write a function that takes in positive integers m and n and finds the number of possible sequences of length n, such that each element is a positive integer and is greater than or equal to twice the previous element but less than or equal to m.
|
def get_total_number_of_sequences(m, n):
"""Write a function that takes in positive integers m and n and finds the number of possible sequences of length n, such that each element is a positive integer and is greater than or equal to twice the previous element but less than or equal to m. """
|
T = [[0 for i in range(n + 1)] for i in range(m + 1)]
|
code_infilling
|
python
|
python
|
MBPP/239/L2
|
[] |
[] |
MBPP_Infilling
|
for j in range(n + 1):
if i == 0 or j == 0:
T[i][j] = 0
elif i < j:
T[i][j] = 0
elif j == 1:
T[i][j] = i
else:
T[i][j] = T[i - 1][j] + T[i // 2][j - 1]
return T[m][n]
|
[
[
"10, 4",
"4"
],
[
"5, 2",
"6"
],
[
"16, 3",
"84"
]
] |
get_total_number_of_sequences
|
[] |
Write a function that takes in positive integers m and n and finds the number of possible sequences of length n, such that each element is a positive integer and is greater than or equal to twice the previous element but less than or equal to m.
|
def get_total_number_of_sequences(m, n):
"""Write a function that takes in positive integers m and n and finds the number of possible sequences of length n, such that each element is a positive integer and is greater than or equal to twice the previous element but less than or equal to m. """
T = [[0 for i in range(n + 1)] for i in range(m + 1)]
|
for i in range(m + 1):
|
code_infilling
|
python
|
python
|
MBPP/239/L3
|
[] |
[] |
MBPP_Infilling
|
if i == 0 or j == 0:
T[i][j] = 0
elif i < j:
T[i][j] = 0
elif j == 1:
T[i][j] = i
else:
T[i][j] = T[i - 1][j] + T[i // 2][j - 1]
return T[m][n]
|
[
[
"10, 4",
"4"
],
[
"5, 2",
"6"
],
[
"16, 3",
"84"
]
] |
get_total_number_of_sequences
|
[] |
Write a function that takes in positive integers m and n and finds the number of possible sequences of length n, such that each element is a positive integer and is greater than or equal to twice the previous element but less than or equal to m.
|
def get_total_number_of_sequences(m, n):
"""Write a function that takes in positive integers m and n and finds the number of possible sequences of length n, such that each element is a positive integer and is greater than or equal to twice the previous element but less than or equal to m. """
T = [[0 for i in range(n + 1)] for i in range(m + 1)]
for i in range(m + 1):
|
for j in range(n + 1):
|
code_infilling
|
python
|
python
|
MBPP/239/L4
|
[] |
[] |
MBPP_Infilling
|
T[i][j] = 0
elif i < j:
T[i][j] = 0
elif j == 1:
T[i][j] = i
else:
T[i][j] = T[i - 1][j] + T[i // 2][j - 1]
return T[m][n]
|
[
[
"10, 4",
"4"
],
[
"5, 2",
"6"
],
[
"16, 3",
"84"
]
] |
get_total_number_of_sequences
|
[] |
Write a function that takes in positive integers m and n and finds the number of possible sequences of length n, such that each element is a positive integer and is greater than or equal to twice the previous element but less than or equal to m.
|
def get_total_number_of_sequences(m, n):
"""Write a function that takes in positive integers m and n and finds the number of possible sequences of length n, such that each element is a positive integer and is greater than or equal to twice the previous element but less than or equal to m. """
T = [[0 for i in range(n + 1)] for i in range(m + 1)]
for i in range(m + 1):
for j in range(n + 1):
|
if i == 0 or j == 0:
|
code_infilling
|
python
|
python
|
MBPP/239/L5
|
[] |
[] |
MBPP_Infilling
|
elif i < j:
T[i][j] = 0
elif j == 1:
T[i][j] = i
else:
T[i][j] = T[i - 1][j] + T[i // 2][j - 1]
return T[m][n]
|
[
[
"10, 4",
"4"
],
[
"5, 2",
"6"
],
[
"16, 3",
"84"
]
] |
get_total_number_of_sequences
|
[] |
Write a function that takes in positive integers m and n and finds the number of possible sequences of length n, such that each element is a positive integer and is greater than or equal to twice the previous element but less than or equal to m.
|
def get_total_number_of_sequences(m, n):
"""Write a function that takes in positive integers m and n and finds the number of possible sequences of length n, such that each element is a positive integer and is greater than or equal to twice the previous element but less than or equal to m. """
T = [[0 for i in range(n + 1)] for i in range(m + 1)]
for i in range(m + 1):
for j in range(n + 1):
if i == 0 or j == 0:
|
T[i][j] = 0
|
code_infilling
|
python
|
python
|
MBPP/239/L6
|
[] |
[] |
MBPP_Infilling
|
T[i][j] = 0
elif j == 1:
T[i][j] = i
else:
T[i][j] = T[i - 1][j] + T[i // 2][j - 1]
return T[m][n]
|
[
[
"10, 4",
"4"
],
[
"5, 2",
"6"
],
[
"16, 3",
"84"
]
] |
get_total_number_of_sequences
|
[] |
Write a function that takes in positive integers m and n and finds the number of possible sequences of length n, such that each element is a positive integer and is greater than or equal to twice the previous element but less than or equal to m.
|
def get_total_number_of_sequences(m, n):
"""Write a function that takes in positive integers m and n and finds the number of possible sequences of length n, such that each element is a positive integer and is greater than or equal to twice the previous element but less than or equal to m. """
T = [[0 for i in range(n + 1)] for i in range(m + 1)]
for i in range(m + 1):
for j in range(n + 1):
if i == 0 or j == 0:
T[i][j] = 0
|
elif i < j:
|
code_infilling
|
python
|
python
|
MBPP/239/L7
|
[] |
[] |
MBPP_Infilling
|
elif j == 1:
T[i][j] = i
else:
T[i][j] = T[i - 1][j] + T[i // 2][j - 1]
return T[m][n]
|
[
[
"10, 4",
"4"
],
[
"5, 2",
"6"
],
[
"16, 3",
"84"
]
] |
get_total_number_of_sequences
|
[] |
Write a function that takes in positive integers m and n and finds the number of possible sequences of length n, such that each element is a positive integer and is greater than or equal to twice the previous element but less than or equal to m.
|
def get_total_number_of_sequences(m, n):
"""Write a function that takes in positive integers m and n and finds the number of possible sequences of length n, such that each element is a positive integer and is greater than or equal to twice the previous element but less than or equal to m. """
T = [[0 for i in range(n + 1)] for i in range(m + 1)]
for i in range(m + 1):
for j in range(n + 1):
if i == 0 or j == 0:
T[i][j] = 0
elif i < j:
|
T[i][j] = 0
|
code_infilling
|
python
|
python
|
MBPP/239/L8
|
[] |
[] |
MBPP_Infilling
|
T[i][j] = i
else:
T[i][j] = T[i - 1][j] + T[i // 2][j - 1]
return T[m][n]
|
[
[
"10, 4",
"4"
],
[
"5, 2",
"6"
],
[
"16, 3",
"84"
]
] |
get_total_number_of_sequences
|
[] |
Write a function that takes in positive integers m and n and finds the number of possible sequences of length n, such that each element is a positive integer and is greater than or equal to twice the previous element but less than or equal to m.
|
def get_total_number_of_sequences(m, n):
"""Write a function that takes in positive integers m and n and finds the number of possible sequences of length n, such that each element is a positive integer and is greater than or equal to twice the previous element but less than or equal to m. """
T = [[0 for i in range(n + 1)] for i in range(m + 1)]
for i in range(m + 1):
for j in range(n + 1):
if i == 0 or j == 0:
T[i][j] = 0
elif i < j:
T[i][j] = 0
|
elif j == 1:
|
code_infilling
|
python
|
python
|
MBPP/239/L9
|
[] |
[] |
MBPP_Infilling
|
else:
T[i][j] = T[i - 1][j] + T[i // 2][j - 1]
return T[m][n]
|
[
[
"10, 4",
"4"
],
[
"5, 2",
"6"
],
[
"16, 3",
"84"
]
] |
get_total_number_of_sequences
|
[] |
Write a function that takes in positive integers m and n and finds the number of possible sequences of length n, such that each element is a positive integer and is greater than or equal to twice the previous element but less than or equal to m.
|
def get_total_number_of_sequences(m, n):
"""Write a function that takes in positive integers m and n and finds the number of possible sequences of length n, such that each element is a positive integer and is greater than or equal to twice the previous element but less than or equal to m. """
T = [[0 for i in range(n + 1)] for i in range(m + 1)]
for i in range(m + 1):
for j in range(n + 1):
if i == 0 or j == 0:
T[i][j] = 0
elif i < j:
T[i][j] = 0
elif j == 1:
|
T[i][j] = i
|
code_infilling
|
python
|
python
|
MBPP/239/L10
|
[] |
[] |
MBPP_Infilling
|
T[i][j] = T[i - 1][j] + T[i // 2][j - 1]
return T[m][n]
|
[
[
"10, 4",
"4"
],
[
"5, 2",
"6"
],
[
"16, 3",
"84"
]
] |
get_total_number_of_sequences
|
[] |
Write a function that takes in positive integers m and n and finds the number of possible sequences of length n, such that each element is a positive integer and is greater than or equal to twice the previous element but less than or equal to m.
|
def get_total_number_of_sequences(m, n):
"""Write a function that takes in positive integers m and n and finds the number of possible sequences of length n, such that each element is a positive integer and is greater than or equal to twice the previous element but less than or equal to m. """
T = [[0 for i in range(n + 1)] for i in range(m + 1)]
for i in range(m + 1):
for j in range(n + 1):
if i == 0 or j == 0:
T[i][j] = 0
elif i < j:
T[i][j] = 0
elif j == 1:
T[i][j] = i
|
else:
|
code_infilling
|
python
|
python
|
MBPP/239/L11
|
[] |
[] |
MBPP_Infilling
|
return T[m][n]
|
[
[
"10, 4",
"4"
],
[
"5, 2",
"6"
],
[
"16, 3",
"84"
]
] |
get_total_number_of_sequences
|
[] |
Write a function that takes in positive integers m and n and finds the number of possible sequences of length n, such that each element is a positive integer and is greater than or equal to twice the previous element but less than or equal to m.
|
def get_total_number_of_sequences(m, n):
"""Write a function that takes in positive integers m and n and finds the number of possible sequences of length n, such that each element is a positive integer and is greater than or equal to twice the previous element but less than or equal to m. """
T = [[0 for i in range(n + 1)] for i in range(m + 1)]
for i in range(m + 1):
for j in range(n + 1):
if i == 0 or j == 0:
T[i][j] = 0
elif i < j:
T[i][j] = 0
elif j == 1:
T[i][j] = i
else:
|
T[i][j] = T[i - 1][j] + T[i // 2][j - 1]
|
code_infilling
|
python
|
python
|
MBPP/239/L12
|
[] |
[] |
MBPP_Infilling
|
[
[
"10, 4",
"4"
],
[
"5, 2",
"6"
],
[
"16, 3",
"84"
]
] |
get_total_number_of_sequences
|
[] |
Write a function that takes in positive integers m and n and finds the number of possible sequences of length n, such that each element is a positive integer and is greater than or equal to twice the previous element but less than or equal to m.
|
def get_total_number_of_sequences(m, n):
"""Write a function that takes in positive integers m and n and finds the number of possible sequences of length n, such that each element is a positive integer and is greater than or equal to twice the previous element but less than or equal to m. """
T = [[0 for i in range(n + 1)] for i in range(m + 1)]
for i in range(m + 1):
for j in range(n + 1):
if i == 0 or j == 0:
T[i][j] = 0
elif i < j:
T[i][j] = 0
elif j == 1:
T[i][j] = i
else:
T[i][j] = T[i - 1][j] + T[i // 2][j - 1]
|
return T[m][n]
|
|
code_infilling
|
python
|
python
|
MBPP/240/L1
|
[] |
[] |
MBPP_Infilling
|
replace_list = list1
return replace_list
|
[
[
"[1, 3, 5, 7, 9, 10],[2, 4, 6, 8]",
"[1, 3, 5, 7, 9, 2, 4, 6, 8]"
],
[
"[1,2,3,4,5],[5,6,7,8]",
"[1,2,3,4,5,6,7,8]"
],
[
"[\"red\",\"blue\",\"green\"],[\"yellow\"]",
"[\"red\",\"blue\",\"yellow\"]"
]
] |
replace_list
|
[] |
Write a function that takes in two lists and replaces the last element of the first list with the elements of the second list.
|
def replace_list(list1, list2):
"""Write a function that takes in two lists and replaces the last element of the first list with the elements of the second list. """
|
list1[-1:] = list2
|
code_infilling
|
python
|
python
|
MBPP/240/L2
|
[] |
[] |
MBPP_Infilling
|
return replace_list
|
[
[
"[1, 3, 5, 7, 9, 10],[2, 4, 6, 8]",
"[1, 3, 5, 7, 9, 2, 4, 6, 8]"
],
[
"[1,2,3,4,5],[5,6,7,8]",
"[1,2,3,4,5,6,7,8]"
],
[
"[\"red\",\"blue\",\"green\"],[\"yellow\"]",
"[\"red\",\"blue\",\"yellow\"]"
]
] |
replace_list
|
[] |
Write a function that takes in two lists and replaces the last element of the first list with the elements of the second list.
|
def replace_list(list1, list2):
"""Write a function that takes in two lists and replaces the last element of the first list with the elements of the second list. """
list1[-1:] = list2
|
replace_list = list1
|
code_infilling
|
python
|
python
|
MBPP/240/L3
|
[] |
[] |
MBPP_Infilling
|
[
[
"[1, 3, 5, 7, 9, 10],[2, 4, 6, 8]",
"[1, 3, 5, 7, 9, 2, 4, 6, 8]"
],
[
"[1,2,3,4,5],[5,6,7,8]",
"[1,2,3,4,5,6,7,8]"
],
[
"[\"red\",\"blue\",\"green\"],[\"yellow\"]",
"[\"red\",\"blue\",\"yellow\"]"
]
] |
replace_list
|
[] |
Write a function that takes in two lists and replaces the last element of the first list with the elements of the second list.
|
def replace_list(list1, list2):
"""Write a function that takes in two lists and replaces the last element of the first list with the elements of the second list. """
list1[-1:] = list2
replace_list = list1
|
return replace_list
|
|
code_infilling
|
python
|
python
|
MBPP/242/L1
|
[] |
[] |
MBPP_Infilling
|
for i in str1:
total = total + 1
return total
|
[
[
"\"python programming\"",
"18"
],
[
"\"language\"",
"8"
],
[
"\"words\"",
"5"
]
] |
count_charac
|
[] |
Write a function to count the total number of characters in a string.
|
def count_charac(str1):
"""Write a function to count the total number of characters in a string. """
|
total = 0
|
code_infilling
|
python
|
python
|
MBPP/242/L2
|
[] |
[] |
MBPP_Infilling
|
total = total + 1
return total
|
[
[
"\"python programming\"",
"18"
],
[
"\"language\"",
"8"
],
[
"\"words\"",
"5"
]
] |
count_charac
|
[] |
Write a function to count the total number of characters in a string.
|
def count_charac(str1):
"""Write a function to count the total number of characters in a string. """
total = 0
|
for i in str1:
|
code_infilling
|
python
|
python
|
MBPP/242/L3
|
[] |
[] |
MBPP_Infilling
|
return total
|
[
[
"\"python programming\"",
"18"
],
[
"\"language\"",
"8"
],
[
"\"words\"",
"5"
]
] |
count_charac
|
[] |
Write a function to count the total number of characters in a string.
|
def count_charac(str1):
"""Write a function to count the total number of characters in a string. """
total = 0
for i in str1:
|
total = total + 1
|
code_infilling
|
python
|
python
|
MBPP/242/L4
|
[] |
[] |
MBPP_Infilling
|
[
[
"\"python programming\"",
"18"
],
[
"\"language\"",
"8"
],
[
"\"words\"",
"5"
]
] |
count_charac
|
[] |
Write a function to count the total number of characters in a string.
|
def count_charac(str1):
"""Write a function to count the total number of characters in a string. """
total = 0
for i in str1:
total = total + 1
|
return total
|
|
code_infilling
|
python
|
python
|
MBPP/244/L3
|
[] |
[] |
MBPP_Infilling
|
return nextN * nextN
|
[
[
"35",
"36"
],
[
"6",
"9"
],
[
"9",
"16"
]
] |
next_Perfect_Square
|
[
"import math "
] |
Write a python function to find the next perfect square greater than a given number.
|
import math
def next_Perfect_Square(N):
"""Write a python function to find the next perfect square greater than a given number. """
|
nextN = math.floor(math.sqrt(N)) + 1
|
code_infilling
|
python
|
python
|
MBPP/244/L4
|
[] |
[] |
MBPP_Infilling
|
[
[
"35",
"36"
],
[
"6",
"9"
],
[
"9",
"16"
]
] |
next_Perfect_Square
|
[
"import math "
] |
Write a python function to find the next perfect square greater than a given number.
|
import math
def next_Perfect_Square(N):
"""Write a python function to find the next perfect square greater than a given number. """
nextN = math.floor(math.sqrt(N)) + 1
|
return nextN * nextN
|
|
code_infilling
|
python
|
python
|
MBPP/245/L1
|
[] |
[] |
MBPP_Infilling
|
for i in range(len(arr)):
for j in range(0, i):
if arr[i] > arr[j] and MSIBS[i] < MSIBS[j] + arr[i]:
MSIBS[i] = MSIBS[j] + arr[i]
MSDBS = arr[:]
for i in range(1, len(arr) + 1):
for j in range(1, i):
if arr[-i] > arr[-j] and MSDBS[-i] < MSDBS[-j] + arr[-i]:
MSDBS[-i] = MSDBS[-j] + arr[-i]
max_sum = float('-Inf')
for (i, j, k) in zip(MSIBS, MSDBS, arr):
max_sum = max(max_sum, i + j - k)
return max_sum
|
[
[
"[1, 15, 51, 45, 33, 100, 12, 18, 9]",
"194"
],
[
"[80, 60, 30, 40, 20, 10]",
"210"
],
[
"[2, 3 ,14, 16, 21, 23, 29, 30]",
"138"
]
] |
max_sum
|
[] |
Write a function that takes an array and finds the maximum sum of a bitonic subsequence for the given array, where a sequence is bitonic if it is first increasing and then decreasing.
|
def max_sum(arr):
"""Write a function that takes an array and finds the maximum sum of a bitonic subsequence for the given array, where a sequence is bitonic if it is first increasing and then decreasing. """
|
MSIBS = arr[:]
|
code_infilling
|
python
|
python
|
MBPP/245/L2
|
[] |
[] |
MBPP_Infilling
|
for j in range(0, i):
if arr[i] > arr[j] and MSIBS[i] < MSIBS[j] + arr[i]:
MSIBS[i] = MSIBS[j] + arr[i]
MSDBS = arr[:]
for i in range(1, len(arr) + 1):
for j in range(1, i):
if arr[-i] > arr[-j] and MSDBS[-i] < MSDBS[-j] + arr[-i]:
MSDBS[-i] = MSDBS[-j] + arr[-i]
max_sum = float('-Inf')
for (i, j, k) in zip(MSIBS, MSDBS, arr):
max_sum = max(max_sum, i + j - k)
return max_sum
|
[
[
"[1, 15, 51, 45, 33, 100, 12, 18, 9]",
"194"
],
[
"[80, 60, 30, 40, 20, 10]",
"210"
],
[
"[2, 3 ,14, 16, 21, 23, 29, 30]",
"138"
]
] |
max_sum
|
[] |
Write a function that takes an array and finds the maximum sum of a bitonic subsequence for the given array, where a sequence is bitonic if it is first increasing and then decreasing.
|
def max_sum(arr):
"""Write a function that takes an array and finds the maximum sum of a bitonic subsequence for the given array, where a sequence is bitonic if it is first increasing and then decreasing. """
MSIBS = arr[:]
|
for i in range(len(arr)):
|
code_infilling
|
python
|
python
|
MBPP/245/L3
|
[] |
[] |
MBPP_Infilling
|
if arr[i] > arr[j] and MSIBS[i] < MSIBS[j] + arr[i]:
MSIBS[i] = MSIBS[j] + arr[i]
MSDBS = arr[:]
for i in range(1, len(arr) + 1):
for j in range(1, i):
if arr[-i] > arr[-j] and MSDBS[-i] < MSDBS[-j] + arr[-i]:
MSDBS[-i] = MSDBS[-j] + arr[-i]
max_sum = float('-Inf')
for (i, j, k) in zip(MSIBS, MSDBS, arr):
max_sum = max(max_sum, i + j - k)
return max_sum
|
[
[
"[1, 15, 51, 45, 33, 100, 12, 18, 9]",
"194"
],
[
"[80, 60, 30, 40, 20, 10]",
"210"
],
[
"[2, 3 ,14, 16, 21, 23, 29, 30]",
"138"
]
] |
max_sum
|
[] |
Write a function that takes an array and finds the maximum sum of a bitonic subsequence for the given array, where a sequence is bitonic if it is first increasing and then decreasing.
|
def max_sum(arr):
"""Write a function that takes an array and finds the maximum sum of a bitonic subsequence for the given array, where a sequence is bitonic if it is first increasing and then decreasing. """
MSIBS = arr[:]
for i in range(len(arr)):
|
for j in range(0, i):
|
code_infilling
|
python
|
python
|
MBPP/245/L4
|
[] |
[] |
MBPP_Infilling
|
MSIBS[i] = MSIBS[j] + arr[i]
MSDBS = arr[:]
for i in range(1, len(arr) + 1):
for j in range(1, i):
if arr[-i] > arr[-j] and MSDBS[-i] < MSDBS[-j] + arr[-i]:
MSDBS[-i] = MSDBS[-j] + arr[-i]
max_sum = float('-Inf')
for (i, j, k) in zip(MSIBS, MSDBS, arr):
max_sum = max(max_sum, i + j - k)
return max_sum
|
[
[
"[1, 15, 51, 45, 33, 100, 12, 18, 9]",
"194"
],
[
"[80, 60, 30, 40, 20, 10]",
"210"
],
[
"[2, 3 ,14, 16, 21, 23, 29, 30]",
"138"
]
] |
max_sum
|
[] |
Write a function that takes an array and finds the maximum sum of a bitonic subsequence for the given array, where a sequence is bitonic if it is first increasing and then decreasing.
|
def max_sum(arr):
"""Write a function that takes an array and finds the maximum sum of a bitonic subsequence for the given array, where a sequence is bitonic if it is first increasing and then decreasing. """
MSIBS = arr[:]
for i in range(len(arr)):
for j in range(0, i):
|
if arr[i] > arr[j] and MSIBS[i] < MSIBS[j] + arr[i]:
|
code_infilling
|
python
|
python
|
MBPP/245/L5
|
[] |
[] |
MBPP_Infilling
|
MSDBS = arr[:]
for i in range(1, len(arr) + 1):
for j in range(1, i):
if arr[-i] > arr[-j] and MSDBS[-i] < MSDBS[-j] + arr[-i]:
MSDBS[-i] = MSDBS[-j] + arr[-i]
max_sum = float('-Inf')
for (i, j, k) in zip(MSIBS, MSDBS, arr):
max_sum = max(max_sum, i + j - k)
return max_sum
|
[
[
"[1, 15, 51, 45, 33, 100, 12, 18, 9]",
"194"
],
[
"[80, 60, 30, 40, 20, 10]",
"210"
],
[
"[2, 3 ,14, 16, 21, 23, 29, 30]",
"138"
]
] |
max_sum
|
[] |
Write a function that takes an array and finds the maximum sum of a bitonic subsequence for the given array, where a sequence is bitonic if it is first increasing and then decreasing.
|
def max_sum(arr):
"""Write a function that takes an array and finds the maximum sum of a bitonic subsequence for the given array, where a sequence is bitonic if it is first increasing and then decreasing. """
MSIBS = arr[:]
for i in range(len(arr)):
for j in range(0, i):
if arr[i] > arr[j] and MSIBS[i] < MSIBS[j] + arr[i]:
|
MSIBS[i] = MSIBS[j] + arr[i]
|
code_infilling
|
python
|
python
|
MBPP/245/L6
|
[] |
[] |
MBPP_Infilling
|
for i in range(1, len(arr) + 1):
for j in range(1, i):
if arr[-i] > arr[-j] and MSDBS[-i] < MSDBS[-j] + arr[-i]:
MSDBS[-i] = MSDBS[-j] + arr[-i]
max_sum = float('-Inf')
for (i, j, k) in zip(MSIBS, MSDBS, arr):
max_sum = max(max_sum, i + j - k)
return max_sum
|
[
[
"[1, 15, 51, 45, 33, 100, 12, 18, 9]",
"194"
],
[
"[80, 60, 30, 40, 20, 10]",
"210"
],
[
"[2, 3 ,14, 16, 21, 23, 29, 30]",
"138"
]
] |
max_sum
|
[] |
Write a function that takes an array and finds the maximum sum of a bitonic subsequence for the given array, where a sequence is bitonic if it is first increasing and then decreasing.
|
def max_sum(arr):
"""Write a function that takes an array and finds the maximum sum of a bitonic subsequence for the given array, where a sequence is bitonic if it is first increasing and then decreasing. """
MSIBS = arr[:]
for i in range(len(arr)):
for j in range(0, i):
if arr[i] > arr[j] and MSIBS[i] < MSIBS[j] + arr[i]:
MSIBS[i] = MSIBS[j] + arr[i]
|
MSDBS = arr[:]
|
code_infilling
|
python
|
python
|
MBPP/245/L7
|
[] |
[] |
MBPP_Infilling
|
for j in range(1, i):
if arr[-i] > arr[-j] and MSDBS[-i] < MSDBS[-j] + arr[-i]:
MSDBS[-i] = MSDBS[-j] + arr[-i]
max_sum = float('-Inf')
for (i, j, k) in zip(MSIBS, MSDBS, arr):
max_sum = max(max_sum, i + j - k)
return max_sum
|
[
[
"[1, 15, 51, 45, 33, 100, 12, 18, 9]",
"194"
],
[
"[80, 60, 30, 40, 20, 10]",
"210"
],
[
"[2, 3 ,14, 16, 21, 23, 29, 30]",
"138"
]
] |
max_sum
|
[] |
Write a function that takes an array and finds the maximum sum of a bitonic subsequence for the given array, where a sequence is bitonic if it is first increasing and then decreasing.
|
def max_sum(arr):
"""Write a function that takes an array and finds the maximum sum of a bitonic subsequence for the given array, where a sequence is bitonic if it is first increasing and then decreasing. """
MSIBS = arr[:]
for i in range(len(arr)):
for j in range(0, i):
if arr[i] > arr[j] and MSIBS[i] < MSIBS[j] + arr[i]:
MSIBS[i] = MSIBS[j] + arr[i]
MSDBS = arr[:]
|
for i in range(1, len(arr) + 1):
|
code_infilling
|
python
|
python
|
MBPP/245/L8
|
[] |
[] |
MBPP_Infilling
|
if arr[-i] > arr[-j] and MSDBS[-i] < MSDBS[-j] + arr[-i]:
MSDBS[-i] = MSDBS[-j] + arr[-i]
max_sum = float('-Inf')
for (i, j, k) in zip(MSIBS, MSDBS, arr):
max_sum = max(max_sum, i + j - k)
return max_sum
|
[
[
"[1, 15, 51, 45, 33, 100, 12, 18, 9]",
"194"
],
[
"[80, 60, 30, 40, 20, 10]",
"210"
],
[
"[2, 3 ,14, 16, 21, 23, 29, 30]",
"138"
]
] |
max_sum
|
[] |
Write a function that takes an array and finds the maximum sum of a bitonic subsequence for the given array, where a sequence is bitonic if it is first increasing and then decreasing.
|
def max_sum(arr):
"""Write a function that takes an array and finds the maximum sum of a bitonic subsequence for the given array, where a sequence is bitonic if it is first increasing and then decreasing. """
MSIBS = arr[:]
for i in range(len(arr)):
for j in range(0, i):
if arr[i] > arr[j] and MSIBS[i] < MSIBS[j] + arr[i]:
MSIBS[i] = MSIBS[j] + arr[i]
MSDBS = arr[:]
for i in range(1, len(arr) + 1):
|
for j in range(1, i):
|
code_infilling
|
python
|
python
|
MBPP/245/L9
|
[] |
[] |
MBPP_Infilling
|
MSDBS[-i] = MSDBS[-j] + arr[-i]
max_sum = float('-Inf')
for (i, j, k) in zip(MSIBS, MSDBS, arr):
max_sum = max(max_sum, i + j - k)
return max_sum
|
[
[
"[1, 15, 51, 45, 33, 100, 12, 18, 9]",
"194"
],
[
"[80, 60, 30, 40, 20, 10]",
"210"
],
[
"[2, 3 ,14, 16, 21, 23, 29, 30]",
"138"
]
] |
max_sum
|
[] |
Write a function that takes an array and finds the maximum sum of a bitonic subsequence for the given array, where a sequence is bitonic if it is first increasing and then decreasing.
|
def max_sum(arr):
"""Write a function that takes an array and finds the maximum sum of a bitonic subsequence for the given array, where a sequence is bitonic if it is first increasing and then decreasing. """
MSIBS = arr[:]
for i in range(len(arr)):
for j in range(0, i):
if arr[i] > arr[j] and MSIBS[i] < MSIBS[j] + arr[i]:
MSIBS[i] = MSIBS[j] + arr[i]
MSDBS = arr[:]
for i in range(1, len(arr) + 1):
for j in range(1, i):
|
if arr[-i] > arr[-j] and MSDBS[-i] < MSDBS[-j] + arr[-i]:
|
code_infilling
|
python
|
python
|
MBPP/245/L10
|
[] |
[] |
MBPP_Infilling
|
max_sum = float('-Inf')
for (i, j, k) in zip(MSIBS, MSDBS, arr):
max_sum = max(max_sum, i + j - k)
return max_sum
|
[
[
"[1, 15, 51, 45, 33, 100, 12, 18, 9]",
"194"
],
[
"[80, 60, 30, 40, 20, 10]",
"210"
],
[
"[2, 3 ,14, 16, 21, 23, 29, 30]",
"138"
]
] |
max_sum
|
[] |
Write a function that takes an array and finds the maximum sum of a bitonic subsequence for the given array, where a sequence is bitonic if it is first increasing and then decreasing.
|
def max_sum(arr):
"""Write a function that takes an array and finds the maximum sum of a bitonic subsequence for the given array, where a sequence is bitonic if it is first increasing and then decreasing. """
MSIBS = arr[:]
for i in range(len(arr)):
for j in range(0, i):
if arr[i] > arr[j] and MSIBS[i] < MSIBS[j] + arr[i]:
MSIBS[i] = MSIBS[j] + arr[i]
MSDBS = arr[:]
for i in range(1, len(arr) + 1):
for j in range(1, i):
if arr[-i] > arr[-j] and MSDBS[-i] < MSDBS[-j] + arr[-i]:
|
MSDBS[-i] = MSDBS[-j] + arr[-i]
|
code_infilling
|
python
|
python
|
MBPP/245/L11
|
[] |
[] |
MBPP_Infilling
|
for (i, j, k) in zip(MSIBS, MSDBS, arr):
max_sum = max(max_sum, i + j - k)
return max_sum
|
[
[
"[1, 15, 51, 45, 33, 100, 12, 18, 9]",
"194"
],
[
"[80, 60, 30, 40, 20, 10]",
"210"
],
[
"[2, 3 ,14, 16, 21, 23, 29, 30]",
"138"
]
] |
max_sum
|
[] |
Write a function that takes an array and finds the maximum sum of a bitonic subsequence for the given array, where a sequence is bitonic if it is first increasing and then decreasing.
|
def max_sum(arr):
"""Write a function that takes an array and finds the maximum sum of a bitonic subsequence for the given array, where a sequence is bitonic if it is first increasing and then decreasing. """
MSIBS = arr[:]
for i in range(len(arr)):
for j in range(0, i):
if arr[i] > arr[j] and MSIBS[i] < MSIBS[j] + arr[i]:
MSIBS[i] = MSIBS[j] + arr[i]
MSDBS = arr[:]
for i in range(1, len(arr) + 1):
for j in range(1, i):
if arr[-i] > arr[-j] and MSDBS[-i] < MSDBS[-j] + arr[-i]:
MSDBS[-i] = MSDBS[-j] + arr[-i]
|
max_sum = float('-Inf')
|
code_infilling
|
python
|
python
|
MBPP/245/L12
|
[] |
[] |
MBPP_Infilling
|
max_sum = max(max_sum, i + j - k)
return max_sum
|
[
[
"[1, 15, 51, 45, 33, 100, 12, 18, 9]",
"194"
],
[
"[80, 60, 30, 40, 20, 10]",
"210"
],
[
"[2, 3 ,14, 16, 21, 23, 29, 30]",
"138"
]
] |
max_sum
|
[] |
Write a function that takes an array and finds the maximum sum of a bitonic subsequence for the given array, where a sequence is bitonic if it is first increasing and then decreasing.
|
def max_sum(arr):
"""Write a function that takes an array and finds the maximum sum of a bitonic subsequence for the given array, where a sequence is bitonic if it is first increasing and then decreasing. """
MSIBS = arr[:]
for i in range(len(arr)):
for j in range(0, i):
if arr[i] > arr[j] and MSIBS[i] < MSIBS[j] + arr[i]:
MSIBS[i] = MSIBS[j] + arr[i]
MSDBS = arr[:]
for i in range(1, len(arr) + 1):
for j in range(1, i):
if arr[-i] > arr[-j] and MSDBS[-i] < MSDBS[-j] + arr[-i]:
MSDBS[-i] = MSDBS[-j] + arr[-i]
max_sum = float('-Inf')
|
for (i, j, k) in zip(MSIBS, MSDBS, arr):
|
code_infilling
|
python
|
python
|
MBPP/245/L13
|
[] |
[] |
MBPP_Infilling
|
return max_sum
|
[
[
"[1, 15, 51, 45, 33, 100, 12, 18, 9]",
"194"
],
[
"[80, 60, 30, 40, 20, 10]",
"210"
],
[
"[2, 3 ,14, 16, 21, 23, 29, 30]",
"138"
]
] |
max_sum
|
[] |
Write a function that takes an array and finds the maximum sum of a bitonic subsequence for the given array, where a sequence is bitonic if it is first increasing and then decreasing.
|
def max_sum(arr):
"""Write a function that takes an array and finds the maximum sum of a bitonic subsequence for the given array, where a sequence is bitonic if it is first increasing and then decreasing. """
MSIBS = arr[:]
for i in range(len(arr)):
for j in range(0, i):
if arr[i] > arr[j] and MSIBS[i] < MSIBS[j] + arr[i]:
MSIBS[i] = MSIBS[j] + arr[i]
MSDBS = arr[:]
for i in range(1, len(arr) + 1):
for j in range(1, i):
if arr[-i] > arr[-j] and MSDBS[-i] < MSDBS[-j] + arr[-i]:
MSDBS[-i] = MSDBS[-j] + arr[-i]
max_sum = float('-Inf')
for (i, j, k) in zip(MSIBS, MSDBS, arr):
|
max_sum = max(max_sum, i + j - k)
|
code_infilling
|
python
|
python
|
MBPP/245/L14
|
[] |
[] |
MBPP_Infilling
|
[
[
"[1, 15, 51, 45, 33, 100, 12, 18, 9]",
"194"
],
[
"[80, 60, 30, 40, 20, 10]",
"210"
],
[
"[2, 3 ,14, 16, 21, 23, 29, 30]",
"138"
]
] |
max_sum
|
[] |
Write a function that takes an array and finds the maximum sum of a bitonic subsequence for the given array, where a sequence is bitonic if it is first increasing and then decreasing.
|
def max_sum(arr):
"""Write a function that takes an array and finds the maximum sum of a bitonic subsequence for the given array, where a sequence is bitonic if it is first increasing and then decreasing. """
MSIBS = arr[:]
for i in range(len(arr)):
for j in range(0, i):
if arr[i] > arr[j] and MSIBS[i] < MSIBS[j] + arr[i]:
MSIBS[i] = MSIBS[j] + arr[i]
MSDBS = arr[:]
for i in range(1, len(arr) + 1):
for j in range(1, i):
if arr[-i] > arr[-j] and MSDBS[-i] < MSDBS[-j] + arr[-i]:
MSDBS[-i] = MSDBS[-j] + arr[-i]
max_sum = float('-Inf')
for (i, j, k) in zip(MSIBS, MSDBS, arr):
max_sum = max(max_sum, i + j - k)
|
return max_sum
|
|
code_infilling
|
python
|
python
|
MBPP/246/L1
|
[] |
[] |
MBPP_Infilling
|
return 0
g = number / 2.0
g2 = g + 1
while g != g2:
n = number / g
g2 = g
g = (g + n) / 2
return g
|
[] |
babylonian_squareroot
|
[] |
Write a function for computing square roots using the babylonian method.
|
def babylonian_squareroot(number):
"""Write a function for computing square roots using the babylonian method. """
|
if number == 0:
|
code_infilling
|
python
|
python
|
MBPP/246/L2
|
[] |
[] |
MBPP_Infilling
|
g = number / 2.0
g2 = g + 1
while g != g2:
n = number / g
g2 = g
g = (g + n) / 2
return g
|
[] |
babylonian_squareroot
|
[] |
Write a function for computing square roots using the babylonian method.
|
def babylonian_squareroot(number):
"""Write a function for computing square roots using the babylonian method. """
if number == 0:
|
return 0
|
code_infilling
|
python
|
python
|
MBPP/246/L3
|
[] |
[] |
MBPP_Infilling
|
g2 = g + 1
while g != g2:
n = number / g
g2 = g
g = (g + n) / 2
return g
|
[] |
babylonian_squareroot
|
[] |
Write a function for computing square roots using the babylonian method.
|
def babylonian_squareroot(number):
"""Write a function for computing square roots using the babylonian method. """
if number == 0:
return 0
|
g = number / 2.0
|
code_infilling
|
python
|
python
|
MBPP/246/L4
|
[] |
[] |
MBPP_Infilling
|
while g != g2:
n = number / g
g2 = g
g = (g + n) / 2
return g
|
[] |
babylonian_squareroot
|
[] |
Write a function for computing square roots using the babylonian method.
|
def babylonian_squareroot(number):
"""Write a function for computing square roots using the babylonian method. """
if number == 0:
return 0
g = number / 2.0
|
g2 = g + 1
|
code_infilling
|
python
|
python
|
MBPP/246/L5
|
[] |
[] |
MBPP_Infilling
|
n = number / g
g2 = g
g = (g + n) / 2
return g
|
[] |
babylonian_squareroot
|
[] |
Write a function for computing square roots using the babylonian method.
|
def babylonian_squareroot(number):
"""Write a function for computing square roots using the babylonian method. """
if number == 0:
return 0
g = number / 2.0
g2 = g + 1
|
while g != g2:
|
code_infilling
|
python
|
python
|
MBPP/246/L6
|
[] |
[] |
MBPP_Infilling
|
g2 = g
g = (g + n) / 2
return g
|
[] |
babylonian_squareroot
|
[] |
Write a function for computing square roots using the babylonian method.
|
def babylonian_squareroot(number):
"""Write a function for computing square roots using the babylonian method. """
if number == 0:
return 0
g = number / 2.0
g2 = g + 1
while g != g2:
|
n = number / g
|
code_infilling
|
python
|
python
|
MBPP/246/L7
|
[] |
[] |
MBPP_Infilling
|
g = (g + n) / 2
return g
|
[] |
babylonian_squareroot
|
[] |
Write a function for computing square roots using the babylonian method.
|
def babylonian_squareroot(number):
"""Write a function for computing square roots using the babylonian method. """
if number == 0:
return 0
g = number / 2.0
g2 = g + 1
while g != g2:
n = number / g
|
g2 = g
|
code_infilling
|
python
|
python
|
MBPP/246/L8
|
[] |
[] |
MBPP_Infilling
|
return g
|
[] |
babylonian_squareroot
|
[] |
Write a function for computing square roots using the babylonian method.
|
def babylonian_squareroot(number):
"""Write a function for computing square roots using the babylonian method. """
if number == 0:
return 0
g = number / 2.0
g2 = g + 1
while g != g2:
n = number / g
g2 = g
|
g = (g + n) / 2
|
code_infilling
|
python
|
python
|
MBPP/246/L9
|
[] |
[] |
MBPP_Infilling
|
[] |
babylonian_squareroot
|
[] |
Write a function for computing square roots using the babylonian method.
|
def babylonian_squareroot(number):
"""Write a function for computing square roots using the babylonian method. """
if number == 0:
return 0
g = number / 2.0
g2 = g + 1
while g != g2:
n = number / g
g2 = g
g = (g + n) / 2
|
return g
|
|
code_infilling
|
python
|
python
|
MBPP/247/L1
|
[] |
[] |
MBPP_Infilling
|
L = [[0 for x in range(n)] for x in range(n)]
for i in range(n):
L[i][i] = 1
for cl in range(2, n + 1):
for i in range(n - cl + 1):
j = i + cl - 1
if str[i] == str[j] and cl == 2:
L[i][j] = 2
elif str[i] == str[j]:
L[i][j] = L[i + 1][j - 1] + 2
else:
L[i][j] = max(L[i][j - 1], L[i + 1][j])
return L[0][n - 1]
|
[
[
"\"TENS FOR TENS\"",
"5"
],
[
"\"CARDIO FOR CARDS\"",
"7"
],
[
"\"PART OF THE JOURNEY IS PART\"",
"9"
]
] |
lps
|
[] |
Write a function to find the length of the longest palindromic subsequence in the given string.
|
def lps(str):
"""Write a function to find the length of the longest palindromic subsequence in the given string. """
|
n = len(str)
|
code_infilling
|
python
|
python
|
MBPP/247/L2
|
[] |
[] |
MBPP_Infilling
|
for i in range(n):
L[i][i] = 1
for cl in range(2, n + 1):
for i in range(n - cl + 1):
j = i + cl - 1
if str[i] == str[j] and cl == 2:
L[i][j] = 2
elif str[i] == str[j]:
L[i][j] = L[i + 1][j - 1] + 2
else:
L[i][j] = max(L[i][j - 1], L[i + 1][j])
return L[0][n - 1]
|
[
[
"\"TENS FOR TENS\"",
"5"
],
[
"\"CARDIO FOR CARDS\"",
"7"
],
[
"\"PART OF THE JOURNEY IS PART\"",
"9"
]
] |
lps
|
[] |
Write a function to find the length of the longest palindromic subsequence in the given string.
|
def lps(str):
"""Write a function to find the length of the longest palindromic subsequence in the given string. """
n = len(str)
|
L = [[0 for x in range(n)] for x in range(n)]
|
code_infilling
|
python
|
python
|
MBPP/247/L3
|
[] |
[] |
MBPP_Infilling
|
L[i][i] = 1
for cl in range(2, n + 1):
for i in range(n - cl + 1):
j = i + cl - 1
if str[i] == str[j] and cl == 2:
L[i][j] = 2
elif str[i] == str[j]:
L[i][j] = L[i + 1][j - 1] + 2
else:
L[i][j] = max(L[i][j - 1], L[i + 1][j])
return L[0][n - 1]
|
[
[
"\"TENS FOR TENS\"",
"5"
],
[
"\"CARDIO FOR CARDS\"",
"7"
],
[
"\"PART OF THE JOURNEY IS PART\"",
"9"
]
] |
lps
|
[] |
Write a function to find the length of the longest palindromic subsequence in the given string.
|
def lps(str):
"""Write a function to find the length of the longest palindromic subsequence in the given string. """
n = len(str)
L = [[0 for x in range(n)] for x in range(n)]
|
for i in range(n):
|
code_infilling
|
python
|
python
|
MBPP/247/L4
|
[] |
[] |
MBPP_Infilling
|
for cl in range(2, n + 1):
for i in range(n - cl + 1):
j = i + cl - 1
if str[i] == str[j] and cl == 2:
L[i][j] = 2
elif str[i] == str[j]:
L[i][j] = L[i + 1][j - 1] + 2
else:
L[i][j] = max(L[i][j - 1], L[i + 1][j])
return L[0][n - 1]
|
[
[
"\"TENS FOR TENS\"",
"5"
],
[
"\"CARDIO FOR CARDS\"",
"7"
],
[
"\"PART OF THE JOURNEY IS PART\"",
"9"
]
] |
lps
|
[] |
Write a function to find the length of the longest palindromic subsequence in the given string.
|
def lps(str):
"""Write a function to find the length of the longest palindromic subsequence in the given string. """
n = len(str)
L = [[0 for x in range(n)] for x in range(n)]
for i in range(n):
|
L[i][i] = 1
|
code_infilling
|
python
|
python
|
MBPP/247/L5
|
[] |
[] |
MBPP_Infilling
|
for i in range(n - cl + 1):
j = i + cl - 1
if str[i] == str[j] and cl == 2:
L[i][j] = 2
elif str[i] == str[j]:
L[i][j] = L[i + 1][j - 1] + 2
else:
L[i][j] = max(L[i][j - 1], L[i + 1][j])
return L[0][n - 1]
|
[
[
"\"TENS FOR TENS\"",
"5"
],
[
"\"CARDIO FOR CARDS\"",
"7"
],
[
"\"PART OF THE JOURNEY IS PART\"",
"9"
]
] |
lps
|
[] |
Write a function to find the length of the longest palindromic subsequence in the given string.
|
def lps(str):
"""Write a function to find the length of the longest palindromic subsequence in the given string. """
n = len(str)
L = [[0 for x in range(n)] for x in range(n)]
for i in range(n):
L[i][i] = 1
|
for cl in range(2, n + 1):
|
code_infilling
|
python
|
python
|
MBPP/247/L6
|
[] |
[] |
MBPP_Infilling
|
j = i + cl - 1
if str[i] == str[j] and cl == 2:
L[i][j] = 2
elif str[i] == str[j]:
L[i][j] = L[i + 1][j - 1] + 2
else:
L[i][j] = max(L[i][j - 1], L[i + 1][j])
return L[0][n - 1]
|
[
[
"\"TENS FOR TENS\"",
"5"
],
[
"\"CARDIO FOR CARDS\"",
"7"
],
[
"\"PART OF THE JOURNEY IS PART\"",
"9"
]
] |
lps
|
[] |
Write a function to find the length of the longest palindromic subsequence in the given string.
|
def lps(str):
"""Write a function to find the length of the longest palindromic subsequence in the given string. """
n = len(str)
L = [[0 for x in range(n)] for x in range(n)]
for i in range(n):
L[i][i] = 1
for cl in range(2, n + 1):
|
for i in range(n - cl + 1):
|
code_infilling
|
python
|
python
|
MBPP/247/L7
|
[] |
[] |
MBPP_Infilling
|
if str[i] == str[j] and cl == 2:
L[i][j] = 2
elif str[i] == str[j]:
L[i][j] = L[i + 1][j - 1] + 2
else:
L[i][j] = max(L[i][j - 1], L[i + 1][j])
return L[0][n - 1]
|
[
[
"\"TENS FOR TENS\"",
"5"
],
[
"\"CARDIO FOR CARDS\"",
"7"
],
[
"\"PART OF THE JOURNEY IS PART\"",
"9"
]
] |
lps
|
[] |
Write a function to find the length of the longest palindromic subsequence in the given string.
|
def lps(str):
"""Write a function to find the length of the longest palindromic subsequence in the given string. """
n = len(str)
L = [[0 for x in range(n)] for x in range(n)]
for i in range(n):
L[i][i] = 1
for cl in range(2, n + 1):
for i in range(n - cl + 1):
|
j = i + cl - 1
|
code_infilling
|
python
|
python
|
MBPP/247/L8
|
[] |
[] |
MBPP_Infilling
|
L[i][j] = 2
elif str[i] == str[j]:
L[i][j] = L[i + 1][j - 1] + 2
else:
L[i][j] = max(L[i][j - 1], L[i + 1][j])
return L[0][n - 1]
|
[
[
"\"TENS FOR TENS\"",
"5"
],
[
"\"CARDIO FOR CARDS\"",
"7"
],
[
"\"PART OF THE JOURNEY IS PART\"",
"9"
]
] |
lps
|
[] |
Write a function to find the length of the longest palindromic subsequence in the given string.
|
def lps(str):
"""Write a function to find the length of the longest palindromic subsequence in the given string. """
n = len(str)
L = [[0 for x in range(n)] for x in range(n)]
for i in range(n):
L[i][i] = 1
for cl in range(2, n + 1):
for i in range(n - cl + 1):
j = i + cl - 1
|
if str[i] == str[j] and cl == 2:
|
code_infilling
|
python
|
python
|
MBPP/247/L9
|
[] |
[] |
MBPP_Infilling
|
elif str[i] == str[j]:
L[i][j] = L[i + 1][j - 1] + 2
else:
L[i][j] = max(L[i][j - 1], L[i + 1][j])
return L[0][n - 1]
|
[
[
"\"TENS FOR TENS\"",
"5"
],
[
"\"CARDIO FOR CARDS\"",
"7"
],
[
"\"PART OF THE JOURNEY IS PART\"",
"9"
]
] |
lps
|
[] |
Write a function to find the length of the longest palindromic subsequence in the given string.
|
def lps(str):
"""Write a function to find the length of the longest palindromic subsequence in the given string. """
n = len(str)
L = [[0 for x in range(n)] for x in range(n)]
for i in range(n):
L[i][i] = 1
for cl in range(2, n + 1):
for i in range(n - cl + 1):
j = i + cl - 1
if str[i] == str[j] and cl == 2:
|
L[i][j] = 2
|
code_infilling
|
python
|
python
|
MBPP/247/L10
|
[] |
[] |
MBPP_Infilling
|
L[i][j] = L[i + 1][j - 1] + 2
else:
L[i][j] = max(L[i][j - 1], L[i + 1][j])
return L[0][n - 1]
|
[
[
"\"TENS FOR TENS\"",
"5"
],
[
"\"CARDIO FOR CARDS\"",
"7"
],
[
"\"PART OF THE JOURNEY IS PART\"",
"9"
]
] |
lps
|
[] |
Write a function to find the length of the longest palindromic subsequence in the given string.
|
def lps(str):
"""Write a function to find the length of the longest palindromic subsequence in the given string. """
n = len(str)
L = [[0 for x in range(n)] for x in range(n)]
for i in range(n):
L[i][i] = 1
for cl in range(2, n + 1):
for i in range(n - cl + 1):
j = i + cl - 1
if str[i] == str[j] and cl == 2:
L[i][j] = 2
|
elif str[i] == str[j]:
|
code_infilling
|
python
|
python
|
MBPP/247/L11
|
[] |
[] |
MBPP_Infilling
|
else:
L[i][j] = max(L[i][j - 1], L[i + 1][j])
return L[0][n - 1]
|
[
[
"\"TENS FOR TENS\"",
"5"
],
[
"\"CARDIO FOR CARDS\"",
"7"
],
[
"\"PART OF THE JOURNEY IS PART\"",
"9"
]
] |
lps
|
[] |
Write a function to find the length of the longest palindromic subsequence in the given string.
|
def lps(str):
"""Write a function to find the length of the longest palindromic subsequence in the given string. """
n = len(str)
L = [[0 for x in range(n)] for x in range(n)]
for i in range(n):
L[i][i] = 1
for cl in range(2, n + 1):
for i in range(n - cl + 1):
j = i + cl - 1
if str[i] == str[j] and cl == 2:
L[i][j] = 2
elif str[i] == str[j]:
|
L[i][j] = L[i + 1][j - 1] + 2
|
code_infilling
|
python
|
python
|
MBPP/247/L12
|
[] |
[] |
MBPP_Infilling
|
L[i][j] = max(L[i][j - 1], L[i + 1][j])
return L[0][n - 1]
|
[
[
"\"TENS FOR TENS\"",
"5"
],
[
"\"CARDIO FOR CARDS\"",
"7"
],
[
"\"PART OF THE JOURNEY IS PART\"",
"9"
]
] |
lps
|
[] |
Write a function to find the length of the longest palindromic subsequence in the given string.
|
def lps(str):
"""Write a function to find the length of the longest palindromic subsequence in the given string. """
n = len(str)
L = [[0 for x in range(n)] for x in range(n)]
for i in range(n):
L[i][i] = 1
for cl in range(2, n + 1):
for i in range(n - cl + 1):
j = i + cl - 1
if str[i] == str[j] and cl == 2:
L[i][j] = 2
elif str[i] == str[j]:
L[i][j] = L[i + 1][j - 1] + 2
|
else:
|
code_infilling
|
python
|
python
|
MBPP/247/L13
|
[] |
[] |
MBPP_Infilling
|
return L[0][n - 1]
|
[
[
"\"TENS FOR TENS\"",
"5"
],
[
"\"CARDIO FOR CARDS\"",
"7"
],
[
"\"PART OF THE JOURNEY IS PART\"",
"9"
]
] |
lps
|
[] |
Write a function to find the length of the longest palindromic subsequence in the given string.
|
def lps(str):
"""Write a function to find the length of the longest palindromic subsequence in the given string. """
n = len(str)
L = [[0 for x in range(n)] for x in range(n)]
for i in range(n):
L[i][i] = 1
for cl in range(2, n + 1):
for i in range(n - cl + 1):
j = i + cl - 1
if str[i] == str[j] and cl == 2:
L[i][j] = 2
elif str[i] == str[j]:
L[i][j] = L[i + 1][j - 1] + 2
else:
|
L[i][j] = max(L[i][j - 1], L[i + 1][j])
|
code_infilling
|
python
|
python
|
MBPP/247/L14
|
[] |
[] |
MBPP_Infilling
|
[
[
"\"TENS FOR TENS\"",
"5"
],
[
"\"CARDIO FOR CARDS\"",
"7"
],
[
"\"PART OF THE JOURNEY IS PART\"",
"9"
]
] |
lps
|
[] |
Write a function to find the length of the longest palindromic subsequence in the given string.
|
def lps(str):
"""Write a function to find the length of the longest palindromic subsequence in the given string. """
n = len(str)
L = [[0 for x in range(n)] for x in range(n)]
for i in range(n):
L[i][i] = 1
for cl in range(2, n + 1):
for i in range(n - cl + 1):
j = i + cl - 1
if str[i] == str[j] and cl == 2:
L[i][j] = 2
elif str[i] == str[j]:
L[i][j] = L[i + 1][j - 1] + 2
else:
L[i][j] = max(L[i][j - 1], L[i + 1][j])
|
return L[0][n - 1]
|
|
code_infilling
|
python
|
python
|
MBPP/248/L1
|
[] |
[] |
MBPP_Infilling
|
return 1
else:
return 1 / n + harmonic_sum(n - 1)
|
[] |
harmonic_sum
|
[] |
Write a function that takes in an integer n and calculates the harmonic sum of n-1.
|
def harmonic_sum(n):
"""Write a function that takes in an integer n and calculates the harmonic sum of n-1. """
|
if n < 2:
|
code_infilling
|
python
|
python
|
MBPP/248/L2
|
[] |
[] |
MBPP_Infilling
|
else:
return 1 / n + harmonic_sum(n - 1)
|
[] |
harmonic_sum
|
[] |
Write a function that takes in an integer n and calculates the harmonic sum of n-1.
|
def harmonic_sum(n):
"""Write a function that takes in an integer n and calculates the harmonic sum of n-1. """
if n < 2:
|
return 1
|
code_infilling
|
python
|
python
|
MBPP/248/L3
|
[] |
[] |
MBPP_Infilling
|
return 1 / n + harmonic_sum(n - 1)
|
[] |
harmonic_sum
|
[] |
Write a function that takes in an integer n and calculates the harmonic sum of n-1.
|
def harmonic_sum(n):
"""Write a function that takes in an integer n and calculates the harmonic sum of n-1. """
if n < 2:
return 1
|
else:
|
code_infilling
|
python
|
python
|
MBPP/248/L4
|
[] |
[] |
MBPP_Infilling
|
[] |
harmonic_sum
|
[] |
Write a function that takes in an integer n and calculates the harmonic sum of n-1.
|
def harmonic_sum(n):
"""Write a function that takes in an integer n and calculates the harmonic sum of n-1. """
if n < 2:
return 1
else:
|
return 1 / n + harmonic_sum(n - 1)
|
|
code_infilling
|
python
|
python
|
MBPP/249/L1
|
[] |
[] |
MBPP_Infilling
|
return result
|
[
[
"[1, 2, 3, 5, 7, 8, 9, 10],[1, 2, 4, 8, 9]",
"[1, 2, 8, 9]"
],
[
"[1, 2, 3, 5, 7, 8, 9, 10],[3,5,7,9]",
"[3,5,7,9]"
],
[
"[1, 2, 3, 5, 7, 8, 9, 10],[10,20,30,40]",
"[10]"
]
] |
intersection_array
|
[] |
Write a function to find the intersection of two arrays.
|
def intersection_array(array_nums1, array_nums2):
"""Write a function to find the intersection of two arrays. """
|
result = list(filter(lambda x: x in array_nums1, array_nums2))
|
code_infilling
|
python
|
python
|
MBPP/249/L2
|
[] |
[] |
MBPP_Infilling
|
[
[
"[1, 2, 3, 5, 7, 8, 9, 10],[1, 2, 4, 8, 9]",
"[1, 2, 8, 9]"
],
[
"[1, 2, 3, 5, 7, 8, 9, 10],[3,5,7,9]",
"[3,5,7,9]"
],
[
"[1, 2, 3, 5, 7, 8, 9, 10],[10,20,30,40]",
"[10]"
]
] |
intersection_array
|
[] |
Write a function to find the intersection of two arrays.
|
def intersection_array(array_nums1, array_nums2):
"""Write a function to find the intersection of two arrays. """
result = list(filter(lambda x: x in array_nums1, array_nums2))
|
return result
|
|
code_infilling
|
python
|
python
|
MBPP/250/L1
|
[] |
[] |
MBPP_Infilling
|
for ele in tup:
if ele == x:
count = count + 1
return count
|
[
[
"(10, 8, 5, 2, 10, 15, 10, 8, 5, 8, 8, 2),4",
"0"
],
[
"(10, 8, 5, 2, 10, 15, 10, 8, 5, 8, 8, 2),10",
"3"
],
[
"(10, 8, 5, 2, 10, 15, 10, 8, 5, 8, 8, 2),8",
"4"
]
] |
count_X
|
[] |
Write a python function that takes in a tuple and an element and counts the occcurences of the element in the tuple.
|
def count_X(tup, x):
"""Write a python function that takes in a tuple and an element and counts the occcurences of the element in the tuple. """
|
count = 0
|
code_infilling
|
python
|
python
|
MBPP/250/L2
|
[] |
[] |
MBPP_Infilling
|
if ele == x:
count = count + 1
return count
|
[
[
"(10, 8, 5, 2, 10, 15, 10, 8, 5, 8, 8, 2),4",
"0"
],
[
"(10, 8, 5, 2, 10, 15, 10, 8, 5, 8, 8, 2),10",
"3"
],
[
"(10, 8, 5, 2, 10, 15, 10, 8, 5, 8, 8, 2),8",
"4"
]
] |
count_X
|
[] |
Write a python function that takes in a tuple and an element and counts the occcurences of the element in the tuple.
|
def count_X(tup, x):
"""Write a python function that takes in a tuple and an element and counts the occcurences of the element in the tuple. """
count = 0
|
for ele in tup:
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.