question_title
stringlengths 7
8
| question_content
stringlengths 37
191
| question_id
stringlengths 2
3
| contest_id
stringclasses 1
value | test_id
int64 0
5
| contest_date
timestamp[us] | starter_code
stringlengths 37
1.33k
| function_name
stringlengths 3
32
| difficulty
stringclasses 1
value | test
stringlengths 57
1.94k
|
---|---|---|---|---|---|---|---|---|---|
Mbpp_144 | Write a python function to find the sum of absolute differences in all pairs of the given array. | 144 | mbpp | 1 | 2024-11-26T21:40:54.184965 | def sum_Pairs(arr,n):
sum = 0
for i in range(n - 1,-1,-1):
sum += i*arr[i] - (n-1-i) * arr[i]
return sum | sum_Pairs | easy | [{"input": "[1,2,3,4],4", "output": "10", "testtype": "functional"}] |
Mbpp_144 | Write a python function to find the sum of absolute differences in all pairs of the given array. | 144 | mbpp | 2 | 2024-11-26T21:40:54.185359 | def sum_Pairs(arr,n):
sum = 0
for i in range(n - 1,-1,-1):
sum += i*arr[i] - (n-1-i) * arr[i]
return sum | sum_Pairs | easy | [{"input": "[1,2,3,4,5,7,9,11,14],9", "output": "188", "testtype": "functional"}] |
Mbpp_145 | Write a python function to find the maximum difference between any two elements in a given array. | 145 | mbpp | 0 | 2024-11-26T21:40:54.185737 | def max_Abs_Diff(arr,n):
minEle = arr[0]
maxEle = arr[0]
for i in range(1, n):
minEle = min(minEle,arr[i])
maxEle = max(maxEle,arr[i])
return (maxEle - minEle) | max_Abs_Diff | easy | [{"input": "(2,1,5,3),4", "output": "4", "testtype": "functional"}] |
Mbpp_145 | Write a python function to find the maximum difference between any two elements in a given array. | 145 | mbpp | 1 | 2024-11-26T21:40:54.186032 | def max_Abs_Diff(arr,n):
minEle = arr[0]
maxEle = arr[0]
for i in range(1, n):
minEle = min(minEle,arr[i])
maxEle = max(maxEle,arr[i])
return (maxEle - minEle) | max_Abs_Diff | easy | [{"input": "(9,3,2,5,1),5", "output": "8", "testtype": "functional"}] |
Mbpp_145 | Write a python function to find the maximum difference between any two elements in a given array. | 145 | mbpp | 2 | 2024-11-26T21:40:54.186304 | def max_Abs_Diff(arr,n):
minEle = arr[0]
maxEle = arr[0]
for i in range(1, n):
minEle = min(minEle,arr[i])
maxEle = max(maxEle,arr[i])
return (maxEle - minEle) | max_Abs_Diff | easy | [{"input": "(3,2,1),3", "output": "2", "testtype": "functional"}] |
Mbpp_146 | Write a function to find the ascii value of total characters in a string. | 146 | mbpp | 0 | 2024-11-26T21:40:54.186465 | def ascii_value_string(str1):
for i in range(len(str1)):
return ord(str1[i]) | ascii_value_string | easy | [{"input": "\"python\"", "output": "112", "testtype": "functional"}] |
Mbpp_146 | Write a function to find the ascii value of total characters in a string. | 146 | mbpp | 1 | 2024-11-26T21:40:54.186600 | def ascii_value_string(str1):
for i in range(len(str1)):
return ord(str1[i]) | ascii_value_string | easy | [{"input": "\"Program\"", "output": "80", "testtype": "functional"}] |
Mbpp_146 | Write a function to find the ascii value of total characters in a string. | 146 | mbpp | 2 | 2024-11-26T21:40:54.186758 | def ascii_value_string(str1):
for i in range(len(str1)):
return ord(str1[i]) | ascii_value_string | easy | [{"input": "\"Language\"", "output": "76", "testtype": "functional"}] |
Mbpp_147 | Write a function to find the maximum total path sum in the given triangle. | 147 | mbpp | 0 | 2024-11-26T21:40:54.187228 | def max_path_sum(tri, m, n):
for i in range(m-1, -1, -1):
for j in range(i+1):
if (tri[i+1][j] > tri[i+1][j+1]):
tri[i][j] += tri[i+1][j]
else:
tri[i][j] += tri[i+1][j+1]
return tri[0][0] | max_path_sum | easy | [{"input": "[[1, 0, 0], [4, 8, 0], [1, 5, 3]], 2, 2", "output": "14", "testtype": "functional"}] |
Mbpp_147 | Write a function to find the maximum total path sum in the given triangle. | 147 | mbpp | 1 | 2024-11-26T21:40:54.187697 | def max_path_sum(tri, m, n):
for i in range(m-1, -1, -1):
for j in range(i+1):
if (tri[i+1][j] > tri[i+1][j+1]):
tri[i][j] += tri[i+1][j]
else:
tri[i][j] += tri[i+1][j+1]
return tri[0][0] | max_path_sum | easy | [{"input": "[[13, 0, 0], [7, 4, 0], [2, 4, 6]], 2, 2", "output": "24", "testtype": "functional"}] |
Mbpp_147 | Write a function to find the maximum total path sum in the given triangle. | 147 | mbpp | 2 | 2024-11-26T21:40:54.188150 | def max_path_sum(tri, m, n):
for i in range(m-1, -1, -1):
for j in range(i+1):
if (tri[i+1][j] > tri[i+1][j+1]):
tri[i][j] += tri[i+1][j]
else:
tri[i][j] += tri[i+1][j+1]
return tri[0][0] | max_path_sum | easy | [{"input": "[[2, 0, 0], [11, 18, 0], [21, 25, 33]], 2, 2", "output": "53", "testtype": "functional"}] |
Mbpp_149 | Write a function to find the longest subsequence such that the difference between adjacents is one for the given array. | 149 | mbpp | 0 | 2024-11-26T21:40:54.189168 | def longest_subseq_with_diff_one(arr, n):
dp = [1 for i in range(n)]
for i in range(n):
for j in range(i):
if ((arr[i] == arr[j]+1) or (arr[i] == arr[j]-1)):
dp[i] = max(dp[i], dp[j]+1)
result = 1
for i in range(n):
if (result < dp[i]):
result = dp[i]
return result | longest_subseq_with_diff_one | easy | [{"input": "[1, 2, 3, 4, 5, 3, 2], 7", "output": "6", "testtype": "functional"}] |
Mbpp_149 | Write a function to find the longest subsequence such that the difference between adjacents is one for the given array. | 149 | mbpp | 1 | 2024-11-26T21:40:54.189710 | def longest_subseq_with_diff_one(arr, n):
dp = [1 for i in range(n)]
for i in range(n):
for j in range(i):
if ((arr[i] == arr[j]+1) or (arr[i] == arr[j]-1)):
dp[i] = max(dp[i], dp[j]+1)
result = 1
for i in range(n):
if (result < dp[i]):
result = dp[i]
return result | longest_subseq_with_diff_one | easy | [{"input": "[10, 9, 4, 5, 4, 8, 6], 7", "output": "3", "testtype": "functional"}] |
Mbpp_149 | Write a function to find the longest subsequence such that the difference between adjacents is one for the given array. | 149 | mbpp | 2 | 2024-11-26T21:40:54.190227 | def longest_subseq_with_diff_one(arr, n):
dp = [1 for i in range(n)]
for i in range(n):
for j in range(i):
if ((arr[i] == arr[j]+1) or (arr[i] == arr[j]-1)):
dp[i] = max(dp[i], dp[j]+1)
result = 1
for i in range(n):
if (result < dp[i]):
result = dp[i]
return result | longest_subseq_with_diff_one | easy | [{"input": "[1, 2, 3, 2, 3, 7, 2, 1], 8", "output": "7", "testtype": "functional"}] |
Mbpp_150 | Write a python function to find whether the given number is present in the infinite sequence or not. | 150 | mbpp | 0 | 2024-11-26T21:40:54.190459 | def does_Contain_B(a,b,c):
if (a == b):
return True
if ((b - a) * c > 0 and (b - a) % c == 0):
return True
return False | does_Contain_B | easy | [{"input": "1,7,3", "output": "True", "testtype": "functional"}] |
Mbpp_150 | Write a python function to find whether the given number is present in the infinite sequence or not. | 150 | mbpp | 1 | 2024-11-26T21:40:54.190697 | def does_Contain_B(a,b,c):
if (a == b):
return True
if ((b - a) * c > 0 and (b - a) % c == 0):
return True
return False | does_Contain_B | easy | [{"input": "1,-3,5", "output": "False", "testtype": "functional"}] |
Mbpp_150 | Write a python function to find whether the given number is present in the infinite sequence or not. | 150 | mbpp | 2 | 2024-11-26T21:40:54.190908 | def does_Contain_B(a,b,c):
if (a == b):
return True
if ((b - a) * c > 0 and (b - a) % c == 0):
return True
return False | does_Contain_B | easy | [{"input": "3,2,5", "output": "False", "testtype": "functional"}] |
Mbpp_153 | Write a function to find the vertex of a parabola. | 153 | mbpp | 0 | 2024-11-26T21:40:54.192332 | def parabola_vertex(a, b, c):
vertex=(((-b / (2 * a)),(((4 * a * c) - (b * b)) / (4 * a))))
return vertex | parabola_vertex | easy | [{"input": "5,3,2", "output": "(-0.3, 1.55)", "testtype": "functional"}] |
Mbpp_153 | Write a function to find the vertex of a parabola. | 153 | mbpp | 1 | 2024-11-26T21:40:54.192819 | def parabola_vertex(a, b, c):
vertex=(((-b / (2 * a)),(((4 * a * c) - (b * b)) / (4 * a))))
return vertex | parabola_vertex | easy | [{"input": "9,8,4", "output": "(-0.4444444444444444, 2.2222222222222223)", "testtype": "functional"}] |
Mbpp_153 | Write a function to find the vertex of a parabola. | 153 | mbpp | 2 | 2024-11-26T21:40:54.193055 | def parabola_vertex(a, b, c):
vertex=(((-b / (2 * a)),(((4 * a * c) - (b * b)) / (4 * a))))
return vertex | parabola_vertex | easy | [{"input": "2,4,6", "output": "(-1.0, 4.0)", "testtype": "functional"}] |
Mbpp_154 | Write a function to extract every specified element from a given two dimensional list. | 154 | mbpp | 0 | 2024-11-26T21:40:54.193213 | def specified_element(nums, N):
result = [i[N] for i in nums]
return result | specified_element | easy | [{"input": "[[1, 2, 3, 2], [4, 5, 6, 2], [7, 1, 9, 5]],0", "output": "[1, 4, 7]", "testtype": "functional"}] |
Mbpp_154 | Write a function to extract every specified element from a given two dimensional list. | 154 | mbpp | 1 | 2024-11-26T21:40:54.193397 | def specified_element(nums, N):
result = [i[N] for i in nums]
return result | specified_element | easy | [{"input": "[[1, 2, 3, 2], [4, 5, 6, 2], [7, 1, 9, 5]],2", "output": "[3, 6, 9]", "testtype": "functional"}] |
Mbpp_154 | Write a function to extract every specified element from a given two dimensional list. | 154 | mbpp | 2 | 2024-11-26T21:40:54.193558 | def specified_element(nums, N):
result = [i[N] for i in nums]
return result | specified_element | easy | [{"input": "[[1, 2, 3, 2], [4, 5, 6, 2], [7, 1, 9, 5]],3", "output": "[2,2,5]", "testtype": "functional"}] |
Mbpp_155 | Write a python function to toggle all even bits of a given number. | 155 | mbpp | 0 | 2024-11-26T21:40:54.193913 | def even_bit_toggle_number(n) :
res = 0; count = 0; temp = n
while (temp > 0) :
if (count % 2 == 1) :
res = res | (1 << count)
count = count + 1
temp >>= 1
return n ^ res | even_bit_toggle_number | easy | [{"input": "10", "output": "0", "testtype": "functional"}] |
Mbpp_155 | Write a python function to toggle all even bits of a given number. | 155 | mbpp | 1 | 2024-11-26T21:40:54.194217 | def even_bit_toggle_number(n) :
res = 0; count = 0; temp = n
while (temp > 0) :
if (count % 2 == 1) :
res = res | (1 << count)
count = count + 1
temp >>= 1
return n ^ res | even_bit_toggle_number | easy | [{"input": "20", "output": "30", "testtype": "functional"}] |
Mbpp_155 | Write a python function to toggle all even bits of a given number. | 155 | mbpp | 2 | 2024-11-26T21:40:54.194511 | def even_bit_toggle_number(n) :
res = 0; count = 0; temp = n
while (temp > 0) :
if (count % 2 == 1) :
res = res | (1 << count)
count = count + 1
temp >>= 1
return n ^ res | even_bit_toggle_number | easy | [{"input": "30", "output": "20", "testtype": "functional"}] |
Mbpp_156 | Write a function to convert a tuple of string values to a tuple of integer values. | 156 | mbpp | 0 | 2024-11-26T21:40:54.194732 | def tuple_int_str(tuple_str):
result = tuple((int(x[0]), int(x[1])) for x in tuple_str)
return result | tuple_int_str | easy | [{"input": "(('333', '33'), ('1416', '55'))", "output": "((333, 33), (1416, 55))", "testtype": "functional"}] |
Mbpp_156 | Write a function to convert a tuple of string values to a tuple of integer values. | 156 | mbpp | 1 | 2024-11-26T21:40:54.194921 | def tuple_int_str(tuple_str):
result = tuple((int(x[0]), int(x[1])) for x in tuple_str)
return result | tuple_int_str | easy | [{"input": "(('999', '99'), ('1000', '500'))", "output": "((999, 99), (1000, 500))", "testtype": "functional"}] |
Mbpp_156 | Write a function to convert a tuple of string values to a tuple of integer values. | 156 | mbpp | 2 | 2024-11-26T21:40:54.195101 | def tuple_int_str(tuple_str):
result = tuple((int(x[0]), int(x[1])) for x in tuple_str)
return result | tuple_int_str | easy | [{"input": "(('666', '66'), ('1500', '555'))", "output": "((666, 66), (1500, 555))", "testtype": "functional"}] |
Mbpp_157 | Write a function to reflect the run-length encoding from a list. | 157 | mbpp | 0 | 2024-11-26T21:40:54.195291 | from itertools import groupby
def encode_list(list1):
return [[len(list(group)), key] for key, group in groupby(list1)] | encode_list | easy | [{"input": "[1,1,2,3,4,4.3,5,1]", "output": "[[2, 1], [1, 2], [1, 3], [1, 4], [1, 4.3], [1, 5], [1, 1]]", "testtype": "functional"}] |
Mbpp_157 | Write a function to reflect the run-length encoding from a list. | 157 | mbpp | 1 | 2024-11-26T21:40:54.195468 | from itertools import groupby
def encode_list(list1):
return [[len(list(group)), key] for key, group in groupby(list1)] | encode_list | easy | [{"input": "'automatically'", "output": "[[1, 'a'], [1, 'u'], [1, 't'], [1, 'o'], [1, 'm'], [1, 'a'], [1, 't'], [1, 'i'], [1, 'c'], [1, 'a'], [2, 'l'], [1, 'y']]", "testtype": "functional"}] |
Mbpp_157 | Write a function to reflect the run-length encoding from a list. | 157 | mbpp | 2 | 2024-11-26T21:40:54.195630 | from itertools import groupby
def encode_list(list1):
return [[len(list(group)), key] for key, group in groupby(list1)] | encode_list | easy | [{"input": "'python'", "output": "[[1, 'p'], [1, 'y'], [1, 't'], [1, 'h'], [1, 'o'], [1, 'n']]", "testtype": "functional"}] |
Mbpp_158 | Write a python function to find k number of operations required to make all elements equal. | 158 | mbpp | 0 | 2024-11-26T21:40:54.195985 | def min_Ops(arr,n,k):
max1 = max(arr)
res = 0
for i in range(0,n):
if ((max1 - arr[i]) % k != 0):
return -1
else:
res += (max1 - arr[i]) / k
return int(res) | min_Ops | easy | [{"input": "[2,2,2,2],4,3", "output": "0", "testtype": "functional"}] |
Mbpp_158 | Write a python function to find k number of operations required to make all elements equal. | 158 | mbpp | 1 | 2024-11-26T21:40:54.196295 | def min_Ops(arr,n,k):
max1 = max(arr)
res = 0
for i in range(0,n):
if ((max1 - arr[i]) % k != 0):
return -1
else:
res += (max1 - arr[i]) / k
return int(res) | min_Ops | easy | [{"input": "[4,2,6,8],4,3", "output": "-1", "testtype": "functional"}] |
Mbpp_158 | Write a python function to find k number of operations required to make all elements equal. | 158 | mbpp | 2 | 2024-11-26T21:40:54.196598 | def min_Ops(arr,n,k):
max1 = max(arr)
res = 0
for i in range(0,n):
if ((max1 - arr[i]) % k != 0):
return -1
else:
res += (max1 - arr[i]) / k
return int(res) | min_Ops | easy | [{"input": "[21,33,9,45,63],5,6", "output": "24", "testtype": "functional"}] |
Mbpp_159 | Write a function to print the season for the given month and day. | 159 | mbpp | 0 | 2024-11-26T21:40:54.197268 | def month_season(month,days):
if month in ('January', 'February', 'March'):
season = 'winter'
elif month in ('April', 'May', 'June'):
season = 'spring'
elif month in ('July', 'August', 'September'):
season = 'summer'
else:
season = 'autumn'
if (month == 'March') and (days > 19):
season = 'spring'
elif (month == 'June') and (days > 20):
season = 'summer'
elif (month == 'September') and (days > 21):
season = 'autumn'
elif (month == 'October') and (days > 21):
season = 'autumn'
elif (month == 'November') and (days > 21):
season = 'autumn'
elif (month == 'December') and (days > 20):
season = 'winter'
return season | month_season | easy | [{"input": "'January',4", "output": "('winter')", "testtype": "functional"}] |
Mbpp_159 | Write a function to print the season for the given month and day. | 159 | mbpp | 1 | 2024-11-26T21:40:54.197927 | def month_season(month,days):
if month in ('January', 'February', 'March'):
season = 'winter'
elif month in ('April', 'May', 'June'):
season = 'spring'
elif month in ('July', 'August', 'September'):
season = 'summer'
else:
season = 'autumn'
if (month == 'March') and (days > 19):
season = 'spring'
elif (month == 'June') and (days > 20):
season = 'summer'
elif (month == 'September') and (days > 21):
season = 'autumn'
elif (month == 'October') and (days > 21):
season = 'autumn'
elif (month == 'November') and (days > 21):
season = 'autumn'
elif (month == 'December') and (days > 20):
season = 'winter'
return season | month_season | easy | [{"input": "'October',28", "output": "('autumn')", "testtype": "functional"}] |
Mbpp_159 | Write a function to print the season for the given month and day. | 159 | mbpp | 2 | 2024-11-26T21:40:54.198571 | def month_season(month,days):
if month in ('January', 'February', 'March'):
season = 'winter'
elif month in ('April', 'May', 'June'):
season = 'spring'
elif month in ('July', 'August', 'September'):
season = 'summer'
else:
season = 'autumn'
if (month == 'March') and (days > 19):
season = 'spring'
elif (month == 'June') and (days > 20):
season = 'summer'
elif (month == 'September') and (days > 21):
season = 'autumn'
elif (month == 'October') and (days > 21):
season = 'autumn'
elif (month == 'November') and (days > 21):
season = 'autumn'
elif (month == 'December') and (days > 20):
season = 'winter'
return season | month_season | easy | [{"input": "'June',6", "output": "('spring')", "testtype": "functional"}] |
Mbpp_160 | Write a function to find x and y that satisfies ax + by = n. | 160 | mbpp | 0 | 2024-11-26T21:40:54.198928 | def solution (a, b, n):
i = 0
while i * a <= n:
if (n - (i * a)) % b == 0:
return ("x = ",i ,", y = ",
int((n - (i * a)) / b))
return 0
i = i + 1
return ("No solution") | solution | easy | [{"input": "2, 3, 7", "output": "('x = ', 2, ', y = ', 1)", "testtype": "functional"}] |
Mbpp_160 | Write a function to find x and y that satisfies ax + by = n. | 160 | mbpp | 1 | 2024-11-26T21:40:54.199200 | def solution (a, b, n):
i = 0
while i * a <= n:
if (n - (i * a)) % b == 0:
return ("x = ",i ,", y = ",
int((n - (i * a)) / b))
return 0
i = i + 1
return ("No solution") | solution | easy | [{"input": "4, 2, 7", "output": "'No solution'", "testtype": "functional"}] |
Mbpp_160 | Write a function to find x and y that satisfies ax + by = n. | 160 | mbpp | 2 | 2024-11-26T21:40:54.199495 | def solution (a, b, n):
i = 0
while i * a <= n:
if (n - (i * a)) % b == 0:
return ("x = ",i ,", y = ",
int((n - (i * a)) / b))
return 0
i = i + 1
return ("No solution") | solution | easy | [{"input": "1, 13, 17", "output": "('x = ', 4, ', y = ', 1)", "testtype": "functional"}] |
Mbpp_161 | Write a function to remove all elements from a given list present in another list. | 161 | mbpp | 0 | 2024-11-26T21:40:54.199679 | def remove_elements(list1, list2):
result = [x for x in list1 if x not in list2]
return result | remove_elements | easy | [{"input": "[1,2,3,4,5,6,7,8,9,10],[2,4,6,8]", "output": "[1, 3, 5, 7, 9, 10]", "testtype": "functional"}] |
Mbpp_161 | Write a function to remove all elements from a given list present in another list. | 161 | mbpp | 1 | 2024-11-26T21:40:54.199823 | def remove_elements(list1, list2):
result = [x for x in list1 if x not in list2]
return result | remove_elements | easy | [{"input": "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10],[1, 3, 5, 7]", "output": "[2, 4, 6, 8, 9, 10]", "testtype": "functional"}] |
Mbpp_161 | Write a function to remove all elements from a given list present in another list. | 161 | mbpp | 2 | 2024-11-26T21:40:54.199965 | def remove_elements(list1, list2):
result = [x for x in list1 if x not in list2]
return result | remove_elements | easy | [{"input": "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10],[5,7]", "output": "[1, 2, 3, 4, 6, 8, 9, 10]", "testtype": "functional"}] |
Mbpp_162 | Write a function to calculate the sum of the positive integers of n+(n-2)+(n-4)... (until n-x =< 0). | 162 | mbpp | 0 | 2024-11-26T21:40:54.200105 | def sum_series(n):
if n < 1:
return 0
else:
return n + sum_series(n - 2) | sum_series | easy | [{"input": "6", "output": "12", "testtype": "functional"}] |
Mbpp_162 | Write a function to calculate the sum of the positive integers of n+(n-2)+(n-4)... (until n-x =< 0). | 162 | mbpp | 1 | 2024-11-26T21:40:54.200237 | def sum_series(n):
if n < 1:
return 0
else:
return n + sum_series(n - 2) | sum_series | easy | [{"input": "10", "output": "30", "testtype": "functional"}] |
Mbpp_162 | Write a function to calculate the sum of the positive integers of n+(n-2)+(n-4)... (until n-x =< 0). | 162 | mbpp | 2 | 2024-11-26T21:40:54.200369 | def sum_series(n):
if n < 1:
return 0
else:
return n + sum_series(n - 2) | sum_series | easy | [{"input": "9", "output": "25", "testtype": "functional"}] |
Mbpp_163 | Write a function to calculate the area of a regular polygon. | 163 | mbpp | 0 | 2024-11-26T21:40:54.200548 | from math import tan, pi
def area_polygon(s,l):
area = s * (l ** 2) / (4 * tan(pi / s))
return area | area_polygon | easy | [{"input": "4,20", "output": "400.00000000000006", "testtype": "functional"}] |
Mbpp_163 | Write a function to calculate the area of a regular polygon. | 163 | mbpp | 1 | 2024-11-26T21:40:54.200738 | from math import tan, pi
def area_polygon(s,l):
area = s * (l ** 2) / (4 * tan(pi / s))
return area | area_polygon | easy | [{"input": "10,15", "output": "1731.1969896610804", "testtype": "functional"}] |
Mbpp_163 | Write a function to calculate the area of a regular polygon. | 163 | mbpp | 2 | 2024-11-26T21:40:54.200907 | from math import tan, pi
def area_polygon(s,l):
area = s * (l ** 2) / (4 * tan(pi / s))
return area | area_polygon | easy | [{"input": "9,7", "output": "302.90938549487214", "testtype": "functional"}] |
Mbpp_165 | Write a python function to count characters at same position in a given string (lower and uppercase characters) as in english alphabet. | 165 | mbpp | 0 | 2024-11-26T21:40:54.201769 | def count_char_position(str1):
count_chars = 0
for i in range(len(str1)):
if ((i == ord(str1[i]) - ord('A')) or
(i == ord(str1[i]) - ord('a'))):
count_chars += 1
return count_chars | count_char_position | easy | [{"input": "\"xbcefg\"", "output": "2", "testtype": "functional"}] |
Mbpp_165 | Write a python function to count characters at same position in a given string (lower and uppercase characters) as in english alphabet. | 165 | mbpp | 1 | 2024-11-26T21:40:54.202092 | def count_char_position(str1):
count_chars = 0
for i in range(len(str1)):
if ((i == ord(str1[i]) - ord('A')) or
(i == ord(str1[i]) - ord('a'))):
count_chars += 1
return count_chars | count_char_position | easy | [{"input": "\"ABcED\"", "output": "3", "testtype": "functional"}] |
Mbpp_165 | Write a python function to count characters at same position in a given string (lower and uppercase characters) as in english alphabet. | 165 | mbpp | 2 | 2024-11-26T21:40:54.202400 | def count_char_position(str1):
count_chars = 0
for i in range(len(str1)):
if ((i == ord(str1[i]) - ord('A')) or
(i == ord(str1[i]) - ord('a'))):
count_chars += 1
return count_chars | count_char_position | easy | [{"input": "\"AbgdeF\"", "output": "5", "testtype": "functional"}] |
Mbpp_166 | Write a python function to count the pairs with xor as an even number. | 166 | mbpp | 0 | 2024-11-26T21:40:54.202677 | def find_even_Pair(A,N):
evenPair = 0
for i in range(0,N):
for j in range(i+1,N):
if ((A[i] ^ A[j]) % 2 == 0):
evenPair+=1
return evenPair; | find_even_Pair | easy | [{"input": "[5,4,7,2,1],5", "output": "4", "testtype": "functional"}] |
Mbpp_166 | Write a python function to count the pairs with xor as an even number. | 166 | mbpp | 1 | 2024-11-26T21:40:54.202966 | def find_even_Pair(A,N):
evenPair = 0
for i in range(0,N):
for j in range(i+1,N):
if ((A[i] ^ A[j]) % 2 == 0):
evenPair+=1
return evenPair; | find_even_Pair | easy | [{"input": "[7,2,8,1,0,5,11],7", "output": "9", "testtype": "functional"}] |
Mbpp_166 | Write a python function to count the pairs with xor as an even number. | 166 | mbpp | 2 | 2024-11-26T21:40:54.203221 | def find_even_Pair(A,N):
evenPair = 0
for i in range(0,N):
for j in range(i+1,N):
if ((A[i] ^ A[j]) % 2 == 0):
evenPair+=1
return evenPair; | find_even_Pair | easy | [{"input": "[1,2,3],3", "output": "1", "testtype": "functional"}] |
Mbpp_167 | Write a python function to find smallest power of 2 greater than or equal to n. | 167 | mbpp | 0 | 2024-11-26T21:40:54.203470 | def next_Power_Of_2(n):
count = 0;
if (n and not(n & (n - 1))):
return n
while( n != 0):
n >>= 1
count += 1
return 1 << count; | next_Power_Of_2 | easy | [{"input": "0", "output": "1", "testtype": "functional"}] |
Mbpp_167 | Write a python function to find smallest power of 2 greater than or equal to n. | 167 | mbpp | 1 | 2024-11-26T21:40:54.203728 | def next_Power_Of_2(n):
count = 0;
if (n and not(n & (n - 1))):
return n
while( n != 0):
n >>= 1
count += 1
return 1 << count; | next_Power_Of_2 | easy | [{"input": "5", "output": "8", "testtype": "functional"}] |
Mbpp_167 | Write a python function to find smallest power of 2 greater than or equal to n. | 167 | mbpp | 2 | 2024-11-26T21:40:54.203953 | def next_Power_Of_2(n):
count = 0;
if (n and not(n & (n - 1))):
return n
while( n != 0):
n >>= 1
count += 1
return 1 << count; | next_Power_Of_2 | easy | [{"input": "17", "output": "32", "testtype": "functional"}] |
Mbpp_168 | Write a python function to find the frequency of a number in a given array. | 168 | mbpp | 0 | 2024-11-26T21:40:54.204118 | def frequency(a,x):
count = 0
for i in a:
if i == x: count += 1
return count | frequency | easy | [{"input": "[1,2,3],4", "output": "0", "testtype": "functional"}] |
Mbpp_168 | Write a python function to find the frequency of a number in a given array. | 168 | mbpp | 1 | 2024-11-26T21:40:54.204263 | def frequency(a,x):
count = 0
for i in a:
if i == x: count += 1
return count | frequency | easy | [{"input": "[1,2,2,3,3,3,4],3", "output": "3", "testtype": "functional"}] |
Mbpp_168 | Write a python function to find the frequency of a number in a given array. | 168 | mbpp | 2 | 2024-11-26T21:40:54.204416 | def frequency(a,x):
count = 0
for i in a:
if i == x: count += 1
return count | frequency | easy | [{"input": "[0,1,2,3,1,2],1", "output": "2", "testtype": "functional"}] |
Mbpp_169 | Write a function to calculate the nth pell number. | 169 | mbpp | 0 | 2024-11-26T21:40:54.204677 | def get_pell(n):
if (n <= 2):
return n
a = 1
b = 2
for i in range(3, n+1):
c = 2 * b + a
a = b
b = c
return b | get_pell | easy | [{"input": "4", "output": "12", "testtype": "functional"}] |
Mbpp_169 | Write a function to calculate the nth pell number. | 169 | mbpp | 1 | 2024-11-26T21:40:54.204921 | def get_pell(n):
if (n <= 2):
return n
a = 1
b = 2
for i in range(3, n+1):
c = 2 * b + a
a = b
b = c
return b | get_pell | easy | [{"input": "7", "output": "169", "testtype": "functional"}] |
Mbpp_169 | Write a function to calculate the nth pell number. | 169 | mbpp | 2 | 2024-11-26T21:40:54.205164 | def get_pell(n):
if (n <= 2):
return n
a = 1
b = 2
for i in range(3, n+1):
c = 2 * b + a
a = b
b = c
return b | get_pell | easy | [{"input": "8", "output": "408", "testtype": "functional"}] |
Mbpp_170 | Write a function to find sum of the numbers in a list between the indices of a specified range. | 170 | mbpp | 0 | 2024-11-26T21:40:54.205378 | def sum_range_list(list1, m, n):
sum_range = 0
for i in range(m, n+1, 1):
sum_range += list1[i]
return sum_range | sum_range_list | easy | [{"input": " [2,1,5,6,8,3,4,9,10,11,8,12],8,10", "output": "29", "testtype": "functional"}] |
Mbpp_170 | Write a function to find sum of the numbers in a list between the indices of a specified range. | 170 | mbpp | 1 | 2024-11-26T21:40:54.205570 | def sum_range_list(list1, m, n):
sum_range = 0
for i in range(m, n+1, 1):
sum_range += list1[i]
return sum_range | sum_range_list | easy | [{"input": " [2,1,5,6,8,3,4,9,10,11,8,12],5,7", "output": "16", "testtype": "functional"}] |
Mbpp_170 | Write a function to find sum of the numbers in a list between the indices of a specified range. | 170 | mbpp | 2 | 2024-11-26T21:40:54.205778 | def sum_range_list(list1, m, n):
sum_range = 0
for i in range(m, n+1, 1):
sum_range += list1[i]
return sum_range | sum_range_list | easy | [{"input": " [2,1,5,6,8,3,4,9,10,11,8,12],7,10", "output": "38", "testtype": "functional"}] |
Mbpp_171 | Write a function to find the perimeter of a pentagon. | 171 | mbpp | 0 | 2024-11-26T21:40:54.205905 | import math
def perimeter_pentagon(a):
perimeter=(5*a)
return perimeter | perimeter_pentagon | easy | [{"input": "5", "output": "25", "testtype": "functional"}] |
Mbpp_171 | Write a function to find the perimeter of a pentagon. | 171 | mbpp | 1 | 2024-11-26T21:40:54.206006 | import math
def perimeter_pentagon(a):
perimeter=(5*a)
return perimeter | perimeter_pentagon | easy | [{"input": "10", "output": "50", "testtype": "functional"}] |
Mbpp_171 | Write a function to find the perimeter of a pentagon. | 171 | mbpp | 2 | 2024-11-26T21:40:54.206099 | import math
def perimeter_pentagon(a):
perimeter=(5*a)
return perimeter | perimeter_pentagon | easy | [{"input": "15", "output": "75", "testtype": "functional"}] |
Mbpp_172 | Write a function to find the occurence of characters 'std' in the given string 1. list item 1. list item 1. list item 2. list item 2. list item 2. list item | 172 | mbpp | 0 | 2024-11-26T21:40:54.206372 | def count_occurance(s):
count=0
for i in range(len(s)):
if (s[i]== 's' and s[i+1]=='t' and s[i+2]== 'd'):
count = count + 1
return count | count_occurance | easy | [{"input": "\"letstdlenstdporstd\"", "output": "3", "testtype": "functional"}] |
Mbpp_172 | Write a function to find the occurence of characters 'std' in the given string 1. list item 1. list item 1. list item 2. list item 2. list item 2. list item | 172 | mbpp | 1 | 2024-11-26T21:40:54.206668 | def count_occurance(s):
count=0
for i in range(len(s)):
if (s[i]== 's' and s[i+1]=='t' and s[i+2]== 'd'):
count = count + 1
return count | count_occurance | easy | [{"input": "\"truststdsolensporsd\"", "output": "1", "testtype": "functional"}] |
Mbpp_172 | Write a function to find the occurence of characters 'std' in the given string 1. list item 1. list item 1. list item 2. list item 2. list item 2. list item | 172 | mbpp | 2 | 2024-11-26T21:40:54.206937 | def count_occurance(s):
count=0
for i in range(len(s)):
if (s[i]== 's' and s[i+1]=='t' and s[i+2]== 'd'):
count = count + 1
return count | count_occurance | easy | [{"input": "\"makestdsostdworthit\"", "output": "2", "testtype": "functional"}] |
Mbpp_173 | Write a function to remove everything except alphanumeric characters from a string. | 173 | mbpp | 0 | 2024-11-26T21:40:54.207128 | import re
def remove_splchar(text):
pattern = re.compile('[\W_]+')
return (pattern.sub('', text)) | remove_splchar | easy | [{"input": "'python @#&^%$*program123'", "output": "('pythonprogram123')", "testtype": "functional"}] |
Mbpp_173 | Write a function to remove everything except alphanumeric characters from a string. | 173 | mbpp | 1 | 2024-11-26T21:40:54.207283 | import re
def remove_splchar(text):
pattern = re.compile('[\W_]+')
return (pattern.sub('', text)) | remove_splchar | easy | [{"input": "'python %^$@!^&*() programming24%$^^() language'", "output": "('pythonprogramming24language')", "testtype": "functional"}] |
Mbpp_173 | Write a function to remove everything except alphanumeric characters from a string. | 173 | mbpp | 2 | 2024-11-26T21:40:54.207436 | import re
def remove_splchar(text):
pattern = re.compile('[\W_]+')
return (pattern.sub('', text)) | remove_splchar | easy | [{"input": "'python ^%&^()(+_)(_^&67) program'", "output": "('python67program')", "testtype": "functional"}] |
Mbpp_174 | Write a function to group a sequence of key-value pairs into a dictionary of lists. | 174 | mbpp | 0 | 2024-11-26T21:40:54.207629 | def group_keyvalue(l):
result = {}
for k, v in l:
result.setdefault(k, []).append(v)
return result | group_keyvalue | easy | [{"input": "[('yellow', 1), ('blue', 2), ('yellow', 3), ('blue', 4), ('red', 1)]", "output": "{'yellow': [1, 3], 'blue': [2, 4], 'red': [1]}", "testtype": "functional"}] |
Mbpp_174 | Write a function to group a sequence of key-value pairs into a dictionary of lists. | 174 | mbpp | 1 | 2024-11-26T21:40:54.207842 | def group_keyvalue(l):
result = {}
for k, v in l:
result.setdefault(k, []).append(v)
return result | group_keyvalue | easy | [{"input": "[('python', 1), ('python', 2), ('python', 3), ('python', 4), ('python', 5)]", "output": "{'python': [1,2,3,4,5]}", "testtype": "functional"}] |
Mbpp_174 | Write a function to group a sequence of key-value pairs into a dictionary of lists. | 174 | mbpp | 2 | 2024-11-26T21:40:54.208009 | def group_keyvalue(l):
result = {}
for k, v in l:
result.setdefault(k, []).append(v)
return result | group_keyvalue | easy | [{"input": "[('yellow',100), ('blue', 200), ('yellow', 300), ('blue', 400), ('red', 100)]", "output": "{'yellow': [100, 300], 'blue': [200, 400], 'red': [100]}", "testtype": "functional"}] |
Mbpp_175 | Write a function to verify validity of a string of parentheses. | 175 | mbpp | 0 | 2024-11-26T21:40:54.208381 | def is_valid_parenthese( str1):
stack, pchar = [], {"(": ")", "{": "}", "[": "]"}
for parenthese in str1:
if parenthese in pchar:
stack.append(parenthese)
elif len(stack) == 0 or pchar[stack.pop()] != parenthese:
return False
return len(stack) == 0 | is_valid_parenthese | easy | [{"input": "\"(){}[]\"", "output": "True", "testtype": "functional"}] |
Mbpp_175 | Write a function to verify validity of a string of parentheses. | 175 | mbpp | 1 | 2024-11-26T21:40:54.208765 | def is_valid_parenthese( str1):
stack, pchar = [], {"(": ")", "{": "}", "[": "]"}
for parenthese in str1:
if parenthese in pchar:
stack.append(parenthese)
elif len(stack) == 0 or pchar[stack.pop()] != parenthese:
return False
return len(stack) == 0 | is_valid_parenthese | easy | [{"input": "\"()[{)}\"", "output": "False", "testtype": "functional"}] |
Mbpp_175 | Write a function to verify validity of a string of parentheses. | 175 | mbpp | 2 | 2024-11-26T21:40:54.209116 | def is_valid_parenthese( str1):
stack, pchar = [], {"(": ")", "{": "}", "[": "]"}
for parenthese in str1:
if parenthese in pchar:
stack.append(parenthese)
elif len(stack) == 0 or pchar[stack.pop()] != parenthese:
return False
return len(stack) == 0 | is_valid_parenthese | easy | [{"input": "\"()\"", "output": "True", "testtype": "functional"}] |
Mbpp_176 | Write a function to find the perimeter of a triangle. | 176 | mbpp | 0 | 2024-11-26T21:40:54.209262 | def perimeter_triangle(a,b,c):
perimeter=a+b+c
return perimeter | perimeter_triangle | easy | [{"input": "10,20,30", "output": "60", "testtype": "functional"}] |
Mbpp_176 | Write a function to find the perimeter of a triangle. | 176 | mbpp | 1 | 2024-11-26T21:40:54.209379 | def perimeter_triangle(a,b,c):
perimeter=a+b+c
return perimeter | perimeter_triangle | easy | [{"input": "3,4,5", "output": "12", "testtype": "functional"}] |
Mbpp_176 | Write a function to find the perimeter of a triangle. | 176 | mbpp | 2 | 2024-11-26T21:40:54.209484 | def perimeter_triangle(a,b,c):
perimeter=a+b+c
return perimeter | perimeter_triangle | easy | [{"input": "25,35,45", "output": "105", "testtype": "functional"}] |
Mbpp_177 | Write a python function to find two distinct numbers such that their lcm lies within the given range. | 177 | mbpp | 0 | 2024-11-26T21:40:54.209630 | def answer(L,R):
if (2 * L <= R):
return (L ,2*L)
else:
return (-1) | answer | easy | [{"input": "3,8", "output": "(3,6)", "testtype": "functional"}] |
Mbpp_177 | Write a python function to find two distinct numbers such that their lcm lies within the given range. | 177 | mbpp | 1 | 2024-11-26T21:40:54.209818 | def answer(L,R):
if (2 * L <= R):
return (L ,2*L)
else:
return (-1) | answer | easy | [{"input": "2,6", "output": "(2,4)", "testtype": "functional"}] |
Mbpp_177 | Write a python function to find two distinct numbers such that their lcm lies within the given range. | 177 | mbpp | 2 | 2024-11-26T21:40:54.209956 | def answer(L,R):
if (2 * L <= R):
return (L ,2*L)
else:
return (-1) | answer | easy | [{"input": "1,3", "output": "(1,2)", "testtype": "functional"}] |
Mbpp_178 | Write a function to search some literals strings in a string. | 178 | mbpp | 0 | 2024-11-26T21:40:54.210131 | import re
def string_literals(patterns,text):
for pattern in patterns:
if re.search(pattern, text):
return ('Matched!')
else:
return ('Not Matched!') | string_literals | easy | [{"input": "['language'],'python language'", "output": "('Matched!')", "testtype": "functional"}] |
Mbpp_178 | Write a function to search some literals strings in a string. | 178 | mbpp | 1 | 2024-11-26T21:40:54.210292 | import re
def string_literals(patterns,text):
for pattern in patterns:
if re.search(pattern, text):
return ('Matched!')
else:
return ('Not Matched!') | string_literals | easy | [{"input": "['program'],'python language'", "output": "('Not Matched!')", "testtype": "functional"}] |
Mbpp_178 | Write a function to search some literals strings in a string. | 178 | mbpp | 2 | 2024-11-26T21:40:54.210449 | import re
def string_literals(patterns,text):
for pattern in patterns:
if re.search(pattern, text):
return ('Matched!')
else:
return ('Not Matched!') | string_literals | easy | [{"input": "['python'],'programming language'", "output": "('Not Matched!')", "testtype": "functional"}] |
Mbpp_179 | Write a function to find if the given number is a keith number or not. | 179 | mbpp | 0 | 2024-11-26T21:40:54.210966 | def is_num_keith(x):
terms = []
temp = x
n = 0
while (temp > 0):
terms.append(temp % 10)
temp = int(temp / 10)
n+=1
terms.reverse()
next_term = 0
i = n
while (next_term < x):
next_term = 0
for j in range(1,n+1):
next_term += terms[i - j]
terms.append(next_term)
i+=1
return (next_term == x) | is_num_keith | easy | [{"input": "14", "output": "True", "testtype": "functional"}] |
Mbpp_179 | Write a function to find if the given number is a keith number or not. | 179 | mbpp | 1 | 2024-11-26T21:40:54.211541 | def is_num_keith(x):
terms = []
temp = x
n = 0
while (temp > 0):
terms.append(temp % 10)
temp = int(temp / 10)
n+=1
terms.reverse()
next_term = 0
i = n
while (next_term < x):
next_term = 0
for j in range(1,n+1):
next_term += terms[i - j]
terms.append(next_term)
i+=1
return (next_term == x) | is_num_keith | easy | [{"input": "12", "output": "False", "testtype": "functional"}] |
Mbpp_179 | Write a function to find if the given number is a keith number or not. | 179 | mbpp | 2 | 2024-11-26T21:40:54.212122 | def is_num_keith(x):
terms = []
temp = x
n = 0
while (temp > 0):
terms.append(temp % 10)
temp = int(temp / 10)
n+=1
terms.reverse()
next_term = 0
i = n
while (next_term < x):
next_term = 0
for j in range(1,n+1):
next_term += terms[i - j]
terms.append(next_term)
i+=1
return (next_term == x) | is_num_keith | easy | [{"input": "197", "output": "True", "testtype": "functional"}] |
Mbpp_180 | Write a function to calculate distance between two points using latitude and longitude. | 180 | mbpp | 0 | 2024-11-26T21:40:54.212418 | from math import radians, sin, cos, acos
def distance_lat_long(slat,slon,elat,elon):
dist = 6371.01 * acos(sin(slat)*sin(elat) + cos(slat)*cos(elat)*cos(slon - elon))
return dist | distance_lat_long | easy | [{"input": "23.5,67.5,25.5,69.5", "output": "12179.372041317429", "testtype": "functional"}] |
Mbpp_180 | Write a function to calculate distance between two points using latitude and longitude. | 180 | mbpp | 1 | 2024-11-26T21:40:54.212692 | from math import radians, sin, cos, acos
def distance_lat_long(slat,slon,elat,elon):
dist = 6371.01 * acos(sin(slat)*sin(elat) + cos(slat)*cos(elat)*cos(slon - elon))
return dist | distance_lat_long | easy | [{"input": "10.5,20.5,30.5,40.5", "output": "6069.397933300514", "testtype": "functional"}] |
Mbpp_180 | Write a function to calculate distance between two points using latitude and longitude. | 180 | mbpp | 2 | 2024-11-26T21:40:54.212970 | from math import radians, sin, cos, acos
def distance_lat_long(slat,slon,elat,elon):
dist = 6371.01 * acos(sin(slat)*sin(elat) + cos(slat)*cos(elat)*cos(slon - elon))
return dist | distance_lat_long | easy | [{"input": "10,20,30,40", "output": "6783.751974994595", "testtype": "functional"}] |
Mbpp_182 | Write a function to find uppercase, lowercase, special character and numeric values using regex. | 182 | mbpp | 0 | 2024-11-26T21:40:54.214034 | import re
def find_character(string):
uppercase_characters = re.findall(r"[A-Z]", string)
lowercase_characters = re.findall(r"[a-z]", string)
numerical_characters = re.findall(r"[0-9]", string)
special_characters = re.findall(r"[, .!?]", string)
return uppercase_characters, lowercase_characters, numerical_characters, special_characters | find_character | easy | [{"input": "\"ThisIsGeeksforGeeks\"", "output": "(['T', 'I', 'G', 'G'], ['h', 'i', 's', 's', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'e', 'e', 'k', 's'], [], [])", "testtype": "functional"}] |
Mbpp_182 | Write a function to find uppercase, lowercase, special character and numeric values using regex. | 182 | mbpp | 1 | 2024-11-26T21:40:54.214318 | import re
def find_character(string):
uppercase_characters = re.findall(r"[A-Z]", string)
lowercase_characters = re.findall(r"[a-z]", string)
numerical_characters = re.findall(r"[0-9]", string)
special_characters = re.findall(r"[, .!?]", string)
return uppercase_characters, lowercase_characters, numerical_characters, special_characters | find_character | easy | [{"input": "\"Hithere2\"", "output": "(['H'], ['i', 't', 'h', 'e', 'r', 'e'], ['2'], [])", "testtype": "functional"}] |