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_496 | Write a function to find the smallest integers from a given list of numbers using heap queue algorithm. | 496 | mbpp | 1 | 2024-11-26T21:40:54.480435 | import heapq as hq
def heap_queue_smallest(nums,n):
smallest_nums = hq.nsmallest(n, nums)
return smallest_nums | heap_queue_smallest | easy | [{"input": " [25, 35, 22, 85, 14, 65, 75, 25, 58],2", "output": "[14, 22]", "testtype": "functional"}] |
Mbpp_496 | Write a function to find the smallest integers from a given list of numbers using heap queue algorithm. | 496 | mbpp | 2 | 2024-11-26T21:40:54.480569 | import heapq as hq
def heap_queue_smallest(nums,n):
smallest_nums = hq.nsmallest(n, nums)
return smallest_nums | heap_queue_smallest | easy | [{"input": " [25, 35, 22, 85, 14, 65, 75, 22, 58],5", "output": "[14, 22, 22, 25, 35]", "testtype": "functional"}] |
Mbpp_497 | Write a function to find the surface area of a cone. | 497 | mbpp | 0 | 2024-11-26T21:40:54.480803 | import math
def surfacearea_cone(r,h):
l = math.sqrt(r * r + h * h)
SA = math.pi * r * (r + l)
return SA | surfacearea_cone | easy | [{"input": "5,12", "output": "282.7433388230814", "testtype": "functional"}] |
Mbpp_497 | Write a function to find the surface area of a cone. | 497 | mbpp | 1 | 2024-11-26T21:40:54.481009 | import math
def surfacearea_cone(r,h):
l = math.sqrt(r * r + h * h)
SA = math.pi * r * (r + l)
return SA | surfacearea_cone | easy | [{"input": "10,15", "output": "880.5179353159282", "testtype": "functional"}] |
Mbpp_497 | Write a function to find the surface area of a cone. | 497 | mbpp | 2 | 2024-11-26T21:40:54.481266 | import math
def surfacearea_cone(r,h):
l = math.sqrt(r * r + h * h)
SA = math.pi * r * (r + l)
return SA | surfacearea_cone | easy | [{"input": "19,17", "output": "2655.923961165254", "testtype": "functional"}] |
Mbpp_498 | Write a python function to find gcd of two positive integers. | 498 | mbpp | 0 | 2024-11-26T21:40:54.481614 | def gcd(x, y):
gcd = 1
if x % y == 0:
return y
for k in range(int(y / 2), 0, -1):
if x % k == 0 and y % k == 0:
gcd = k
break
return gcd | gcd | easy | [{"input": "12, 17", "output": "1", "testtype": "functional"}] |
Mbpp_498 | Write a python function to find gcd of two positive integers. | 498 | mbpp | 1 | 2024-11-26T21:40:54.481924 | def gcd(x, y):
gcd = 1
if x % y == 0:
return y
for k in range(int(y / 2), 0, -1):
if x % k == 0 and y % k == 0:
gcd = k
break
return gcd | gcd | easy | [{"input": "4,6", "output": "2", "testtype": "functional"}] |
Mbpp_498 | Write a python function to find gcd of two positive integers. | 498 | mbpp | 2 | 2024-11-26T21:40:54.482230 | def gcd(x, y):
gcd = 1
if x % y == 0:
return y
for k in range(int(y / 2), 0, -1):
if x % k == 0 and y % k == 0:
gcd = k
break
return gcd | gcd | easy | [{"input": "2,9", "output": "1", "testtype": "functional"}] |
Mbpp_499 | Write a function to find the diameter of a circle. | 499 | mbpp | 0 | 2024-11-26T21:40:54.482350 | def diameter_circle(r):
diameter=2*r
return diameter | diameter_circle | easy | [{"input": "10", "output": "20", "testtype": "functional"}] |
Mbpp_499 | Write a function to find the diameter of a circle. | 499 | mbpp | 1 | 2024-11-26T21:40:54.482444 | def diameter_circle(r):
diameter=2*r
return diameter | diameter_circle | easy | [{"input": "40", "output": "80", "testtype": "functional"}] |
Mbpp_499 | Write a function to find the diameter of a circle. | 499 | mbpp | 2 | 2024-11-26T21:40:54.482538 | def diameter_circle(r):
diameter=2*r
return diameter | diameter_circle | easy | [{"input": "15", "output": "30", "testtype": "functional"}] |
Mbpp_500 | Write a function to concatenate all elements of the given list into a string. | 500 | mbpp | 0 | 2024-11-26T21:40:54.482710 | def concatenate_elements(list):
ans = ' '
for i in list:
ans = ans+ ' '+i
return (ans) | concatenate_elements | easy | [{"input": "['hello','there','have','a','rocky','day'] ", "output": "' hello there have a rocky day'", "testtype": "functional"}] |
Mbpp_500 | Write a function to concatenate all elements of the given list into a string. | 500 | mbpp | 1 | 2024-11-26T21:40:54.482866 | def concatenate_elements(list):
ans = ' '
for i in list:
ans = ans+ ' '+i
return (ans) | concatenate_elements | easy | [{"input": "[ 'Hi', 'there', 'How','are', 'you'] ", "output": "' Hi there How are you'", "testtype": "functional"}] |
Mbpp_500 | Write a function to concatenate all elements of the given list into a string. | 500 | mbpp | 2 | 2024-11-26T21:40:54.483032 | def concatenate_elements(list):
ans = ' '
for i in list:
ans = ans+ ' '+i
return (ans) | concatenate_elements | easy | [{"input": "[ 'Part', 'of', 'the','journey', 'is', 'end'] ", "output": "' Part of the journey is end'", "testtype": "functional"}] |
Mbpp_502 | Write a python function to find remainder of two numbers. | 502 | mbpp | 0 | 2024-11-26T21:40:54.483856 | def find(n,m):
r = n%m
return (r) | find | easy | [{"input": "3,3", "output": "0", "testtype": "functional"}] |
Mbpp_502 | Write a python function to find remainder of two numbers. | 502 | mbpp | 1 | 2024-11-26T21:40:54.483949 | def find(n,m):
r = n%m
return (r) | find | easy | [{"input": "10,3", "output": "1", "testtype": "functional"}] |
Mbpp_502 | Write a python function to find remainder of two numbers. | 502 | mbpp | 2 | 2024-11-26T21:40:54.484026 | def find(n,m):
r = n%m
return (r) | find | easy | [{"input": "16,5", "output": "1", "testtype": "functional"}] |
Mbpp_503 | Write a function to add consecutive numbers of a given list. | 503 | mbpp | 0 | 2024-11-26T21:40:54.484704 | def add_consecutive_nums(nums):
result = [b+a for a, b in zip(nums[:-1], nums[1:])]
return result | add_consecutive_nums | easy | [{"input": "[1, 1, 3, 4, 4, 5, 6, 7]", "output": "[2, 4, 7, 8, 9, 11, 13]", "testtype": "functional"}] |
Mbpp_503 | Write a function to add consecutive numbers of a given list. | 503 | mbpp | 1 | 2024-11-26T21:40:54.484957 | def add_consecutive_nums(nums):
result = [b+a for a, b in zip(nums[:-1], nums[1:])]
return result | add_consecutive_nums | easy | [{"input": "[4, 5, 8, 9, 6, 10]", "output": "[9, 13, 17, 15, 16]", "testtype": "functional"}] |
Mbpp_503 | Write a function to add consecutive numbers of a given list. | 503 | mbpp | 2 | 2024-11-26T21:40:54.485187 | def add_consecutive_nums(nums):
result = [b+a for a, b in zip(nums[:-1], nums[1:])]
return result | add_consecutive_nums | easy | [{"input": "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]", "output": "[3, 5, 7, 9, 11, 13, 15, 17, 19]", "testtype": "functional"}] |
Mbpp_504 | Write a python function to find the cube sum of first n natural numbers. | 504 | mbpp | 0 | 2024-11-26T21:40:54.485370 | def sum_Of_Series(n):
sum = 0
for i in range(1,n + 1):
sum += i * i*i
return sum | sum_Of_Series | easy | [{"input": "5", "output": "225", "testtype": "functional"}] |
Mbpp_504 | Write a python function to find the cube sum of first n natural numbers. | 504 | mbpp | 1 | 2024-11-26T21:40:54.485516 | def sum_Of_Series(n):
sum = 0
for i in range(1,n + 1):
sum += i * i*i
return sum | sum_Of_Series | easy | [{"input": "2", "output": "9", "testtype": "functional"}] |
Mbpp_504 | Write a python function to find the cube sum of first n natural numbers. | 504 | mbpp | 2 | 2024-11-26T21:40:54.485679 | def sum_Of_Series(n):
sum = 0
for i in range(1,n + 1):
sum += i * i*i
return sum | sum_Of_Series | easy | [{"input": "3", "output": "36", "testtype": "functional"}] |
Mbpp_505 | Write a function to move all zeroes to the end of the given array. | 505 | mbpp | 0 | 2024-11-26T21:40:54.485897 | def re_order(A):
k = 0
for i in A:
if i:
A[k] = i
k = k + 1
for i in range(k, len(A)):
A[i] = 0
return A | re_order | easy | [{"input": "[6, 0, 8, 2, 3, 0, 4, 0, 1]", "output": "[6, 8, 2, 3, 4, 1, 0, 0, 0]", "testtype": "functional"}] |
Mbpp_505 | Write a function to move all zeroes to the end of the given array. | 505 | mbpp | 1 | 2024-11-26T21:40:54.486614 | def re_order(A):
k = 0
for i in A:
if i:
A[k] = i
k = k + 1
for i in range(k, len(A)):
A[i] = 0
return A | re_order | easy | [{"input": "[4, 0, 2, 7, 0, 9, 0, 12, 0]", "output": "[4, 2, 7, 9, 12, 0, 0, 0, 0]", "testtype": "functional"}] |
Mbpp_505 | Write a function to move all zeroes to the end of the given array. | 505 | mbpp | 2 | 2024-11-26T21:40:54.486916 | def re_order(A):
k = 0
for i in A:
if i:
A[k] = i
k = k + 1
for i in range(k, len(A)):
A[i] = 0
return A | re_order | easy | [{"input": "[3, 11, 0, 74, 14, 0, 1, 0, 2]", "output": "[3, 11, 74, 14, 1, 2, 0, 0, 0]", "testtype": "functional"}] |
Mbpp_506 | Write a function to calculate the permutation coefficient of given p(n, k). | 506 | mbpp | 0 | 2024-11-26T21:40:54.487601 | def permutation_coefficient(n, k):
P = [[0 for i in range(k + 1)]
for j in range(n + 1)]
for i in range(n + 1):
for j in range(min(i, k) + 1):
if (j == 0):
P[i][j] = 1
else:
P[i][j] = P[i - 1][j] + (
j * P[i - 1][j - 1])
if (j < k):
P[i][j + 1] = 0
return P[n][k] | permutation_coefficient | easy | [{"input": "10, 2", "output": "90", "testtype": "functional"}] |
Mbpp_506 | Write a function to calculate the permutation coefficient of given p(n, k). | 506 | mbpp | 1 | 2024-11-26T21:40:54.488175 | def permutation_coefficient(n, k):
P = [[0 for i in range(k + 1)]
for j in range(n + 1)]
for i in range(n + 1):
for j in range(min(i, k) + 1):
if (j == 0):
P[i][j] = 1
else:
P[i][j] = P[i - 1][j] + (
j * P[i - 1][j - 1])
if (j < k):
P[i][j + 1] = 0
return P[n][k] | permutation_coefficient | easy | [{"input": "10, 3", "output": "720", "testtype": "functional"}] |
Mbpp_506 | Write a function to calculate the permutation coefficient of given p(n, k). | 506 | mbpp | 2 | 2024-11-26T21:40:54.488794 | def permutation_coefficient(n, k):
P = [[0 for i in range(k + 1)]
for j in range(n + 1)]
for i in range(n + 1):
for j in range(min(i, k) + 1):
if (j == 0):
P[i][j] = 1
else:
P[i][j] = P[i - 1][j] + (
j * P[i - 1][j - 1])
if (j < k):
P[i][j + 1] = 0
return P[n][k] | permutation_coefficient | easy | [{"input": "10, 1", "output": "10", "testtype": "functional"}] |
Mbpp_507 | Write a function to remove specific words from a given list. | 507 | mbpp | 0 | 2024-11-26T21:40:54.489017 | def remove_words(list1, removewords):
for word in list(list1):
if word in removewords:
list1.remove(word)
return list1 | remove_words | easy | [{"input": "['red', 'green', 'blue', 'white', 'black', 'orange'],['white', 'orange']", "output": "['red', 'green', 'blue', 'black']", "testtype": "functional"}] |
Mbpp_507 | Write a function to remove specific words from a given list. | 507 | mbpp | 1 | 2024-11-26T21:40:54.489196 | def remove_words(list1, removewords):
for word in list(list1):
if word in removewords:
list1.remove(word)
return list1 | remove_words | easy | [{"input": "['red', 'green', 'blue', 'white', 'black', 'orange'],['black', 'orange']", "output": "['red', 'green', 'blue', 'white']", "testtype": "functional"}] |
Mbpp_507 | Write a function to remove specific words from a given list. | 507 | mbpp | 2 | 2024-11-26T21:40:54.489363 | def remove_words(list1, removewords):
for word in list(list1):
if word in removewords:
list1.remove(word)
return list1 | remove_words | easy | [{"input": "['red', 'green', 'blue', 'white', 'black', 'orange'],['blue', 'white']", "output": "['red', 'green', 'black', 'orange']", "testtype": "functional"}] |
Mbpp_508 | Write a function to check if the common elements between two given lists are in the same order or not. | 508 | mbpp | 0 | 2024-11-26T21:40:54.489784 | def same_order(l1, l2):
common_elements = set(l1) & set(l2)
l1 = [e for e in l1 if e in common_elements]
l2 = [e for e in l2 if e in common_elements]
return l1 == l2 | same_order | easy | [{"input": "[\"red\",\"green\",\"black\",\"orange\"],[\"red\",\"pink\",\"green\",\"white\",\"black\"]", "output": "True", "testtype": "functional"}] |
Mbpp_508 | Write a function to check if the common elements between two given lists are in the same order or not. | 508 | mbpp | 1 | 2024-11-26T21:40:54.490090 | def same_order(l1, l2):
common_elements = set(l1) & set(l2)
l1 = [e for e in l1 if e in common_elements]
l2 = [e for e in l2 if e in common_elements]
return l1 == l2 | same_order | easy | [{"input": "[\"red\",\"pink\",\"green\",\"white\",\"black\"],[\"white\",\"orange\",\"pink\",\"black\"]", "output": "False", "testtype": "functional"}] |
Mbpp_508 | Write a function to check if the common elements between two given lists are in the same order or not. | 508 | mbpp | 2 | 2024-11-26T21:40:54.491566 | def same_order(l1, l2):
common_elements = set(l1) & set(l2)
l1 = [e for e in l1 if e in common_elements]
l2 = [e for e in l2 if e in common_elements]
return l1 == l2 | same_order | easy | [{"input": "[\"red\",\"green\",\"black\",\"orange\"],[\"red\",\"pink\",\"green\",\"white\",\"black\"]", "output": "True", "testtype": "functional"}] |
Mbpp_509 | Write a python function to find the average of odd numbers till a given odd number. | 509 | mbpp | 0 | 2024-11-26T21:40:54.491917 | def average_Odd(n) :
if (n%2==0) :
return ("Invalid Input")
return -1
sm =0
count =0
while (n>=1) :
count=count+1
sm = sm + n
n = n-2
return sm//count | average_Odd | easy | [{"input": "9", "output": "5", "testtype": "functional"}] |
Mbpp_509 | Write a python function to find the average of odd numbers till a given odd number. | 509 | mbpp | 1 | 2024-11-26T21:40:54.492203 | def average_Odd(n) :
if (n%2==0) :
return ("Invalid Input")
return -1
sm =0
count =0
while (n>=1) :
count=count+1
sm = sm + n
n = n-2
return sm//count | average_Odd | easy | [{"input": "5", "output": "3", "testtype": "functional"}] |
Mbpp_509 | Write a python function to find the average of odd numbers till a given odd number. | 509 | mbpp | 2 | 2024-11-26T21:40:54.492483 | def average_Odd(n) :
if (n%2==0) :
return ("Invalid Input")
return -1
sm =0
count =0
while (n>=1) :
count=count+1
sm = sm + n
n = n-2
return sm//count | average_Odd | easy | [{"input": "11", "output": "6", "testtype": "functional"}] |
Mbpp_510 | Write a function to find the number of subsequences having product smaller than k for the given non negative array. | 510 | mbpp | 0 | 2024-11-26T21:40:54.493090 | def no_of_subsequences(arr, k):
n = len(arr)
dp = [[0 for i in range(n + 1)]
for j in range(k + 1)]
for i in range(1, k + 1):
for j in range(1, n + 1):
dp[i][j] = dp[i][j - 1]
if arr[j - 1] <= i and arr[j - 1] > 0:
dp[i][j] += dp[i // arr[j - 1]][j - 1] + 1
return dp[k][n] | no_of_subsequences | easy | [{"input": "[1,2,3,4], 10", "output": "11", "testtype": "functional"}] |
Mbpp_510 | Write a function to find the number of subsequences having product smaller than k for the given non negative array. | 510 | mbpp | 1 | 2024-11-26T21:40:54.493687 | def no_of_subsequences(arr, k):
n = len(arr)
dp = [[0 for i in range(n + 1)]
for j in range(k + 1)]
for i in range(1, k + 1):
for j in range(1, n + 1):
dp[i][j] = dp[i][j - 1]
if arr[j - 1] <= i and arr[j - 1] > 0:
dp[i][j] += dp[i // arr[j - 1]][j - 1] + 1
return dp[k][n] | no_of_subsequences | easy | [{"input": "[4,8,7,2], 50", "output": "9", "testtype": "functional"}] |
Mbpp_510 | Write a function to find the number of subsequences having product smaller than k for the given non negative array. | 510 | mbpp | 2 | 2024-11-26T21:40:54.494248 | def no_of_subsequences(arr, k):
n = len(arr)
dp = [[0 for i in range(n + 1)]
for j in range(k + 1)]
for i in range(1, k + 1):
for j in range(1, n + 1):
dp[i][j] = dp[i][j - 1]
if arr[j - 1] <= i and arr[j - 1] > 0:
dp[i][j] += dp[i // arr[j - 1]][j - 1] + 1
return dp[k][n] | no_of_subsequences | easy | [{"input": "[5,6,7,8], 15", "output": "4", "testtype": "functional"}] |