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_285 | Write a function that matches a string that has an a followed by two to three 'b'. | 285 | mbpp | 1 | 2024-11-26T21:40:54.305711 | import re
def text_match_two_three(text):
patterns = 'ab{2,3}'
if re.search(patterns, text):
return 'Found a match!'
else:
return('Not matched!') | text_match_two_three | easy | [{"input": "\"dc\"", "output": "('Not matched!')", "testtype": "functional"}] |
Mbpp_285 | Write a function that matches a string that has an a followed by two to three 'b'. | 285 | mbpp | 2 | 2024-11-26T21:40:54.305876 | import re
def text_match_two_three(text):
patterns = 'ab{2,3}'
if re.search(patterns, text):
return 'Found a match!'
else:
return('Not matched!') | text_match_two_three | easy | [{"input": "\"abbbba\"", "output": "('Found a match!')", "testtype": "functional"}] |
Mbpp_286 | Write a function to find the largest sum of contiguous array in the modified array which is formed by repeating the given array k times. | 286 | mbpp | 0 | 2024-11-26T21:40:54.306188 | def max_sub_array_sum_repeated(a, n, k):
max_so_far = -2147483648
max_ending_here = 0
for i in range(n*k):
max_ending_here = max_ending_here + a[i%n]
if (max_so_far < max_ending_here):
max_so_far = max_ending_here
if (max_ending_here < 0):
max_ending_here = 0
return max_so_far | max_sub_array_sum_repeated | easy | [{"input": "[10, 20, -30, -1], 4, 3", "output": "30", "testtype": "functional"}] |
Mbpp_286 | Write a function to find the largest sum of contiguous array in the modified array which is formed by repeating the given array k times. | 286 | mbpp | 1 | 2024-11-26T21:40:54.306498 | def max_sub_array_sum_repeated(a, n, k):
max_so_far = -2147483648
max_ending_here = 0
for i in range(n*k):
max_ending_here = max_ending_here + a[i%n]
if (max_so_far < max_ending_here):
max_so_far = max_ending_here
if (max_ending_here < 0):
max_ending_here = 0
return max_so_far | max_sub_array_sum_repeated | easy | [{"input": "[-1, 10, 20], 3, 2", "output": "59", "testtype": "functional"}] |
Mbpp_286 | Write a function to find the largest sum of contiguous array in the modified array which is formed by repeating the given array k times. | 286 | mbpp | 2 | 2024-11-26T21:40:54.306810 | def max_sub_array_sum_repeated(a, n, k):
max_so_far = -2147483648
max_ending_here = 0
for i in range(n*k):
max_ending_here = max_ending_here + a[i%n]
if (max_so_far < max_ending_here):
max_so_far = max_ending_here
if (max_ending_here < 0):
max_ending_here = 0
return max_so_far | max_sub_array_sum_repeated | easy | [{"input": "[-1, -2, -3], 3, 3", "output": "-1", "testtype": "functional"}] |
Mbpp_287 | Write a python function to find the sum of squares of first n even natural numbers. | 287 | mbpp | 0 | 2024-11-26T21:40:54.306979 | def square_Sum(n):
return int(2*n*(n+1)*(2*n+1)/3) | square_Sum | easy | [{"input": "2", "output": "20", "testtype": "functional"}] |
Mbpp_287 | Write a python function to find the sum of squares of first n even natural numbers. | 287 | mbpp | 1 | 2024-11-26T21:40:54.307126 | def square_Sum(n):
return int(2*n*(n+1)*(2*n+1)/3) | square_Sum | easy | [{"input": "3", "output": "56", "testtype": "functional"}] |
Mbpp_287 | Write a python function to find the sum of squares of first n even natural numbers. | 287 | mbpp | 2 | 2024-11-26T21:40:54.307270 | def square_Sum(n):
return int(2*n*(n+1)*(2*n+1)/3) | square_Sum | easy | [{"input": "4", "output": "120", "testtype": "functional"}] |
Mbpp_288 | Write a function to count array elements having modular inverse under given prime number p equal to itself. | 288 | mbpp | 0 | 2024-11-26T21:40:54.307527 | def modular_inverse(arr, N, P):
current_element = 0
for i in range(0, N):
if ((arr[i] * arr[i]) % P == 1):
current_element = current_element + 1
return current_element | modular_inverse | easy | [{"input": "[ 1, 6, 4, 5 ], 4, 7", "output": "2", "testtype": "functional"}] |
Mbpp_288 | Write a function to count array elements having modular inverse under given prime number p equal to itself. | 288 | mbpp | 1 | 2024-11-26T21:40:54.308134 | def modular_inverse(arr, N, P):
current_element = 0
for i in range(0, N):
if ((arr[i] * arr[i]) % P == 1):
current_element = current_element + 1
return current_element | modular_inverse | easy | [{"input": "[1, 3, 8, 12, 12], 5, 13", "output": "3", "testtype": "functional"}] |
Mbpp_288 | Write a function to count array elements having modular inverse under given prime number p equal to itself. | 288 | mbpp | 2 | 2024-11-26T21:40:54.308406 | def modular_inverse(arr, N, P):
current_element = 0
for i in range(0, N):
if ((arr[i] * arr[i]) % P == 1):
current_element = current_element + 1
return current_element | modular_inverse | easy | [{"input": "[2, 3, 4, 5], 4, 6", "output": "1", "testtype": "functional"}] |
Mbpp_289 | Write a python function to calculate the number of odd days in a given year. | 289 | mbpp | 0 | 2024-11-26T21:40:54.308779 | def odd_Days(N):
hund1 = N // 100
hund4 = N // 400
leap = N >> 2
ordd = N - leap
if (hund1):
ordd += hund1
leap -= hund1
if (hund4):
ordd -= hund4
leap += hund4
days = ordd + leap * 2
odd = days % 7
return odd | odd_Days | easy | [{"input": "100", "output": "5", "testtype": "functional"}] |
Mbpp_289 | Write a python function to calculate the number of odd days in a given year. | 289 | mbpp | 1 | 2024-11-26T21:40:54.309118 | def odd_Days(N):
hund1 = N // 100
hund4 = N // 400
leap = N >> 2
ordd = N - leap
if (hund1):
ordd += hund1
leap -= hund1
if (hund4):
ordd -= hund4
leap += hund4
days = ordd + leap * 2
odd = days % 7
return odd | odd_Days | easy | [{"input": "50", "output": "6", "testtype": "functional"}] |
Mbpp_289 | Write a python function to calculate the number of odd days in a given year. | 289 | mbpp | 2 | 2024-11-26T21:40:54.309489 | def odd_Days(N):
hund1 = N // 100
hund4 = N // 400
leap = N >> 2
ordd = N - leap
if (hund1):
ordd += hund1
leap -= hund1
if (hund4):
ordd -= hund4
leap += hund4
days = ordd + leap * 2
odd = days % 7
return odd | odd_Days | easy | [{"input": "75", "output": "2", "testtype": "functional"}] |
Mbpp_290 | Write a function to find the list of lists with maximum length. | 290 | mbpp | 0 | 2024-11-26T21:40:54.309736 | def max_length(list1):
max_length = max(len(x) for x in list1 )
max_list = max((x) for x in list1)
return(max_length, max_list) | max_length | easy | [{"input": "[[0], [1, 3], [5, 7], [9, 11], [13, 15, 17]]", "output": "(3, [13, 15, 17])", "testtype": "functional"}] |
Mbpp_290 | Write a function to find the list of lists with maximum length. | 290 | mbpp | 1 | 2024-11-26T21:40:54.309942 | def max_length(list1):
max_length = max(len(x) for x in list1 )
max_list = max((x) for x in list1)
return(max_length, max_list) | max_length | easy | [{"input": "[[1], [5, 7], [10, 12, 14,15]]", "output": "(4, [10, 12, 14,15])", "testtype": "functional"}] |
Mbpp_290 | Write a function to find the list of lists with maximum length. | 290 | mbpp | 2 | 2024-11-26T21:40:54.310124 | def max_length(list1):
max_length = max(len(x) for x in list1 )
max_list = max((x) for x in list1)
return(max_length, max_list) | max_length | easy | [{"input": "[[5], [15,20,25]]", "output": "(3, [15,20,25])", "testtype": "functional"}] |
Mbpp_291 | Write a function to find out the number of ways of painting the fence such that at most 2 adjacent posts have the same color for the given fence with n posts and k colors. | 291 | mbpp | 0 | 2024-11-26T21:40:54.310526 | def count_no_of_ways(n, k):
dp = [0] * (n + 1)
total = k
mod = 1000000007
dp[1] = k
dp[2] = k * k
for i in range(3,n+1):
dp[i] = ((k - 1) * (dp[i - 1] + dp[i - 2])) % mod
return dp[n] | count_no_of_ways | easy | [{"input": "2, 4", "output": "16", "testtype": "functional"}] |
Mbpp_291 | Write a function to find out the number of ways of painting the fence such that at most 2 adjacent posts have the same color for the given fence with n posts and k colors. | 291 | mbpp | 1 | 2024-11-26T21:40:54.310910 | def count_no_of_ways(n, k):
dp = [0] * (n + 1)
total = k
mod = 1000000007
dp[1] = k
dp[2] = k * k
for i in range(3,n+1):
dp[i] = ((k - 1) * (dp[i - 1] + dp[i - 2])) % mod
return dp[n] | count_no_of_ways | easy | [{"input": "3, 2", "output": "6", "testtype": "functional"}] |
Mbpp_291 | Write a function to find out the number of ways of painting the fence such that at most 2 adjacent posts have the same color for the given fence with n posts and k colors. | 291 | mbpp | 2 | 2024-11-26T21:40:54.311271 | def count_no_of_ways(n, k):
dp = [0] * (n + 1)
total = k
mod = 1000000007
dp[1] = k
dp[2] = k * k
for i in range(3,n+1):
dp[i] = ((k - 1) * (dp[i - 1] + dp[i - 2])) % mod
return dp[n] | count_no_of_ways | easy | [{"input": "4, 4", "output": "228", "testtype": "functional"}] |
Mbpp_292 | Write a python function to find quotient of two numbers. | 292 | mbpp | 0 | 2024-11-26T21:40:54.311415 | def find(n,m):
q = n//m
return (q) | find | easy | [{"input": "10,3", "output": "3", "testtype": "functional"}] |
Mbpp_292 | Write a python function to find quotient of two numbers. | 292 | mbpp | 1 | 2024-11-26T21:40:54.311512 | def find(n,m):
q = n//m
return (q) | find | easy | [{"input": "4,2", "output": "2", "testtype": "functional"}] |
Mbpp_292 | Write a python function to find quotient of two numbers. | 292 | mbpp | 2 | 2024-11-26T21:40:54.311607 | def find(n,m):
q = n//m
return (q) | find | easy | [{"input": "20,5", "output": "4", "testtype": "functional"}] |
Mbpp_293 | Write a function to find the third side of a right angled triangle. | 293 | mbpp | 0 | 2024-11-26T21:40:54.311789 | import math
def otherside_rightangle(w,h):
s=math.sqrt((w*w)+(h*h))
return s | otherside_rightangle | easy | [{"input": "7,8", "output": "10.63014581273465", "testtype": "functional"}] |
Mbpp_293 | Write a function to find the third side of a right angled triangle. | 293 | mbpp | 1 | 2024-11-26T21:40:54.311939 | import math
def otherside_rightangle(w,h):
s=math.sqrt((w*w)+(h*h))
return s | otherside_rightangle | easy | [{"input": "3,4", "output": "5", "testtype": "functional"}] |
Mbpp_293 | Write a function to find the third side of a right angled triangle. | 293 | mbpp | 2 | 2024-11-26T21:40:54.312364 | import math
def otherside_rightangle(w,h):
s=math.sqrt((w*w)+(h*h))
return s | otherside_rightangle | easy | [{"input": "7,15", "output": "16.55294535724685", "testtype": "functional"}] |
Mbpp_294 | Write a function to find the maximum value in a given heterogeneous list. | 294 | mbpp | 0 | 2024-11-26T21:40:54.312546 | def max_val(listval):
max_val = max(i for i in listval if isinstance(i, int))
return(max_val) | max_val | easy | [{"input": "['Python', 3, 2, 4, 5, 'version']", "output": "5", "testtype": "functional"}] |
Mbpp_294 | Write a function to find the maximum value in a given heterogeneous list. | 294 | mbpp | 1 | 2024-11-26T21:40:54.312711 | def max_val(listval):
max_val = max(i for i in listval if isinstance(i, int))
return(max_val) | max_val | easy | [{"input": "['Python', 15, 20, 25]", "output": "25", "testtype": "functional"}] |
Mbpp_294 | Write a function to find the maximum value in a given heterogeneous list. | 294 | mbpp | 2 | 2024-11-26T21:40:54.312867 | def max_val(listval):
max_val = max(i for i in listval if isinstance(i, int))
return(max_val) | max_val | easy | [{"input": "['Python', 30, 20, 40, 50, 'version']", "output": "50", "testtype": "functional"}] |
Mbpp_295 | Write a function to return the sum of all divisors of a number. | 295 | mbpp | 0 | 2024-11-26T21:40:54.313100 | def sum_div(number):
divisors = [1]
for i in range(2, number):
if (number % i)==0:
divisors.append(i)
return sum(divisors) | sum_div | easy | [{"input": "8", "output": "7", "testtype": "functional"}] |
Mbpp_295 | Write a function to return the sum of all divisors of a number. | 295 | mbpp | 1 | 2024-11-26T21:40:54.313323 | def sum_div(number):
divisors = [1]
for i in range(2, number):
if (number % i)==0:
divisors.append(i)
return sum(divisors) | sum_div | easy | [{"input": "12", "output": "16", "testtype": "functional"}] |
Mbpp_295 | Write a function to return the sum of all divisors of a number. | 295 | mbpp | 2 | 2024-11-26T21:40:54.313562 | def sum_div(number):
divisors = [1]
for i in range(2, number):
if (number % i)==0:
divisors.append(i)
return sum(divisors) | sum_div | easy | [{"input": "7", "output": "1", "testtype": "functional"}] |
Mbpp_296 | Write a python function to count inversions in an array. | 296 | mbpp | 0 | 2024-11-26T21:40:54.313841 | def get_Inv_Count(arr,n):
inv_count = 0
for i in range(n):
for j in range(i + 1,n):
if (arr[i] > arr[j]):
inv_count += 1
return inv_count | get_Inv_Count | easy | [{"input": "[1,20,6,4,5],5", "output": "5", "testtype": "functional"}] |
Mbpp_296 | Write a python function to count inversions in an array. | 296 | mbpp | 1 | 2024-11-26T21:40:54.314087 | def get_Inv_Count(arr,n):
inv_count = 0
for i in range(n):
for j in range(i + 1,n):
if (arr[i] > arr[j]):
inv_count += 1
return inv_count | get_Inv_Count | easy | [{"input": "[1,2,1],3", "output": "1", "testtype": "functional"}] |
Mbpp_296 | Write a python function to count inversions in an array. | 296 | mbpp | 2 | 2024-11-26T21:40:54.314314 | def get_Inv_Count(arr,n):
inv_count = 0
for i in range(n):
for j in range(i + 1,n):
if (arr[i] > arr[j]):
inv_count += 1
return inv_count | get_Inv_Count | easy | [{"input": "[1,2,5,6,1],5", "output": "3", "testtype": "functional"}] |
Mbpp_297 | Write a function to flatten a given nested list structure. | 297 | mbpp | 0 | 2024-11-26T21:40:54.314790 | def flatten_list(list1):
result_list = []
if not list1: return result_list
stack = [list(list1)]
while stack:
c_num = stack.pop()
next = c_num.pop()
if c_num: stack.append(c_num)
if isinstance(next, list):
if next: stack.append(list(next))
el... | flatten_list | easy | [{"input": "[0, 10, [20, 30], 40, 50, [60, 70, 80], [90, 100, 110, 120]]", "output": "[0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120]", "testtype": "functional"}] |
Mbpp_297 | Write a function to flatten a given nested list structure. | 297 | mbpp | 1 | 2024-11-26T21:40:54.315184 | def flatten_list(list1):
result_list = []
if not list1: return result_list
stack = [list(list1)]
while stack:
c_num = stack.pop()
next = c_num.pop()
if c_num: stack.append(c_num)
if isinstance(next, list):
if next: stack.append(list(next))
el... | flatten_list | easy | [{"input": "[[10, 20], [40], [30, 56, 25], [10, 20], [33], [40]]", "output": "[10, 20, 40, 30, 56, 25, 10, 20, 33, 40]", "testtype": "functional"}] |
Mbpp_297 | Write a function to flatten a given nested list structure. | 297 | mbpp | 2 | 2024-11-26T21:40:54.316296 | def flatten_list(list1):
result_list = []
if not list1: return result_list
stack = [list(list1)]
while stack:
c_num = stack.pop()
next = c_num.pop()
if c_num: stack.append(c_num)
if isinstance(next, list):
if next: stack.append(list(next))
el... | flatten_list | easy | [{"input": "[[1,2,3], [4,5,6], [10,11,12], [7,8,9]]", "output": "[1, 2, 3, 4, 5, 6, 10, 11, 12, 7, 8, 9]", "testtype": "functional"}] |
Mbpp_298 | Write a function to find the nested list elements which are present in another list. | 298 | mbpp | 0 | 2024-11-26T21:40:54.316525 | def intersection_nested_lists(l1, l2):
result = [[n for n in lst if n in l1] for lst in l2]
return result | intersection_nested_lists | easy | [{"input": " [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14],[[12, 18, 23, 25, 45], [7, 11, 19, 24, 28], [1, 5, 8, 18, 15, 16]]", "output": "[[12], [7, 11], [1, 5, 8]]", "testtype": "functional"}] |
Mbpp_298 | Write a function to find the nested list elements which are present in another list. | 298 | mbpp | 1 | 2024-11-26T21:40:54.316711 | def intersection_nested_lists(l1, l2):
result = [[n for n in lst if n in l1] for lst in l2]
return result | intersection_nested_lists | easy | [{"input": "[[2, 3, 1], [4, 5], [6, 8]], [[4, 5], [6, 8]]", "output": "[[], []]", "testtype": "functional"}] |
Mbpp_298 | Write a function to find the nested list elements which are present in another list. | 298 | mbpp | 2 | 2024-11-26T21:40:54.316886 | def intersection_nested_lists(l1, l2):
result = [[n for n in lst if n in l1] for lst in l2]
return result | intersection_nested_lists | easy | [{"input": "['john','amal','joel','george'],[['john'],['jack','john','mary'],['howard','john'],['jude']]", "output": "[['john'], ['john'], ['john'], []]", "testtype": "functional"}] |
Mbpp_299 | Write a function to calculate the maximum aggregate from the list of tuples. | 299 | mbpp | 0 | 2024-11-26T21:40:54.317164 | from collections import defaultdict
def max_aggregate(stdata):
temp = defaultdict(int)
for name, marks in stdata:
temp[name] += marks
return max(temp.items(), key=lambda x: x[1]) | max_aggregate | easy | [{"input": "[('Juan Whelan',90),('Sabah Colley',88),('Peter Nichols',7),('Juan Whelan',122),('Sabah Colley',84)]", "output": "('Juan Whelan', 212)", "testtype": "functional"}] |
Mbpp_299 | Write a function to calculate the maximum aggregate from the list of tuples. | 299 | mbpp | 1 | 2024-11-26T21:40:54.317452 | from collections import defaultdict
def max_aggregate(stdata):
temp = defaultdict(int)
for name, marks in stdata:
temp[name] += marks
return max(temp.items(), key=lambda x: x[1]) | max_aggregate | easy | [{"input": "[('Juan Whelan',50),('Sabah Colley',48),('Peter Nichols',37),('Juan Whelan',22),('Sabah Colley',14)]", "output": "('Juan Whelan', 72)", "testtype": "functional"}] |
Mbpp_299 | Write a function to calculate the maximum aggregate from the list of tuples. | 299 | mbpp | 2 | 2024-11-26T21:40:54.317725 | from collections import defaultdict
def max_aggregate(stdata):
temp = defaultdict(int)
for name, marks in stdata:
temp[name] += marks
return max(temp.items(), key=lambda x: x[1]) | max_aggregate | easy | [{"input": "[('Juan Whelan',10),('Sabah Colley',20),('Peter Nichols',30),('Juan Whelan',40),('Sabah Colley',50)]", "output": "('Sabah Colley', 70)", "testtype": "functional"}] |
Mbpp_300 | Write a function to find the count of all binary sequences of length 2n such that sum of first n bits is same as sum of last n bits. | 300 | mbpp | 0 | 2024-11-26T21:40:54.317974 | def count_binary_seq(n):
nCr = 1
res = 1
for r in range(1, n + 1):
nCr = (nCr * (n + 1 - r)) / r
res += nCr * nCr
return res | count_binary_seq | easy | [{"input": "1", "output": "2.0", "testtype": "functional"}] |
Mbpp_300 | Write a function to find the count of all binary sequences of length 2n such that sum of first n bits is same as sum of last n bits. | 300 | mbpp | 1 | 2024-11-26T21:40:54.319388 | def count_binary_seq(n):
nCr = 1
res = 1
for r in range(1, n + 1):
nCr = (nCr * (n + 1 - r)) / r
res += nCr * nCr
return res | count_binary_seq | easy | [{"input": "2", "output": "6.0", "testtype": "functional"}] |
Mbpp_300 | Write a function to find the count of all binary sequences of length 2n such that sum of first n bits is same as sum of last n bits. | 300 | mbpp | 2 | 2024-11-26T21:40:54.319673 | def count_binary_seq(n):
nCr = 1
res = 1
for r in range(1, n + 1):
nCr = (nCr * (n + 1 - r)) / r
res += nCr * nCr
return res | count_binary_seq | easy | [{"input": "3", "output": "20.0", "testtype": "functional"}] |
Mbpp_301 | Write a function to find the depth of a dictionary. | 301 | mbpp | 0 | 2024-11-26T21:40:54.319879 | def dict_depth(d):
if isinstance(d, dict):
return 1 + (max(map(dict_depth, d.values())) if d else 0)
return 0 | dict_depth | easy | [{"input": "{'a':1, 'b': {'c': {'d': {}}}}", "output": "4", "testtype": "functional"}] |
Mbpp_301 | Write a function to find the depth of a dictionary. | 301 | mbpp | 1 | 2024-11-26T21:40:54.320055 | def dict_depth(d):
if isinstance(d, dict):
return 1 + (max(map(dict_depth, d.values())) if d else 0)
return 0 | dict_depth | easy | [{"input": "{'a':1, 'b': {'c':'python'}}", "output": "2", "testtype": "functional"}] |
Mbpp_301 | Write a function to find the depth of a dictionary. | 301 | mbpp | 2 | 2024-11-26T21:40:54.320238 | def dict_depth(d):
if isinstance(d, dict):
return 1 + (max(map(dict_depth, d.values())) if d else 0)
return 0 | dict_depth | easy | [{"input": "{1: 'Sun', 2: {3: {4:'Mon'}}}", "output": "3", "testtype": "functional"}] |
Mbpp_302 | Write a python function to find the most significant bit number which is also a set bit. | 302 | mbpp | 0 | 2024-11-26T21:40:54.320516 | def set_Bit_Number(n):
if (n == 0):
return 0;
msb = 0;
n = int(n / 2);
while (n > 0):
n = int(n / 2);
msb += 1;
return (1 << msb) | set_Bit_Number | easy | [{"input": "6", "output": "4", "testtype": "functional"}] |
Mbpp_302 | Write a python function to find the most significant bit number which is also a set bit. | 302 | mbpp | 1 | 2024-11-26T21:40:54.320810 | def set_Bit_Number(n):
if (n == 0):
return 0;
msb = 0;
n = int(n / 2);
while (n > 0):
n = int(n / 2);
msb += 1;
return (1 << msb) | set_Bit_Number | easy | [{"input": "10", "output": "8", "testtype": "functional"}] |
Mbpp_302 | Write a python function to find the most significant bit number which is also a set bit. | 302 | mbpp | 2 | 2024-11-26T21:40:54.321077 | def set_Bit_Number(n):
if (n == 0):
return 0;
msb = 0;
n = int(n / 2);
while (n > 0):
n = int(n / 2);
msb += 1;
return (1 << msb) | set_Bit_Number | easy | [{"input": "18", "output": "16", "testtype": "functional"}] |
Mbpp_303 | Write a python function to check whether the count of inversion of two types are same or not. | 303 | mbpp | 0 | 2024-11-26T21:40:54.321573 | import sys
def solve(a,n):
mx = -sys.maxsize - 1
for j in range(1,n):
if (mx > a[j]):
return False
mx = max(mx,a[j - 1])
return True | solve | easy | [{"input": "[1,0,2],3", "output": "True", "testtype": "functional"}] |
Mbpp_303 | Write a python function to check whether the count of inversion of two types are same or not. | 303 | mbpp | 1 | 2024-11-26T21:40:54.321893 | import sys
def solve(a,n):
mx = -sys.maxsize - 1
for j in range(1,n):
if (mx > a[j]):
return False
mx = max(mx,a[j - 1])
return True | solve | easy | [{"input": "[1,2,0],3", "output": "False", "testtype": "functional"}] |
Mbpp_303 | Write a python function to check whether the count of inversion of two types are same or not. | 303 | mbpp | 2 | 2024-11-26T21:40:54.322166 | import sys
def solve(a,n):
mx = -sys.maxsize - 1
for j in range(1,n):
if (mx > a[j]):
return False
mx = max(mx,a[j - 1])
return True | solve | easy | [{"input": "[1,2,1],3", "output": "True", "testtype": "functional"}] |
Mbpp_304 | Write a python function to find element at a given index after number of rotations. | 304 | mbpp | 0 | 2024-11-26T21:40:54.322572 | def find_Element(arr,ranges,rotations,index) :
for i in range(rotations - 1,-1,-1 ) :
left = ranges[i][0]
right = ranges[i][1]
if (left <= index and right >= index) :
if (index == left) :
index = right
else :
index = in... | find_Element | easy | [{"input": "[1,2,3,4,5],[[0,2],[0,3]],2,1", "output": "3", "testtype": "functional"}] |
Mbpp_304 | Write a python function to find element at a given index after number of rotations. | 304 | mbpp | 1 | 2024-11-26T21:40:54.323164 | def find_Element(arr,ranges,rotations,index) :
for i in range(rotations - 1,-1,-1 ) :
left = ranges[i][0]
right = ranges[i][1]
if (left <= index and right >= index) :
if (index == left) :
index = right
else :
index = in... | find_Element | easy | [{"input": "[1,2,3,4],[[0,1],[0,2]],1,2", "output": "3", "testtype": "functional"}] |
Mbpp_304 | Write a python function to find element at a given index after number of rotations. | 304 | mbpp | 2 | 2024-11-26T21:40:54.323582 | def find_Element(arr,ranges,rotations,index) :
for i in range(rotations - 1,-1,-1 ) :
left = ranges[i][0]
right = ranges[i][1]
if (left <= index and right >= index) :
if (index == left) :
index = right
else :
index = in... | find_Element | easy | [{"input": "[1,2,3,4,5,6],[[0,1],[0,2]],1,1", "output": "1", "testtype": "functional"}] |
Mbpp_305 | Write a function to match two words from a list of words starting with letter 'p'. | 305 | mbpp | 0 | 2024-11-26T21:40:54.323869 | import re
def start_withp(words):
for w in words:
m = re.match("(P\w+)\W(P\w+)", w)
if m:
return m.groups() | start_withp | easy | [{"input": "[\"Python PHP\", \"Java JavaScript\", \"c c++\"]", "output": "('Python', 'PHP')", "testtype": "functional"}] |
Mbpp_305 | Write a function to match two words from a list of words starting with letter 'p'. | 305 | mbpp | 1 | 2024-11-26T21:40:54.324074 | import re
def start_withp(words):
for w in words:
m = re.match("(P\w+)\W(P\w+)", w)
if m:
return m.groups() | start_withp | easy | [{"input": "[\"Python Programming\",\"Java Programming\"]", "output": "('Python','Programming')", "testtype": "functional"}] |
Mbpp_305 | Write a function to match two words from a list of words starting with letter 'p'. | 305 | mbpp | 2 | 2024-11-26T21:40:54.324287 | import re
def start_withp(words):
for w in words:
m = re.match("(P\w+)\W(P\w+)", w)
if m:
return m.groups() | start_withp | easy | [{"input": "[\"Pqrst Pqr\",\"qrstuv\"]", "output": "('Pqrst','Pqr')", "testtype": "functional"}] |
Mbpp_306 | Write a function to find the maximum sum of increasing subsequence from prefix till ith index and also including a given kth element which is after i, i.e., k > i . | 306 | mbpp | 0 | 2024-11-26T21:40:54.325305 | def max_sum_increasing_subseq(a, n, index, k):
dp = [[0 for i in range(n)]
for i in range(n)]
for i in range(n):
if a[i] > a[0]:
dp[0][i] = a[i] + a[0]
else:
dp[0][i] = a[i]
for i in range(1, n):
for j in range(n):
if a[j] > a[i] and j > i:
if dp[i - 1][i] + a[j] > dp[i - 1][j]:
... | max_sum_increasing_subseq | easy | [{"input": "[1, 101, 2, 3, 100, 4, 5 ], 7, 4, 6", "output": "11", "testtype": "functional"}] |
Mbpp_306 | Write a function to find the maximum sum of increasing subsequence from prefix till ith index and also including a given kth element which is after i, i.e., k > i . | 306 | mbpp | 1 | 2024-11-26T21:40:54.326232 | def max_sum_increasing_subseq(a, n, index, k):
dp = [[0 for i in range(n)]
for i in range(n)]
for i in range(n):
if a[i] > a[0]:
dp[0][i] = a[i] + a[0]
else:
dp[0][i] = a[i]
for i in range(1, n):
for j in range(n):
if a[j] > a[i] and j > i:
if dp[i - 1][i] + a[j] > dp[i - 1][j]:
... | max_sum_increasing_subseq | easy | [{"input": "[1, 101, 2, 3, 100, 4, 5 ], 7, 2, 5", "output": "7", "testtype": "functional"}] |
Mbpp_306 | Write a function to find the maximum sum of increasing subsequence from prefix till ith index and also including a given kth element which is after i, i.e., k > i . | 306 | mbpp | 2 | 2024-11-26T21:40:54.327103 | def max_sum_increasing_subseq(a, n, index, k):
dp = [[0 for i in range(n)]
for i in range(n)]
for i in range(n):
if a[i] > a[0]:
dp[0][i] = a[i] + a[0]
else:
dp[0][i] = a[i]
for i in range(1, n):
for j in range(n):
if a[j] > a[i] and j > i:
if dp[i - 1][i] + a[j] > dp[i - 1][j]:
... | max_sum_increasing_subseq | easy | [{"input": "[11, 15, 19, 21, 26, 28, 31], 7, 2, 4", "output": "71", "testtype": "functional"}] |
Mbpp_307 | Write a function to get a colon of a tuple. | 307 | mbpp | 0 | 2024-11-26T21:40:54.327332 | from copy import deepcopy
def colon_tuplex(tuplex,m,n):
tuplex_colon = deepcopy(tuplex)
tuplex_colon[m].append(n)
return tuplex_colon | colon_tuplex | easy | [{"input": "(\"HELLO\", 5, [], True) ,2,50", "output": "(\"HELLO\", 5, [50], True)", "testtype": "functional"}] |
Mbpp_307 | Write a function to get a colon of a tuple. | 307 | mbpp | 1 | 2024-11-26T21:40:54.327502 | from copy import deepcopy
def colon_tuplex(tuplex,m,n):
tuplex_colon = deepcopy(tuplex)
tuplex_colon[m].append(n)
return tuplex_colon | colon_tuplex | easy | [{"input": "(\"HELLO\", 5, [], True) ,2,100", "output": "((\"HELLO\", 5, [100],True))", "testtype": "functional"}] |
Mbpp_307 | Write a function to get a colon of a tuple. | 307 | mbpp | 2 | 2024-11-26T21:40:54.327689 | from copy import deepcopy
def colon_tuplex(tuplex,m,n):
tuplex_colon = deepcopy(tuplex)
tuplex_colon[m].append(n)
return tuplex_colon | colon_tuplex | easy | [{"input": "(\"HELLO\", 5, [], True) ,2,500", "output": "(\"HELLO\", 5, [500], True)", "testtype": "functional"}] |
Mbpp_308 | Write a function to find the specified number of largest products from two given lists. | 308 | mbpp | 0 | 2024-11-26T21:40:54.327909 | def large_product(nums1, nums2, N):
result = sorted([x*y for x in nums1 for y in nums2], reverse=True)[:N]
return result | large_product | easy | [{"input": "[1, 2, 3, 4, 5, 6],[3, 6, 8, 9, 10, 6],3", "output": "[60, 54, 50]", "testtype": "functional"}] |
Mbpp_308 | Write a function to find the specified number of largest products from two given lists. | 308 | mbpp | 1 | 2024-11-26T21:40:54.328115 | def large_product(nums1, nums2, N):
result = sorted([x*y for x in nums1 for y in nums2], reverse=True)[:N]
return result | large_product | easy | [{"input": "[1, 2, 3, 4, 5, 6],[3, 6, 8, 9, 10, 6],4", "output": "[60, 54, 50, 48]", "testtype": "functional"}] |
Mbpp_308 | Write a function to find the specified number of largest products from two given lists. | 308 | mbpp | 2 | 2024-11-26T21:40:54.328306 | def large_product(nums1, nums2, N):
result = sorted([x*y for x in nums1 for y in nums2], reverse=True)[:N]
return result | large_product | easy | [{"input": "[1, 2, 3, 4, 5, 6],[3, 6, 8, 9, 10, 6],5", "output": "[60, 54, 50, 48, 45]", "testtype": "functional"}] |
Mbpp_309 | Write a python function to find the maximum of two numbers. | 309 | mbpp | 0 | 2024-11-26T21:40:54.328430 | def maximum(a,b):
if a >= b:
return a
else:
return b | maximum | easy | [{"input": "5,10", "output": "10", "testtype": "functional"}] |
Mbpp_309 | Write a python function to find the maximum of two numbers. | 309 | mbpp | 1 | 2024-11-26T21:40:54.328543 | def maximum(a,b):
if a >= b:
return a
else:
return b | maximum | easy | [{"input": "-1,-2", "output": "-1", "testtype": "functional"}] |
Mbpp_309 | Write a python function to find the maximum of two numbers. | 309 | mbpp | 2 | 2024-11-26T21:40:54.328665 | def maximum(a,b):
if a >= b:
return a
else:
return b | maximum | easy | [{"input": "9,7", "output": "9", "testtype": "functional"}] |
Mbpp_310 | Write a function to convert a given string to a tuple. | 310 | mbpp | 0 | 2024-11-26T21:40:54.328827 | def string_to_tuple(str1):
result = tuple(x for x in str1 if not x.isspace())
return result | string_to_tuple | easy | [{"input": "\"python 3.0\"", "output": "('p', 'y', 't', 'h', 'o', 'n', '3', '.', '0')", "testtype": "functional"}] |
Mbpp_310 | Write a function to convert a given string to a tuple. | 310 | mbpp | 1 | 2024-11-26T21:40:54.328970 | def string_to_tuple(str1):
result = tuple(x for x in str1 if not x.isspace())
return result | string_to_tuple | easy | [{"input": "\"item1\"", "output": "('i', 't', 'e', 'm', '1')", "testtype": "functional"}] |
Mbpp_310 | Write a function to convert a given string to a tuple. | 310 | mbpp | 2 | 2024-11-26T21:40:54.329126 | def string_to_tuple(str1):
result = tuple(x for x in str1 if not x.isspace())
return result | string_to_tuple | easy | [{"input": "\"15.10\"", "output": "('1', '5', '.', '1', '0')", "testtype": "functional"}] |
Mbpp_311 | Write a python function to set the left most unset bit. | 311 | mbpp | 0 | 2024-11-26T21:40:54.329437 | def set_left_most_unset_bit(n):
if not (n & (n + 1)):
return n
pos, temp, count = 0, n, 0
while temp:
if not (temp & 1):
pos = count
count += 1; temp>>=1
return (n | (1 << (pos))) | set_left_most_unset_bit | easy | [{"input": "10", "output": "14", "testtype": "functional"}] |
Mbpp_311 | Write a python function to set the left most unset bit. | 311 | mbpp | 1 | 2024-11-26T21:40:54.329768 | def set_left_most_unset_bit(n):
if not (n & (n + 1)):
return n
pos, temp, count = 0, n, 0
while temp:
if not (temp & 1):
pos = count
count += 1; temp>>=1
return (n | (1 << (pos))) | set_left_most_unset_bit | easy | [{"input": "12", "output": "14", "testtype": "functional"}] |
Mbpp_311 | Write a python function to set the left most unset bit. | 311 | mbpp | 2 | 2024-11-26T21:40:54.330065 | def set_left_most_unset_bit(n):
if not (n & (n + 1)):
return n
pos, temp, count = 0, n, 0
while temp:
if not (temp & 1):
pos = count
count += 1; temp>>=1
return (n | (1 << (pos))) | set_left_most_unset_bit | easy | [{"input": "15", "output": "15", "testtype": "functional"}] |
Mbpp_312 | Write a function to find the volume of a cone. | 312 | mbpp | 0 | 2024-11-26T21:40:54.330267 | import math
def volume_cone(r,h):
volume = (1.0/3) * math.pi * r * r * h
return volume | volume_cone | easy | [{"input": "5,12", "output": "314.15926535897927", "testtype": "functional"}] |
Mbpp_312 | Write a function to find the volume of a cone. | 312 | mbpp | 1 | 2024-11-26T21:40:54.330421 | import math
def volume_cone(r,h):
volume = (1.0/3) * math.pi * r * r * h
return volume | volume_cone | easy | [{"input": "10,15", "output": "1570.7963267948965", "testtype": "functional"}] |
Mbpp_312 | Write a function to find the volume of a cone. | 312 | mbpp | 2 | 2024-11-26T21:40:54.330580 | import math
def volume_cone(r,h):
volume = (1.0/3) * math.pi * r * r * h
return volume | volume_cone | easy | [{"input": "19,17", "output": "6426.651371693521", "testtype": "functional"}] |
Mbpp_313 | Write a python function to print positive numbers in a list. | 313 | mbpp | 0 | 2024-11-26T21:40:54.330753 | def pos_nos(list1):
for num in list1:
if num >= 0:
return num | pos_nos | easy | [{"input": "[-1,-2,1,2]", "output": "1,2", "testtype": "functional"}] |
Mbpp_313 | Write a python function to print positive numbers in a list. | 313 | mbpp | 1 | 2024-11-26T21:40:54.330869 | def pos_nos(list1):
for num in list1:
if num >= 0:
return num | pos_nos | easy | [{"input": "[3,4,-5]", "output": "3,4", "testtype": "functional"}] |
Mbpp_313 | Write a python function to print positive numbers in a list. | 313 | mbpp | 2 | 2024-11-26T21:40:54.330977 | def pos_nos(list1):
for num in list1:
if num >= 0:
return num | pos_nos | easy | [{"input": "[-2,-3,1]", "output": "1", "testtype": "functional"}] |
Mbpp_314 | Write a function to find out the maximum sum such that no two chosen numbers are adjacent for the given rectangular grid of dimension 2 x n. | 314 | mbpp | 0 | 2024-11-26T21:40:54.331374 | def max_sum_rectangular_grid(grid, n) :
incl = max(grid[0][0], grid[1][0])
excl = 0
for i in range(1, n) :
excl_new = max(excl, incl)
incl = excl + max(grid[0][i], grid[1][i])
excl = excl_new
return max(excl, incl) | max_sum_rectangular_grid | easy | [{"input": "[ [1, 4, 5], [2, 0, 0 ] ], 3", "output": "7", "testtype": "functional"}] |
Mbpp_314 | Write a function to find out the maximum sum such that no two chosen numbers are adjacent for the given rectangular grid of dimension 2 x n. | 314 | mbpp | 1 | 2024-11-26T21:40:54.332264 | def max_sum_rectangular_grid(grid, n) :
incl = max(grid[0][0], grid[1][0])
excl = 0
for i in range(1, n) :
excl_new = max(excl, incl)
incl = excl + max(grid[0][i], grid[1][i])
excl = excl_new
return max(excl, incl) | max_sum_rectangular_grid | easy | [{"input": "[ [ 1, 2, 3, 4, 5], [ 6, 7, 8, 9, 10] ], 5", "output": "24", "testtype": "functional"}] |
Mbpp_314 | Write a function to find out the maximum sum such that no two chosen numbers are adjacent for the given rectangular grid of dimension 2 x n. | 314 | mbpp | 2 | 2024-11-26T21:40:54.332763 | def max_sum_rectangular_grid(grid, n) :
incl = max(grid[0][0], grid[1][0])
excl = 0
for i in range(1, n) :
excl_new = max(excl, incl)
incl = excl + max(grid[0][i], grid[1][i])
excl = excl_new
return max(excl, incl) | max_sum_rectangular_grid | easy | [{"input": "[ [7, 9, 11, 15, 19], [21, 25, 28, 31, 32] ], 5", "output": "81", "testtype": "functional"}] |
Mbpp_315 | Write a python function to find the first maximum length of even word. | 315 | mbpp | 0 | 2024-11-26T21:40:54.333406 | def find_Max_Len_Even(str):
n = len(str)
i = 0
currlen = 0
maxlen = 0
st = -1
while (i < n):
if (str[i] == ' '):
if (currlen % 2 == 0):
if (maxlen < currlen):
maxlen = currlen
st = i - currlen
... | find_Max_Len_Even | easy | [{"input": "\"python language\"", "output": "\"language\"", "testtype": "functional"}] |
Mbpp_315 | Write a python function to find the first maximum length of even word. | 315 | mbpp | 1 | 2024-11-26T21:40:54.334032 | def find_Max_Len_Even(str):
n = len(str)
i = 0
currlen = 0
maxlen = 0
st = -1
while (i < n):
if (str[i] == ' '):
if (currlen % 2 == 0):
if (maxlen < currlen):
maxlen = currlen
st = i - currlen
... | find_Max_Len_Even | easy | [{"input": "\"maximum even length\"", "output": "\"length\"", "testtype": "functional"}] |
Mbpp_315 | Write a python function to find the first maximum length of even word. | 315 | mbpp | 2 | 2024-11-26T21:40:54.334788 | def find_Max_Len_Even(str):
n = len(str)
i = 0
currlen = 0
maxlen = 0
st = -1
while (i < n):
if (str[i] == ' '):
if (currlen % 2 == 0):
if (maxlen < currlen):
maxlen = currlen
st = i - currlen
... | find_Max_Len_Even | easy | [{"input": "\"eve\"", "output": "\"-1\"", "testtype": "functional"}] |
Mbpp_316 | Write a function to find the index of the last occurrence of a given number in a sorted array. | 316 | mbpp | 0 | 2024-11-26T21:40:54.335405 | def find_last_occurrence(A, x):
(left, right) = (0, len(A) - 1)
result = -1
while left <= right:
mid = (left + right) // 2
if x == A[mid]:
result = mid
left = mid + 1
elif x < A[mid]:
right = mid - 1
else:
left = mid ... | find_last_occurrence | easy | [{"input": "[2, 5, 5, 5, 6, 6, 8, 9, 9, 9], 5", "output": "3", "testtype": "functional"}] |
Mbpp_316 | Write a function to find the index of the last occurrence of a given number in a sorted array. | 316 | mbpp | 1 | 2024-11-26T21:40:54.335889 | def find_last_occurrence(A, x):
(left, right) = (0, len(A) - 1)
result = -1
while left <= right:
mid = (left + right) // 2
if x == A[mid]:
result = mid
left = mid + 1
elif x < A[mid]:
right = mid - 1
else:
left = mid ... | find_last_occurrence | easy | [{"input": "[2, 3, 5, 8, 6, 6, 8, 9, 9, 9], 9", "output": "9", "testtype": "functional"}] |
Mbpp_316 | Write a function to find the index of the last occurrence of a given number in a sorted array. | 316 | mbpp | 2 | 2024-11-26T21:40:54.336339 | def find_last_occurrence(A, x):
(left, right) = (0, len(A) - 1)
result = -1
while left <= right:
mid = (left + right) // 2
if x == A[mid]:
result = mid
left = mid + 1
elif x < A[mid]:
right = mid - 1
else:
left = mid ... | find_last_occurrence | easy | [{"input": "[2, 2, 1, 5, 6, 6, 6, 9, 9, 9], 6", "output": "6", "testtype": "functional"}] |
Mbpp_318 | Write a python function to find the maximum volume of a cuboid with given sum of sides. | 318 | mbpp | 0 | 2024-11-26T21:40:54.337193 | def max_volume (s):
maxvalue = 0
i = 1
for i in range(s - 1):
j = 1
for j in range(s):
k = s - i - j
maxvalue = max(maxvalue, i * j * k)
return maxvalue | max_volume | easy | [{"input": "8", "output": "18", "testtype": "functional"}] |
Mbpp_318 | Write a python function to find the maximum volume of a cuboid with given sum of sides. | 318 | mbpp | 1 | 2024-11-26T21:40:54.337483 | def max_volume (s):
maxvalue = 0
i = 1
for i in range(s - 1):
j = 1
for j in range(s):
k = s - i - j
maxvalue = max(maxvalue, i * j * k)
return maxvalue | max_volume | easy | [{"input": "4", "output": "2", "testtype": "functional"}] |
Mbpp_318 | Write a python function to find the maximum volume of a cuboid with given sum of sides. | 318 | mbpp | 2 | 2024-11-26T21:40:54.337786 | def max_volume (s):
maxvalue = 0
i = 1
for i in range(s - 1):
j = 1
for j in range(s):
k = s - i - j
maxvalue = max(maxvalue, i * j * k)
return maxvalue | max_volume | easy | [{"input": "1", "output": "0", "testtype": "functional"}] |
Mbpp_319 | Write a function to find all five characters long word in the given string by using regex. | 319 | mbpp | 0 | 2024-11-26T21:40:54.337923 | import re
def find_long_word(text):
return (re.findall(r"\b\w{5}\b", text)) | find_long_word | easy | [{"input": "'Please move back to strem'", "output": "['strem']", "testtype": "functional"}] |
Mbpp_319 | Write a function to find all five characters long word in the given string by using regex. | 319 | mbpp | 1 | 2024-11-26T21:40:54.338029 | import re
def find_long_word(text):
return (re.findall(r"\b\w{5}\b", text)) | find_long_word | easy | [{"input": "'4K Ultra HD streaming player'", "output": "['Ultra']", "testtype": "functional"}] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.