task_id
stringlengths 1
3
| prompt
stringclasses 1
value | description
stringlengths 37
249
| entry_point
stringlengths 3
33
⌀ | canonical_solution
stringlengths 30
1.33k
| given_tests
sequencelengths 3
3
| test
stringlengths 127
4.21k
|
---|---|---|---|---|---|---|
301 | Write a function to find the depth of a dictionary. | dict_depth | def dict_depth(d):
if isinstance(d, dict):
return 1 + (max(map(dict_depth, d.values())) if d else 0)
return 0 | [
"assert dict_depth({1: 'StoVGm', 2: {5: {9: 'uCcLmc'}}}) == 3",
"assert dict_depth({6: 'XlGSCVR', 1: {2: {4: 'rHORFRde'}}}) == 3",
"assert dict_depth({3: 'BVHVlGdwP', 2: {6: {4: 'NItuDFc'}}}) == 3"
] | def check(candidate):
# Check some simple cases
assert dict_depth({'a':1, 'b': {'c': {'d': {}}}})==4
assert dict_depth({'a':1, 'b': {'c':'python'}})==2
assert dict_depth({1: 'Sun', 2: {3: {4:'Mon'}}})==3
|
|
302 | Write a python function to find the most significant bit number which is also a set bit. | set_Bit_Number | 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) | [
"assert set_Bit_Number(23) == 16",
"assert set_Bit_Number(15) == 8",
"assert set_Bit_Number(16) == 16"
] | def check(candidate):
# Check some simple cases
assert set_Bit_Number(6) == 4
assert set_Bit_Number(10) == 8
assert set_Bit_Number(18) == 16
|
|
303 | Write a python function to check whether the count of inversion of two types are same or not. | solve | 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 | [
"assert solve([5, 6, 3], 2) == True",
"assert solve([5, 7, 3], 6) == False",
"assert solve([5, 5, 2], 1) == True"
] | def check(candidate):
# Check some simple cases
assert solve([1,0,2],3) == True
assert solve([1,2,0],3) == False
assert solve([1,2,1],3) == True
|
|
304 | Write a python function to find element at a given index after number of rotations. | find_Element | 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 = index - 1
return arr[index] | [
"assert find_Element([4, 7, 2, 8, 5, 1], [[1, 6], [2, 6]], 1, 4) == 8",
"assert find_Element([4, 3, 6, 6, 2, 1], [[3, 2], [4, 2]], 2, 4) == 2",
"assert find_Element([2, 1, 4, 9, 7, 9], [[5, 2], [5, 5]], 2, 2) == 4"
] | def check(candidate):
# Check some simple cases
assert find_Element([1,2,3,4,5],[[0,2],[0,3]],2,1) == 3
assert find_Element([1,2,3,4],[[0,1],[0,2]],1,2) == 3
assert find_Element([1,2,3,4,5,6],[[0,1],[0,2]],1,1) == 1
|
|
305 | Write a function to match two words from a list of words starting with letter 'p'. | start_withp | import re
def start_withp(words):
for w in words:
m = re.match("(P\w+)\W(P\w+)", w)
if m:
return m.groups() | [
"assert start_withp(['PvwIjCXZpspL', 'hyihxov']) == None",
"assert start_withp(['ZtuvCYJazjsjRYX', 'uaclryyrh']) == None",
"assert start_withp(['ARrJFecRB', 'vuxrwjcw']) == None"
] | def check(candidate):
# Check some simple cases
assert start_withp(["Python PHP", "Java JavaScript", "c c++"])==('Python', 'PHP')
assert start_withp(["Python Programming","Java Programming"])==('Python','Programming')
assert start_withp(["Pqrst Pqr","qrstuv"])==('Pqrst','Pqr')
|
|
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 . | max_sum_increasing_subseq | 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]:
dp[i][j] = dp[i - 1][i] + a[j]
else:
dp[i][j] = dp[i - 1][j]
else:
dp[i][j] = dp[i - 1][j]
return dp[index][k] | [
"assert max_sum_increasing_subseq([6, 10, 14, 22, 29, 24, 27], 5, 1, 3) == 38",
"assert max_sum_increasing_subseq([11, 17, 15, 24, 22, 26, 28], 6, 4, 5) == 78",
"assert max_sum_increasing_subseq([16, 11, 22, 21, 25, 25, 32], 5, 3, 1) == 11"
] | def check(candidate):
# Check some simple cases
assert max_sum_increasing_subseq([1, 101, 2, 3, 100, 4, 5 ], 7, 4, 6) == 11
assert max_sum_increasing_subseq([1, 101, 2, 3, 100, 4, 5 ], 7, 2, 5) == 7
assert max_sum_increasing_subseq([11, 15, 19, 21, 26, 28, 31], 7, 2, 4) == 71
|
|
307 | Write a function to get a colon of a tuple. | colon_tuplex | from copy import deepcopy
def colon_tuplex(tuplex,m,n):
tuplex_colon = deepcopy(tuplex)
tuplex_colon[m].append(n)
return tuplex_colon | [
"assert colon_tuplex(('LTA', 5, [], 6), 2, 505) == ('LTA', 5, [505], 6)",
"assert colon_tuplex(('AWLFTG', 6, [], 1), 2, 496) == ('AWLFTG', 6, [496], 1)",
"assert colon_tuplex(('YGF', 3, [], 2), 2, 502) == ('YGF', 3, [502], 2)"
] | def check(candidate):
# Check some simple cases
assert colon_tuplex(("HELLO", 5, [], True) ,2,50)==("HELLO", 5, [50], True)
assert colon_tuplex(("HELLO", 5, [], True) ,2,100)==(("HELLO", 5, [100],True))
assert colon_tuplex(("HELLO", 5, [], True) ,2,500)==("HELLO", 5, [500], True)
|
|
308 | Write a function to find the specified number of largest products from two given lists. | large_product | def large_product(nums1, nums2, N):
result = sorted([x*y for x in nums1 for y in nums2], reverse=True)[:N]
return result | [
"assert large_product([2, 1, 3, 2, 9, 4], [1, 9, 11, 12, 7, 2], 1) == [108]",
"assert large_product([6, 2, 6, 5, 9, 8], [5, 9, 6, 10, 12, 6], 7) == [108, 96, 90, 81, 80, 72, 72]",
"assert large_product([4, 6, 7, 8, 2, 7], [2, 11, 6, 12, 10, 3], 2) == [96, 88]"
] | def check(candidate):
# Check some simple cases
assert large_product([1, 2, 3, 4, 5, 6],[3, 6, 8, 9, 10, 6],3)==[60, 54, 50]
assert large_product([1, 2, 3, 4, 5, 6],[3, 6, 8, 9, 10, 6],4)==[60, 54, 50, 48]
assert large_product([1, 2, 3, 4, 5, 6],[3, 6, 8, 9, 10, 6],5)==[60, 54, 50, 48, 45]
|
|
309 | Write a python function to find the maximum of two numbers. | maximum | def maximum(a,b):
if a >= b:
return a
else:
return b | [
"assert maximum(12, 7) == 12",
"assert maximum(9, 5) == 9",
"assert maximum(4, 9) == 9"
] | def check(candidate):
# Check some simple cases
assert maximum(5,10) == 10
assert maximum(-1,-2) == -1
assert maximum(9,7) == 9
|
|
310 | Write a function to convert a given string to a tuple. | string_to_tuple | def string_to_tuple(str1):
result = tuple(x for x in str1 if not x.isspace())
return result | [
"assert string_to_tuple(\"5245\") == ('5', '2', '4', '5')",
"assert string_to_tuple(\"2809\") == ('2', '8', '0', '9')",
"assert string_to_tuple(\"655.96085\") == ('6', '5', '5', '.', '9', '6', '0', '8', '5')"
] | def check(candidate):
# Check some simple cases
assert string_to_tuple("python 3.0")==('p', 'y', 't', 'h', 'o', 'n', '3', '.', '0')
assert string_to_tuple("item1")==('i', 't', 'e', 'm', '1')
assert string_to_tuple("15.10")==('1', '5', '.', '1', '0')
|
|
311 | Write a python function to set the left most unset bit. | set_left_most_unset_bit | 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))) | [
"assert set_left_most_unset_bit(19) == 27",
"assert set_left_most_unset_bit(16) == 24",
"assert set_left_most_unset_bit(18) == 26"
] | def check(candidate):
# Check some simple cases
assert set_left_most_unset_bit(10) == 14
assert set_left_most_unset_bit(12) == 14
assert set_left_most_unset_bit(15) == 15
|
|
312 | Write a function to find the volume of a cone. | volume_cone | import math
def volume_cone(r,h):
volume = (1.0/3) * math.pi * r * r * h
return volume | [
"assert volume_cone(14, 17) == 3489.2622405870634",
"assert volume_cone(15, 20) == 4712.388980384689",
"assert volume_cone(16, 22) == 5897.816608339238"
] | def check(candidate):
# Check some simple cases
assert volume_cone(5,12)==314.15926535897927
assert volume_cone(10,15)==1570.7963267948965
assert volume_cone(19,17)==6426.651371693521
|
|
313 | Write a python function to print positive numbers in a list. | pos_nos | def pos_nos(list1):
for num in list1:
if num >= 0:
return num | [
"assert pos_nos([2, -8, 2]) == 2",
"assert pos_nos([0, -5, 6]) == 0",
"assert pos_nos([-3, 1, 5]) == 1"
] | def check(candidate):
# Check some simple cases
assert pos_nos([-1,-2,1,2]) == 1,2
assert pos_nos([3,4,-5]) == 3,4
assert pos_nos([-2,-3,1]) == 1
|
|
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. | max_sum_rectangular_grid | 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) | [
"assert max_sum_rectangular_grid([[10, 13, 14, 18, 16], [16, 29, 26, 34, 27]], 4) == 63",
"assert max_sum_rectangular_grid([[8, 11, 6, 19, 16], [21, 20, 23, 29, 37]], 1) == 21",
"assert max_sum_rectangular_grid([[8, 13, 16, 17, 22], [16, 30, 33, 26, 30]], 5) == 79"
] | def check(candidate):
# Check some simple cases
assert max_sum_rectangular_grid([ [1, 4, 5], [2, 0, 0 ] ], 3) == 7
assert max_sum_rectangular_grid([ [ 1, 2, 3, 4, 5], [ 6, 7, 8, 9, 10] ], 5) == 24
assert max_sum_rectangular_grid([ [7, 9, 11, 15, 19], [21, 25, 28, 31, 32] ], 5) == 81
|
|
315 | Write a python function to find the first maximum length of even word. | find_Max_Len_Even | 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
currlen = 0
else :
currlen += 1
i += 1
if (currlen % 2 == 0):
if (maxlen < currlen):
maxlen = currlen
st = i - currlen
if (st == -1):
return "-1"
return str[st: st + maxlen] | [
"assert find_Max_Len_Even(\"fgabjragk\") == -1",
"assert find_Max_Len_Even(\"ycse\") == \"ycse\"",
"assert find_Max_Len_Even(\"zkumcf\") == \"zkumcf\""
] | def check(candidate):
# Check some simple cases
assert find_Max_Len_Even("python language") == "language"
assert find_Max_Len_Even("maximum even length") == "length"
assert find_Max_Len_Even("eve") == "-1"
|
|
316 | Write a function to find the index of the last occurrence of a given number in a sorted array. | find_last_occurrence | 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 + 1
return result | [
"assert find_last_occurrence([2, 4, 6, 3, 7, 10, 10, 8, 12, 11], 11) == -1",
"assert find_last_occurrence([6, 2, 6, 5, 2, 8, 11, 10, 5, 14], 5) == -1",
"assert find_last_occurrence([1, 4, 6, 4, 3, 10, 9, 5, 10, 13], 2) == -1"
] | def check(candidate):
# Check some simple cases
assert find_last_occurrence([2, 5, 5, 5, 6, 6, 8, 9, 9, 9], 5) == 3
assert find_last_occurrence([2, 3, 5, 8, 6, 6, 8, 9, 9, 9], 9) == 9
assert find_last_occurrence([2, 2, 1, 5, 6, 6, 6, 9, 9, 9], 6) == 6
|
|
317 | Write a function to reflect the modified run-length encoding from a list. | modified_encode | from itertools import groupby
def modified_encode(alist):
def ctr_ele(el):
if len(el)>1: return [len(el), el[0]]
else: return el[0]
return [ctr_ele(list(group)) for key, group in groupby(alist)] | [
"assert modified_encode(\"zdzpc\") == ['z', 'd', 'z', 'p', 'c']",
"assert modified_encode(\"qdhfbeohbifd\") == ['q', 'd', 'h', 'f', 'b', 'e', 'o', 'h', 'b', 'i', 'f', 'd']",
"assert modified_encode(\"uesdks\") == ['u', 'e', 's', 'd', 'k', 's']"
] | def check(candidate):
# Check some simple cases
assert modified_encode([1,1,2,3,4,4,5,1])==[[2, 1], 2, 3, [2, 4], 5, 1]
assert modified_encode('automatically')==['a', 'u', 't', 'o', 'm', 'a', 't', 'i', 'c', 'a', [2, 'l'], 'y']
assert modified_encode('python')==['p', 'y', 't', 'h', 'o', 'n']
|
|
318 | Write a python function to find the maximum volume of a cuboid with given sum of sides. | max_volume | 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 | [
"assert max_volume(3) == 1",
"assert max_volume(4) == 2",
"assert max_volume(3) == 1"
] | def check(candidate):
# Check some simple cases
assert max_volume(8) == 18
assert max_volume(4) == 2
assert max_volume(1) == 0
|
|
319 | Write a function to find all five characters long word in the given string by using regex. | find_long_word | import re
def find_long_word(text):
return (re.findall(r"\b\w{5}\b", text)) | [
"assert find_long_word(\"LApUexGcpW sSDTFYWboOcPW\") == []",
"assert find_long_word(\"HwyGVUUVDC SaxFDwfYVZ\") == []",
"assert find_long_word(\"nLDHgpYgBYKiSSpaPmOoUUwopH\") == []"
] | def check(candidate):
# Check some simple cases
assert find_long_word('Please move back to strem') == ['strem']
assert find_long_word('4K Ultra HD streaming player') == ['Ultra']
assert find_long_word('Streaming Media Player') == ['Media']
|
|
320 | Write a function to calculate the difference between the squared sum of first n natural numbers and the sum of squared first n natural numbers. | sum_difference | def sum_difference(n):
sumofsquares = 0
squareofsum = 0
for num in range(1, n+1):
sumofsquares += num * num
squareofsum += num
squareofsum = squareofsum ** 2
return squareofsum - sumofsquares | [
"assert sum_difference(49) == 1460200",
"assert sum_difference(50) == 1582700",
"assert sum_difference(58) == 2860792"
] | def check(candidate):
# Check some simple cases
assert sum_difference(12)==5434
assert sum_difference(20)==41230
assert sum_difference(54)==2151270
|
|
321 | Write a function to find the demlo number for the given number. | find_demlo | def find_demlo(s):
l = len(s)
res = ""
for i in range(1,l+1):
res = res + str(i)
for i in range(l-1,0,-1):
res = res + str(i)
return res | [
"assert find_demlo(\"478007138454\") == 1234567891011121110987654321",
"assert find_demlo(\"84015371563\") == 123456789101110987654321",
"assert find_demlo(\"914789910\") == 12345678987654321"
] | def check(candidate):
# Check some simple cases
assert find_demlo("111111") == '12345654321'
assert find_demlo("1111") == '1234321'
assert find_demlo("13333122222") == '123456789101110987654321'
|
|
322 | Write a function to find all index positions of the minimum values in a given list. | position_min | def position_min(list1):
min_val = min(list1)
min_result = [i for i, j in enumerate(list1) if j == min_val]
return min_result | [
"assert position_min([1, 3, 10, 5, 7, 2, 8, 9, 5, 15, 11, 12]) == [0]",
"assert position_min([6, 5, 8, 7, 3, 1, 7, 6, 5, 7, 6, 11]) == [5]",
"assert position_min([7, 1, 10, 4, 9, 5, 2, 13, 8, 16, 8, 10]) == [1]"
] | def check(candidate):
# Check some simple cases
assert position_min([12,33,23,10,67,89,45,667,23,12,11,10,54])==[3,11]
assert position_min([1,2,2,2,4,4,4,5,5,5,5])==[0]
assert position_min([2,1,5,6,8,3,4,9,10,11,8,12])==[1]
|
|
323 | Write a function to re-arrange the given array in alternating positive and negative items. | re_arrange | def right_rotate(arr, n, out_of_place, cur):
temp = arr[cur]
for i in range(cur, out_of_place, -1):
arr[i] = arr[i - 1]
arr[out_of_place] = temp
return arr
def re_arrange(arr, n):
out_of_place = -1
for index in range(n):
if (out_of_place >= 0):
if ((arr[index] >= 0 and arr[out_of_place] < 0) or
(arr[index] < 0 and arr[out_of_place] >= 0)):
arr = right_rotate(arr, n, out_of_place, index)
if (index-out_of_place > 2):
out_of_place += 2
else:
out_of_place = - 1
if (out_of_place == -1):
if ((arr[index] >= 0 and index % 2 == 0) or
(arr[index] < 0 and index % 2 == 1)):
out_of_place = index
return arr | [
"assert re_arrange([4, 6, 14, 80, -9, 4, -8, -13], 3) == [4, 6, 14, 80, -9, 4, -8, -13]",
"assert re_arrange([6, 10, 10, 75, -7, 4, 0, -12], 7) == [-7, 6, 10, 10, 75, 4, 0, -12]",
"assert re_arrange([9, 6, 10, 79, -1, 2, -6, -12], 4) == [9, 6, 10, 79, -1, 2, -6, -12]"
] | def check(candidate):
# Check some simple cases
assert re_arrange([-5, -2, 5, 2, 4, 7, 1, 8, 0, -8], 10) == [-5, 5, -2, 2, -8, 4, 7, 1, 8, 0]
assert re_arrange([1, 2, 3, -4, -1, 4], 6) == [-4, 1, -1, 2, 3, 4]
assert re_arrange([4, 7, 9, 77, -4, 5, -3, -9], 8) == [-4, 4, -3, 7, -9, 9, 77, 5]
|
|
324 | Write a function to extract the sum of alternate chains of tuples. | sum_of_alternates | def sum_of_alternates(test_tuple):
sum1 = 0
sum2 = 0
for idx, ele in enumerate(test_tuple):
if idx % 2:
sum1 += ele
else:
sum2 += ele
return ((sum1),(sum2)) | [
"assert sum_of_alternates((3, 11, 10, 7, 9, 4)) == (22, 22)",
"assert sum_of_alternates((1, 9, 6, 5, 5, 8)) == (22, 12)",
"assert sum_of_alternates((2, 7, 13, 8, 3, 10)) == (25, 18)"
] | def check(candidate):
# Check some simple cases
assert sum_of_alternates((5, 6, 3, 6, 10, 34)) == (46, 18)
assert sum_of_alternates((1, 2, 3, 4, 5)) == (6, 9)
assert sum_of_alternates((6, 7, 8, 9, 4, 5)) == (21, 18)
|
|
325 | Write a python function to find the minimum number of squares whose sum is equal to a given number. | get_Min_Squares | def get_Min_Squares(n):
if n <= 3:
return n;
res = n
for x in range(1,n + 1):
temp = x * x;
if temp > n:
break
else:
res = min(res,1 + get_Min_Squares(n - temp))
return res; | [
"assert get_Min_Squares(3) == 3",
"assert get_Min_Squares(7) == 4",
"assert get_Min_Squares(9) == 1"
] | def check(candidate):
# Check some simple cases
assert get_Min_Squares(6) == 3
assert get_Min_Squares(2) == 2
assert get_Min_Squares(4) == 1
|
|
326 | Write a function to get the word with most number of occurrences in the given strings list. | most_occurrences | from collections import defaultdict
def most_occurrences(test_list):
temp = defaultdict(int)
for sub in test_list:
for wrd in sub.split():
temp[wrd] += 1
res = max(temp, key=temp.get)
return (str(res)) | [
"assert most_occurrences(['kLacwTFrlOWqWAgDfThJRgYgUA', 'qozoiztqrmjfmvsrbtnz', 'fgTLLUopGtOTngebfREvfBUR']) == \"kLacwTFrlOWqWAgDfThJRgYgUA\"",
"assert most_occurrences(['HYkiCYPXvPWcNJCQZrmXjYfDhJkl', 'efou wzfhztlimhsmrfdxb', 'FcsyRjnzIrMajDmCVKAnZ']) == \"HYkiCYPXvPWcNJCQZrmXjYfDhJkl\"",
"assert most_occurrences(['ZRTtBRZcRPVQuuq z SoqeZBrA', 'qnfiwqblrnlhyzceuxulbgz', 'k kODimKQFxfRceQYWQEavuBt']) == \"ZRTtBRZcRPVQuuq\""
] | def check(candidate):
# Check some simple cases
assert most_occurrences(["UTS is best for RTF", "RTF love UTS", "UTS is best"] ) == 'UTS'
assert most_occurrences(["Its been a great year", "this year is so worse", "this year is okay"] ) == 'year'
assert most_occurrences(["Families can be reunited", "people can be reunited", "Tasks can be achieved "] ) == 'can'
|
|
327 | Write a function to print check if the triangle is isosceles or not. | check_isosceles | def check_isosceles(x,y,z):
if x==y or y==z or z==x:
return True
else:
return False | [
"assert check_isosceles(4, 14, 16) == False",
"assert check_isosceles(4, 15, 24) == False",
"assert check_isosceles(11, 20, 18) == False"
] | def check(candidate):
# Check some simple cases
assert check_isosceles(6,8,12)==False
assert check_isosceles(6,6,12)==True
assert check_isosceles(6,16,20)==False
|
|
328 | Write a function to rotate a given list by specified number of items to the left direction. | rotate_left | def rotate_left(list1,m,n):
result = list1[m:]+list1[:n]
return result | [
"assert rotate_left([4, 5, 6, 5, 4, 5, 4, 9, 7, 8], 2, 3) == [6, 5, 4, 5, 4, 9, 7, 8, 4, 5, 6]",
"assert rotate_left([1, 3, 4, 7, 4, 9, 10, 4, 8, 9], 2, 5) == [4, 7, 4, 9, 10, 4, 8, 9, 1, 3, 4, 7, 4]",
"assert rotate_left([3, 4, 7, 2, 7, 1, 5, 12, 4, 10], 3, 2) == [2, 7, 1, 5, 12, 4, 10, 3, 4]"
] | def check(candidate):
# Check some simple cases
assert rotate_left([1, 2, 3, 4, 5, 6, 7, 8, 9, 10],3,4)==[4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4]
assert rotate_left([1, 2, 3, 4, 5, 6, 7, 8, 9, 10],2,2)==[3, 4, 5, 6, 7, 8, 9, 10, 1, 2]
assert rotate_left([1, 2, 3, 4, 5, 6, 7, 8, 9, 10],5,2)==[6, 7, 8, 9, 10, 1, 2]
|
|
329 | Write a python function to count negative numbers in a list. | neg_count | def neg_count(list):
neg_count= 0
for num in list:
if num <= 0:
neg_count += 1
return neg_count | [
"assert neg_count([2, 1, 2, -10, 21]) == 1",
"assert neg_count([3, 6, -6, -7, 18]) == 2",
"assert neg_count([6, 1, 0, -14, 21]) == 2"
] | def check(candidate):
# Check some simple cases
assert neg_count([-1,-2,3,-4,-5]) == 4
assert neg_count([1,2,3]) == 0
assert neg_count([1,2,-3,-10,20]) == 2
|
|
330 | Write a function to find all three, four, five characters long words in the given string by using regex. | find_char | import re
def find_char(text):
return (re.findall(r"\b\w{3,5}\b", text)) | [
"assert find_char(\"K WPYHlUZAuXmpZIJJThTnhvwrilNhVDL\") == []",
"assert find_char(\"uNxBpNWDMGS NBgxPStLmjpK\") == []",
"assert find_char(\"JEakuAhwSP rgYjTrRNvWw O\") == []"
] | def check(candidate):
# Check some simple cases
assert find_char('For the four consumer complaints contact manager AKR reddy') == ['For', 'the', 'four', 'AKR', 'reddy']
assert find_char('Certain service are subject to change MSR') == ['are', 'MSR']
assert find_char('Third party legal desclaimers') == ['Third', 'party', 'legal']
|
|
331 | Write a python function to count unset bits of a given number. | count_unset_bits | def count_unset_bits(n):
count = 0
x = 1
while(x < n + 1):
if ((x & n) == 0):
count += 1
x = x << 1
return count | [
"assert count_unset_bits(3) == 0",
"assert count_unset_bits(2) == 1",
"assert count_unset_bits(9) == 2"
] | def check(candidate):
# Check some simple cases
assert count_unset_bits(2) == 1
assert count_unset_bits(4) == 2
assert count_unset_bits(6) == 1
|
|
332 | Write a function to count character frequency of a given string. | char_frequency | def char_frequency(str1):
dict = {}
for n in str1:
keys = dict.keys()
if n in keys:
dict[n] += 1
else:
dict[n] = 1
return dict | [
"assert char_frequency(\"ggscyauom\") == {'g': 2, 's': 1, 'c': 1, 'y': 1, 'a': 1, 'u': 1, 'o': 1, 'm': 1}",
"assert char_frequency(\"yilaljnrxx\") == {'y': 1, 'i': 1, 'l': 2, 'a': 1, 'j': 1, 'n': 1, 'r': 1, 'x': 2}",
"assert char_frequency(\"xflz\") == {'x': 1, 'f': 1, 'l': 1, 'z': 1}"
] | def check(candidate):
# Check some simple cases
assert char_frequency('python')=={'p': 1, 'y': 1, 't': 1, 'h': 1, 'o': 1, 'n': 1}
assert char_frequency('program')=={'p': 1, 'r': 2, 'o': 1, 'g': 1, 'a': 1, 'm': 1}
assert char_frequency('language')=={'l': 1, 'a': 2, 'n': 1, 'g': 2, 'u': 1, 'e': 1}
|
|
333 | Write a python function to sort a list according to the second element in sublist. | Sort | def Sort(sub_li):
sub_li.sort(key = lambda x: x[1])
return sub_li | [
"assert Sort([['hdtzyjoci', 9], ['xlyhaenvw', 5], ['mjhssqkug', 24], ['oxfexvlac', 13]]) == [['xlyhaenvw', 5], ['hdtzyjoci', 9], ['oxfexvlac', 13], ['mjhssqkug', 24]]",
"assert Sort([['cpcbgz', 13], ['gaegdis', 6], ['ufqtqjy', 20], ['tfwczy', 18]]) == [['gaegdis', 6], ['cpcbgz', 13], ['tfwczy', 18], ['ufqtqjy', 20]]",
"assert Sort([['fjkxg', 9], ['daahle', 7], ['kmbce', 15], ['ouio', 11]]) == [['daahle', 7], ['fjkxg', 9], ['ouio', 11], ['kmbce', 15]]"
] | def check(candidate):
# Check some simple cases
assert Sort([['a', 10], ['b', 5], ['c', 20], ['d', 15]]) == [['b', 5], ['a', 10], ['d', 15], ['c', 20]]
assert Sort([['452', 10], ['256', 5], ['100', 20], ['135', 15]]) == [['256', 5], ['452', 10], ['135', 15], ['100', 20]]
assert Sort([['rishi', 10], ['akhil', 5], ['ramya', 20], ['gaur', 15]]) == [['akhil', 5], ['rishi', 10], ['gaur', 15], ['ramya', 20]]
|
|
334 | Write a python function to check whether the triangle is valid or not if sides are given. | check_Validity | def check_Validity(a,b,c):
if (a + b <= c) or (a + c <= b) or (b + c <= a) :
return False
else:
return True | [
"assert check_Validity(8, 14, 9) == True",
"assert check_Validity(12, 8, 5) == True",
"assert check_Validity(8, 15, 8) == True"
] | def check(candidate):
# Check some simple cases
assert check_Validity(1,2,3) == False
assert check_Validity(2,3,5) == False
assert check_Validity(7,10,5) == True
|
|
335 | Write a function to find the sum of arithmetic progression. | ap_sum | def ap_sum(a,n,d):
total = (n * (2 * a + (n - 1) * d)) / 2
return total | [
"assert ap_sum(3, 7, 2) == 63.0",
"assert ap_sum(5, 3, 3) == 24.0",
"assert ap_sum(4, 8, 7) == 228.0"
] | def check(candidate):
# Check some simple cases
assert ap_sum(1,5,2)==25
assert ap_sum(2,6,4)==72
assert ap_sum(1,4,5)==34
|
|
336 | Write a function to check whether the given month name contains 28 days or not. | check_monthnum | def check_monthnum(monthname1):
if monthname1 == "February":
return True
else:
return False | [
"assert check_monthnum(\"ldjNvPgDa\") == False",
"assert check_monthnum(\"POCwZPWDq\") == False",
"assert check_monthnum(\"dOt\") == False"
] | def check(candidate):
# Check some simple cases
assert check_monthnum("February")==True
assert check_monthnum("January")==False
assert check_monthnum("March")==False
|
|
337 | Write a function that matches a word at the end of a string, with optional punctuation. | text_match_word | import re
def text_match_word(text):
patterns = '\w+\S*$'
if re.search(patterns, text):
return 'Found a match!'
else:
return 'Not matched!' | [
"assert text_match_word(\"phgr.f.ttfk\") == \"Found a match!\"",
"assert text_match_word(\"lfjxqgchdxdqvn\") == \"Found a match!\"",
"assert text_match_word(\"zlcruv\") == \"Found a match!\""
] | def check(candidate):
# Check some simple cases
assert text_match_word("python.")==('Found a match!')
assert text_match_word("python.")==('Found a match!')
assert text_match_word(" lang .")==('Not matched!')
|
|
338 | Write a python function to count the number of substrings with same first and last characters. | count_Substring_With_Equal_Ends | def check_Equality(s):
return (ord(s[0]) == ord(s[len(s) - 1]));
def count_Substring_With_Equal_Ends(s):
result = 0;
n = len(s);
for i in range(n):
for j in range(1,n-i+1):
if (check_Equality(s[i:i+j])):
result+=1;
return result; | [
"assert count_Substring_With_Equal_Ends(\"oszpwoh\") == 8",
"assert count_Substring_With_Equal_Ends(\"vaz\") == 3",
"assert count_Substring_With_Equal_Ends(\"lgah\") == 4"
] | def check(candidate):
# Check some simple cases
assert count_Substring_With_Equal_Ends('aba') == 4
assert count_Substring_With_Equal_Ends('abcab') == 7
assert count_Substring_With_Equal_Ends('abc') == 3
|
|
339 | Write a python function to find the maximum occuring divisor in an interval. | find_Divisor | def find_Divisor(x,y):
if (x==y):
return y
return 2 | [
"assert find_Divisor(8, 15) == 2",
"assert find_Divisor(9, 13) == 2",
"assert find_Divisor(9, 13) == 2"
] | def check(candidate):
# Check some simple cases
assert find_Divisor(2,2) == 2
assert find_Divisor(2,5) == 2
assert find_Divisor(5,10) == 2
|
|
340 | Write a python function to find the sum of the three lowest positive numbers from a given list of numbers. | sum_three_smallest_nums | def sum_three_smallest_nums(lst):
return sum(sorted([x for x in lst if x > 0])[:3]) | [
"assert sum_three_smallest_nums([1, 5, 4, 5, 7, 4]) == 9",
"assert sum_three_smallest_nums([2, 2, 2, 3, 5, 8]) == 6",
"assert sum_three_smallest_nums([5, 1, 4, 3, 6, 5]) == 8"
] | def check(candidate):
# Check some simple cases
assert sum_three_smallest_nums([10,20,30,40,50,60,7]) == 37
assert sum_three_smallest_nums([1,2,3,4,5]) == 6
assert sum_three_smallest_nums([0,1,2,3,4,5]) == 6
|
|
341 | Write a function to convert the given set into ordered tuples. | set_to_tuple | def set_to_tuple(s):
t = tuple(sorted(s))
return (t) | [
"assert set_to_tuple({9, 11, 12, 13, 19}) == (9, 11, 12, 13, 19)",
"assert set_to_tuple({8, 12, 13, 14, 20}) == (8, 12, 13, 14, 20)",
"assert set_to_tuple({8, 12, 15, 17, 19}) == (8, 12, 15, 17, 19)"
] | def check(candidate):
# Check some simple cases
assert set_to_tuple({1, 2, 3, 4, 5}) == (1, 2, 3, 4, 5)
assert set_to_tuple({6, 7, 8, 9, 10, 11}) == (6, 7, 8, 9, 10, 11)
assert set_to_tuple({12, 13, 14, 15, 16}) == (12, 13, 14, 15, 16)
|
|
342 | Write a function to find the smallest range that includes at-least one element from each of the given arrays. | find_minimum_range | from heapq import heappop, heappush
class Node:
def __init__(self, value, list_num, index):
self.value = value
self.list_num = list_num
self.index = index
def __lt__(self, other):
return self.value < other.value
def find_minimum_range(list):
high = float('-inf')
p = (0, float('inf'))
pq = []
for i in range(len(list)):
heappush(pq, Node(list[i][0], i, 0))
high = max(high, list[i][0])
while True:
top = heappop(pq)
low = top.value
i = top.list_num
j = top.index
if high - low < p[1] - p[0]:
p = (low, high)
if j == len(list[i]) - 1:
return p
heappush(pq, Node(list[i][j + 1], i, j + 1))
high = max(high, list[i][j + 1]) | [
"assert find_minimum_range([[3, 8, 5, 7, 13], [5, 3, 9], [8, 14, 19, 14], [2, 2]]) == (2, 8)",
"assert find_minimum_range([[5, 3, 4, 10, 19], [6, 7, 9], [1, 13, 13, 20], [6, 7]]) == (1, 6)",
"assert find_minimum_range([[6, 6, 8, 7, 20], [1, 3, 8], [1, 6, 21, 13], [7, 2]]) == (6, 8)"
] | def check(candidate):
# Check some simple cases
assert find_minimum_range([[3, 6, 8, 10, 15], [1, 5, 12], [4, 8, 15, 16], [2, 6]]) == (4, 6)
assert find_minimum_range([[ 2, 3, 4, 8, 10, 15 ], [1, 5, 12], [7, 8, 15, 16], [3, 6]]) == (4, 7)
assert find_minimum_range([[4, 7, 9, 11, 16], [2, 6, 13], [5, 9, 16, 17], [3, 7]]) == (5, 7)
|
|
343 | Write a function to calculate the number of digits and letters in a string. | dig_let | def dig_let(s):
d=l=0
for c in s:
if c.isdigit():
d=d+1
elif c.isalpha():
l=l+1
else:
pass
return (l,d) | [
"assert dig_let(\"x.g5gsn\") == (5, 1)",
"assert dig_let(\"tnaxgk1g.\") == (7, 1)",
"assert dig_let(\"ayhqhs650ywrmlk\") == (12, 3)"
] | def check(candidate):
# Check some simple cases
assert dig_let("python")==(6,0)
assert dig_let("program")==(7,0)
assert dig_let("python3.0")==(6,2)
|
|
344 | Write a python function to find number of elements with odd factors in a given range. | count_Odd_Squares | def count_Odd_Squares(n,m):
return int(m**0.5) - int((n-1)**0.5) | [
"assert count_Odd_Squares(7, 3) == -1",
"assert count_Odd_Squares(5, 10) == 1",
"assert count_Odd_Squares(1, 9) == 3"
] | def check(candidate):
# Check some simple cases
assert count_Odd_Squares(5,100) == 8
assert count_Odd_Squares(8,65) == 6
assert count_Odd_Squares(2,5) == 1
|
|
345 | Write a function to find the difference between two consecutive numbers in a given list. | diff_consecutivenums | def diff_consecutivenums(nums):
result = [b-a for a, b in zip(nums[:-1], nums[1:])]
return result | [
"assert diff_consecutivenums([4, 4, 6, 5, 6, 5, 3, 8, 5, 4]) == [0, 2, -1, 1, -1, -2, 5, -3, -1]",
"assert diff_consecutivenums([4, 4, 6, 1, 5, 5, 6, 2, 7, 9]) == [0, 2, -5, 4, 0, 1, -4, 5, 2]",
"assert diff_consecutivenums([2, 2, 5, 1, 2, 2, 2, 3, 9, 2]) == [0, 3, -4, 1, 0, 0, 1, 6, -7]"
] | def check(candidate):
# Check some simple cases
assert diff_consecutivenums([1, 1, 3, 4, 4, 5, 6, 7])==[0, 2, 1, 0, 1, 1, 1]
assert diff_consecutivenums([4, 5, 8, 9, 6, 10])==[1, 3, 1, -3, 4]
assert diff_consecutivenums([0, 1, 2, 3, 4, 4, 4, 4, 5, 7])==[1, 1, 1, 1, 0, 0, 0, 1, 2]
|
|
346 | Write a function to find entringer number e(n, k). | zigzag | def zigzag(n, k):
if (n == 0 and k == 0):
return 1
if (k == 0):
return 0
return zigzag(n, k - 1) + zigzag(n - 1, n - k) | [
"assert zigzag(7, 5) == 256",
"assert zigzag(4, 1) == 2",
"assert zigzag(5, 3) == 14"
] | def check(candidate):
# Check some simple cases
assert zigzag(4, 3) == 5
assert zigzag(4, 2) == 4
assert zigzag(3, 1) == 1
|
|
347 | Write a python function to count the number of squares in a rectangle. | count_Squares | def count_Squares(m,n):
if (n < m):
temp = m
m = n
n = temp
return n * (n + 1) * (3 * m - n + 1) // 6 | [
"assert count_Squares(4, 1) == 0",
"assert count_Squares(6, 3) == 28",
"assert count_Squares(6, 4) == 49"
] | def check(candidate):
# Check some simple cases
assert count_Squares(4,3) == 20
assert count_Squares(1,2) == 2
assert count_Squares(2,2) == 5
|
|
348 | Write a function to count sequences of given length having non-negative prefix sums that can be generated by given values. | find_ways | def bin_coff(n, r):
val = 1
if (r > (n - r)):
r = (n - r)
for i in range(0, r):
val *= (n - i)
val //= (i + 1)
return val
def find_ways(M):
n = M // 2
a = bin_coff(2 * n, n)
b = a // (n + 1)
return (b) | [
"assert find_ways(4) == 2",
"assert find_ways(11) == 42",
"assert find_ways(11) == 42"
] | def check(candidate):
# Check some simple cases
assert find_ways(4) == 2
assert find_ways(6) == 5
assert find_ways(8) == 14
|
|
349 | Write a python function to check whether the given string is a binary string or not. | check | def check(string) :
p = set(string)
s = {'0', '1'}
if s == p or p == {'0'} or p == {'1'}:
return ("Yes")
else :
return ("No") | [
"assert check(\"3234\") == \"No\"",
"assert check(\"1912\") == \"No\"",
"assert check(\"2629237\") == \"No\""
] | def check(candidate):
# Check some simple cases
assert check("01010101010") == "Yes"
assert check("name0") == "No"
assert check("101") == "Yes"
|
|
350 | Write a python function to minimize the length of the string by removing occurrence of only one character. | minimum_Length | def minimum_Length(s) :
maxOcc = 0
n = len(s)
arr = [0]*26
for i in range(n) :
arr[ord(s[i]) -ord('a')] += 1
for i in range(26) :
if arr[i] > maxOcc :
maxOcc = arr[i]
return n - maxOcc | [
"assert minimum_Length(\"quujcnsu\") == 5",
"assert minimum_Length(\"mmjv\") == 2",
"assert minimum_Length(\"iryewrap\") == 6"
] | def check(candidate):
# Check some simple cases
assert minimum_Length("mnm") == 1
assert minimum_Length("abcda") == 3
assert minimum_Length("abcb") == 2
|
|
351 | Write a python function to find the first element occurring k times in a given array. | first_Element | def first_Element(arr,n,k):
count_map = {};
for i in range(0, n):
if(arr[i] in count_map.keys()):
count_map[arr[i]] += 1
else:
count_map[arr[i]] = 1
i += 1
for i in range(0, n):
if (count_map[arr[i]] == k):
return arr[i]
i += 1
return -1 | [
"assert first_Element([7, 6, 8, 6, 7, 12, 2, 2, 8, 1], 7, 5) == -1",
"assert first_Element([6, 7, 8, 5, 1, 2, 1, 7, 6, 6], 8, 1) == 6",
"assert first_Element([5, 4, 8, 7, 4, 6, 2, 6, 4, 5], 5, 1) == 5"
] | def check(candidate):
# Check some simple cases
assert first_Element([0,1,2,3,4,5],6,1) == 0
assert first_Element([1,2,1,3,4],5,2) == 1
assert first_Element([2,3,4,3,5,7,1,2,3,5],10,2) == 2
|
|
352 | Write a python function to check whether all the characters in a given string are unique. | unique_Characters | def unique_Characters(str):
for i in range(len(str)):
for j in range(i + 1,len(str)):
if (str[i] == str[j]):
return False;
return True; | [
"assert unique_Characters(\"khxdxcsce\") == False",
"assert unique_Characters(\"zjufyfbv\") == False",
"assert unique_Characters(\"vph\") == True"
] | def check(candidate):
# Check some simple cases
assert unique_Characters('aba') == False
assert unique_Characters('abc') == True
assert unique_Characters('abab') == False
|
|
353 | Write a function to remove a specified column from a given nested list. | remove_column | def remove_column(list1, n):
for i in list1:
del i[n]
return list1 | [
"assert remove_column([[4, 3], [7, 9], [5, 5], [9, 17, 12], [10, 6], [5, 9]], 1) == [[4], [7], [5], [9, 12], [10], [5]]",
"assert remove_column([[2, 8], [3, 11], [1, 5], [12, 20, 15], [8, 6], [7, 7]], 1) == [[2], [3], [1], [12, 15], [8], [7]]",
"assert remove_column([[2, 2], [1, 2], [2, 6], [8, 16, 12], [8, 6], [5, 16]], 1) == [[2], [1], [2], [8, 12], [8], [5]]"
] | def check(candidate):
# Check some simple cases
assert remove_column([[1, 2, 3], [2, 4, 5], [1, 1, 1]],0)==[[2, 3], [4, 5], [1, 1]]
assert remove_column([[1, 2, 3], [-2, 4, -5], [1, -1, 1]],2)==[[1, 2], [-2, 4], [1, -1]]
assert remove_column([[1, 3], [5, 7], [1, 3], [13, 15, 17], [5, 7], [9, 11]],0)==[[3], [7], [3], [15, 17], [7], [11]]
|
|
354 | Write a function to find t-nth term of arithemetic progression. | tn_ap | def tn_ap(a,n,d):
tn = a + (n - 1) * d
return tn | [
"assert tn_ap(1, 6, 7) == 36",
"assert tn_ap(6, 2, 7) == 13",
"assert tn_ap(5, 3, 8) == 21"
] | def check(candidate):
# Check some simple cases
assert tn_ap(1,5,2)==9
assert tn_ap(2,6,4)==22
assert tn_ap(1,4,5)==16
|
|
355 | Write a python function to count the number of rectangles in a circle of radius r. | count_Rectangles | def count_Rectangles(radius):
rectangles = 0
diameter = 2 * radius
diameterSquare = diameter * diameter
for a in range(1, 2 * radius):
for b in range(1, 2 * radius):
diagnalLengthSquare = (a * a + b * b)
if (diagnalLengthSquare <= diameterSquare) :
rectangles += 1
return rectangles | [
"assert count_Rectangles(3) == 22",
"assert count_Rectangles(5) == 69",
"assert count_Rectangles(4) == 41"
] | def check(candidate):
# Check some simple cases
assert count_Rectangles(2) == 8
assert count_Rectangles(1) == 1
assert count_Rectangles(0) == 0
|
|
356 | Write a function to find the third angle of a triangle using two angles. | find_angle | def find_angle(a,b):
c = 180 - (a + b)
return c
| [
"assert find_angle(54, 35) == 91",
"assert find_angle(54, 42) == 84",
"assert find_angle(53, 42) == 85"
] | def check(candidate):
# Check some simple cases
assert find_angle(47,89)==44
assert find_angle(45,95)==40
assert find_angle(50,40)==90
|
|
357 | Write a function to find the maximum element of all the given tuple records. | find_max | def find_max(test_list):
res = max(int(j) for i in test_list for j in i)
return (res) | [
"assert find_max([(7, 6), (8, 12), (12, 4), (13, 9), (13, 13)]) == 13",
"assert find_max([(2, 11), (13, 6), (5, 8), (11, 9), (13, 14)]) == 14",
"assert find_max([(3, 2), (13, 11), (9, 4), (13, 16), (13, 11)]) == 16"
] | def check(candidate):
# Check some simple cases
assert find_max([(2, 4), (6, 7), (5, 1), (6, 10), (8, 7)]) == 10
assert find_max([(3, 5), (7, 8), (6, 2), (7, 11), (9, 8)]) == 11
assert find_max([(4, 6), (8, 9), (7, 3), (8, 12), (10, 9)]) == 12
|
|
358 | Write a function to find modulo division of two lists using map and lambda function. | moddiv_list | def moddiv_list(nums1,nums2):
result = map(lambda x, y: x % y, nums1, nums2)
return list(result) | [
"assert moddiv_list([95, 116], [47, 65]) == [1, 51]",
"assert moddiv_list([92, 117], [49, 66]) == [43, 51]",
"assert moddiv_list([95, 120], [45, 74]) == [5, 46]"
] | def check(candidate):
# Check some simple cases
assert moddiv_list([4,5,6],[1, 2, 3])==[0, 1, 0]
assert moddiv_list([3,2],[1,4])==[0, 2]
assert moddiv_list([90,120],[50,70])==[40, 50]
|
|
359 | Write a python function to check whether one root of the quadratic equation is twice of the other or not. | Check_Solution | def Check_Solution(a,b,c):
if (2*b*b == 9*a*c):
return ("Yes");
else:
return ("No"); | [
"assert Check_Solution(6, -4, 6) == No",
"assert Check_Solution(5, -3, 11) == No",
"assert Check_Solution(3, -2, 2) == No"
] | def check(candidate):
# Check some simple cases
assert Check_Solution(1,3,2) == "Yes"
assert Check_Solution(1,2,3) == "No"
assert Check_Solution(1,-5,6) == "No"
|
|
360 | Write a function to find the n’th carol number. | get_carol | def get_carol(n):
result = (2**n) - 1
return result * result - 2 | [
"assert get_carol(4) == 223",
"assert get_carol(1) == -1",
"assert get_carol(5) == 959"
] | def check(candidate):
# Check some simple cases
assert get_carol(2) == 7
assert get_carol(4) == 223
assert get_carol(5) == 959
|
|
361 | Write a function to remove empty lists from a given list of lists. | remove_empty | def remove_empty(list1):
remove_empty = [x for x in list1 if x]
return remove_empty | [
"assert remove_empty([[], [], [], 'Dvr', [], [], 'tisfhvpbyca', 'ndpqeehna', [], [], [], [], []]) == ['Dvr', 'tisfhvpbyca', 'ndpqeehna']",
"assert remove_empty([[], [], [], 'HuekEJBeQAXh', [], [], 'zlmvgjfzyij', 'ytnynu', [], [], [], [], []]) == ['HuekEJBeQAXh', 'zlmvgjfzyij', 'ytnynu']",
"assert remove_empty([[], [], [], 'IqVf', [], [], 'qcueeglpse', 'gidnabq', [], [], [], [], []]) == ['IqVf', 'qcueeglpse', 'gidnabq']"
] | def check(candidate):
# Check some simple cases
assert remove_empty([[], [], [], 'Red', 'Green', [1,2], 'Blue', [], []])==['Red', 'Green', [1, 2], 'Blue']
assert remove_empty([[], [], [],[],[], 'Green', [1,2], 'Blue', [], []])==[ 'Green', [1, 2], 'Blue']
assert remove_empty([[], [], [], 'Python',[],[], 'programming', 'language',[],[],[], [], []])==['Python', 'programming', 'language']
|
|
362 | Write a python function to find the item with maximum occurrences in a given list. | max_occurrences | def max_occurrences(nums):
max_val = 0
result = nums[0]
for i in nums:
occu = nums.count(i)
if occu > max_val:
max_val = occu
result = i
return result | [
"assert max_occurrences([6, 6, 2, 4, 6, 8, 1]) == 6",
"assert max_occurrences([3, 4, 5, 2, 3, 3, 2]) == 3",
"assert max_occurrences([4, 2, 8, 1, 3, 9, 2]) == 2"
] | def check(candidate):
# Check some simple cases
assert max_occurrences([1,2,3,1,2,3,12,4,2]) == 2
assert max_occurrences([1,2,6,7,0,1,0,1,0]) == 1,0
assert max_occurrences([1,2,3,1,2,4,1]) == 1
|
|
363 | Write a function to add the k elements to each element in the tuple. | add_K_element | def add_K_element(test_list, K):
res = [tuple(j + K for j in sub ) for sub in test_list]
return (res) | [
"assert add_K_element([(12, 17, 15), (15, 11, 21), (18, 19, 21)], 4) == [(16, 21, 19), (19, 15, 25), (22, 23, 25)]",
"assert add_K_element([(14, 11, 16), (15, 11, 13), (18, 17, 22)], 5) == [(19, 16, 21), (20, 16, 18), (23, 22, 27)]",
"assert add_K_element([(14, 10, 9), (19, 11, 12), (13, 20, 22)], 11) == [(25, 21, 20), (30, 22, 23), (24, 31, 33)]"
] | def check(candidate):
# Check some simple cases
assert add_K_element([(1, 3, 4), (2, 4, 6), (3, 8, 1)], 4) == [(5, 7, 8), (6, 8, 10), (7, 12, 5)]
assert add_K_element([(1, 2, 3), (4, 5, 6), (7, 8, 9)], 8) == [(9, 10, 11), (12, 13, 14), (15, 16, 17)]
assert add_K_element([(11, 12, 13), (14, 15, 16), (17, 18, 19)], 9) == [(20, 21, 22), (23, 24, 25), (26, 27, 28)]
|
|
364 | Write a function to find the number of flips required to make the given binary string a sequence of alternate characters. | min_flip_to_make_string_alternate | def make_flip(ch):
return '1' if (ch == '0') else '0'
def get_flip_with_starting_charcter(str, expected):
flip_count = 0
for i in range(len( str)):
if (str[i] != expected):
flip_count += 1
expected = make_flip(expected)
return flip_count
def min_flip_to_make_string_alternate(str):
return min(get_flip_with_starting_charcter(str, '0'),get_flip_with_starting_charcter(str, '1')) | [
"assert min_flip_to_make_string_alternate(\"916201067\") == 5",
"assert min_flip_to_make_string_alternate(\"78732549881\") == 10",
"assert min_flip_to_make_string_alternate(\"2561049798191\") == 11"
] | def check(candidate):
# Check some simple cases
assert min_flip_to_make_string_alternate("0001010111") == 2
assert min_flip_to_make_string_alternate("001") == 1
assert min_flip_to_make_string_alternate("010111011") == 2
|
|
365 | Write a python function to count the number of digits of a given number. | count_Digit | def count_Digit(n):
count = 0
while n != 0:
n //= 10
count += 1
return count | [
"assert count_Digit(4123042) == 7",
"assert count_Digit(4124365) == 7",
"assert count_Digit(4122763) == 7"
] | def check(candidate):
# Check some simple cases
assert count_Digit(12345) == 5
assert count_Digit(11223305) == 8
assert count_Digit(4123459) == 7
|
|
366 | Write a python function to find the largest product of the pair of adjacent elements from a given list of integers. | adjacent_num_product | def adjacent_num_product(list_nums):
return max(a*b for a, b in zip(list_nums, list_nums[1:])) | [
"assert adjacent_num_product([6, 8]) == 48",
"assert adjacent_num_product([3, 4]) == 12",
"assert adjacent_num_product([2, 7]) == 14"
] | def check(candidate):
# Check some simple cases
assert adjacent_num_product([1,2,3,4,5,6]) == 30
assert adjacent_num_product([1,2,3,4,5]) == 20
assert adjacent_num_product([2,3]) == 6
|
|
367 | Write a function to check if a binary tree is balanced or not. | is_tree_balanced | class Node:
def __init__(self, data):
self.data = data
self.left = None
self.right = None
def get_height(root):
if root is None:
return 0
return max(get_height(root.left), get_height(root.right)) + 1
def is_tree_balanced(root):
if root is None:
return True
lh = get_height(root.left)
rh = get_height(root.right)
if (abs(lh - rh) <= 1) and is_tree_balanced(
root.left) is True and is_tree_balanced( root.right) is True:
return True
return False | [
"assert is_tree_balanced(root) == False",
"assert is_tree_balanced(root1) == True",
"assert is_tree_balanced(root2) == False "
] | def check(candidate):
# Check some simple cases
assert is_tree_balanced(root) == False
assert is_tree_balanced(root1) == True
assert is_tree_balanced(root2) == False
|
|
368 | Write a function to repeat the given tuple n times. | repeat_tuples | def repeat_tuples(test_tup, N):
res = ((test_tup, ) * N)
return (res) | [
"assert repeat_tuples((7, 5), 8) == ((7, 5), (7, 5), (7, 5), (7, 5), (7, 5), (7, 5), (7, 5), (7, 5))",
"assert repeat_tuples((8, 8), 3) == ((8, 8), (8, 8), (8, 8))",
"assert repeat_tuples((6, 8), 8) == ((6, 8), (6, 8), (6, 8), (6, 8), (6, 8), (6, 8), (6, 8), (6, 8))"
] | def check(candidate):
# Check some simple cases
assert repeat_tuples((1, 3), 4) == ((1, 3), (1, 3), (1, 3), (1, 3))
assert repeat_tuples((1, 2), 3) == ((1, 2), (1, 2), (1, 2))
assert repeat_tuples((3, 4), 5) == ((3, 4), (3, 4), (3, 4), (3, 4), (3, 4))
|
|
369 | Write a function to find the lateral surface area of cuboid | lateralsurface_cuboid | def lateralsurface_cuboid(l,w,h):
LSA = 2*h*(l+w)
return LSA | [
"assert lateralsurface_cuboid(5, 16, 30) == 1260",
"assert lateralsurface_cuboid(13, 24, 34) == 2516",
"assert lateralsurface_cuboid(12, 21, 35) == 2310"
] | def check(candidate):
# Check some simple cases
assert lateralsurface_cuboid(8,5,6)==156
assert lateralsurface_cuboid(7,9,10)==320
assert lateralsurface_cuboid(10,20,30)==1800
|
|
370 | Write a function to sort a tuple by its float element. | float_sort | def float_sort(price):
float_sort=sorted(price, key=lambda x: float(x[1]), reverse=True)
return float_sort | [
"assert float_sort([('2oa', '0'), ('7w4u17ora', '4620'), ('23x', '868')]) == [('7w4u17ora', '4620'), ('23x', '868'), ('2oa', '0')]",
"assert float_sort([('wf4tcwaz', '6'), ('tcbsdsnn2', '622'), ('i2wug', '20370')]) == [('i2wug', '20370'), ('tcbsdsnn2', '622'), ('wf4tcwaz', '6')]",
"assert float_sort([('gv24', '3'), ('a4v5', '516'), ('9wfbm7', '146770')]) == [('9wfbm7', '146770'), ('a4v5', '516'), ('gv24', '3')]"
] | def check(candidate):
# Check some simple cases
assert float_sort([('item1', '12.20'), ('item2', '15.10'), ('item3', '24.5')])==[('item3', '24.5'), ('item2', '15.10'), ('item1', '12.20')]
assert float_sort([('item1', '15'), ('item2', '10'), ('item3', '20')])==[('item3', '20'), ('item1', '15'), ('item2', '10')]
assert float_sort([('item1', '5'), ('item2', '10'), ('item3', '14')])==[('item3', '14'), ('item2', '10'), ('item1', '5')]
|
|
371 | Write a function to find the smallest missing element in a sorted array. | smallest_missing | def smallest_missing(A, left_element, right_element):
if left_element > right_element:
return left_element
mid = left_element + (right_element - left_element) // 2
if A[mid] == mid:
return smallest_missing(A, mid + 1, right_element)
else:
return smallest_missing(A, left_element, mid - 1) | [
"assert smallest_missing([5, 3, 2, 7, 11, 5, 13, 17], 5, 7) == 6",
"assert smallest_missing([6, 2, 5, 4, 11, 9, 16, 17], 1, 12) == 1",
"assert smallest_missing([4, 2, 4, 8, 7, 11, 8, 16], 5, 2) == 5"
] | def check(candidate):
# Check some simple cases
assert smallest_missing([0, 1, 2, 3, 4, 5, 6], 0, 6) == 7
assert smallest_missing([0, 1, 2, 6, 9, 11, 15], 0, 6) == 3
assert smallest_missing([1, 2, 3, 4, 6, 9, 11, 15], 0, 7) == 0
|
|
372 | Write a function to sort a given list of elements in ascending order using heap queue algorithm. | heap_assending | import heapq as hq
def heap_assending(nums):
hq.heapify(nums)
s_result = [hq.heappop(nums) for i in range(len(nums))]
return s_result | [
"assert heap_assending([2, 2, 6, 11, 8, 7, 8, 5, 12, 2]) == [2, 2, 2, 5, 6, 7, 8, 8, 11, 12]",
"assert heap_assending([5, 1, 8, 3, 10, 4, 3, 3, 13, 1]) == [1, 1, 3, 3, 3, 4, 5, 8, 10, 13]",
"assert heap_assending([6, 7, 8, 12, 5, 6, 4, 6, 8, 2]) == [2, 4, 5, 6, 6, 6, 7, 8, 8, 12]"
] | def check(candidate):
# Check some simple cases
assert heap_assending([18, 14, 10, 9, 8, 7, 9, 3, 2, 4, 1])==[1, 2, 3, 4, 7, 8, 9, 9, 10, 14, 18]
assert heap_assending([25, 35, 22, 85, 14, 65, 75, 25, 58])==[14, 22, 25, 25, 35, 58, 65, 75, 85]
assert heap_assending([1, 3, 5, 7, 9, 2, 4, 6, 8, 0])==[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
|
|
373 | Write a function to find the volume of a cuboid. | volume_cuboid | def volume_cuboid(l,w,h):
volume=l*w*h
return volume | [
"assert volume_cuboid(8, 18, 17) == 2448",
"assert volume_cuboid(10, 16, 21) == 3360",
"assert volume_cuboid(5, 20, 26) == 2600"
] | def check(candidate):
# Check some simple cases
assert volume_cuboid(1,2,3)==6
assert volume_cuboid(5,7,9)==315
assert volume_cuboid(10,15,21)==3150
|
|
374 | Write a function to print all permutations of a given string including duplicates. | permute_string | def permute_string(str):
if len(str) == 0:
return ['']
prev_list = permute_string(str[1:len(str)])
next_list = []
for i in range(0,len(prev_list)):
for j in range(0,len(str)):
new_str = prev_list[i][0:j]+str[0]+prev_list[i][j:len(str)-1]
if new_str not in next_list:
next_list.append(new_str)
return next_list | [
"assert permute_string(\"stj\") == ['stj', 'tsj', 'tjs', 'sjt', 'jst', 'jts']",
"assert permute_string(\"ytok\") == ['ytok', 'tyok', 'toyk', 'toky', 'yotk', 'oytk', 'otyk', 'otky', 'yokt', 'oykt', 'okyt', 'okty', 'ytko', 'tyko', 'tkyo', 'tkoy', 'ykto', 'kyto', 'ktyo', 'ktoy', 'ykot', 'kyot', 'koyt', 'koty']",
"assert permute_string(\"uybcwh\") == ['uybcwh', 'yubcwh', 'ybucwh', 'ybcuwh', 'ybcwuh', 'ybcwhu', 'ubycwh', 'buycwh', 'byucwh', 'bycuwh', 'bycwuh', 'bycwhu', 'ubcywh', 'bucywh', 'bcuywh', 'bcyuwh', 'bcywuh', 'bcywhu', 'ubcwyh', 'bucwyh', 'bcuwyh', 'bcwuyh', 'bcwyuh', 'bcwyhu', 'ubcwhy', 'bucwhy', 'bcuwhy', 'bcwuhy', 'bcwhuy', 'bcwhyu', 'uycbwh', 'yucbwh', 'ycubwh', 'ycbuwh', 'ycbwuh', 'ycbwhu', 'ucybwh', 'cuybwh', 'cyubwh', 'cybuwh', 'cybwuh', 'cybwhu', 'ucbywh', 'cubywh', 'cbuywh', 'cbyuwh', 'cbywuh', 'cbywhu', 'ucbwyh', 'cubwyh', 'cbuwyh', 'cbwuyh', 'cbwyuh', 'cbwyhu', 'ucbwhy', 'cubwhy', 'cbuwhy', 'cbwuhy', 'cbwhuy', 'cbwhyu', 'uycwbh', 'yucwbh', 'ycuwbh', 'ycwubh', 'ycwbuh', 'ycwbhu', 'ucywbh', 'cuywbh', 'cyuwbh', 'cywubh', 'cywbuh', 'cywbhu', 'ucwybh', 'cuwybh', 'cwuybh', 'cwyubh', 'cwybuh', 'cwybhu', 'ucwbyh', 'cuwbyh', 'cwubyh', 'cwbuyh', 'cwbyuh', 'cwbyhu', 'ucwbhy', 'cuwbhy', 'cwubhy', 'cwbuhy', 'cwbhuy', 'cwbhyu', 'uycwhb', 'yucwhb', 'ycuwhb', 'ycwuhb', 'ycwhub', 'ycwhbu', 'ucywhb', 'cuywhb', 'cyuwhb', 'cywuhb', 'cywhub', 'cywhbu', 'ucwyhb', 'cuwyhb', 'cwuyhb', 'cwyuhb', 'cwyhub', 'cwyhbu', 'ucwhyb', 'cuwhyb', 'cwuhyb', 'cwhuyb', 'cwhyub', 'cwhybu', 'ucwhby', 'cuwhby', 'cwuhby', 'cwhuby', 'cwhbuy', 'cwhbyu', 'uybwch', 'yubwch', 'ybuwch', 'ybwuch', 'ybwcuh', 'ybwchu', 'ubywch', 'buywch', 'byuwch', 'bywuch', 'bywcuh', 'bywchu', 'ubwych', 'buwych', 'bwuych', 'bwyuch', 'bwycuh', 'bwychu', 'ubwcyh', 'buwcyh', 'bwucyh', 'bwcuyh', 'bwcyuh', 'bwcyhu', 'ubwchy', 'buwchy', 'bwuchy', 'bwcuhy', 'bwchuy', 'bwchyu', 'uywbch', 'yuwbch', 'ywubch', 'ywbuch', 'ywbcuh', 'ywbchu', 'uwybch', 'wuybch', 'wyubch', 'wybuch', 'wybcuh', 'wybchu', 'uwbych', 'wubych', 'wbuych', 'wbyuch', 'wbycuh', 'wbychu', 'uwbcyh', 'wubcyh', 'wbucyh', 'wbcuyh', 'wbcyuh', 'wbcyhu', 'uwbchy', 'wubchy', 'wbuchy', 'wbcuhy', 'wbchuy', 'wbchyu', 'uywcbh', 'yuwcbh', 'ywucbh', 'ywcubh', 'ywcbuh', 'ywcbhu', 'uwycbh', 'wuycbh', 'wyucbh', 'wycubh', 'wycbuh', 'wycbhu', 'uwcybh', 'wucybh', 'wcuybh', 'wcyubh', 'wcybuh', 'wcybhu', 'uwcbyh', 'wucbyh', 'wcubyh', 'wcbuyh', 'wcbyuh', 'wcbyhu', 'uwcbhy', 'wucbhy', 'wcubhy', 'wcbuhy', 'wcbhuy', 'wcbhyu', 'uywchb', 'yuwchb', 'ywuchb', 'ywcuhb', 'ywchub', 'ywchbu', 'uwychb', 'wuychb', 'wyuchb', 'wycuhb', 'wychub', 'wychbu', 'uwcyhb', 'wucyhb', 'wcuyhb', 'wcyuhb', 'wcyhub', 'wcyhbu', 'uwchyb', 'wuchyb', 'wcuhyb', 'wchuyb', 'wchyub', 'wchybu', 'uwchby', 'wuchby', 'wcuhby', 'wchuby', 'wchbuy', 'wchbyu', 'uybwhc', 'yubwhc', 'ybuwhc', 'ybwuhc', 'ybwhuc', 'ybwhcu', 'ubywhc', 'buywhc', 'byuwhc', 'bywuhc', 'bywhuc', 'bywhcu', 'ubwyhc', 'buwyhc', 'bwuyhc', 'bwyuhc', 'bwyhuc', 'bwyhcu', 'ubwhyc', 'buwhyc', 'bwuhyc', 'bwhuyc', 'bwhyuc', 'bwhycu', 'ubwhcy', 'buwhcy', 'bwuhcy', 'bwhucy', 'bwhcuy', 'bwhcyu', 'uywbhc', 'yuwbhc', 'ywubhc', 'ywbuhc', 'ywbhuc', 'ywbhcu', 'uwybhc', 'wuybhc', 'wyubhc', 'wybuhc', 'wybhuc', 'wybhcu', 'uwbyhc', 'wubyhc', 'wbuyhc', 'wbyuhc', 'wbyhuc', 'wbyhcu', 'uwbhyc', 'wubhyc', 'wbuhyc', 'wbhuyc', 'wbhyuc', 'wbhycu', 'uwbhcy', 'wubhcy', 'wbuhcy', 'wbhucy', 'wbhcuy', 'wbhcyu', 'uywhbc', 'yuwhbc', 'ywuhbc', 'ywhubc', 'ywhbuc', 'ywhbcu', 'uwyhbc', 'wuyhbc', 'wyuhbc', 'wyhubc', 'wyhbuc', 'wyhbcu', 'uwhybc', 'wuhybc', 'whuybc', 'whyubc', 'whybuc', 'whybcu', 'uwhbyc', 'wuhbyc', 'whubyc', 'whbuyc', 'whbyuc', 'whbycu', 'uwhbcy', 'wuhbcy', 'whubcy', 'whbucy', 'whbcuy', 'whbcyu', 'uywhcb', 'yuwhcb', 'ywuhcb', 'ywhucb', 'ywhcub', 'ywhcbu', 'uwyhcb', 'wuyhcb', 'wyuhcb', 'wyhucb', 'wyhcub', 'wyhcbu', 'uwhycb', 'wuhycb', 'whuycb', 'whyucb', 'whycub', 'whycbu', 'uwhcyb', 'wuhcyb', 'whucyb', 'whcuyb', 'whcyub', 'whcybu', 'uwhcby', 'wuhcby', 'whucby', 'whcuby', 'whcbuy', 'whcbyu', 'uybchw', 'yubchw', 'ybuchw', 'ybcuhw', 'ybchuw', 'ybchwu', 'ubychw', 'buychw', 'byuchw', 'bycuhw', 'bychuw', 'bychwu', 'ubcyhw', 'bucyhw', 'bcuyhw', 'bcyuhw', 'bcyhuw', 'bcyhwu', 'ubchyw', 'buchyw', 'bcuhyw', 'bchuyw', 'bchyuw', 'bchywu', 'ubchwy', 'buchwy', 'bcuhwy', 'bchuwy', 'bchwuy', 'bchwyu', 'uycbhw', 'yucbhw', 'ycubhw', 'ycbuhw', 'ycbhuw', 'ycbhwu', 'ucybhw', 'cuybhw', 'cyubhw', 'cybuhw', 'cybhuw', 'cybhwu', 'ucbyhw', 'cubyhw', 'cbuyhw', 'cbyuhw', 'cbyhuw', 'cbyhwu', 'ucbhyw', 'cubhyw', 'cbuhyw', 'cbhuyw', 'cbhyuw', 'cbhywu', 'ucbhwy', 'cubhwy', 'cbuhwy', 'cbhuwy', 'cbhwuy', 'cbhwyu', 'uychbw', 'yuchbw', 'ycuhbw', 'ychubw', 'ychbuw', 'ychbwu', 'ucyhbw', 'cuyhbw', 'cyuhbw', 'cyhubw', 'cyhbuw', 'cyhbwu', 'uchybw', 'cuhybw', 'chuybw', 'chyubw', 'chybuw', 'chybwu', 'uchbyw', 'cuhbyw', 'chubyw', 'chbuyw', 'chbyuw', 'chbywu', 'uchbwy', 'cuhbwy', 'chubwy', 'chbuwy', 'chbwuy', 'chbwyu', 'uychwb', 'yuchwb', 'ycuhwb', 'ychuwb', 'ychwub', 'ychwbu', 'ucyhwb', 'cuyhwb', 'cyuhwb', 'cyhuwb', 'cyhwub', 'cyhwbu', 'uchywb', 'cuhywb', 'chuywb', 'chyuwb', 'chywub', 'chywbu', 'uchwyb', 'cuhwyb', 'chuwyb', 'chwuyb', 'chwyub', 'chwybu', 'uchwby', 'cuhwby', 'chuwby', 'chwuby', 'chwbuy', 'chwbyu', 'uybhcw', 'yubhcw', 'ybuhcw', 'ybhucw', 'ybhcuw', 'ybhcwu', 'ubyhcw', 'buyhcw', 'byuhcw', 'byhucw', 'byhcuw', 'byhcwu', 'ubhycw', 'buhycw', 'bhuycw', 'bhyucw', 'bhycuw', 'bhycwu', 'ubhcyw', 'buhcyw', 'bhucyw', 'bhcuyw', 'bhcyuw', 'bhcywu', 'ubhcwy', 'buhcwy', 'bhucwy', 'bhcuwy', 'bhcwuy', 'bhcwyu', 'uyhbcw', 'yuhbcw', 'yhubcw', 'yhbucw', 'yhbcuw', 'yhbcwu', 'uhybcw', 'huybcw', 'hyubcw', 'hybucw', 'hybcuw', 'hybcwu', 'uhbycw', 'hubycw', 'hbuycw', 'hbyucw', 'hbycuw', 'hbycwu', 'uhbcyw', 'hubcyw', 'hbucyw', 'hbcuyw', 'hbcyuw', 'hbcywu', 'uhbcwy', 'hubcwy', 'hbucwy', 'hbcuwy', 'hbcwuy', 'hbcwyu', 'uyhcbw', 'yuhcbw', 'yhucbw', 'yhcubw', 'yhcbuw', 'yhcbwu', 'uhycbw', 'huycbw', 'hyucbw', 'hycubw', 'hycbuw', 'hycbwu', 'uhcybw', 'hucybw', 'hcuybw', 'hcyubw', 'hcybuw', 'hcybwu', 'uhcbyw', 'hucbyw', 'hcubyw', 'hcbuyw', 'hcbyuw', 'hcbywu', 'uhcbwy', 'hucbwy', 'hcubwy', 'hcbuwy', 'hcbwuy', 'hcbwyu', 'uyhcwb', 'yuhcwb', 'yhucwb', 'yhcuwb', 'yhcwub', 'yhcwbu', 'uhycwb', 'huycwb', 'hyucwb', 'hycuwb', 'hycwub', 'hycwbu', 'uhcywb', 'hucywb', 'hcuywb', 'hcyuwb', 'hcywub', 'hcywbu', 'uhcwyb', 'hucwyb', 'hcuwyb', 'hcwuyb', 'hcwyub', 'hcwybu', 'uhcwby', 'hucwby', 'hcuwby', 'hcwuby', 'hcwbuy', 'hcwbyu', 'uybhwc', 'yubhwc', 'ybuhwc', 'ybhuwc', 'ybhwuc', 'ybhwcu', 'ubyhwc', 'buyhwc', 'byuhwc', 'byhuwc', 'byhwuc', 'byhwcu', 'ubhywc', 'buhywc', 'bhuywc', 'bhyuwc', 'bhywuc', 'bhywcu', 'ubhwyc', 'buhwyc', 'bhuwyc', 'bhwuyc', 'bhwyuc', 'bhwycu', 'ubhwcy', 'buhwcy', 'bhuwcy', 'bhwucy', 'bhwcuy', 'bhwcyu', 'uyhbwc', 'yuhbwc', 'yhubwc', 'yhbuwc', 'yhbwuc', 'yhbwcu', 'uhybwc', 'huybwc', 'hyubwc', 'hybuwc', 'hybwuc', 'hybwcu', 'uhbywc', 'hubywc', 'hbuywc', 'hbyuwc', 'hbywuc', 'hbywcu', 'uhbwyc', 'hubwyc', 'hbuwyc', 'hbwuyc', 'hbwyuc', 'hbwycu', 'uhbwcy', 'hubwcy', 'hbuwcy', 'hbwucy', 'hbwcuy', 'hbwcyu', 'uyhwbc', 'yuhwbc', 'yhuwbc', 'yhwubc', 'yhwbuc', 'yhwbcu', 'uhywbc', 'huywbc', 'hyuwbc', 'hywubc', 'hywbuc', 'hywbcu', 'uhwybc', 'huwybc', 'hwuybc', 'hwyubc', 'hwybuc', 'hwybcu', 'uhwbyc', 'huwbyc', 'hwubyc', 'hwbuyc', 'hwbyuc', 'hwbycu', 'uhwbcy', 'huwbcy', 'hwubcy', 'hwbucy', 'hwbcuy', 'hwbcyu', 'uyhwcb', 'yuhwcb', 'yhuwcb', 'yhwucb', 'yhwcub', 'yhwcbu', 'uhywcb', 'huywcb', 'hyuwcb', 'hywucb', 'hywcub', 'hywcbu', 'uhwycb', 'huwycb', 'hwuycb', 'hwyucb', 'hwycub', 'hwycbu', 'uhwcyb', 'huwcyb', 'hwucyb', 'hwcuyb', 'hwcyub', 'hwcybu', 'uhwcby', 'huwcby', 'hwucby', 'hwcuby', 'hwcbuy', 'hwcbyu']"
] | def check(candidate):
# Check some simple cases
assert permute_string('ab')==['ab', 'ba']
assert permute_string('abc')==['abc', 'bac', 'bca', 'acb', 'cab', 'cba']
assert permute_string('abcd')==['abcd', 'bacd', 'bcad', 'bcda', 'acbd', 'cabd', 'cbad', 'cbda', 'acdb', 'cadb', 'cdab', 'cdba', 'abdc', 'badc', 'bdac', 'bdca', 'adbc', 'dabc', 'dbac', 'dbca', 'adcb', 'dacb', 'dcab', 'dcba']
|
|
375 | Write a function to round the given number to the nearest multiple of a specific number. | round_num | def round_num(n,m):
a = (n //m) * m
b = a + m
return (b if n - a > b - n else a) | [
"assert round_num(217, 5) == 215",
"assert round_num(214, 2) == 214",
"assert round_num(216, 6) == 216"
] | def check(candidate):
# Check some simple cases
assert round_num(4722,10)==4720
assert round_num(1111,5)==1110
assert round_num(219,2)==218
|
|
376 | Write a function to remove tuple elements that occur more than once and replace the duplicates with some custom value. | remove_replica | def remove_replica(test_tup):
temp = set()
res = tuple(ele if ele not in temp and not temp.add(ele)
else 'MSP' for ele in test_tup)
return (res) | [
"assert remove_replica((6, 3, 4, 8, 6, 5, 8, 5, 10, 6)) == (6, 3, 4, 8, 'MSP', 5, 'MSP', 'MSP', 10, 'MSP')",
"assert remove_replica((6, 3, 7, 9, 9, 2, 6, 10, 9, 7)) == (6, 3, 7, 9, 'MSP', 2, 'MSP', 10, 'MSP', 'MSP')",
"assert remove_replica((4, 4, 10, 7, 2, 7, 9, 4, 5, 6)) == (4, 'MSP', 10, 7, 2, 'MSP', 9, 'MSP', 5, 6)"
] | def check(candidate):
# Check some simple cases
assert remove_replica((1, 1, 4, 4, 4, 5, 5, 6, 7, 7)) == (1, 'MSP', 4, 'MSP', 'MSP', 5, 'MSP', 6, 7, 'MSP')
assert remove_replica((2, 3, 4, 4, 5, 6, 6, 7, 8, 9, 9)) == (2, 3, 4, 'MSP', 5, 6, 'MSP', 7, 8, 9, 'MSP')
assert remove_replica((2, 2, 5, 4, 5, 7, 5, 6, 7, 7)) == (2, 'MSP', 5, 4, 'MSP', 7, 'MSP', 6, 'MSP', 'MSP')
|
|
377 | Write a python function to remove all occurrences of a character in a given string. | remove_Char | def remove_Char(s,c) :
counts = s.count(c)
s = list(s)
while counts :
s.remove(c)
counts -= 1
s = '' . join(s)
return (s) | [
"assert remove_Char('kjcqa', 'c') == \"kjqa\"",
"assert remove_Char('rnicuye', 'z') == \"rnicuye\"",
"assert remove_Char('wbqhnpw', 'y') == \"wbqhnpw\""
] | def check(candidate):
# Check some simple cases
assert remove_Char("aba",'a') == "b"
assert remove_Char("toggle",'g') == "tole"
assert remove_Char("aabbc",'b') == "aac"
|
|
378 | Write a python function to shift last element to first position in the given list. | move_first | def move_first(test_list):
test_list = test_list[-1:] + test_list[:-1]
return test_list | [
"assert move_first([11, 4, 9, 5]) == [5, 11, 4, 9]",
"assert move_first([5, 9, 3, 6]) == [6, 5, 9, 3]",
"assert move_first([7, 11, 3, 4]) == [4, 7, 11, 3]"
] | def check(candidate):
# Check some simple cases
assert move_first([1,2,3,4]) == [4,1,2,3]
assert move_first([0,1,2,3]) == [3,0,1,2]
assert move_first([9,8,7,1]) == [1,9,8,7]
|
|
379 | Write a function to find the surface area of a cuboid. | surfacearea_cuboid | def surfacearea_cuboid(l,w,h):
SA = 2*(l*w + l * h + w * h)
return SA | [
"assert surfacearea_cuboid(13, 11, 20) == 1246",
"assert surfacearea_cuboid(12, 17, 22) == 1684",
"assert surfacearea_cuboid(8, 19, 23) == 1546"
] | def check(candidate):
# Check some simple cases
assert surfacearea_cuboid(1,2,3)==22
assert surfacearea_cuboid(5,7,9)==286
assert surfacearea_cuboid(10,15,21)==1350
|
|
380 | Write a function to generate a two-dimensional array. | multi_list | def multi_list(rownum,colnum):
multi_list = [[0 for col in range(colnum)] for row in range(rownum)]
for row in range(rownum):
for col in range(colnum):
multi_list[row][col]= row*col
return multi_list
| [
"assert multi_list(9, 18) == [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17], [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34], [0, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51], [0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60, 64, 68], [0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85], [0, 6, 12, 18, 24, 30, 36, 42, 48, 54, 60, 66, 72, 78, 84, 90, 96, 102], [0, 7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91, 98, 105, 112, 119], [0, 8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120, 128, 136]]",
"assert multi_list(12, 18) == [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17], [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34], [0, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51], [0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60, 64, 68], [0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85], [0, 6, 12, 18, 24, 30, 36, 42, 48, 54, 60, 66, 72, 78, 84, 90, 96, 102], [0, 7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91, 98, 105, 112, 119], [0, 8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120, 128, 136], [0, 9, 18, 27, 36, 45, 54, 63, 72, 81, 90, 99, 108, 117, 126, 135, 144, 153], [0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170], [0, 11, 22, 33, 44, 55, 66, 77, 88, 99, 110, 121, 132, 143, 154, 165, 176, 187]]",
"assert multi_list(6, 12) == [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22], [0, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33], [0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44], [0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55]]"
] | def check(candidate):
# Check some simple cases
assert multi_list(3,4)==[[0, 0, 0, 0], [0, 1, 2, 3], [0, 2, 4, 6]]
assert multi_list(5,7)==[[0, 0, 0, 0, 0, 0, 0], [0, 1, 2, 3, 4, 5, 6], [0, 2, 4, 6, 8, 10, 12], [0, 3, 6, 9, 12, 15, 18], [0, 4, 8, 12, 16, 20, 24]]
assert multi_list(10,15)==[[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14], [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28], [0, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42], [0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56], [0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70], [0, 6, 12, 18, 24, 30, 36, 42, 48, 54, 60, 66, 72, 78, 84], [0, 7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91, 98], [0, 8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104, 112], [0, 9, 18, 27, 36, 45, 54, 63, 72, 81, 90, 99, 108, 117, 126]]
|
|
381 | Write a function to sort a list of lists by a given index of the inner list. | index_on_inner_list | from operator import itemgetter
def index_on_inner_list(list_data, index_no):
result = sorted(list_data, key=itemgetter(index_no))
return result | [
"assert index_on_inner_list([('yvNxglyLK', 98, 96), ('cjwjTqo VGTiY', 102, 96), ('ToYxBSv ', 94, 90), ('mZjxQHUggsfYy', 98, 101)], 1) == [('ToYxBSv ', 94, 90), ('yvNxglyLK', 98, 96), ('mZjxQHUggsfYy', 98, 101), ('cjwjTqo VGTiY', 102, 96)]",
"assert index_on_inner_list([('bcejqxBpxBbC', 101, 101), ('bCAJBkFaNhetnW', 95, 93), ('DmolEPurqoyU', 95, 90), ('LPogjwbhUcRnv', 93, 95)], 2) == [('DmolEPurqoyU', 95, 90), ('bCAJBkFaNhetnW', 95, 93), ('LPogjwbhUcRnv', 93, 95), ('bcejqxBpxBbC', 101, 101)]",
"assert index_on_inner_list([('NjQorKHBzr', 101, 103), ('EnUyXWvxoVPwxP', 94, 92), ('ruvCvQq', 91, 91), ('avXZszRVeMQTIFuCU', 89, 103)], 1) == [('avXZszRVeMQTIFuCU', 89, 103), ('ruvCvQq', 91, 91), ('EnUyXWvxoVPwxP', 94, 92), ('NjQorKHBzr', 101, 103)]"
] | def check(candidate):
# Check some simple cases
assert index_on_inner_list([('Greyson Fulton', 98, 99), ('Brady Kent', 97, 96), ('Wyatt Knott', 91, 94), ('Beau Turnbull', 94, 98)] ,0)==[('Beau Turnbull', 94, 98), ('Brady Kent', 97, 96), ('Greyson Fulton', 98, 99), ('Wyatt Knott', 91, 94)]
assert index_on_inner_list([('Greyson Fulton', 98, 99), ('Brady Kent', 97, 96), ('Wyatt Knott', 91, 94), ('Beau Turnbull', 94, 98)] ,1)==[('Wyatt Knott', 91, 94), ('Beau Turnbull', 94, 98), ('Brady Kent', 97, 96), ('Greyson Fulton', 98, 99)]
assert index_on_inner_list([('Greyson Fulton', 98, 99), ('Brady Kent', 97, 96), ('Wyatt Knott', 91, 94), ('Beau Turnbull', 94, 98)] ,2)==[('Wyatt Knott', 91, 94), ('Brady Kent', 97, 96), ('Beau Turnbull', 94, 98), ('Greyson Fulton', 98, 99)]
|
|
382 | Write a function to find the number of rotations in a circularly sorted array. | find_rotation_count | def find_rotation_count(A):
(left, right) = (0, len(A) - 1)
while left <= right:
if A[left] <= A[right]:
return left
mid = (left + right) // 2
next = (mid + 1) % len(A)
prev = (mid - 1 + len(A)) % len(A)
if A[mid] <= A[next] and A[mid] <= A[prev]:
return mid
elif A[mid] <= A[right]:
right = mid - 1
elif A[mid] >= A[left]:
left = mid + 1
return -1 | [
"assert find_rotation_count([91, 91, 92, 93, 13, 17, 57, 71, 87]) == 4",
"assert find_rotation_count([20, 27, 28, 29, 47, 54, 60, 62, 63, 64, 77, 78, 79, 80, 0, 3, 15, 18, 20]) == 0",
"assert find_rotation_count([70, 78, 78, 81, 84, 97, 12, 24, 33, 36, 37, 38, 42, 49, 61]) == 6"
] | def check(candidate):
# Check some simple cases
assert find_rotation_count([8, 9, 10, 1, 2, 3, 4, 5, 6, 7]) == 3
assert find_rotation_count([8, 9, 10,2, 5, 6]) == 3
assert find_rotation_count([2, 5, 6, 8, 9, 10]) == 0
|
|
383 | Write a python function to toggle all odd bits of a given number. | even_bit_toggle_number | def even_bit_toggle_number(n) :
res = 0; count = 0; temp = n
while(temp > 0 ) :
if (count % 2 == 0) :
res = res | (1 << count)
count = count + 1
temp >>= 1
return n ^ res | [
"assert even_bit_toggle_number(31) == 10",
"assert even_bit_toggle_number(27) == 14",
"assert even_bit_toggle_number(26) == 15"
] | def check(candidate):
# Check some simple cases
assert even_bit_toggle_number(10) == 15
assert even_bit_toggle_number(20) == 1
assert even_bit_toggle_number(30) == 11
|
|
384 | Write a python function to find the frequency of the smallest value in a given array. | frequency_Of_Smallest | def frequency_Of_Smallest(n,arr):
mn = arr[0]
freq = 1
for i in range(1,n):
if (arr[i] < mn):
mn = arr[i]
freq = 1
elif (arr[i] == mn):
freq += 1
return freq | [
"assert frequency_Of_Smallest(4, [5, 7, 8, 7, 5, 8, 14]) == 1",
"assert frequency_Of_Smallest(7, [6, 3, 11, 1, 8, 5, 6]) == 1",
"assert frequency_Of_Smallest(2, [8, 6, 4, 5, 3, 9, 12]) == 1"
] | def check(candidate):
# Check some simple cases
assert frequency_Of_Smallest(5,[1,2,3,4,3]) == 1
assert frequency_Of_Smallest(7,[3,1,2,5,6,2,3]) == 1
assert frequency_Of_Smallest(7,[3,3,6,3,7,4,9]) == 3
|
|
385 | Write a function to find the n'th perrin number using recursion. | get_perrin | def get_perrin(n):
if (n == 0):
return 3
if (n == 1):
return 0
if (n == 2):
return 2
return get_perrin(n - 2) + get_perrin(n - 3) | [
"assert get_perrin(8) == 10",
"assert get_perrin(9) == 12",
"assert get_perrin(3) == 3"
] | def check(candidate):
# Check some simple cases
assert get_perrin(9) == 12
assert get_perrin(4) == 2
assert get_perrin(6) == 5
|
|
386 | Write a function to find out the minimum no of swaps required for bracket balancing in the given string. | swap_count | def swap_count(s):
chars = s
count_left = 0
count_right = 0
swap = 0
imbalance = 0;
for i in range(len(chars)):
if chars[i] == '[':
count_left += 1
if imbalance > 0:
swap += imbalance
imbalance -= 1
elif chars[i] == ']':
count_right += 1
imbalance = (count_right - count_left)
return swap | [
"assert swap_count(\"]{[\") == 1",
"assert swap_count(\"({<{{><>>)]{\") == 0",
"assert swap_count(\")<}\") == 0"
] | def check(candidate):
# Check some simple cases
assert swap_count("[]][][") == 2
assert swap_count("[[][]]") == 0
assert swap_count("[[][]]][") == 1
|
|
387 | Write a python function to check whether the hexadecimal number is even or odd. | even_or_odd | def even_or_odd(N):
l = len(N)
if (N[l-1] =='0'or N[l-1] =='2'or
N[l-1] =='4'or N[l-1] =='6'or
N[l-1] =='8'or N[l-1] =='A'or
N[l-1] =='C'or N[l-1] =='E'):
return ("Even")
else:
return ("Odd") | [
"assert even_or_odd(\"RRG\") == \"Odd\"",
"assert even_or_odd(\"RZAJ\") == \"Odd\"",
"assert even_or_odd(\"AFWXA\") == \"Even\""
] | def check(candidate):
# Check some simple cases
assert even_or_odd("AB3454D") =="Odd"
assert even_or_odd("ABC") == "Even"
assert even_or_odd("AAD") == "Odd"
|
|
388 | Write a python function to find the highest power of 2 that is less than or equal to n. | highest_Power_of_2 | def highest_Power_of_2(n):
res = 0;
for i in range(n, 0, -1):
if ((i & (i - 1)) == 0):
res = i;
break;
return res; | [
"assert highest_Power_of_2(31) == 16",
"assert highest_Power_of_2(30) == 16",
"assert highest_Power_of_2(34) == 32"
] | def check(candidate):
# Check some simple cases
assert highest_Power_of_2(10) == 8
assert highest_Power_of_2(19) == 16
assert highest_Power_of_2(32) == 32
|
|
389 | Write a function to find the n'th lucas number. | find_lucas | def find_lucas(n):
if (n == 0):
return 2
if (n == 1):
return 1
return find_lucas(n - 1) + find_lucas(n - 2) | [
"assert find_lucas(8) == 47",
"assert find_lucas(8) == 47",
"assert find_lucas(4) == 7"
] | def check(candidate):
# Check some simple cases
assert find_lucas(9) == 76
assert find_lucas(4) == 7
assert find_lucas(3) == 4
|
|
390 | Write a function to insert a given string at the beginning of all items in a list. | add_string | def add_string(list,string):
add_string=[string.format(i) for i in list]
return add_string | [
"assert add_string([5, 2, 6, 7], 'kiip)4t>tg') == ['kiip)4t>tg', 'kiip)4t>tg', 'kiip)4t>tg', 'kiip)4t>tg']",
"assert add_string([1, 7, 12, 11], 'p17bel') == ['p17bel', 'p17bel', 'p17bel', 'p17bel']",
"assert add_string([9, 11, 12, 11], 'mb1]7c1i]p') == ['mb1]7c1i]p', 'mb1]7c1i]p', 'mb1]7c1i]p', 'mb1]7c1i]p']"
] | def check(candidate):
# Check some simple cases
assert add_string([1,2,3,4],'temp{0}')==['temp1', 'temp2', 'temp3', 'temp4']
assert add_string(['a','b','c','d'], 'python{0}')==[ 'pythona', 'pythonb', 'pythonc', 'pythond']
assert add_string([5,6,7,8],'string{0}')==['string5', 'string6', 'string7', 'string8']
|
|
391 | Write a function to convert more than one list to nested dictionary. | convert_list_dictionary | def convert_list_dictionary(l1, l2, l3):
result = [{x: {y: z}} for (x, y, z) in zip(l1, l2, l3)]
return result | [
"assert convert_list_dictionary(['P567WD', 'HH28', 'TD6', '2KH15'], ['spr', 'B', 'B$F?A:', 'OXUA'], [7, 18, 25, 40]) == [{'P567WD': {'spr': 7}}, {'HH28': {'B': 18}}, {'TD6': {'B$F?A:': 25}}, {'2KH15': {'OXUA': 40}}]",
"assert convert_list_dictionary(['8GJX', 'NEXZ6', 'OMZ1W', 'GZ1'], ['sqf', 'B', 'N-D', 'SBROW'], [15, 19, 35, 44]) == [{'8GJX': {'sqf': 15}}, {'NEXZ6': {'B': 19}}, {'OMZ1W': {'N-D': 35}}, {'GZ1': {'SBROW': 44}}]",
"assert convert_list_dictionary(['XON', '248', 'A11', 'W4NFH6'], ['dxamm', 'F', 'KJJ|VXD', 'VCGQ'], [8, 15, 28, 43]) == [{'XON': {'dxamm': 8}}, {'248': {'F': 15}}, {'A11': {'KJJ|VXD': 28}}, {'W4NFH6': {'VCGQ': 43}}]"
] | def check(candidate):
# Check some simple cases
assert convert_list_dictionary(["S001", "S002", "S003", "S004"],["Adina Park", "Leyton Marsh", "Duncan Boyle", "Saim Richards"] ,[85, 98, 89, 92])==[{'S001': {'Adina Park': 85}}, {'S002': {'Leyton Marsh': 98}}, {'S003': {'Duncan Boyle': 89}}, {'S004': {'Saim Richards': 92}}]
assert convert_list_dictionary(["abc","def","ghi","jkl"],["python","program","language","programs"],[100,200,300,400])==[{'abc':{'python':100}},{'def':{'program':200}},{'ghi':{'language':300}},{'jkl':{'programs':400}}]
assert convert_list_dictionary(["A1","A2","A3","A4"],["java","C","C++","DBMS"],[10,20,30,40])==[{'A1':{'java':10}},{'A2':{'C':20}},{'A3':{'C++':30}},{'A4':{'DBMS':40}}]
|
|
392 | Write a function to find the maximum sum possible by using the given equation f(n) = max( (f(n/2) + f(n/3) + f(n/4) + f(n/5)), n). | get_max_sum | def get_max_sum (n):
res = list()
res.append(0)
res.append(1)
i = 2
while i<n + 1:
res.append(max(i, (res[int(i / 2)]
+ res[int(i / 3)] +
res[int(i / 4)]
+ res[int(i / 5)])))
i = i + 1
return res[n] | [
"assert get_max_sum(3) == 3",
"assert get_max_sum(3) == 3",
"assert get_max_sum(1) == 1"
] | def check(candidate):
# Check some simple cases
assert get_max_sum(60) == 106
assert get_max_sum(10) == 12
assert get_max_sum(2) == 2
|
|
393 | Write a function to find the list with maximum length using lambda function. | max_length_list | def max_length_list(input_list):
max_length = max(len(x) for x in input_list )
max_list = max(input_list, key = lambda i: len(i))
return(max_length, max_list) | [
"assert max_length_list([[4, 6, 9], [1, 4, 11, 14], [5, 8, 11]]) == (4, [1, 4, 11, 14])",
"assert max_length_list([[6, 2, 7], [8, 10, 5, 14], [8, 16, 13]]) == (4, [8, 10, 5, 14])",
"assert max_length_list([[8, 1, 7], [5, 7, 7, 13], [7, 7, 16]]) == (4, [5, 7, 7, 13])"
] | def check(candidate):
# Check some simple cases
assert max_length_list([[0], [1, 3], [5, 7], [9, 11], [13, 15, 17]])==(3, [13, 15, 17])
assert max_length_list([[1,2,3,4,5],[1,2,3,4],[1,2,3],[1,2],[1]])==(5,[1,2,3,4,5])
assert max_length_list([[3,4,5],[6,7,8,9],[10,11,12]])==(4,[6,7,8,9])
|
|
394 | Write a function to check if given tuple is distinct or not. | check_distinct | def check_distinct(test_tup):
res = True
temp = set()
for ele in test_tup:
if ele in temp:
res = False
break
temp.add(ele)
return (res) | [
"assert check_distinct((2, 6, 8, 8, 5)) == False",
"assert check_distinct((2, 7, 1, 5, 11)) == True",
"assert check_distinct((6, 7, 1, 10, 6)) == False"
] | def check(candidate):
# Check some simple cases
assert check_distinct((1, 4, 5, 6, 1, 4)) == False
assert check_distinct((1, 4, 5, 6)) == True
assert check_distinct((2, 3, 4, 5, 6)) == True
|
|
395 | Write a python function to find the first non-repeated character in a given string. | first_non_repeating_character | def first_non_repeating_character(str1):
char_order = []
ctr = {}
for c in str1:
if c in ctr:
ctr[c] += 1
else:
ctr[c] = 1
char_order.append(c)
for c in char_order:
if ctr[c] == 1:
return c
return None | [
"assert first_non_repeating_character(\"mcehozioe\") == \"m\"",
"assert first_non_repeating_character(\"mbpoe\") == \"m\"",
"assert first_non_repeating_character(\"uiqnvtjtr\") == \"u\""
] | def check(candidate):
# Check some simple cases
assert first_non_repeating_character("abcabc") == None
assert first_non_repeating_character("abc") == "a"
assert first_non_repeating_character("ababc") == "c"
|
|
396 | Write a function to check whether the given string starts and ends with the same character or not using regex. | check_char | import re
regex = r'^[a-z]$|^([a-z]).*\1$'
def check_char(string):
if(re.search(regex, string)):
return "Valid"
else:
return "Invalid" | [
"assert check_char(\"wsuhdr\") == \"Invalid\"",
"assert check_char(\"jrrx\") == \"Invalid\"",
"assert check_char(\"arghmhbm\") == \"Invalid\""
] | def check(candidate):
# Check some simple cases
assert check_char("abba") == "Valid"
assert check_char("a") == "Valid"
assert check_char("abcd") == "Invalid"
|
|
397 | Write a function to find the median of three specific numbers. | median_numbers | def median_numbers(a,b,c):
if a > b:
if a < c:
median = a
elif b > c:
median = b
else:
median = c
else:
if a > c:
median = a
elif b < c:
median = b
else:
median = c
return median | [
"assert median_numbers(10, 42, 75) == 42",
"assert median_numbers(10, 42, 74) == 42",
"assert median_numbers(15, 41, 74) == 41"
] | def check(candidate):
# Check some simple cases
assert median_numbers(25,55,65)==55.0
assert median_numbers(20,10,30)==20.0
assert median_numbers(15,45,75)==45.0
|
|
398 | Write a function to compute the sum of digits of each number of a given list. | sum_of_digits | def sum_of_digits(nums):
return sum(int(el) for n in nums for el in str(n) if el.isdigit()) | [
"assert sum_of_digits([11, 18, -7, 4, -75]) == 34",
"assert sum_of_digits([12, 21, 0, 3, -70]) == 16",
"assert sum_of_digits([12, 18, -3, 3, -67]) == 31"
] | def check(candidate):
# Check some simple cases
assert sum_of_digits([10,2,56])==14
assert sum_of_digits([[10,20,4,5,'b',70,'a']])==19
assert sum_of_digits([10,20,-4,5,-70])==19
|
|
399 | Write a function to perform the mathematical bitwise xor operation across the given tuples. | bitwise_xor | def bitwise_xor(test_tup1, test_tup2):
res = tuple(ele1 ^ ele2 for ele1, ele2 in zip(test_tup1, test_tup2))
return (res) | [
"assert bitwise_xor((10, 7, 11, 10), (8, 9, 1, 7)) == (2, 14, 10, 13)",
"assert bitwise_xor((10, 6, 6, 16), (2, 9, 2, 4)) == (8, 15, 4, 20)",
"assert bitwise_xor((16, 11, 4, 14), (4, 7, 2, 8)) == (20, 12, 6, 6)"
] | def check(candidate):
# Check some simple cases
assert bitwise_xor((10, 4, 6, 9), (5, 2, 3, 3)) == (15, 6, 5, 10)
assert bitwise_xor((11, 5, 7, 10), (6, 3, 4, 4)) == (13, 6, 3, 14)
assert bitwise_xor((12, 6, 8, 11), (7, 4, 5, 6)) == (11, 2, 13, 13)
|
|
400 | Write a function to extract the frequency of unique tuples in the given list order irrespective. | extract_freq | def extract_freq(test_list):
res = len(list(set(tuple(sorted(sub)) for sub in test_list)))
return (res) | [
"assert extract_freq([(10, 17), (7, 3), (9, 5), (4, 12)]) == 4",
"assert extract_freq([(8, 16), (2, 5), (11, 10), (5, 14)]) == 4",
"assert extract_freq([(9, 18), (5, 2), (3, 2), (7, 11)]) == 4"
] | def check(candidate):
# Check some simple cases
assert extract_freq([(3, 4), (1, 2), (4, 3), (5, 6)] ) == 3
assert extract_freq([(4, 15), (2, 3), (5, 4), (6, 7)] ) == 4
assert extract_freq([(5, 16), (2, 3), (6, 5), (6, 9)] ) == 4
|
Subsets and Splits