Dataset Preview
The full dataset viewer is not available (click to read why). Only showing a preview of the rows.
The dataset generation failed
Error code: DatasetGenerationError
Exception: ArrowInvalid
Message: JSON parse error: Column(/metadata/original_id) changed from number to string in row 66
Traceback: Traceback (most recent call last):
File "/usr/local/lib/python3.12/site-packages/datasets/packaged_modules/json/json.py", line 183, in _generate_tables
df = pandas_read_json(f)
^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/datasets/packaged_modules/json/json.py", line 38, in pandas_read_json
return pd.read_json(path_or_buf, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/pandas/io/json/_json.py", line 815, in read_json
return json_reader.read()
^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/pandas/io/json/_json.py", line 1014, in read
obj = self._get_object_parser(self.data)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/pandas/io/json/_json.py", line 1040, in _get_object_parser
obj = FrameParser(json, **kwargs).parse()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/pandas/io/json/_json.py", line 1176, in parse
self._parse()
File "/usr/local/lib/python3.12/site-packages/pandas/io/json/_json.py", line 1392, in _parse
ujson_loads(json, precise_float=self.precise_float), dtype=None
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: Trailing data
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.12/site-packages/datasets/builder.py", line 1869, in _prepare_split_single
for key, table in generator:
^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/datasets/packaged_modules/json/json.py", line 186, in _generate_tables
raise e
File "/usr/local/lib/python3.12/site-packages/datasets/packaged_modules/json/json.py", line 160, in _generate_tables
pa_table = paj.read_json(
^^^^^^^^^^^^^^
File "pyarrow/_json.pyx", line 342, in pyarrow._json.read_json
File "pyarrow/error.pxi", line 155, in pyarrow.lib.pyarrow_internal_check_status
File "pyarrow/error.pxi", line 92, in pyarrow.lib.check_status
pyarrow.lib.ArrowInvalid: JSON parse error: Column(/metadata/original_id) changed from number to string in row 66
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/src/services/worker/src/worker/job_runners/config/parquet_and_info.py", line 1347, in compute_config_parquet_and_info_response
parquet_operations = convert_to_parquet(builder)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/src/services/worker/src/worker/job_runners/config/parquet_and_info.py", line 980, in convert_to_parquet
builder.download_and_prepare(
File "/usr/local/lib/python3.12/site-packages/datasets/builder.py", line 884, in download_and_prepare
self._download_and_prepare(
File "/usr/local/lib/python3.12/site-packages/datasets/builder.py", line 947, in _download_and_prepare
self._prepare_split(split_generator, **prepare_split_kwargs)
File "/usr/local/lib/python3.12/site-packages/datasets/builder.py", line 1736, in _prepare_split
for job_id, done, content in self._prepare_split_single(
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/datasets/builder.py", line 1919, in _prepare_split_single
raise DatasetGenerationError("An error occurred while generating the dataset") from e
datasets.exceptions.DatasetGenerationError: An error occurred while generating the datasetNeed help to make the dataset viewer work? Make sure to review how to configure the dataset viewer, and open a discussion for direct support.
problem string | answer string | id int64 | metadata dict |
|---|---|---|---|
Write a python function to remove first and last occurrence of a given character from the string. | def remove_Occ(s,ch):
for i in range(len(s)):
if (s[i] == ch):
s = s[0 : i] + s[i + 1:]
break
for i in range(len(s) - 1,-1,-1):
if (s[i] == ch):
s = s[0 : i] + s[i + 1:]
break
return s | 1 | {
"test_cases": [
"assert remove_Occ(\"hello\",\"l\") == \"heo\"",
"assert remove_Occ(\"abcda\",\"a\") == \"bcd\"",
"assert remove_Occ(\"PHP\",\"P\") == \"H\"",
"assert remove_Occ(\"hellolloll\",\"l\") == \"helollol\"",
"assert remove_Occ(\"\",\"l\") == \"\""
],
"test_list": [
"assert remo... |
Write a function to count the most common words in a dictionary. | from collections import Counter
def count_common(words):
word_counts = Counter(words)
top_four = word_counts.most_common(4)
return (top_four)
| 2 | {
"test_cases": [
"assert count_common(['red','green','black','pink','black','white','black','eyes','white','black','orange','pink','pink','red','red','white','orange','white',\"black\",'pink','green','green','pink','green','pink','white','orange',\"orange\",'red']) == [('pink', 6), ('black', 5), ('white', 5), ('... |
Write a function to split a string at lowercase letters. | import re
def split_lowerstring(text):
return (re.findall('[a-z][^a-z]*', text)) | 3 | {
"test_cases": [
"assert split_lowerstring(\"AbCd\")==['bC','d']",
"assert split_lowerstring(\"Python\")==['y', 't', 'h', 'o', 'n']",
"assert split_lowerstring(\"Programming\")==['r', 'o', 'g', 'r', 'a', 'm', 'm', 'i', 'n', 'g']"
],
"test_list": [
"assert split_lowerstring(\"AbCd\")==['bC','d']",... |
Write a function to check if the given number is woodball or not. | def is_woodall(x):
if (x % 2 == 0):
return False
if (x == 1):
return True
x = x + 1
p = 0
while (x % 2 == 0):
x = x/2
p = p + 1
if (p == x):
return True
return False | 4 | {
"test_cases": [
"assert is_woodall(383) == True",
"assert is_woodall(254) == False",
"assert is_woodall(200) == False",
"assert is_woodall(32212254719) == True",
"assert is_woodall(32212254718) == False",
"assert is_woodall(159) == True"
],
"test_list": [
"assert is_woodall(383) == T... |
Write a function to find the first duplicate element in a given array of integers. | def find_first_duplicate(nums):
num_set = set()
no_duplicate = -1
for i in range(len(nums)):
if nums[i] in num_set:
return nums[i]
else:
num_set.add(nums[i])
return no_duplicate | 5 | {
"test_cases": [
"assert find_first_duplicate(([1, 2, 3, 4, 4, 5]))==4",
"assert find_first_duplicate([1, 2, 3, 4])==-1",
"assert find_first_duplicate([1, 1, 2, 3, 3, 2, 2])==1"
],
"test_list": [
"assert find_first_duplicate(([1, 2, 3, 4, 4, 5]))==4",
"assert find_first_duplicate([1, 2, 3, 4]... |
Write a function to check if the given tuple list has all k elements. | def check_k_elements(test_list, K):
res = True
for tup in test_list:
for ele in tup:
if ele != K:
res = False
return (res) | 6 | {
"test_cases": [
"assert check_k_elements([(4, 4), (4, 4, 4), (4, 4), (4, 4, 4, 4), (4, )], 4) == True",
"assert check_k_elements([(7, 7, 7), (7, 7)], 7) == True",
"assert check_k_elements([(9, 9), (9, 9, 9, 9)], 7) == False",
"assert check_k_elements([(4, 4), (4, 4, 4), (4, 4), (4, 4, 6, 4), (4, )],... |
Write a python function to find binomial co-efficient. | def binomial_Coeff(n,k):
if k > n :
return 0
if k==0 or k ==n :
return 1
return binomial_Coeff(n-1,k-1) + binomial_Coeff(n-1,k) | 7 | {
"test_cases": [
"assert binomial_Coeff(5,2) == 10",
"assert binomial_Coeff(4,3) == 4",
"assert binomial_Coeff(3,2) == 3",
"assert binomial_Coeff(14,6) == 3003"
],
"test_list": [
"assert binomial_Coeff(5,2) == 10",
"assert binomial_Coeff(4,3) == 4",
"assert binomial_Coeff(3,2) == 3"
... |
Write a python function to count all the substrings starting and ending with same characters. | 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; | 8 | {
"test_cases": [
"assert count_Substring_With_Equal_Ends(\"abc\") == 3",
"assert count_Substring_With_Equal_Ends(\"abcda\") == 6",
"assert count_Substring_With_Equal_Ends(\"ab\") == 2"
],
"test_list": [
"assert count_Substring_With_Equal_Ends(\"abc\") == 3",
"assert count_Substring_With_Equal... |
Write a function to find the top k integers that occur most frequently from given lists of sorted and distinct integers using heap queue algorithm. | def func(nums, k):
import collections
d = collections.defaultdict(int)
for row in nums:
for i in row:
d[i] += 1
temp = []
import heapq
for key, v in d.items():
if len(temp) < k:
temp.append((v, key))
if len(temp) == k:
... | 9 | {
"test_cases": [
"assert func([[1, 2, 6], [1, 3, 4, 5, 7, 8], [1, 3, 5, 6, 8, 9], [2, 5, 7, 11], [1, 4, 7, 8, 12]],3)==[5, 7, 1]",
"assert func([[1, 2, 6], [1, 3, 4, 5, 7, 8], [1, 3, 5, 6, 8, 9], [2, 5, 7, 11], [1, 4, 7, 8, 12]],1)==[1]",
"assert func([[1, 2, 6], [1, 3, 4, 5, 7, 8], [1, 3, 5, 6, 8, 9], [... |
Write a python function to find the missing number in a sorted array. | def find_missing(ar,N):
l = 0
r = N - 1
while (l <= r):
mid = (l + r) / 2
mid= int (mid)
if (ar[mid] != mid + 1 and ar[mid - 1] == mid):
return (mid + 1)
elif (ar[mid] != mid + 1):
r = mid - 1
else:
l = mid + 1
... | 10 | {
"test_cases": [
"assert find_missing([1,2,3,5],4) == 4",
"assert find_missing([1,3,4,5],4) == 2",
"assert find_missing([1,2,3,5,6,7],5) == 4"
],
"test_list": [
"assert find_missing([1,2,3,5],4) == 4",
"assert find_missing([1,3,4,5],4) == 2",
"assert find_missing([1,2,3,5,6,7],5) == 4"
... |
Write a python function to find the nth digit in the proper fraction of two given numbers. | def find_Nth_Digit(p,q,N) :
while (N > 0) :
N -= 1;
p *= 10;
res = p // q;
p %= q;
return res; | 11 | {
"test_cases": [
"assert find_Nth_Digit(1,2,1) == 5",
"assert find_Nth_Digit(3,5,1) == 6",
"assert find_Nth_Digit(5,6,5) == 3"
],
"test_list": [
"assert find_Nth_Digit(1,2,1) == 5",
"assert find_Nth_Digit(3,5,1) == 6",
"assert find_Nth_Digit(5,6,5) == 3"
],
"challenge_test_list": [],
... |
Write a function to find the division of first even and odd number of a given list. | def div_even_odd(list1):
first_even = next((el for el in list1 if el%2==0),-1)
first_odd = next((el for el in list1 if el%2!=0),-1)
return (first_even/first_odd) | 12 | {
"test_cases": [
"assert div_even_odd([1,3,5,7,4,1,6,8])==4",
"assert div_even_odd([1,2,3,4,5,6,7,8,9,10])==2",
"assert div_even_odd([1,5,7,9,10])==10"
],
"test_list": [
"assert div_even_odd([1,3,5,7,4,1,6,8])==4",
"assert div_even_odd([1,2,3,4,5,6,7,8,9,10])==2",
"assert div_even_odd([1,... |
Write a function to check if the letters of a given string can be rearranged so that two characters that are adjacent to each other are different. | import heapq
from collections import Counter
def rearange_string(S):
ctr = Counter(S)
heap = [(-value, key) for key, value in ctr.items()]
heapq.heapify(heap)
if (-heap[0][0]) * 2 > len(S) + 1:
return ""
ans = []
while len(heap) >= 2:
nct1, char1 = heapq.heappop(heap)
... | 13 | {
"test_cases": [
"assert rearange_string(\"aab\")==('aba')",
"assert rearange_string(\"aabb\")==('abab')",
"assert rearange_string(\"abccdd\")==('cdabcd')"
],
"test_list": [
"assert rearange_string(\"aab\")==('aba')",
"assert rearange_string(\"aabb\")==('abab')",
"assert rearange_string(\... |
Write a python function to find the sum of repeated elements in a given array. | def find_Sum(arr,n):
return sum([x for x in arr if arr.count(x) > 1]) | 14 | {
"test_cases": [
"assert find_Sum([1,2,3,1,1,4,5,6],8) == 3",
"assert find_Sum([1,2,3,1,1],5) == 3",
"assert find_Sum([1,1,2],3) == 2",
"assert find_Sum([1,1,2,3,4,5,6,3,5],9) == 18"
],
"test_list": [
"assert find_Sum([1,2,3,1,1,4,5,6],8) == 3",
"assert find_Sum([1,2,3,1,1],5) == 3",
... |
Write a python function to find the last digit when factorial of a divides factorial of b. | def compute_Last_Digit(A,B):
variable = 1
if (A == B):
return 1
elif ((B - A) >= 5):
return 0
else:
for i in range(A + 1,B + 1):
variable = (variable * (i % 10)) % 10
return variable % 10 | 15 | {
"test_cases": [
"assert compute_Last_Digit(2,4) == 2",
"assert compute_Last_Digit(6,8) == 6",
"assert compute_Last_Digit(1,2) == 2",
"assert compute_Last_Digit(3,7) == 0",
"assert compute_Last_Digit(20,23) == 6",
"assert compute_Last_Digit(1021,1024) == 4"
],
"test_list": [
"assert c... |
Write a python function to set all odd bits of a given number. | def odd_bit_set_number(n):
count = 0;res = 0;temp = n
while temp > 0:
if count % 2 == 0:
res |= (1 << count)
count += 1
temp >>= 1
return (n | res) | 16 | {
"test_cases": [
"assert odd_bit_set_number(10) == 15",
"assert odd_bit_set_number(20) == 21",
"assert odd_bit_set_number(30) == 31"
],
"test_list": [
"assert odd_bit_set_number(10) == 15",
"assert odd_bit_set_number(20) == 21",
"assert odd_bit_set_number(30) == 31"
],
"challenge_test... |
Write a function to find the maximum length of the subsequence with difference between adjacent elements for the given array. | def max_len_sub( arr, n):
mls=[]
max = 0
for i in range(n):
mls.append(1)
for i in range(n):
for j in range(i):
if (abs(arr[i] - arr[j]) <= 1 and mls[i] < mls[j] + 1):
mls[i] = mls[j] + 1
for i in range(n):
if (max < mls[i]):
max = mls[i]
return max | 17 | {
"test_cases": [
"assert max_len_sub([2, 5, 6, 3, 7, 6, 5, 8], 8) == 5",
"assert max_len_sub([-2, -1, 5, -1, 4, 0, 3], 7) == 4",
"assert max_len_sub([9, 11, 13, 15, 18], 5) == 1"
],
"test_list": [
"assert max_len_sub([2, 5, 6, 3, 7, 6, 5, 8], 8) == 5",
"assert max_len_sub([-2, -1, 5, -1, 4, 0... |
Write a python function to count number of substrings with the sum of digits equal to their length. | from collections import defaultdict
def count_Substrings(s,n):
count,sum = 0,0
mp = defaultdict(lambda : 0)
mp[0] += 1
for i in range(n):
sum += ord(s[i]) - ord('0')
count += mp[sum - (i + 1)]
mp[sum - (i + 1)] += 1
return count | 18 | {
"test_cases": [
"assert count_Substrings('112112',6) == 6",
"assert count_Substrings('111',3) == 6",
"assert count_Substrings('1101112',7) == 12"
],
"test_list": [
"assert count_Substrings('112112',6) == 6",
"assert count_Substrings('111',3) == 6",
"assert count_Substrings('1101112',7) =... |
Write a function to find the number of ways to partition a set of bell numbers. | def bell_number(n):
bell = [[0 for i in range(n+1)] for j in range(n+1)]
bell[0][0] = 1
for i in range(1, n+1):
bell[i][0] = bell[i-1][i-1]
for j in range(1, i+1):
bell[i][j] = bell[i-1][j-1] + bell[i][j-1]
return bell[n][0] | 19 | {
"test_cases": [
"assert bell_number(2)==2",
"assert bell_number(10)==115975",
"assert bell_number(56)==6775685320645824322581483068371419745979053216268760300"
],
"test_list": [
"assert bell_number(2)==2",
"assert bell_number(10)==115975",
"assert bell_number(56)==67756853206458243225814... |
Write a function to check whether it follows the sequence given in the patterns array. | def is_samepatterns(colors, patterns):
if len(colors) != len(patterns):
return False
sdict = {}
pset = set()
sset = set()
for i in range(len(patterns)):
pset.add(patterns[i])
sset.add(colors[i])
if patterns[i] not in sdict.keys():
sdi... | 20 | {
"test_cases": [
"assert is_samepatterns([\"red\",\"green\",\"green\"], [\"a\", \"b\", \"b\"])==True ",
"assert is_samepatterns([\"red\",\"green\",\"greenn\"], [\"a\",\"b\",\"b\"])==False ",
"assert is_samepatterns([\"red\",\"green\",\"greenn\"], [\"a\",\"b\"])==False "
],
"test_list": [
"assert ... |
Write a python function to count the number of squares in a rectangle. | def count_Squares(m,n):
if(n < m):
temp = m
m = n
n = temp
return ((m * (m + 1) * (2 * m + 1) / 6 + (n - m) * m * (m + 1) / 2)) | 21 | {
"test_cases": [
"assert count_Squares(4,3) == 20",
"assert count_Squares(2,2) == 5",
"assert count_Squares(1,1) == 1"
],
"test_list": [
"assert count_Squares(4,3) == 20",
"assert count_Squares(2,2) == 5",
"assert count_Squares(1,1) == 1"
],
"challenge_test_list": [],
"reference_cod... |
Write a python function to find the difference between sum of even and odd digits. | def is_Diff(n):
return (n % 11 == 0) | 22 | {
"test_cases": [
"assert is_Diff (12345) == False",
"assert is_Diff(1212112) == True",
"assert is_Diff(1212) == False"
],
"test_list": [
"assert is_Diff (12345) == False",
"assert is_Diff(1212112) == True",
"assert is_Diff(1212) == False"
],
"challenge_test_list": [],
"reference_cod... |
Write a python function to find number of integers with odd number of set bits. | def count_With_Odd_SetBits(n):
if (n % 2 != 0):
return (n + 1) / 2
count = bin(n).count('1')
ans = n / 2
if (count % 2 != 0):
ans += 1
return ans | 23 | {
"test_cases": [
"assert count_With_Odd_SetBits(5) == 3",
"assert count_With_Odd_SetBits(10) == 5",
"assert count_With_Odd_SetBits(15) == 8"
],
"test_list": [
"assert count_With_Odd_SetBits(5) == 3",
"assert count_With_Odd_SetBits(10) == 5",
"assert count_With_Odd_SetBits(15) == 8"
],
... |
Write a function to zip the two given tuples. | def zip_tuples(test_tup1, test_tup2):
res = []
for i, j in enumerate(test_tup1):
res.append((j, test_tup2[i % len(test_tup2)]))
return (res) | 24 | {
"test_cases": [
"assert zip_tuples((7, 8, 4, 5, 9, 10),(1, 5, 6) ) == [(7, 1), (8, 5), (4, 6), (5, 1), (9, 5), (10, 6)]",
"assert zip_tuples((8, 9, 5, 6, 10, 11),(2, 6, 7) ) == [(8, 2), (9, 6), (5, 7), (6, 2), (10, 6), (11, 7)]",
"assert zip_tuples((9, 10, 6, 7, 11, 12),(3, 7, 8) ) == [(9, 3), (10, 7), ... |
Write a function to find the n-th number in newman conway sequence. | def sequence(n):
if n == 1 or n == 2:
return 1
else:
return sequence(sequence(n-1)) + sequence(n-sequence(n-1)) | 25 | {
"test_cases": [
"assert sequence(10) == 6",
"assert sequence(2) == 1",
"assert sequence(3) == 2"
],
"test_list": [
"assert sequence(10) == 6",
"assert sequence(2) == 1",
"assert sequence(3) == 2"
],
"challenge_test_list": [],
"reference_code": "def sequence(n): \r\n\tif n == 1 or n... |
Write a function to merge three dictionaries into a single expression. | import collections as ct
def merge_dictionaries_three(dict1,dict2, dict3):
merged_dict = dict(ct.ChainMap({},dict1,dict2,dict3))
return merged_dict | 26 | {
"test_cases": [
"assert merge_dictionaries_three({ \"R\": \"Red\", \"B\": \"Black\", \"P\": \"Pink\" }, { \"G\": \"Green\", \"W\": \"White\" },{ \"O\": \"Orange\", \"W\": \"White\", \"B\": \"Black\" })=={'B': 'Black', 'R': 'Red', 'P': 'Pink', 'G': 'Green', 'W': 'White', 'O': 'Orange'}",
"assert merge_dictio... |
Write a function to find the next smallest palindrome of a specified number. | import sys
def next_smallest_palindrome(num):
numstr = str(num)
for i in range(num+1,sys.maxsize):
if str(i) == str(i)[::-1]:
return i | 27 | {
"test_cases": [
"assert next_smallest_palindrome(99)==101",
"assert next_smallest_palindrome(1221)==1331",
"assert next_smallest_palindrome(120)==121"
],
"test_list": [
"assert next_smallest_palindrome(99)==101",
"assert next_smallest_palindrome(1221)==1331",
"assert next_smallest_palind... |
Write a function to find the kth element in the given array. | def kth_element(arr, n, k):
for i in range(n):
for j in range(0, n-i-1):
if arr[j] > arr[j+1]:
arr[j], arr[j+1] == arr[j+1], arr[j]
return arr[k-1] | 28 | {
"test_cases": [
"assert kth_element([12,3,5,7,19], 5, 2) == 3",
"assert kth_element([17,24,8,23], 4, 3) == 8",
"assert kth_element([16,21,25,36,4], 5, 4) == 36"
],
"test_list": [
"assert kth_element([12,3,5,7,19], 5, 2) == 3",
"assert kth_element([17,24,8,23], 4, 3) == 8",
"assert kth_el... |
Write a function to find eulerian number a(n, m). | def eulerian_num(n, m):
if (m >= n or n == 0):
return 0
if (m == 0):
return 1
return ((n - m) * eulerian_num(n - 1, m - 1) +(m + 1) * eulerian_num(n - 1, m)) | 29 | {
"test_cases": [
"assert eulerian_num(3, 1) == 4",
"assert eulerian_num(4, 1) == 11",
"assert eulerian_num(5, 3) == 26"
],
"test_list": [
"assert eulerian_num(3, 1) == 4",
"assert eulerian_num(4, 1) == 11",
"assert eulerian_num(5, 3) == 26"
],
"challenge_test_list": [],
"reference_c... |
Write a python function to count hexadecimal numbers for a given range. | def count_Hexadecimal(L,R) :
count = 0;
for i in range(L,R + 1) :
if (i >= 10 and i <= 15) :
count += 1;
elif (i > 15) :
k = i;
while (k != 0) :
if (k % 16 >= 10) :
count += 1;
k = k... | 30 | {
"test_cases": [
"assert count_Hexadecimal(10,15) == 6",
"assert count_Hexadecimal(2,4) == 0",
"assert count_Hexadecimal(15,16) == 1"
],
"test_list": [
"assert count_Hexadecimal(10,15) == 6",
"assert count_Hexadecimal(2,4) == 0",
"assert count_Hexadecimal(15,16) == 1"
],
"challenge_te... |
Write a function to merge multiple sorted inputs into a single sorted iterator using heap queue algorithm. | import heapq
def merge_sorted_list(num1,num2,num3):
num1=sorted(num1)
num2=sorted(num2)
num3=sorted(num3)
result = heapq.merge(num1,num2,num3)
return list(result) | 31 | {
"test_cases": [
"assert merge_sorted_list([25, 24, 15, 4, 5, 29, 110],[19, 20, 11, 56, 25, 233, 154],[24, 26, 54, 48])==[4, 5, 11, 15, 19, 20, 24, 24, 25, 25, 26, 29, 48, 54, 56, 110, 154, 233]",
"assert merge_sorted_list([1, 3, 5, 6, 8, 9], [2, 5, 7, 11], [1, 4, 7, 8, 12])==[1, 1, 2, 3, 4, 5, 5, 6, 7, 7, 8... |
Write a python function to find the count of rotations of a binary string with odd value. | def odd_Equivalent(s,n):
count=0
for i in range(0,n):
if (s[i] == '1'):
count = count + 1
return count | 32 | {
"test_cases": [
"assert odd_Equivalent(\"011001\",6) == 3",
"assert odd_Equivalent(\"11011\",5) == 4",
"assert odd_Equivalent(\"1010\",4) == 2"
],
"test_list": [
"assert odd_Equivalent(\"011001\",6) == 3",
"assert odd_Equivalent(\"11011\",5) == 4",
"assert odd_Equivalent(\"1010\",4) == 2... |
Write a function to extract the ranges that are missing from the given list with the given start range and end range values. | def extract_missing(test_list, strt_val, stop_val):
res = []
for sub in test_list:
if sub[0] > strt_val:
res.append((strt_val, sub[0]))
strt_val = sub[1]
if strt_val < stop_val:
res.append((strt_val, stop_val))
return (res) | 33 | {
"test_cases": [
"assert extract_missing([(6, 9), (15, 34), (48, 70)], 2, 100) == [(2, 6), (9, 100), (9, 15), (34, 100), (34, 48), (70, 100)]",
"assert extract_missing([(7, 2), (15, 19), (38, 50)], 5, 60) == [(5, 7), (2, 60), (2, 15), (19, 60), (19, 38), (50, 60)]",
"assert extract_missing([(7, 2), (15, ... |
Write a function to find common elements in given nested lists. * list item * list item * list item * list item | def common_in_nested_lists(nestedlist):
result = list(set.intersection(*map(set, nestedlist)))
return result | 34 | {
"test_cases": [
"assert common_in_nested_lists([[12, 18, 23, 25, 45], [7, 12, 18, 24, 28], [1, 5, 8, 12, 15, 16, 18]])==[18, 12]",
"assert common_in_nested_lists([[12, 5, 23, 25, 45], [7, 11, 5, 23, 28], [1, 5, 8, 18, 23, 16]])==[5,23]",
"assert common_in_nested_lists([[2, 3,4, 1], [4, 5], [6,4, 8],[4, ... |
Write a function to assign frequency to each tuple in the given tuple list. | from collections import Counter
def assign_freq(test_list):
res = [(*key, val) for key, val in Counter(test_list).items()]
return (str(res)) | 35 | {
"test_cases": [
"assert assign_freq([(6, 5, 8), (2, 7), (6, 5, 8), (6, 5, 8), (9, ), (2, 7)] ) == '[(6, 5, 8, 3), (2, 7, 2), (9, 1)]'",
"assert assign_freq([(4, 2, 4), (7, 1), (4, 8), (4, 2, 4), (9, 2), (7, 1)] ) == '[(4, 2, 4, 2), (7, 1, 2), (4, 8, 1), (9, 2, 1)]'",
"assert assign_freq([(11, 13, 10), (... |
Write a function to check whether all dictionaries in a list are empty or not. | def empty_dit(list1):
empty_dit=all(not d for d in list1)
return empty_dit | 36 | {
"test_cases": [
"assert empty_dit([{},{},{}])==True",
"assert empty_dit([{1,2},{},{}])==False",
"assert empty_dit({})==True"
],
"test_list": [
"assert empty_dit([{},{},{}])==True",
"assert empty_dit([{1,2},{},{}])==False",
"assert empty_dit({})==True"
],
"challenge_test_list": [],
... |
Write a function to convert a given tuple of positive integers into an integer. | def tuple_to_int(nums):
result = int(''.join(map(str,nums)))
return result | 37 | {
"test_cases": [
"assert tuple_to_int((1,2,3))==123",
"assert tuple_to_int((4,5,6))==456",
"assert tuple_to_int((5,6,7))==567"
],
"test_list": [
"assert tuple_to_int((1,2,3))==123",
"assert tuple_to_int((4,5,6))==456",
"assert tuple_to_int((5,6,7))==567"
],
"challenge_test_list": [],
... |
Write a python function to find the element that appears only once in a sorted array. | def search(arr,n) :
XOR = 0
for i in range(n) :
XOR = XOR ^ arr[i]
return (XOR) | 38 | {
"test_cases": [
"assert search([1,1,2,2,3],5) == 3",
"assert search([1,1,3,3,4,4,5,5,7,7,8],11) == 8",
"assert search([1,2,2,3,3,4,4],7) == 1"
],
"test_list": [
"assert search([1,1,2,2,3],5) == 3",
"assert search([1,1,3,3,4,4,5,5,7,7,8],11) == 8",
"assert search([1,2,2,3,3,4,4],7) == 1"
... |
Write a function to find the maximum product from the pairs of tuples within a given list. | def max_product_tuple(list1):
result_max = max([abs(x * y) for x, y in list1] )
return result_max | 39 | {
"test_cases": [
"assert max_product_tuple([(2, 7), (2, 6), (1, 8), (4, 9)] )==36",
"assert max_product_tuple([(10,20), (15,2), (5,10)] )==200",
"assert max_product_tuple([(11,44), (10,15), (20,5), (12, 9)] )==484"
],
"test_list": [
"assert max_product_tuple([(2, 7), (2, 6), (1, 8), (4, 9)] )==36... |
Write a function to find the triplet with sum of the given array | def check_triplet(A, n, sum, count):
if count == 3 and sum == 0:
return True
if count == 3 or n == 0 or sum < 0:
return False
return check_triplet(A, n - 1, sum - A[n - 1], count + 1) or\
check_triplet(A, n - 1, sum, count) | 40 | {
"test_cases": [
"assert check_triplet([2, 7, 4, 0, 9, 5, 1, 3], 8, 6, 0) == True",
"assert check_triplet([1, 4, 5, 6, 7, 8, 5, 9], 8, 6, 0) == False",
"assert check_triplet([10, 4, 2, 3, 5], 5, 15, 0) == True"
],
"test_list": [
"assert check_triplet([2, 7, 4, 0, 9, 5, 1, 3], 8, 6, 0) == True",
... |
Write a function to find n’th smart number. | MAX = 3000
def smartNumber(n):
primes = [0] * MAX
result = []
for i in range(2, MAX):
if (primes[i] == 0):
primes[i] = 1
j = i * 2
while (j < MAX):
primes[j] -= 1
if ( (primes[j] + 3) == 0):
result.append(j)
j = j + i
result.sort()
return result[n - 1] | 41 | {
"test_cases": [
"assert smartNumber(1) == 30",
"assert smartNumber(50) == 273",
"assert smartNumber(1000) == 2664"
],
"test_list": [
"assert smartNumber(1) == 30",
"assert smartNumber(50) == 273",
"assert smartNumber(1000) == 2664"
],
"challenge_test_list": [],
"reference_code": "M... |
Write a function to sum all amicable numbers from 1 to a specified number. | def amicable_numbers_sum(limit):
if not isinstance(limit, int):
return "Input is not an integer!"
if limit < 1:
return "Input must be bigger than 0!"
amicables = set()
for num in range(2, limit+1):
if num in amicables:
continue
sum_fact = sum([fact fo... | 42 | {
"test_cases": [
"assert amicable_numbers_sum(999)==504",
"assert amicable_numbers_sum(9999)==31626",
"assert amicable_numbers_sum(99)==0"
],
"test_list": [
"assert amicable_numbers_sum(999)==504",
"assert amicable_numbers_sum(9999)==31626",
"assert amicable_numbers_sum(99)==0"
],
"ch... |
Write a function to get the angle of a complex number. | import cmath
def angle_complex(a,b):
cn=complex(a,b)
angle=cmath.phase(a+b)
return angle | 43 | {
"test_cases": [
"assert angle_complex(0,1j)==1.5707963267948966 ",
"assert angle_complex(2,1j)==0.4636476090008061",
"assert angle_complex(0,2j)==1.5707963267948966"
],
"test_list": [
"assert angle_complex(0,1j)==1.5707963267948966 ",
"assert angle_complex(2,1j)==0.4636476090008061",
"as... |
Write a function to find the maximum difference between the number of 0s and number of 1s in any sub-string of the given binary string. | def find_length(string, n):
current_sum = 0
max_sum = 0
for i in range(n):
current_sum += (1 if string[i] == '0' else -1)
if current_sum < 0:
current_sum = 0
max_sum = max(current_sum, max_sum)
return max_sum if max_sum else 0 | 44 | {
"test_cases": [
"assert find_length(\"11000010001\", 11) == 6",
"assert find_length(\"10111\", 5) == 1",
"assert find_length(\"11011101100101\", 14) == 2 "
],
"test_list": [
"assert find_length(\"11000010001\", 11) == 6",
"assert find_length(\"10111\", 5) == 1",
"assert find_length(\"110... |
Write a function to multiply two integers without using the * operator in python. | def multiply_int(x, y):
if y < 0:
return -multiply_int(x, -y)
elif y == 0:
return 0
elif y == 1:
return x
else:
return x + multiply_int(x, y - 1) | 45 | {
"test_cases": [
"assert multiply_int(10,20)==200",
"assert multiply_int(5,10)==50",
"assert multiply_int(4,8)==32"
],
"test_list": [
"assert multiply_int(10,20)==200",
"assert multiply_int(5,10)==50",
"assert multiply_int(4,8)==32"
],
"challenge_test_list": [],
"reference_code": "d... |
Write a function to calculate magic square. | def magic_square_test(my_matrix):
iSize = len(my_matrix[0])
sum_list = []
sum_list.extend([sum (lines) for lines in my_matrix])
for col in range(iSize):
sum_list.append(sum(row[col] for row in my_matrix))
result1 = 0
for i in range(0,iSize):
result1 +=my_matrix[i][i]
... | 46 | {
"test_cases": [
"assert magic_square_test([[7, 12, 1, 14], [2, 13, 8, 11], [16, 3, 10, 5], [9, 6, 15, 4]])==True",
"assert magic_square_test([[2, 7, 6], [9, 5, 1], [4, 3, 8]])==True",
"assert magic_square_test([[2, 7, 6], [9, 5, 1], [4, 3, 7]])==False"
],
"test_list": [
"assert magic_square_test... |
Write a function to find the item with maximum frequency in a given list. | from collections import defaultdict
def max_occurrences(nums):
dict = defaultdict(int)
for i in nums:
dict[i] += 1
result = max(dict.items(), key=lambda x: x[1])
return result | 47 | {
"test_cases": [
"assert max_occurrences([2,3,8,4,7,9,8,2,6,5,1,6,1,2,3,2,4,6,9,1,2])==(2, 5)",
"assert max_occurrences([2,3,8,4,7,9,8,7,9,15,14,10,12,13,16,16,18])==(8, 2)",
"assert max_occurrences([10,20,20,30,40,90,80,50,30,20,50,10])==(20, 3)"
],
"test_list": [
"assert max_occurrences([2,3,8,... |
Write a python function to reverse only the vowels of a given string. | def reverse_vowels(str1):
vowels = ""
for char in str1:
if char in "aeiouAEIOU":
vowels += char
result_string = ""
for char in str1:
if char in "aeiouAEIOU":
result_string += vowels[-1]
vowels = vowels[:-1]
else:
result_string += char
return result_string | 48 | {
"test_cases": [
"assert reverse_vowels(\"Python\") == \"Python\"",
"assert reverse_vowels(\"USA\") == \"ASU\"",
"assert reverse_vowels(\"ab\") == \"ab\""
],
"test_list": [
"assert reverse_vowels(\"Python\") == \"Python\"",
"assert reverse_vowels(\"USA\") == \"ASU\"",
"assert reverse_vowe... |
Write a python function to check whether the last element of given array is even or odd after performing an operation p times. | def check_last (arr,n,p):
_sum = 0
for i in range(n):
_sum = _sum + arr[i]
if p == 1:
if _sum % 2 == 0:
return "ODD"
else:
return "EVEN"
return "EVEN"
| 49 | {
"test_cases": [
"assert check_last([5,7,10],3,1) == \"ODD\"",
"assert check_last([2,3],2,3) == \"EVEN\"",
"assert check_last([1,2,3],3,1) == \"ODD\""
],
"test_list": [
"assert check_last([5,7,10],3,1) == \"ODD\"",
"assert check_last([2,3],2,3) == \"EVEN\"",
"assert check_last([1,2,3],3,1... |
Write a function to calculate electricity bill. | def cal_electbill(units):
if(units < 50):
amount = units * 2.60
surcharge = 25
elif(units <= 100):
amount = 130 + ((units - 50) * 3.25)
surcharge = 35
elif(units <= 200):
amount = 130 + 162.50 + ((units - 100) * 5.26)
surcharge = 45
else:
amount = 130 + 162.50 + 526 + ((units ... | 50 | {
"test_cases": [
"assert cal_electbill(75)==246.25",
"assert cal_electbill(265)==1442.75",
"assert cal_electbill(100)==327.5"
],
"test_list": [
"assert cal_electbill(75)==246.25",
"assert cal_electbill(265)==1442.75",
"assert cal_electbill(100)==327.5"
],
"challenge_test_list": [],
... |
Write a python function to check whether the given number can be represented as sum of non-zero powers of 2 or not. | def is_Sum_Of_Powers_Of_Two(n):
if (n % 2 == 1):
return False
else:
return True | 51 | {
"test_cases": [
"assert is_Sum_Of_Powers_Of_Two(10) == True",
"assert is_Sum_Of_Powers_Of_Two(7) == False",
"assert is_Sum_Of_Powers_Of_Two(14) == True"
],
"test_list": [
"assert is_Sum_Of_Powers_Of_Two(10) == True",
"assert is_Sum_Of_Powers_Of_Two(7) == False",
"assert is_Sum_Of_Powers_... |
Write a function to extract elements that occur singly in the given tuple list. | def extract_singly(test_list):
res = []
temp = set()
for inner in test_list:
for ele in inner:
if not ele in temp:
temp.add(ele)
res.append(ele)
return (res) | 52 | {
"test_cases": [
"assert extract_singly([(3, 4, 5), (4, 5, 7), (1, 4)]) == [3, 4, 5, 7, 1]",
"assert extract_singly([(1, 2, 3), (4, 2, 3), (7, 8)]) == [1, 2, 3, 4, 7, 8]",
"assert extract_singly([(7, 8, 9), (10, 11, 12), (10, 11)]) == [7, 8, 9, 10, 11, 12]"
],
"test_list": [
"assert extract_singl... |
Write a function to find number of lists present in the given tuple. | def find_lists(Input):
if isinstance(Input, list):
return 1
else:
return len(Input) | 53 | {
"test_cases": [
"assert find_lists(([1, 2, 3, 4], [5, 6, 7, 8])) == 2",
"assert find_lists(([1, 2], [3, 4], [5, 6])) == 3",
"assert find_lists(([9, 8, 7, 6, 5, 4, 3, 2, 1])) == 1"
],
"test_list": [
"assert find_lists(([1, 2, 3, 4], [5, 6, 7, 8])) == 2",
"assert find_lists(([1, 2], [3, 4], [... |
Write a python function to find the sum of absolute differences in all pairs of the given array. | def sum_Pairs(arr,n):
sum = 0
for i in range(n - 1,-1,-1):
sum += i*arr[i] - (n-1-i) * arr[i]
return sum | 54 | {
"test_cases": [
"assert sum_Pairs([1,8,9,15,16],5) == 74",
"assert sum_Pairs([1,2,3,4],4) == 10",
"assert sum_Pairs([1,2,3,4,5,7,9,11,14],9) == 188"
],
"test_list": [
"assert sum_Pairs([1,8,9,15,16],5) == 74",
"assert sum_Pairs([1,2,3,4],4) == 10",
"assert sum_Pairs([1,2,3,4,5,7,9,11,14]... |
Write a function to find the maximum total path sum in the given triangle. | def max_path_sum(tri, m, n):
for i in range(m-1, -1, -1):
for j in range(i+1):
if (tri[i+1][j] > tri[i+1][j+1]):
tri[i][j] += tri[i+1][j]
else:
tri[i][j] += tri[i+1][j+1]
return tri[0][0] | 55 | {
"test_cases": [
"assert max_path_sum([[1, 0, 0], [4, 8, 0], [1, 5, 3]], 2, 2) == 14",
"assert max_path_sum([[13, 0, 0], [7, 4, 0], [2, 4, 6]], 2, 2) == 24 ",
"assert max_path_sum([[2, 0, 0], [11, 18, 0], [21, 25, 33]], 2, 2) == 53"
],
"test_list": [
"assert max_path_sum([[1, 0, 0], [4, 8, 0], [1... |
Write a function to divide a number into two parts such that the sum of digits is maximum. | def sum_digits_single(x) :
ans = 0
while x :
ans += x % 10
x //= 10
return ans
def closest(x) :
ans = 0
while (ans * 10 + 9 <= x) :
ans = ans * 10 + 9
return ans
def sum_digits_twoparts(N) :
A = closest(N)
return sum_digits_single(A) + ... | 56 | {
"test_cases": [
"assert sum_digits_twoparts(35)==17",
"assert sum_digits_twoparts(7)==7",
"assert sum_digits_twoparts(100)==19"
],
"test_list": [
"assert sum_digits_twoparts(35)==17",
"assert sum_digits_twoparts(7)==7",
"assert sum_digits_twoparts(100)==19"
],
"challenge_test_list": ... |
Write a function to find the longest subsequence such that the difference between adjacents is one for the given array. | def longest_subseq_with_diff_one(arr, n):
dp = [1 for i in range(n)]
for i in range(n):
for j in range(i):
if ((arr[i] == arr[j]+1) or (arr[i] == arr[j]-1)):
dp[i] = max(dp[i], dp[j]+1)
result = 1
for i in range(n):
if (result < dp[i]):
result = dp[i]
return result | 57 | {
"test_cases": [
"assert longest_subseq_with_diff_one([1, 2, 3, 4, 5, 3, 2], 7) == 6",
"assert longest_subseq_with_diff_one([10, 9, 4, 5, 4, 8, 6], 7) == 3",
"assert longest_subseq_with_diff_one([1, 2, 3, 2, 3, 7, 2, 1], 8) == 7"
],
"test_list": [
"assert longest_subseq_with_diff_one([1, 2, 3, 4,... |
Write a python function to find whether the given number is present in the infinite sequence or not. | def does_Contain_B(a,b,c):
if (a == b):
return True
if ((b - a) * c > 0 and (b - a) % c == 0):
return True
return False | 58 | {
"test_cases": [
"assert does_Contain_B(1,7,3) == True",
"assert does_Contain_B(1,-3,5) == False",
"assert does_Contain_B(3,2,5) == False"
],
"test_list": [
"assert does_Contain_B(1,7,3) == True",
"assert does_Contain_B(1,-3,5) == False",
"assert does_Contain_B(3,2,5) == False"
],
"ch... |
Write a python function to toggle all even bits of a given number. | def even_bit_toggle_number(n) :
res = 0; count = 0; temp = n
while (temp > 0) :
if (count % 2 == 1) :
res = res | (1 << count)
count = count + 1
temp >>= 1
return n ^ res | 59 | {
"test_cases": [
"assert even_bit_toggle_number(10) == 0",
"assert even_bit_toggle_number(20) == 30",
"assert even_bit_toggle_number(30) == 20"
],
"test_list": [
"assert even_bit_toggle_number(10) == 0",
"assert even_bit_toggle_number(20) == 30",
"assert even_bit_toggle_number(30) == 20"
... |
Write a function to reflect the run-length encoding from a list. | from itertools import groupby
def encode_list(list1):
return [[len(list(group)), key] for key, group in groupby(list1)] | 60 | {
"test_cases": [
"assert encode_list([1,1,2,3,4,4.3,5,1])==[[2, 1], [1, 2], [1, 3], [1, 4], [1, 4.3], [1, 5], [1, 1]]",
"assert encode_list('automatically')==[[1, 'a'], [1, 'u'], [1, 't'], [1, 'o'], [1, 'm'], [1, 'a'], [1, 't'], [1, 'i'], [1, 'c'], [1, 'a'], [2, 'l'], [1, 'y']]",
"assert encode_list('pyt... |
Write a python function to find k number of operations required to make all elements equal. | def min_Ops(arr,n,k):
max1 = max(arr)
res = 0
for i in range(0,n):
if ((max1 - arr[i]) % k != 0):
return -1
else:
res += (max1 - arr[i]) / k
return int(res) | 61 | {
"test_cases": [
"assert min_Ops([2,2,2,2],4,3) == 0",
"assert min_Ops([4,2,6,8],4,3) == -1",
"assert min_Ops([21,33,9,45,63],5,6) == 24"
],
"test_list": [
"assert min_Ops([2,2,2,2],4,3) == 0",
"assert min_Ops([4,2,6,8],4,3) == -1",
"assert min_Ops([21,33,9,45,63],5,6) == 24"
],
"chal... |
Write a function to find x and y that satisfies ax + by = n. | def solution (a, b, n):
i = 0
while i * a <= n:
if (n - (i * a)) % b == 0:
return ("x = ",i ,", y = ",
int((n - (i * a)) / b))
return 0
i = i + 1
return ("No solution") | 62 | {
"test_cases": [
"assert solution(2, 3, 7) == ('x = ', 2, ', y = ', 1)",
"assert solution(4, 2, 7) == 'No solution'",
"assert solution(1, 13, 17) == ('x = ', 4, ', y = ', 1)"
],
"test_list": [
"assert solution(2, 3, 7) == ('x = ', 2, ', y = ', 1)",
"assert solution(4, 2, 7) == 'No solution'",... |
Write a python function to check whether the sum of divisors are same or not. | import math
def divSum(n):
sum = 1;
i = 2;
while(i * i <= n):
if (n % i == 0):
sum = (sum + i +math.floor(n / i));
i += 1;
return sum;
def areEquivalent(num1,num2):
return divSum(num1) == divSum(num2); | 63 | {
"test_cases": [
"assert areEquivalent(36,57) == False",
"assert areEquivalent(2,4) == False",
"assert areEquivalent(23,47) == True"
],
"test_list": [
"assert areEquivalent(36,57) == False",
"assert areEquivalent(2,4) == False",
"assert areEquivalent(23,47) == True"
],
"challenge_test... |
Write a python function to count characters at same position in a given string (lower and uppercase characters) as in english alphabet. | def count_char_position(str1):
count_chars = 0
for i in range(len(str1)):
if ((i == ord(str1[i]) - ord('A')) or
(i == ord(str1[i]) - ord('a'))):
count_chars += 1
return count_chars | 64 | {
"test_cases": [
"assert count_char_position(\"xbcefg\") == 2",
"assert count_char_position(\"ABcED\") == 3",
"assert count_char_position(\"AbgdeF\") == 5"
],
"test_list": [
"assert count_char_position(\"xbcefg\") == 2",
"assert count_char_position(\"ABcED\") == 3",
"assert count_char_pos... |
Write a python function to count the pairs with xor as an even number. | def find_even_Pair(A,N):
evenPair = 0
for i in range(0,N):
for j in range(i+1,N):
if ((A[i] ^ A[j]) % 2 == 0):
evenPair+=1
return evenPair; | 65 | {
"test_cases": [
"assert find_even_Pair([5,4,7,2,1],5) == 4",
"assert find_even_Pair([7,2,8,1,0,5,11],7) == 9",
"assert find_even_Pair([1,2,3],3) == 1"
],
"test_list": [
"assert find_even_Pair([5,4,7,2,1],5) == 4",
"assert find_even_Pair([7,2,8,1,0,5,11],7) == 9",
"assert find_even_Pair([... |
Write a python function to find two distinct numbers such that their lcm lies within the given range. | def answer(L,R):
if (2 * L <= R):
return (L ,2*L)
else:
return (-1) | 66 | {
"test_cases": [
"assert answer(3,8) == (3,6)",
"assert answer(2,6) == (2,4)",
"assert answer(1,3) == (1,2)"
],
"test_list": [
"assert answer(3,8) == (3,6)",
"assert answer(2,6) == (2,4)",
"assert answer(1,3) == (1,2)"
],
"challenge_test_list": [],
"reference_code": "def answer(L,R)... |
Write a function to calculate distance between two points using latitude and longitude. | from math import radians, sin, cos, acos
def distance_lat_long(slat,slon,elat,elon):
dist = 6371.01 * acos(sin(slat)*sin(elat) + cos(slat)*cos(elat)*cos(slon - elon))
return dist | 67 | {
"test_cases": [
"assert distance_lat_long(23.5,67.5,25.5,69.5)==12179.372041317429",
"assert distance_lat_long(10.5,20.5,30.5,40.5)==6069.397933300514",
"assert distance_lat_long(10,20,30,40)==6783.751974994595"
],
"test_list": [
"assert distance_lat_long(23.5,67.5,25.5,69.5)==12179.372041317429... |
Write a function to count all the distinct pairs having a difference of k in any array. | def count_pairs(arr, n, k):
count=0;
for i in range(0,n):
for j in range(i+1, n):
if arr[i] - arr[j] == k or arr[j] - arr[i] == k:
count += 1
return count | 68 | {
"test_cases": [
"assert count_pairs([1, 5, 3, 4, 2], 5, 3) == 2",
"assert count_pairs([8, 12, 16, 4, 0, 20], 6, 4) == 5",
"assert count_pairs([2, 4, 1, 3, 4], 5, 2) == 3"
],
"test_list": [
"assert count_pairs([1, 5, 3, 4, 2], 5, 3) == 2",
"assert count_pairs([8, 12, 16, 4, 0, 20], 6, 4) == 5... |
Write a function to find the focus of a parabola. | def parabola_focus(a, b, c):
focus= (((-b / (2 * a)),(((4 * a * c) - (b * b) + 1) / (4 * a))))
return focus | 69 | {
"test_cases": [
"assert parabola_focus(5,3,2)==(-0.3, 1.6)",
"assert parabola_focus(9,8,4)==(-0.4444444444444444, 2.25)",
"assert parabola_focus(2,4,6)==(-1.0, 4.125)"
],
"test_list": [
"assert parabola_focus(5,3,2)==(-0.3, 1.6)",
"assert parabola_focus(9,8,4)==(-0.4444444444444444, 2.25)",
... |
Write a python function to check whether the given number can be represented by product of two squares or not. | def prod_Square(n):
for i in range(2,(n) + 1):
if (i*i < (n+1)):
for j in range(2,n + 1):
if ((i*i*j*j) == n):
return True;
return False; | 70 | {
"test_cases": [
"assert prod_Square(25) == False",
"assert prod_Square(30) == False",
"assert prod_Square(16) == True"
],
"test_list": [
"assert prod_Square(25) == False",
"assert prod_Square(30) == False",
"assert prod_Square(16) == True"
],
"challenge_test_list": [],
"reference_c... |
Write a python function to find the first missing positive number. | def first_Missing_Positive(arr,n):
ptr = 0
for i in range(n):
if arr[i] == 1:
ptr = 1
break
if ptr == 0:
return(1)
for i in range(n):
if arr[i] <= 0 or arr[i] > n:
arr[i] = 1
for i in range(n):
arr[(arr[i] - 1) % n] += ... | 71 | {
"test_cases": [
"assert first_Missing_Positive([1,2,3,-1,5],5) == 4",
"assert first_Missing_Positive([0,-1,-2,1,5,8],6) == 2",
"assert first_Missing_Positive([0,1,2,5,-8],5) == 3"
],
"test_list": [
"assert first_Missing_Positive([1,2,3,-1,5],5) == 4",
"assert first_Missing_Positive([0,-1,-2,... |
Write a python function to count the number of integral co-ordinates that lie inside a square. | def count_Intgral_Points(x1,y1,x2,y2):
return ((y2 - y1 - 1) * (x2 - x1 - 1)) | 72 | {
"test_cases": [
"assert count_Intgral_Points(1,1,4,4) == 4",
"assert count_Intgral_Points(1,2,1,2) == 1",
"assert count_Intgral_Points(4,2,6,4) == 1"
],
"test_list": [
"assert count_Intgral_Points(1,1,4,4) == 4",
"assert count_Intgral_Points(1,2,1,2) == 1",
"assert count_Intgral_Points(4... |
Write a function to remove the duplicates from the given tuple. | def remove_tuple(test_tup):
res = tuple(set(test_tup))
return (res) | 73 | {
"test_cases": [
"assert remove_tuple((1, 3, 5, 2, 3, 5, 1, 1, 3)) == (1, 2, 3, 5)",
"assert remove_tuple((2, 3, 4, 4, 5, 6, 6, 7, 8, 8)) == (2, 3, 4, 5, 6, 7, 8)",
"assert remove_tuple((11, 12, 13, 11, 11, 12, 14, 13)) == (11, 12, 13, 14)"
],
"test_list": [
"assert remove_tuple((1, 3, 5, 2, 3, 5... |
Write a python function to find the first position of an element in a sorted array. | def first(arr,x,n):
low = 0
high = n - 1
res = -1
while (low <= high):
mid = (low + high) // 2
if arr[mid] > x:
high = mid - 1
elif arr[mid] < x:
low = mid + 1
else:
res = mid
high = mid - 1
return res | 74 | {
"test_cases": [
"assert first([1,2,3,4,5,6,6],6,6) == 5",
"assert first([1,2,2,2,3,2,2,4,2],2,9) == 1",
"assert first([1,2,3],1,3) == 0"
],
"test_list": [
"assert first([1,2,3,4,5,6,6],6,6) == 5",
"assert first([1,2,2,2,3,2,2,4,2],2,9) == 1",
"assert first([1,2,3],1,3) == 0"
],
"chal... |
Write a function to find the largest triangle that can be inscribed in an ellipse. | import math
def largest_triangle(a,b):
if (a < 0 or b < 0):
return -1
area = (3 * math.sqrt(3) * pow(a, 2)) / (4 * b);
return area | 75 | {
"test_cases": [
"assert largest_triangle(4,2)==10.392304845413264",
"assert largest_triangle(5,7)==4.639421805988064",
"assert largest_triangle(9,1)==105.2220865598093"
],
"test_list": [
"assert largest_triangle(4,2)==10.392304845413264",
"assert largest_triangle(5,7)==4.639421805988064",
... |
Write a function to remove even characters in a string. | def remove_even(str1):
str2 = ''
for i in range(1, len(str1) + 1):
if(i % 2 != 0):
str2 = str2 + str1[i - 1]
return str2 | 76 | {
"test_cases": [
"assert remove_even(\"python\")==(\"pto\")",
"assert remove_even(\"program\")==(\"porm\")",
"assert remove_even(\"language\")==(\"lnug\")"
],
"test_list": [
"assert remove_even(\"python\")==(\"pto\")",
"assert remove_even(\"program\")==(\"porm\")",
"assert remove_even(\"l... |
Write a function to count the longest repeating subsequences such that the two subsequences don’t have same string characters at same positions. | def find_longest_repeating_subseq(str):
n = len(str)
dp = [[0 for k in range(n+1)] for l in range(n+1)]
for i in range(1, n+1):
for j in range(1, n+1):
if (str[i-1] == str[j-1] and i != j):
dp[i][j] = 1 + dp[i-1][j-1]
else:
dp[i][j] = max(dp[i][j-1], dp[i-1][j])
return dp[n][n] | 77 | {
"test_cases": [
"assert find_longest_repeating_subseq(\"AABEBCDD\") == 3",
"assert find_longest_repeating_subseq(\"aabb\") == 2",
"assert find_longest_repeating_subseq(\"aab\") == 1"
],
"test_list": [
"assert find_longest_repeating_subseq(\"AABEBCDD\") == 3",
"assert find_longest_repeating_s... |
Write a function to delete the smallest element from the given heap and then insert a new item. | import heapq as hq
def heap_replace(heap,a):
hq.heapify(heap)
hq.heapreplace(heap, a)
return heap | 78 | {
"test_cases": [
"assert heap_replace( [25, 44, 68, 21, 39, 23, 89],21)==[21, 25, 23, 44, 39, 68, 89]",
"assert heap_replace([25, 44, 68, 21, 39, 23, 89],110)== [23, 25, 68, 44, 39, 110, 89]",
"assert heap_replace([25, 44, 68, 21, 39, 23, 89],500)==[23, 25, 68, 44, 39, 500, 89]"
],
"test_list": [
... |
Write a python function to count numbers whose oth and nth bits are set. | def count_Num(n):
if (n == 1):
return 1
count = pow(2,n - 2)
return count | 79 | {
"test_cases": [
"assert count_Num(2) == 1",
"assert count_Num(3) == 2",
"assert count_Num(1) == 1"
],
"test_list": [
"assert count_Num(2) == 1",
"assert count_Num(3) == 2",
"assert count_Num(1) == 1"
],
"challenge_test_list": [],
"reference_code": "def count_Num(n): \r\n if (n =... |
Write a function to decode a run-length encoded given list. | def decode_list(alist):
def aux(g):
if isinstance(g, list):
return [(g[1], range(g[0]))]
else:
return [(g, [0])]
return [x for g in alist for x, R in aux(g) for i in R] | 80 | {
"test_cases": [
"assert decode_list([[2, 1], 2, 3, [2, 4], 5,1])==[1,1,2,3,4,4,5,1]",
"assert decode_list(['a', 'u', 't', 'o', 'm', 'a', 't', 'i', 'c', 'a', [2, 'l'], 'y'])==['a', 'u', 't', 'o', 'm', 'a', 't', 'i', 'c', 'a', 'l', 'l', 'y']",
"assert decode_list(['p', 'y', 't', 'h', 'o', 'n'])==['p', 'y'... |
Write a function to check if a nested list is a subset of another nested list. | def check_subset_list(list1, list2):
l1, l2 = list1[0], list2[0]
exist = True
for i in list2:
if i not in list1:
exist = False
return exist | 81 | {
"test_cases": [
"assert check_subset_list([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14],[[12, 18, 23, 25, 45], [7, 11, 19, 24, 28], [1, 5, 8, 18, 15, 16]])==False",
"assert check_subset_list([[2, 3, 1], [4, 5], [6, 8]],[[4, 5], [6, 8]])==True",
"assert check_subset_list([['a', 'b'], ['e'], ['c', 'd']]... |
Write a python function to find the first repeated character in a given string. | def first_Repeated_Char(str):
h = {}
for ch in str:
if ch in h:
return ch;
else:
h[ch] = 0
return '\0' | 82 | {
"test_cases": [
"assert first_Repeated_Char(\"Google\") == \"o\"",
"assert first_Repeated_Char(\"data\") == \"a\"",
"assert first_Repeated_Char(\"python\") == '\\0'"
],
"test_list": [
"assert first_Repeated_Char(\"Google\") == \"o\"",
"assert first_Repeated_Char(\"data\") == \"a\"",
"ass... |
Write a python function to find the minimum operations required to make two numbers equal. | import math
def min_Operations(A,B):
if (A > B):
swap(A,B)
B = B // math.gcd(A,B);
return B - 1 | 83 | {
"test_cases": [
"assert min_Operations(2,4) == 1",
"assert min_Operations(4,10) == 4",
"assert min_Operations(1,4) == 3"
],
"test_list": [
"assert min_Operations(2,4) == 1",
"assert min_Operations(4,10) == 4",
"assert min_Operations(1,4) == 3"
],
"challenge_test_list": [],
"referen... |
Write a function to extract maximum and minimum k elements in the given tuple. |
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) | 84 | {
"test_cases": [
"assert extract_min_max((5, 20, 3, 7, 6, 8), 2) == (3, 5, 8, 20)",
"assert extract_min_max((4, 5, 6, 1, 2, 7), 3) == (1, 2, 4, 5, 6, 7)",
"assert extract_min_max((2, 3, 4, 8, 9, 11, 7), 4) == (2, 3, 4, 7, 8, 9, 11)"
],
"test_list": [
"assert extract_min_max((5, 20, 3, 7, 6, 8), 2... |
Write a function to check for majority element in the given sorted array. | def is_majority(arr, n, x):
i = binary_search(arr, 0, n-1, x)
if i == -1:
return False
if ((i + n//2) <= (n -1)) and arr[i + n//2] == x:
return True
else:
return False
def binary_search(arr, low, high, x):
if high >= low:
mid = (low + high)//2
if (mid == 0 or x > arr[mid-1]) and (arr[mid] == ... | 85 | {
"test_cases": [
"assert is_majority([1, 2, 3, 3, 3, 3, 10], 7, 3) == True",
"assert is_majority([1, 1, 2, 4, 4, 4, 6, 6], 8, 4) == False",
"assert is_majority([1, 1, 1, 2, 2], 5, 1) == True"
],
"test_list": [
"assert is_majority([1, 2, 3, 3, 3, 3, 10], 7, 3) == True",
"assert is_majority([1,... |
Write a python function to find the minimum element in a sorted and rotated array. | 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]; | 86 | {
"test_cases": [
"assert find_Min([1,2,3,4,5],0,4) == 1",
"assert find_Min([4,6,8],0,2) == 4",
"assert find_Min([2,3,5,7,9],0,4) == 2"
],
"test_list": [
"assert find_Min([1,2,3,4,5],0,4) == 1",
"assert find_Min([4,6,8],0,2) == 4",
"assert find_Min([2,3,5,7,9],0,4) == 2"
],
"challenge_... |
Write a python function to check whether all the bits are unset in the given range or not. | 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 | 87 | {
"test_cases": [
"assert all_Bits_Set_In_The_Given_Range(4,1,2) == True",
"assert all_Bits_Set_In_The_Given_Range(17,2,4) == True",
"assert all_Bits_Set_In_The_Given_Range(39,4,6) == False"
],
"test_list": [
"assert all_Bits_Set_In_The_Given_Range(4,1,2) == True",
"assert all_Bits_Set_In_The_... |
Write a function to re-arrange the elements of the given array so that all negative elements appear before positive ones. | 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 | 88 | {
"test_cases": [
"assert re_arrange_array([-1, 2, -3, 4, 5, 6, -7, 8, 9], 9) == [-1, -3, -7, 4, 5, 6, 2, 8, 9]",
"assert re_arrange_array([12, -14, -26, 13, 15], 5) == [-14, -26, 12, 13, 15]",
"assert re_arrange_array([10, 24, 36, -42, -39, -78, 85], 7) == [-42, -39, -78, 10, 24, 36, 85]"
],
"test_li... |
Write a function to find the maximum sum in the given right triangle of numbers. | 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... | 89 | {
"test_cases": [
"assert max_sum([[1], [2,1], [3,3,2]], 3) == 6",
"assert max_sum([[1], [1, 2], [4, 1, 12]], 3) == 15 ",
"assert max_sum([[2], [3,2], [13,23,12]], 3) == 28"
],
"test_list": [
"assert max_sum([[1], [2,1], [3,3,2]], 3) == 6",
"assert max_sum([[1], [1, 2], [4, 1, 12]], 3) == 15 "... |
Write a python function to set all even bits of a given number. | 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) | 90 | {
"test_cases": [
"assert even_bit_set_number(10) == 10",
"assert even_bit_set_number(20) == 30",
"assert even_bit_set_number(30) == 30"
],
"test_list": [
"assert even_bit_set_number(10) == 10",
"assert even_bit_set_number(20) == 30",
"assert even_bit_set_number(30) == 30"
],
"challeng... |
Write a python function to count the maximum number of equilateral triangles that can be formed within a given equilateral triangle. | 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; | 91 | {
"test_cases": [
"assert No_of_Triangle(4,2) == 7",
"assert No_of_Triangle(4,3) == 3",
"assert No_of_Triangle(1,3) == -1"
],
"test_list": [
"assert No_of_Triangle(4,2) == 7",
"assert No_of_Triangle(4,3) == 3",
"assert No_of_Triangle(1,3) == -1"
],
"challenge_test_list": [],
"referen... |
Write a function to check the occurrences of records which occur similar times in the given tuples. | from collections import Counter
def check_occurences(test_list):
res = dict(Counter(tuple(ele) for ele in map(sorted, test_list)))
return (res) | 92 | {
"test_cases": [
"assert check_occurences([(3, 1), (1, 3), (2, 5), (5, 2), (6, 3)] ) == {(1, 3): 2, (2, 5): 2, (3, 6): 1}",
"assert check_occurences([(4, 2), (2, 4), (3, 6), (6, 3), (7, 4)] ) == {(2, 4): 2, (3, 6): 2, (4, 7): 1}",
"assert check_occurences([(13, 2), (11, 23), (12, 25), (25, 12), (16, 23)]... |
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. | 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] | 93 | {
"test_cases": [
"assert get_total_number_of_sequences(10, 4) == 4",
"assert get_total_number_of_sequences(5, 2) == 6",
"assert get_total_number_of_sequences(16, 3) == 84"
],
"test_list": [
"assert get_total_number_of_sequences(10, 4) == 4",
"assert get_total_number_of_sequences(5, 2) == 6",
... |
Write a function to replace the last element of the list with another list. | def replace_list(list1,list2):
list1[-1:] = list2
replace_list=list1
return replace_list
| 94 | {
"test_cases": [
"assert replace_list([1, 3, 5, 7, 9, 10],[2, 4, 6, 8])==[1, 3, 5, 7, 9, 2, 4, 6, 8]",
"assert replace_list([1,2,3,4,5],[5,6,7,8])==[1,2,3,4,5,6,7,8]",
"assert replace_list([\"red\",\"blue\",\"green\"],[\"yellow\"])==[\"red\",\"blue\",\"yellow\"]"
],
"test_list": [
"assert replace... |
Write a function to generate a 3d array having each element as '*'. | 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 | 95 | {
"test_cases": [
"assert array_3d(6,4,3)==[[['*', '*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*', '*']], [['*', '*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*', '*'], ['*', '*', '*', '*', '*', '*']], [['*', '*'... |
Write a function to sort the given list based on the occurrence of first element of tuples. | 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()]) | 96 | {
"test_cases": [
"assert sort_on_occurence([(1, 'Jake'), (2, 'Bob'), (1, 'Cara')]) == [(1, 'Jake', 'Cara', 2), (2, 'Bob', 1)]",
"assert sort_on_occurence([('b', 'ball'), ('a', 'arm'), ('b', 'b'), ('a', 'ant')]) == [('b', 'ball', 'b', 2), ('a', 'arm', 'ant', 2)]",
"assert sort_on_occurence([(2, 'Mark'), (... |
Write a function to find the maximum sum of bi-tonic sub-sequence for the given array. | 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]:
... | 97 | {
"test_cases": [
"assert max_sum([1, 15, 51, 45, 33, 100, 12, 18, 9], 9) == 194",
"assert max_sum([80, 60, 30, 40, 20, 10], 6) == 210",
"assert max_sum([2, 3 ,14, 16, 21, 23, 29, 30], 8) == 138"
],
"test_list": [
"assert max_sum([1, 15, 51, 45, 33, 100, 12, 18, 9], 9) == 194",
"assert max_sum... |
Write a function for computing square roots using the babylonian method. | 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; | 98 | {
"test_cases": [
"assert babylonian_squareroot(10)==3.162277660168379",
"assert babylonian_squareroot(2)==1.414213562373095",
"assert babylonian_squareroot(9)==3.0"
],
"test_list": [
"assert babylonian_squareroot(10)==3.162277660168379",
"assert babylonian_squareroot(2)==1.414213562373095",
... |
Write a function to find the longest palindromic subsequence in the given string. | 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[... | 99 | {
"test_cases": [
"assert lps(\"TENS FOR TENS\") == 5 ",
"assert lps(\"CARDIO FOR CARDS\") == 7",
"assert lps(\"PART OF THE JOURNEY IS PART\") == 9 "
],
"test_list": [
"assert lps(\"TENS FOR TENS\") == 5 ",
"assert lps(\"CARDIO FOR CARDS\") == 7",
"assert lps(\"PART OF THE JOURNEY IS PART\... |
Write a function to find all words starting with 'a' or 'e' in a given string. | import re
def words_ae(text):
list = re.findall("[ae]\w+", text)
return list | 100 | {
"test_cases": [
"assert words_ae(\"python programe\")==['ame']",
"assert words_ae(\"python programe language\")==['ame','anguage']",
"assert words_ae(\"assert statement\")==['assert', 'atement']"
],
"test_list": [
"assert words_ae(\"python programe\")==['ame']",
"assert words_ae(\"python pro... |
End of preview.
No dataset card yet
- Downloads last month
- 37