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_217
Write a python function to find the first repeated character in a given string.
217
mbpp
1
2024-11-26T21:40:54.242272
def first_Repeated_Char(str): h = {} for ch in str: if ch in h: return ch; else: h[ch] = 0 return '\0'
first_Repeated_Char
easy
[{"input": "\"data\"", "output": "\"a\"", "testtype": "functional"}]
Mbpp_217
Write a python function to find the first repeated character in a given string.
217
mbpp
2
2024-11-26T21:40:54.242452
def first_Repeated_Char(str): h = {} for ch in str: if ch in h: return ch; else: h[ch] = 0 return '\0'
first_Repeated_Char
easy
[{"input": "\"python\"", "output": "'\\0'", "testtype": "functional"}]
Mbpp_218
Write a python function to find the minimum operations required to make two numbers equal.
218
mbpp
0
2024-11-26T21:40:54.242701
import math def min_Operations(A,B): if (A > B): swap(A,B) B = B // math.gcd(A,B); return B - 1
min_Operations
easy
[{"input": "2,4", "output": "1", "testtype": "functional"}]
Mbpp_218
Write a python function to find the minimum operations required to make two numbers equal.
218
mbpp
1
2024-11-26T21:40:54.242906
import math def min_Operations(A,B): if (A > B): swap(A,B) B = B // math.gcd(A,B); return B - 1
min_Operations
easy
[{"input": "4,10", "output": "4", "testtype": "functional"}]
Mbpp_218
Write a python function to find the minimum operations required to make two numbers equal.
218
mbpp
2
2024-11-26T21:40:54.243135
import math def min_Operations(A,B): if (A > B): swap(A,B) B = B // math.gcd(A,B); return B - 1
min_Operations
easy
[{"input": "1,4", "output": "3", "testtype": "functional"}]
Mbpp_219
Write a function to extract maximum and minimum k elements in the given tuple.
219
mbpp
0
2024-11-26T21:40:54.243492
def extract_min_max(test_tup, K): res = [] test_tup = list(test_tup) temp = sorted(test_tup) for idx, val in enumerate(temp): if idx < K or idx >= len(temp) - K: res.append(val) res = tuple(res) return (res)
extract_min_max
easy
[{"input": "(5, 20, 3, 7, 6, 8), 2", "output": "(3, 5, 8, 20)", "testtype": "functional"}]
Mbpp_219
Write a function to extract maximum and minimum k elements in the given tuple.
219
mbpp
1
2024-11-26T21:40:54.243846
def extract_min_max(test_tup, K): res = [] test_tup = list(test_tup) temp = sorted(test_tup) for idx, val in enumerate(temp): if idx < K or idx >= len(temp) - K: res.append(val) res = tuple(res) return (res)
extract_min_max
easy
[{"input": "(4, 5, 6, 1, 2, 7), 3", "output": "(1, 2, 4, 5, 6, 7)", "testtype": "functional"}]
Mbpp_219
Write a function to extract maximum and minimum k elements in the given tuple.
219
mbpp
2
2024-11-26T21:40:54.244179
def extract_min_max(test_tup, K): res = [] test_tup = list(test_tup) temp = sorted(test_tup) for idx, val in enumerate(temp): if idx < K or idx >= len(temp) - K: res.append(val) res = tuple(res) return (res)
extract_min_max
easy
[{"input": "(2, 3, 4, 8, 9, 11, 7), 4", "output": "(2, 3, 4, 7, 8, 9, 11)", "testtype": "functional"}]
Mbpp_220
Write a function to replace maximum n occurrences of spaces, commas, or dots with a colon.
220
mbpp
0
2024-11-26T21:40:54.244346
import re def replace_max_specialchar(text,n): return (re.sub("[ ,.]", ":", text, n))
replace_max_specialchar
easy
[{"input": "'Python language, Programming language.',2", "output": "('Python:language: Programming language.')", "testtype": "functional"}]
Mbpp_220
Write a function to replace maximum n occurrences of spaces, commas, or dots with a colon.
220
mbpp
1
2024-11-26T21:40:54.244477
import re def replace_max_specialchar(text,n): return (re.sub("[ ,.]", ":", text, n))
replace_max_specialchar
easy
[{"input": "'a b c,d e f',3", "output": "('a:b:c:d e f')", "testtype": "functional"}]
Mbpp_220
Write a function to replace maximum n occurrences of spaces, commas, or dots with a colon.
220
mbpp
2
2024-11-26T21:40:54.244596
import re def replace_max_specialchar(text,n): return (re.sub("[ ,.]", ":", text, n))
replace_max_specialchar
easy
[{"input": "'ram reshma,ram rahim',1", "output": "('ram:reshma,ram rahim')", "testtype": "functional"}]
Mbpp_221
Write a python function to find the first even number in a given list of numbers.
221
mbpp
1
2024-11-26T21:40:54.245590
def first_even(nums): first_even = next((el for el in nums if el%2==0),-1) return first_even
first_even
easy
[{"input": "[2, 3, 4]", "output": "2", "testtype": "functional"}]
Mbpp_221
Write a python function to find the first even number in a given list of numbers.
221
mbpp
2
2024-11-26T21:40:54.245786
def first_even(nums): first_even = next((el for el in nums if el%2==0),-1) return first_even
first_even
easy
[{"input": "[5, 6, 7]", "output": "6", "testtype": "functional"}]
Mbpp_222
Write a function to check if all the elements in tuple have same data type or not.
222
mbpp
0
2024-11-26T21:40:54.245995
def check_type(test_tuple): res = True for ele in test_tuple: if not isinstance(ele, type(test_tuple[0])): res = False break return (res)
check_type
easy
[{"input": "(5, 6, 7, 3, 5, 6) ", "output": "True", "testtype": "functional"}]
Mbpp_222
Write a function to check if all the elements in tuple have same data type or not.
222
mbpp
1
2024-11-26T21:40:54.246180
def check_type(test_tuple): res = True for ele in test_tuple: if not isinstance(ele, type(test_tuple[0])): res = False break return (res)
check_type
easy
[{"input": "(1, 2, \"4\") ", "output": "False", "testtype": "functional"}]
Mbpp_222
Write a function to check if all the elements in tuple have same data type or not.
222
mbpp
2
2024-11-26T21:40:54.246376
def check_type(test_tuple): res = True for ele in test_tuple: if not isinstance(ele, type(test_tuple[0])): res = False break return (res)
check_type
easy
[{"input": "(3, 2, 1, 4, 5) ", "output": "True", "testtype": "functional"}]
Mbpp_224
Write a python function to count set bits of a given number.
224
mbpp
0
2024-11-26T21:40:54.249613
def count_Set_Bits(n): count = 0 while (n): count += n & 1 n >>= 1 return count
count_Set_Bits
easy
[{"input": "2", "output": "1", "testtype": "functional"}]
Mbpp_224
Write a python function to count set bits of a given number.
224
mbpp
1
2024-11-26T21:40:54.249867
def count_Set_Bits(n): count = 0 while (n): count += n & 1 n >>= 1 return count
count_Set_Bits
easy
[{"input": "4", "output": "1", "testtype": "functional"}]
Mbpp_224
Write a python function to count set bits of a given number.
224
mbpp
2
2024-11-26T21:40:54.250027
def count_Set_Bits(n): count = 0 while (n): count += n & 1 n >>= 1 return count
count_Set_Bits
easy
[{"input": "6", "output": "2", "testtype": "functional"}]
Mbpp_225
Write a python function to find the minimum element in a sorted and rotated array.
225
mbpp
0
2024-11-26T21:40:54.250443
def find_Min(arr,low,high): while (low < high): mid = low + (high - low) // 2; if (arr[mid] == arr[high]): high -= 1; elif (arr[mid] > arr[high]): low = mid + 1; else: high = mid; return arr[high];
find_Min
easy
[{"input": "[1,2,3,4,5],0,4", "output": "1", "testtype": "functional"}]
Mbpp_225
Write a python function to find the minimum element in a sorted and rotated array.
225
mbpp
1
2024-11-26T21:40:54.250851
def find_Min(arr,low,high): while (low < high): mid = low + (high - low) // 2; if (arr[mid] == arr[high]): high -= 1; elif (arr[mid] > arr[high]): low = mid + 1; else: high = mid; return arr[high];
find_Min
easy
[{"input": "[4,6,8],0,2", "output": "4", "testtype": "functional"}]
Mbpp_225
Write a python function to find the minimum element in a sorted and rotated array.
225
mbpp
2
2024-11-26T21:40:54.251230
def find_Min(arr,low,high): while (low < high): mid = low + (high - low) // 2; if (arr[mid] == arr[high]): high -= 1; elif (arr[mid] > arr[high]): low = mid + 1; else: high = mid; return arr[high];
find_Min
easy
[{"input": "[2,3,5,7,9],0,4", "output": "2", "testtype": "functional"}]
Mbpp_226
Write a python function to remove the characters which have odd index values of a given string.
226
mbpp
0
2024-11-26T21:40:54.251489
def odd_values_string(str): result = "" for i in range(len(str)): if i % 2 == 0: result = result + str[i] return result
odd_values_string
easy
[{"input": "'abcdef'", "output": "'ace'", "testtype": "functional"}]
Mbpp_226
Write a python function to remove the characters which have odd index values of a given string.
226
mbpp
1
2024-11-26T21:40:54.251724
def odd_values_string(str): result = "" for i in range(len(str)): if i % 2 == 0: result = result + str[i] return result
odd_values_string
easy
[{"input": "'python'", "output": "'pto'", "testtype": "functional"}]
Mbpp_226
Write a python function to remove the characters which have odd index values of a given string.
226
mbpp
2
2024-11-26T21:40:54.251926
def odd_values_string(str): result = "" for i in range(len(str)): if i % 2 == 0: result = result + str[i] return result
odd_values_string
easy
[{"input": "'data'", "output": "'dt'", "testtype": "functional"}]
Mbpp_227
Write a function to find minimum of three numbers.
227
mbpp
0
2024-11-26T21:40:54.252175
def min_of_three(a,b,c): if (a <= b) and (a <= c): smallest = a elif (b <= a) and (b <= c): smallest = b else: smallest = c return smallest
min_of_three
easy
[{"input": "10,20,0", "output": "0", "testtype": "functional"}]
Mbpp_227
Write a function to find minimum of three numbers.
227
mbpp
1
2024-11-26T21:40:54.252420
def min_of_three(a,b,c): if (a <= b) and (a <= c): smallest = a elif (b <= a) and (b <= c): smallest = b else: smallest = c return smallest
min_of_three
easy
[{"input": "19,15,18", "output": "15", "testtype": "functional"}]
Mbpp_227
Write a function to find minimum of three numbers.
227
mbpp
2
2024-11-26T21:40:54.252690
def min_of_three(a,b,c): if (a <= b) and (a <= c): smallest = a elif (b <= a) and (b <= c): smallest = b else: smallest = c return smallest
min_of_three
easy
[{"input": "-10,-20,-30", "output": "-30", "testtype": "functional"}]
Mbpp_228
Write a python function to check whether all the bits are unset in the given range or not.
228
mbpp
0
2024-11-26T21:40:54.252955
def all_Bits_Set_In_The_Given_Range(n,l,r): num = (((1 << r) - 1) ^ ((1 << (l - 1)) - 1)) new_num = n & num if (new_num == 0): return True return False
all_Bits_Set_In_The_Given_Range
easy
[{"input": "4,1,2", "output": "True", "testtype": "functional"}]
Mbpp_228
Write a python function to check whether all the bits are unset in the given range or not.
228
mbpp
1
2024-11-26T21:40:54.253207
def all_Bits_Set_In_The_Given_Range(n,l,r): num = (((1 << r) - 1) ^ ((1 << (l - 1)) - 1)) new_num = n & num if (new_num == 0): return True return False
all_Bits_Set_In_The_Given_Range
easy
[{"input": "17,2,4", "output": "True", "testtype": "functional"}]
Mbpp_228
Write a python function to check whether all the bits are unset in the given range or not.
228
mbpp
2
2024-11-26T21:40:54.253456
def all_Bits_Set_In_The_Given_Range(n,l,r): num = (((1 << r) - 1) ^ ((1 << (l - 1)) - 1)) new_num = n & num if (new_num == 0): return True return False
all_Bits_Set_In_The_Given_Range
easy
[{"input": "39,4,6", "output": "False", "testtype": "functional"}]
Mbpp_229
Write a function to re-arrange the elements of the given array so that all negative elements appear before positive ones.
229
mbpp
0
2024-11-26T21:40:54.253789
def re_arrange_array(arr, n): j=0 for i in range(0, n): if (arr[i] < 0): temp = arr[i] arr[i] = arr[j] arr[j] = temp j = j + 1 return arr
re_arrange_array
easy
[{"input": "[-1, 2, -3, 4, 5, 6, -7, 8, 9], 9", "output": "[-1, -3, -7, 4, 5, 6, 2, 8, 9]", "testtype": "functional"}]
Mbpp_229
Write a function to re-arrange the elements of the given array so that all negative elements appear before positive ones.
229
mbpp
1
2024-11-26T21:40:54.254078
def re_arrange_array(arr, n): j=0 for i in range(0, n): if (arr[i] < 0): temp = arr[i] arr[i] = arr[j] arr[j] = temp j = j + 1 return arr
re_arrange_array
easy
[{"input": "[12, -14, -26, 13, 15], 5", "output": "[-14, -26, 12, 13, 15]", "testtype": "functional"}]
Mbpp_229
Write a function to re-arrange the elements of the given array so that all negative elements appear before positive ones.
229
mbpp
2
2024-11-26T21:40:54.254386
def re_arrange_array(arr, n): j=0 for i in range(0, n): if (arr[i] < 0): temp = arr[i] arr[i] = arr[j] arr[j] = temp j = j + 1 return arr
re_arrange_array
easy
[{"input": "[10, 24, 36, -42, -39, -78, 85], 7", "output": "[-42, -39, -78, 10, 24, 36, 85]", "testtype": "functional"}]
Mbpp_230
Write a function to replace blank spaces with any character in a string.
230
mbpp
0
2024-11-26T21:40:54.254534
def replace_blank(str1,char): str2 = str1.replace(' ', char) return str2
replace_blank
easy
[{"input": "\"hello people\",'@'", "output": "(\"hello@people\")", "testtype": "functional"}]
Mbpp_230
Write a function to replace blank spaces with any character in a string.
230
mbpp
1
2024-11-26T21:40:54.254670
def replace_blank(str1,char): str2 = str1.replace(' ', char) return str2
replace_blank
easy
[{"input": "\"python program language\",'$'", "output": "(\"python$program$language\")", "testtype": "functional"}]
Mbpp_230
Write a function to replace blank spaces with any character in a string.
230
mbpp
2
2024-11-26T21:40:54.254797
def replace_blank(str1,char): str2 = str1.replace(' ', char) return str2
replace_blank
easy
[{"input": "\"blank space\",\"-\"", "output": "(\"blank-space\")", "testtype": "functional"}]
Mbpp_231
Write a function to find the maximum sum in the given right triangle of numbers.
231
mbpp
0
2024-11-26T21:40:54.255775
def max_sum(tri, n): if n > 1: tri[1][1] = tri[1][1]+tri[0][0] tri[1][0] = tri[1][0]+tri[0][0] for i in range(2, n): tri[i][0] = tri[i][0] + tri[i-1][0] tri[i][i] = tri[i][i] + tri[i-1][i-1] for j in range(1, i): if tri[i][j]+tri[i-1][j-1] >= tri[i][j]+tri[i-1][j]: tri[i][j] = tri[i][j] + tri[i-1][j-1] else: tri[i][j] = tri[i][j]+tri[i-1][j] return (max(tri[n-1]))
max_sum
easy
[{"input": "[[1], [2,1], [3,3,2]], 3", "output": "6", "testtype": "functional"}]
Mbpp_231
Write a function to find the maximum sum in the given right triangle of numbers.
231
mbpp
1
2024-11-26T21:40:54.256732
def max_sum(tri, n): if n > 1: tri[1][1] = tri[1][1]+tri[0][0] tri[1][0] = tri[1][0]+tri[0][0] for i in range(2, n): tri[i][0] = tri[i][0] + tri[i-1][0] tri[i][i] = tri[i][i] + tri[i-1][i-1] for j in range(1, i): if tri[i][j]+tri[i-1][j-1] >= tri[i][j]+tri[i-1][j]: tri[i][j] = tri[i][j] + tri[i-1][j-1] else: tri[i][j] = tri[i][j]+tri[i-1][j] return (max(tri[n-1]))
max_sum
easy
[{"input": "[[1], [1, 2], [4, 1, 12]], 3", "output": "15", "testtype": "functional"}]
Mbpp_231
Write a function to find the maximum sum in the given right triangle of numbers.
231
mbpp
2
2024-11-26T21:40:54.257744
def max_sum(tri, n): if n > 1: tri[1][1] = tri[1][1]+tri[0][0] tri[1][0] = tri[1][0]+tri[0][0] for i in range(2, n): tri[i][0] = tri[i][0] + tri[i-1][0] tri[i][i] = tri[i][i] + tri[i-1][i-1] for j in range(1, i): if tri[i][j]+tri[i-1][j-1] >= tri[i][j]+tri[i-1][j]: tri[i][j] = tri[i][j] + tri[i-1][j-1] else: tri[i][j] = tri[i][j]+tri[i-1][j] return (max(tri[n-1]))
max_sum
easy
[{"input": "[[2], [3,2], [13,23,12]], 3", "output": "28", "testtype": "functional"}]
Mbpp_232
Write a function to get the n largest items from a dataset.
232
mbpp
0
2024-11-26T21:40:54.257926
import heapq def larg_nnum(list1,n): largest=heapq.nlargest(n,list1) return largest
larg_nnum
easy
[{"input": "[10, 20, 50, 70, 90, 20, 50, 40, 60, 80, 100],2", "output": "[100,90]", "testtype": "functional"}]
Mbpp_232
Write a function to get the n largest items from a dataset.
232
mbpp
1
2024-11-26T21:40:54.258052
import heapq def larg_nnum(list1,n): largest=heapq.nlargest(n,list1) return largest
larg_nnum
easy
[{"input": "[10, 20, 50, 70, 90, 20, 50, 40, 60, 80, 100],5", "output": "[100,90,80,70,60]", "testtype": "functional"}]
Mbpp_232
Write a function to get the n largest items from a dataset.
232
mbpp
2
2024-11-26T21:40:54.258173
import heapq def larg_nnum(list1,n): largest=heapq.nlargest(n,list1) return largest
larg_nnum
easy
[{"input": "[10, 20, 50, 70, 90, 20, 50, 40, 60, 80, 100],3", "output": "[100,90,80]", "testtype": "functional"}]
Mbpp_233
Write a function to find the lateral surface area of a cylinder.
233
mbpp
0
2024-11-26T21:40:54.258307
def lateralsuface_cylinder(r,h): lateralsurface= 2*3.1415*r*h return lateralsurface
lateralsuface_cylinder
easy
[{"input": "10,5", "output": "314.15000000000003", "testtype": "functional"}]
Mbpp_233
Write a function to find the lateral surface area of a cylinder.
233
mbpp
1
2024-11-26T21:40:54.258424
def lateralsuface_cylinder(r,h): lateralsurface= 2*3.1415*r*h return lateralsurface
lateralsuface_cylinder
easy
[{"input": "4,5", "output": "125.66000000000001", "testtype": "functional"}]
Mbpp_233
Write a function to find the lateral surface area of a cylinder.
233
mbpp
2
2024-11-26T21:40:54.258539
def lateralsuface_cylinder(r,h): lateralsurface= 2*3.1415*r*h return lateralsurface
lateralsuface_cylinder
easy
[{"input": "4,10", "output": "251.32000000000002", "testtype": "functional"}]
Mbpp_234
Write a function to find the volume of a cube.
234
mbpp
0
2024-11-26T21:40:54.258653
def volume_cube(l): volume = l * l * l return volume
volume_cube
easy
[{"input": "3", "output": "27", "testtype": "functional"}]
Mbpp_234
Write a function to find the volume of a cube.
234
mbpp
1
2024-11-26T21:40:54.258753
def volume_cube(l): volume = l * l * l return volume
volume_cube
easy
[{"input": "2", "output": "8", "testtype": "functional"}]
Mbpp_234
Write a function to find the volume of a cube.
234
mbpp
2
2024-11-26T21:40:54.258845
def volume_cube(l): volume = l * l * l return volume
volume_cube
easy
[{"input": "5", "output": "125", "testtype": "functional"}]
Mbpp_235
Write a python function to set all even bits of a given number.
235
mbpp
0
2024-11-26T21:40:54.259103
def even_bit_set_number(n): count = 0;res = 0;temp = n while(temp > 0): if (count % 2 == 1): res |= (1 << count) count+=1 temp >>= 1 return (n | res)
even_bit_set_number
easy
[{"input": "10", "output": "10", "testtype": "functional"}]
Mbpp_235
Write a python function to set all even bits of a given number.
235
mbpp
1
2024-11-26T21:40:54.259373
def even_bit_set_number(n): count = 0;res = 0;temp = n while(temp > 0): if (count % 2 == 1): res |= (1 << count) count+=1 temp >>= 1 return (n | res)
even_bit_set_number
easy
[{"input": "20", "output": "30", "testtype": "functional"}]
Mbpp_235
Write a python function to set all even bits of a given number.
235
mbpp
2
2024-11-26T21:40:54.259624
def even_bit_set_number(n): count = 0;res = 0;temp = n while(temp > 0): if (count % 2 == 1): res |= (1 << count) count+=1 temp >>= 1 return (n | res)
even_bit_set_number
easy
[{"input": "30", "output": "30", "testtype": "functional"}]
Mbpp_236
Write a python function to count the maximum number of equilateral triangles that can be formed within a given equilateral triangle.
236
mbpp
0
2024-11-26T21:40:54.260002
def No_of_Triangle(N,K): if (N < K): return -1; else: Tri_up = 0; Tri_up = ((N - K + 1) *(N - K + 2)) // 2; Tri_down = 0; Tri_down = ((N - 2 * K + 1) *(N - 2 * K + 2)) // 2; return Tri_up + Tri_down;
No_of_Triangle
easy
[{"input": "4,2", "output": "7", "testtype": "functional"}]
Mbpp_236
Write a python function to count the maximum number of equilateral triangles that can be formed within a given equilateral triangle.
236
mbpp
1
2024-11-26T21:40:54.260612
def No_of_Triangle(N,K): if (N < K): return -1; else: Tri_up = 0; Tri_up = ((N - K + 1) *(N - K + 2)) // 2; Tri_down = 0; Tri_down = ((N - 2 * K + 1) *(N - 2 * K + 2)) // 2; return Tri_up + Tri_down;
No_of_Triangle
easy
[{"input": "4,3", "output": "3", "testtype": "functional"}]
Mbpp_236
Write a python function to count the maximum number of equilateral triangles that can be formed within a given equilateral triangle.
236
mbpp
2
2024-11-26T21:40:54.261035
def No_of_Triangle(N,K): if (N < K): return -1; else: Tri_up = 0; Tri_up = ((N - K + 1) *(N - K + 2)) // 2; Tri_down = 0; Tri_down = ((N - 2 * K + 1) *(N - 2 * K + 2)) // 2; return Tri_up + Tri_down;
No_of_Triangle
easy
[{"input": "1,3", "output": "-1", "testtype": "functional"}]
Mbpp_237
Write a function to check the occurrences of records which occur similar times in the given tuples.
237
mbpp
0
2024-11-26T21:40:54.261448
from collections import Counter def check_occurences(test_list): res = dict(Counter(tuple(ele) for ele in map(sorted, test_list))) return (res)
check_occurences
easy
[{"input": "[(3, 1), (1, 3), (2, 5), (5, 2), (6, 3)] ", "output": "{(1, 3): 2, (2, 5): 2, (3, 6): 1}", "testtype": "functional"}]
Mbpp_237
Write a function to check the occurrences of records which occur similar times in the given tuples.
237
mbpp
1
2024-11-26T21:40:54.261710
from collections import Counter def check_occurences(test_list): res = dict(Counter(tuple(ele) for ele in map(sorted, test_list))) return (res)
check_occurences
easy
[{"input": "[(4, 2), (2, 4), (3, 6), (6, 3), (7, 4)] ", "output": "{(2, 4): 2, (3, 6): 2, (4, 7): 1}", "testtype": "functional"}]
Mbpp_237
Write a function to check the occurrences of records which occur similar times in the given tuples.
237
mbpp
2
2024-11-26T21:40:54.261945
from collections import Counter def check_occurences(test_list): res = dict(Counter(tuple(ele) for ele in map(sorted, test_list))) return (res)
check_occurences
easy
[{"input": "[(13, 2), (11, 23), (12, 25), (25, 12), (16, 23)] ", "output": "{(2, 13): 1, (11, 23): 1, (12, 25): 2, (16, 23): 1}", "testtype": "functional"}]
Mbpp_238
Write a python function to count number of non-empty substrings of a given string.
238
mbpp
0
2024-11-26T21:40:54.262117
def number_of_substrings(str): str_len = len(str); return int(str_len * (str_len + 1) / 2);
number_of_substrings
easy
[{"input": "\"abc\"", "output": "6", "testtype": "functional"}]
Mbpp_238
Write a python function to count number of non-empty substrings of a given string.
238
mbpp
1
2024-11-26T21:40:54.262278
def number_of_substrings(str): str_len = len(str); return int(str_len * (str_len + 1) / 2);
number_of_substrings
easy
[{"input": "\"abcd\"", "output": "10", "testtype": "functional"}]
Mbpp_238
Write a python function to count number of non-empty substrings of a given string.
238
mbpp
2
2024-11-26T21:40:54.262439
def number_of_substrings(str): str_len = len(str); return int(str_len * (str_len + 1) / 2);
number_of_substrings
easy
[{"input": "\"abcde\"", "output": "15", "testtype": "functional"}]
Mbpp_239
Write a function to find the number of possible sequences of length n such that each of the next element is greater than or equal to twice of the previous element but less than or equal to m.
239
mbpp
0
2024-11-26T21:40:54.263089
def get_total_number_of_sequences(m,n): T=[[0 for i in range(n+1)] for i in range(m+1)] for i in range(m+1): for j in range(n+1): if i==0 or j==0: T[i][j]=0 elif i<j: T[i][j]=0 elif j==1: T[i][j]=i else: T[i][j]=T[i-1][j]+T[i//2][j-1] return T[m][n]
get_total_number_of_sequences
easy
[{"input": "10, 4", "output": "4", "testtype": "functional"}]
Mbpp_239
Write a function to find the number of possible sequences of length n such that each of the next element is greater than or equal to twice of the previous element but less than or equal to m.
239
mbpp
1
2024-11-26T21:40:54.263888
def get_total_number_of_sequences(m,n): T=[[0 for i in range(n+1)] for i in range(m+1)] for i in range(m+1): for j in range(n+1): if i==0 or j==0: T[i][j]=0 elif i<j: T[i][j]=0 elif j==1: T[i][j]=i else: T[i][j]=T[i-1][j]+T[i//2][j-1] return T[m][n]
get_total_number_of_sequences
easy
[{"input": "5, 2", "output": "6", "testtype": "functional"}]
Mbpp_239
Write a function to find the number of possible sequences of length n such that each of the next element is greater than or equal to twice of the previous element but less than or equal to m.
239
mbpp
2
2024-11-26T21:40:54.264517
def get_total_number_of_sequences(m,n): T=[[0 for i in range(n+1)] for i in range(m+1)] for i in range(m+1): for j in range(n+1): if i==0 or j==0: T[i][j]=0 elif i<j: T[i][j]=0 elif j==1: T[i][j]=i else: T[i][j]=T[i-1][j]+T[i//2][j-1] return T[m][n]
get_total_number_of_sequences
easy
[{"input": "16, 3", "output": "84", "testtype": "functional"}]
Mbpp_240
Write a function to replace the last element of the list with another list.
240
mbpp
0
2024-11-26T21:40:54.264719
def replace_list(list1,list2): list1[-1:] = list2 replace_list=list1 return replace_list
replace_list
easy
[{"input": "[1, 3, 5, 7, 9, 10],[2, 4, 6, 8]", "output": "[1, 3, 5, 7, 9, 2, 4, 6, 8]", "testtype": "functional"}]
Mbpp_240
Write a function to replace the last element of the list with another list.
240
mbpp
1
2024-11-26T21:40:54.264861
def replace_list(list1,list2): list1[-1:] = list2 replace_list=list1 return replace_list
replace_list
easy
[{"input": "[1,2,3,4,5],[5,6,7,8]", "output": "[1,2,3,4,5,6,7,8]", "testtype": "functional"}]
Mbpp_240
Write a function to replace the last element of the list with another list.
240
mbpp
2
2024-11-26T21:40:54.264986
def replace_list(list1,list2): list1[-1:] = list2 replace_list=list1 return replace_list
replace_list
easy
[{"input": "[\"red\",\"blue\",\"green\"],[\"yellow\"]", "output": "[\"red\",\"blue\",\"yellow\"]", "testtype": "functional"}]
Mbpp_241
Write a function to generate a 3d array having each element as '*'.
241
mbpp
0
2024-11-26T21:40:54.267682
def array_3d(m,n,o): array_3d = [[ ['*' for col in range(m)] for col in range(n)] for row in range(o)] return array_3d
array_3d
easy
[{"input": "6,4,3", "output": "[[['*', '*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*', '*']], [['*', '*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*', '*']], [['*', '*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*', '*']]]", "testtype": "functional"}]
Mbpp_241
Write a function to generate a 3d array having each element as '*'.
241
mbpp
1
2024-11-26T21:40:54.268043
def array_3d(m,n,o): array_3d = [[ ['*' for col in range(m)] for col in range(n)] for row in range(o)] return array_3d
array_3d
easy
[{"input": "5,3,4", "output": "[[['*', '*', '*', '*', '*'], ['*', '*', '*', '*','*'], ['*', '*', '*', '*', '*']], [['*', '*', '*', '*', '*'],['*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*']], [['*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*']], [['*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*']]]", "testtype": "functional"}]
Mbpp_241
Write a function to generate a 3d array having each element as '*'.
241
mbpp
2
2024-11-26T21:40:54.268256
def array_3d(m,n,o): array_3d = [[ ['*' for col in range(m)] for col in range(n)] for row in range(o)] return array_3d
array_3d
easy
[{"input": "1,2,3", "output": "[[['*'],['*']],[['*'],['*']],[['*'],['*']]]", "testtype": "functional"}]
Mbpp_242
Write a function to count total characters in a string.
242
mbpp
0
2024-11-26T21:40:54.268420
def count_charac(str1): total = 0 for i in str1: total = total + 1 return total
count_charac
easy
[{"input": "\"python programming\"", "output": "18", "testtype": "functional"}]
Mbpp_242
Write a function to count total characters in a string.
242
mbpp
1
2024-11-26T21:40:54.268556
def count_charac(str1): total = 0 for i in str1: total = total + 1 return total
count_charac
easy
[{"input": "\"language\"", "output": "8", "testtype": "functional"}]
Mbpp_242
Write a function to count total characters in a string.
242
mbpp
2
2024-11-26T21:40:54.268715
def count_charac(str1): total = 0 for i in str1: total = total + 1 return total
count_charac
easy
[{"input": "\"words\"", "output": "5", "testtype": "functional"}]
Mbpp_243
Write a function to sort the given list based on the occurrence of first element of tuples.
243
mbpp
0
2024-11-26T21:40:54.269048
def sort_on_occurence(lst): dct = {} for i, j in lst: dct.setdefault(i, []).append(j) return ([(i, *dict.fromkeys(j), len(j)) for i, j in dct.items()])
sort_on_occurence
easy
[{"input": "[(1, 'Jake'), (2, 'Bob'), (1, 'Cara')]", "output": "[(1, 'Jake', 'Cara', 2), (2, 'Bob', 1)]", "testtype": "functional"}]
Mbpp_243
Write a function to sort the given list based on the occurrence of first element of tuples.
243
mbpp
1
2024-11-26T21:40:54.269328
def sort_on_occurence(lst): dct = {} for i, j in lst: dct.setdefault(i, []).append(j) return ([(i, *dict.fromkeys(j), len(j)) for i, j in dct.items()])
sort_on_occurence
easy
[{"input": "[('b', 'ball'), ('a', 'arm'), ('b', 'b'), ('a', 'ant')]", "output": "[('b', 'ball', 'b', 2), ('a', 'arm', 'ant', 2)]", "testtype": "functional"}]
Mbpp_243
Write a function to sort the given list based on the occurrence of first element of tuples.
243
mbpp
2
2024-11-26T21:40:54.269591
def sort_on_occurence(lst): dct = {} for i, j in lst: dct.setdefault(i, []).append(j) return ([(i, *dict.fromkeys(j), len(j)) for i, j in dct.items()])
sort_on_occurence
easy
[{"input": "[(2, 'Mark'), (3, 'Maze'), (2, 'Sara')]", "output": "[(2, 'Mark', 'Sara', 2), (3, 'Maze', 1)]", "testtype": "functional"}]
Mbpp_244
Write a python function to find the next perfect square greater than a given number.
244
mbpp
0
2024-11-26T21:40:54.269779
import math def next_Perfect_Square(N): nextN = math.floor(math.sqrt(N)) + 1 return nextN * nextN
next_Perfect_Square
easy
[{"input": "35", "output": "36", "testtype": "functional"}]
Mbpp_244
Write a python function to find the next perfect square greater than a given number.
244
mbpp
1
2024-11-26T21:40:54.269935
import math def next_Perfect_Square(N): nextN = math.floor(math.sqrt(N)) + 1 return nextN * nextN
next_Perfect_Square
easy
[{"input": "6", "output": "9", "testtype": "functional"}]
Mbpp_244
Write a python function to find the next perfect square greater than a given number.
244
mbpp
2
2024-11-26T21:40:54.270079
import math def next_Perfect_Square(N): nextN = math.floor(math.sqrt(N)) + 1 return nextN * nextN
next_Perfect_Square
easy
[{"input": "9", "output": "16", "testtype": "functional"}]
Mbpp_245
Write a function to find the maximum sum of bi-tonic sub-sequence for the given array.
245
mbpp
0
2024-11-26T21:40:54.270890
def max_sum(arr, n): MSIBS = arr[:] for i in range(n): for j in range(0, i): if arr[i] > arr[j] and MSIBS[i] < MSIBS[j] + arr[i]: MSIBS[i] = MSIBS[j] + arr[i] MSDBS = arr[:] for i in range(1, n + 1): for j in range(1, i): if arr[-i] > arr[-j] and MSDBS[-i] < MSDBS[-j] + arr[-i]: MSDBS[-i] = MSDBS[-j] + arr[-i] max_sum = float("-Inf") for i, j, k in zip(MSIBS, MSDBS, arr): max_sum = max(max_sum, i + j - k) return max_sum
max_sum
easy
[{"input": "[1, 15, 51, 45, 33, 100, 12, 18, 9], 9", "output": "194", "testtype": "functional"}]
Mbpp_245
Write a function to find the maximum sum of bi-tonic sub-sequence for the given array.
245
mbpp
1
2024-11-26T21:40:54.271722
def max_sum(arr, n): MSIBS = arr[:] for i in range(n): for j in range(0, i): if arr[i] > arr[j] and MSIBS[i] < MSIBS[j] + arr[i]: MSIBS[i] = MSIBS[j] + arr[i] MSDBS = arr[:] for i in range(1, n + 1): for j in range(1, i): if arr[-i] > arr[-j] and MSDBS[-i] < MSDBS[-j] + arr[-i]: MSDBS[-i] = MSDBS[-j] + arr[-i] max_sum = float("-Inf") for i, j, k in zip(MSIBS, MSDBS, arr): max_sum = max(max_sum, i + j - k) return max_sum
max_sum
easy
[{"input": "[80, 60, 30, 40, 20, 10], 6", "output": "210", "testtype": "functional"}]
Mbpp_245
Write a function to find the maximum sum of bi-tonic sub-sequence for the given array.
245
mbpp
2
2024-11-26T21:40:54.272682
def max_sum(arr, n): MSIBS = arr[:] for i in range(n): for j in range(0, i): if arr[i] > arr[j] and MSIBS[i] < MSIBS[j] + arr[i]: MSIBS[i] = MSIBS[j] + arr[i] MSDBS = arr[:] for i in range(1, n + 1): for j in range(1, i): if arr[-i] > arr[-j] and MSDBS[-i] < MSDBS[-j] + arr[-i]: MSDBS[-i] = MSDBS[-j] + arr[-i] max_sum = float("-Inf") for i, j, k in zip(MSIBS, MSDBS, arr): max_sum = max(max_sum, i + j - k) return max_sum
max_sum
easy
[{"input": "[2, 3 ,14, 16, 21, 23, 29, 30], 8", "output": "138", "testtype": "functional"}]
Mbpp_246
Write a function for computing square roots using the babylonian method.
246
mbpp
0
2024-11-26T21:40:54.273045
def babylonian_squareroot(number): if(number == 0): return 0; g = number/2.0; g2 = g + 1; while(g != g2): n = number/ g; g2 = g; g = (g + n)/2; return g;
babylonian_squareroot
easy
[{"input": "10", "output": "3.162277660168379", "testtype": "functional"}]
Mbpp_246
Write a function for computing square roots using the babylonian method.
246
mbpp
1
2024-11-26T21:40:54.273375
def babylonian_squareroot(number): if(number == 0): return 0; g = number/2.0; g2 = g + 1; while(g != g2): n = number/ g; g2 = g; g = (g + n)/2; return g;
babylonian_squareroot
easy
[{"input": "2", "output": "1.414213562373095", "testtype": "functional"}]
Mbpp_246
Write a function for computing square roots using the babylonian method.
246
mbpp
2
2024-11-26T21:40:54.273680
def babylonian_squareroot(number): if(number == 0): return 0; g = number/2.0; g2 = g + 1; while(g != g2): n = number/ g; g2 = g; g = (g + n)/2; return g;
babylonian_squareroot
easy
[{"input": "9", "output": "3.0", "testtype": "functional"}]
Mbpp_247
Write a function to find the longest palindromic subsequence in the given string.
247
mbpp
0
2024-11-26T21:40:54.274446
def lps(str): n = len(str) L = [[0 for x in range(n)] for x in range(n)] for i in range(n): L[i][i] = 1 for cl in range(2, n+1): for i in range(n-cl+1): j = i+cl-1 if str[i] == str[j] and cl == 2: L[i][j] = 2 elif str[i] == str[j]: L[i][j] = L[i+1][j-1] + 2 else: L[i][j] = max(L[i][j-1], L[i+1][j]); return L[0][n-1]
lps
easy
[{"input": "\"TENS FOR TENS\"", "output": "5", "testtype": "functional"}]
Mbpp_247
Write a function to find the longest palindromic subsequence in the given string.
247
mbpp
1
2024-11-26T21:40:54.275220
def lps(str): n = len(str) L = [[0 for x in range(n)] for x in range(n)] for i in range(n): L[i][i] = 1 for cl in range(2, n+1): for i in range(n-cl+1): j = i+cl-1 if str[i] == str[j] and cl == 2: L[i][j] = 2 elif str[i] == str[j]: L[i][j] = L[i+1][j-1] + 2 else: L[i][j] = max(L[i][j-1], L[i+1][j]); return L[0][n-1]
lps
easy
[{"input": "\"CARDIO FOR CARDS\"", "output": "7", "testtype": "functional"}]
Mbpp_247
Write a function to find the longest palindromic subsequence in the given string.
247
mbpp
2
2024-11-26T21:40:54.275963
def lps(str): n = len(str) L = [[0 for x in range(n)] for x in range(n)] for i in range(n): L[i][i] = 1 for cl in range(2, n+1): for i in range(n-cl+1): j = i+cl-1 if str[i] == str[j] and cl == 2: L[i][j] = 2 elif str[i] == str[j]: L[i][j] = L[i+1][j-1] + 2 else: L[i][j] = max(L[i][j-1], L[i+1][j]); return L[0][n-1]
lps
easy
[{"input": "\"PART OF THE JOURNEY IS PART\"", "output": "9", "testtype": "functional"}]
Mbpp_248
Write a function to calculate the harmonic sum of n-1.
248
mbpp
0
2024-11-26T21:40:54.276155
def harmonic_sum(n): if n < 2: return 1 else: return 1 / n + (harmonic_sum(n - 1))
harmonic_sum
easy
[{"input": "7", "output": "2.5928571428571425", "testtype": "functional"}]
Mbpp_248
Write a function to calculate the harmonic sum of n-1.
248
mbpp
1
2024-11-26T21:40:54.276300
def harmonic_sum(n): if n < 2: return 1 else: return 1 / n + (harmonic_sum(n - 1))
harmonic_sum
easy
[{"input": "4", "output": "2.083333333333333", "testtype": "functional"}]
Mbpp_248
Write a function to calculate the harmonic sum of n-1.
248
mbpp
2
2024-11-26T21:40:54.276450
def harmonic_sum(n): if n < 2: return 1 else: return 1 / n + (harmonic_sum(n - 1))
harmonic_sum
easy
[{"input": "19", "output": "3.547739657143682", "testtype": "functional"}]
Mbpp_249
Write a function to find the intersection of two arrays using lambda function.
249
mbpp
0
2024-11-26T21:40:54.276625
def intersection_array(array_nums1,array_nums2): result = list(filter(lambda x: x in array_nums1, array_nums2)) return result
intersection_array
easy
[{"input": "[1, 2, 3, 5, 7, 8, 9, 10],[1, 2, 4, 8, 9]", "output": "[1, 2, 8, 9]", "testtype": "functional"}]
Mbpp_249
Write a function to find the intersection of two arrays using lambda function.
249
mbpp
1
2024-11-26T21:40:54.278145
def intersection_array(array_nums1,array_nums2): result = list(filter(lambda x: x in array_nums1, array_nums2)) return result
intersection_array
easy
[{"input": "[1, 2, 3, 5, 7, 8, 9, 10],[3,5,7,9]", "output": "[3,5,7,9]", "testtype": "functional"}]
Mbpp_249
Write a function to find the intersection of two arrays using lambda function.
249
mbpp
2
2024-11-26T21:40:54.278322
def intersection_array(array_nums1,array_nums2): result = list(filter(lambda x: x in array_nums1, array_nums2)) return result
intersection_array
easy
[{"input": "[1, 2, 3, 5, 7, 8, 9, 10],[10,20,30,40]", "output": "[10]", "testtype": "functional"}]
Mbpp_250
Write a python function to count the occcurences of an element in a tuple.
250
mbpp
0
2024-11-26T21:40:54.278525
def count_X(tup, x): count = 0 for ele in tup: if (ele == x): count = count + 1 return count
count_X
easy
[{"input": "(10, 8, 5, 2, 10, 15, 10, 8, 5, 8, 8, 2),4", "output": "0", "testtype": "functional"}]
Mbpp_250
Write a python function to count the occcurences of an element in a tuple.
250
mbpp
1
2024-11-26T21:40:54.278710
def count_X(tup, x): count = 0 for ele in tup: if (ele == x): count = count + 1 return count
count_X
easy
[{"input": "(10, 8, 5, 2, 10, 15, 10, 8, 5, 8, 8, 2),10", "output": "3", "testtype": "functional"}]
Mbpp_250
Write a python function to count the occcurences of an element in a tuple.
250
mbpp
2
2024-11-26T21:40:54.278884
def count_X(tup, x): count = 0 for ele in tup: if (ele == x): count = count + 1 return count
count_X
easy
[{"input": "(10, 8, 5, 2, 10, 15, 10, 8, 5, 8, 8, 2),8", "output": "4", "testtype": "functional"}]
Mbpp_251
Write a function to insert an element before each element of a list.
251
mbpp
0
2024-11-26T21:40:54.279047
def insert_element(list,element): list = [v for elt in list for v in (element, elt)] return list
insert_element
easy
[{"input": "['Red', 'Green', 'Black'] ,'c'", "output": "['c', 'Red', 'c', 'Green', 'c', 'Black']", "testtype": "functional"}]
Mbpp_251
Write a function to insert an element before each element of a list.
251
mbpp
1
2024-11-26T21:40:54.279196
def insert_element(list,element): list = [v for elt in list for v in (element, elt)] return list
insert_element
easy
[{"input": "['python', 'java'] ,'program'", "output": "['program', 'python', 'program', 'java']", "testtype": "functional"}]
Mbpp_251
Write a function to insert an element before each element of a list.
251
mbpp
2
2024-11-26T21:40:54.279357
def insert_element(list,element): list = [v for elt in list for v in (element, elt)] return list
insert_element
easy
[{"input": "['happy', 'sad'] ,'laugh'", "output": "['laugh', 'happy', 'laugh', 'sad']", "testtype": "functional"}]