task_id
int64 | text
string | code
string | test_list
list | test_setup_code
string | challenge_test_list
list | context
string | context_id
string | context_length_tokens
int64 | code_length_chars
int64 |
|---|---|---|---|---|---|---|---|---|---|
24 |
Write a function to convert the given binary number to its decimal equivalent.
|
def binary_to_decimal(binary):
binary1 = binary
decimal, i, n = 0, 0, 0
while(binary != 0):
dec = binary % 10
decimal = decimal + dec * pow(2, i)
binary = binary//10
i += 1
return (decimal)
|
[
"assert binary_to_decimal(100) == 4",
"assert binary_to_decimal(1011) == 11",
"assert binary_to_decimal(1101101) == 109"
] |
[] |
Daniel went to the office. John travelled to the kitchen. Mary journeyed to the bedroom. John picked up the apple there. John put down the apple. Sandra travelled to the office. Sandra went to the bathroom. Daniel grabbed the milk there.
|
babilong_0k_qa2_sample_60
| 51 | 249 |
|
83 |
Write a python function to find the character made by adding all the characters of the given string.
|
def get_Char(strr):
summ = 0
for i in range(len(strr)):
summ += (ord(strr[i]) - ord('a') + 1)
if (summ % 26 == 0):
return ord('z')
else:
summ = summ % 26
return chr(ord('a') + summ - 1)
|
[
"assert get_Char(\"abc\") == \"f\"",
"assert get_Char(\"gfg\") == \"t\"",
"assert get_Char(\"ab\") == \"c\""
] |
[] |
Bill travelled to the bathroom. Jeff journeyed to the garden. Mary journeyed to the office. Jeff went back to the office. Fred travelled to the bedroom. Bill went back to the garden. Mary went back to the bedroom. Jeff journeyed to the bathroom. Mary moved to the garden. Mary went back to the kitchen. Mary travelled to the office. Fred moved to the bathroom. Mary travelled to the garden. Jeff grabbed the apple there. Jeff put down the apple. Mary journeyed to the office. Fred picked up the apple there. Jeff took the football there. Fred passed the apple to Jeff. Jeff discarded the apple. Jeff gave the football to Fred. Bill journeyed to the bedroom. Jeff grabbed the apple there. Jeff left the apple. Jeff got the apple there. Bill went back to the bathroom. Jeff gave the apple to Fred. Fred gave the apple to Bill. Mary journeyed to the hallway. Fred went to the garden.
|
babilong_0k_qa5_sample_7
| 195 | 249 |
|
125 |
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
|
[
"assert find_length(\"11000010001\", 11) == 6",
"assert find_length(\"10111\", 5) == 1",
"assert find_length(\"11011101100101\", 14) == 2 "
] |
[] |
The kitchen is east of the bathroom. The garden is west of the bathroom.
|
babilong_0k_qa4_sample_37
| 17 | 252 |
|
311 |
Write a python function to set the 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(10) == 14",
"assert set_left_most_unset_bit(12) == 14",
"assert set_left_most_unset_bit(15) == 15"
] |
[] |
Mary travelled to the garden. John went to the hallway. Sandra went to the kitchen. Mary went to the office. Daniel picked up the milk there. Daniel travelled to the bathroom. Sandra moved to the office. Daniel went to the hallway.
|
babilong_0k_qa3_sample_53
| 50 | 252 |
|
350 |
Write a python function to minimize the length of the string by removing occurrence of only one character.
|
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(\"mnm\") == 1",
"assert minimum_Length(\"abcda\") == 3",
"assert minimum_Length(\"abcb\") == 2"
] |
[] |
Sandra journeyed to the bathroom. Mary took the apple there. Sandra went back to the kitchen. Mary went back to the office. Sandra took the milk there. Mary discarded the apple.
|
babilong_0k_qa2_sample_20
| 40 | 252 |
|
468 |
Write a function to find the maximum product formed by multiplying numbers of an increasing subsequence of that array.
|
def max_product(arr, n ):
mpis =[0] * (n)
for i in range(n):
mpis[i] = arr[i]
for i in range(1, n):
for j in range(i):
if (arr[i] > arr[j] and
mpis[i] < (mpis[j] * arr[i])):
mpis[i] = mpis[j] * arr[i]
return max(mpis)
|
[
"assert max_product([3, 100, 4, 5, 150, 6], 6) == 45000 ",
"assert max_product([4, 42, 55, 68, 80], 5) == 50265600",
"assert max_product([10, 22, 9, 33, 21, 50, 41, 60], 8) == 21780000 "
] |
[] |
The hallway is east of the office. The garden is west of the office.
|
babilong_0k_qa4_sample_41
| 17 | 256 |
|
117 |
Write a function to convert all possible convertible elements in the list to float.
|
def list_to_float(test_list):
res = []
for tup in test_list:
temp = []
for ele in tup:
if ele.isalpha():
temp.append(ele)
else:
temp.append(float(ele))
res.append((temp[0],temp[1]))
return (str(res))
|
[
"assert list_to_float( [(\"3\", \"4\"), (\"1\", \"26.45\"), (\"7.32\", \"8\"), (\"4\", \"8\")] ) == '[(3.0, 4.0), (1.0, 26.45), (7.32, 8.0), (4.0, 8.0)]'",
"assert list_to_float( [(\"4\", \"4\"), (\"2\", \"27\"), (\"4.12\", \"9\"), (\"7\", \"11\")] ) == '[(4.0, 4.0), (2.0, 27.0), (4.12, 9.0), (7.0, 11.0)]'",
"assert list_to_float( [(\"6\", \"78\"), (\"5\", \"26.45\"), (\"1.33\", \"4\"), (\"82\", \"13\")] ) == '[(6.0, 78.0), (5.0, 26.45), (1.33, 4.0), (82.0, 13.0)]'"
] |
[] |
John picked up the milk. Sandra got the football there. Mary went to the hallway. Daniel travelled to the bedroom. John dropped the milk. John grabbed the milk. Sandra went to the kitchen. Sandra travelled to the hallway. Sandra journeyed to the office. Sandra grabbed the apple. John discarded the milk. Sandra discarded the apple. Mary went to the bathroom. Mary moved to the kitchen. Sandra took the apple. Sandra journeyed to the kitchen. John picked up the milk. Sandra dropped the apple. Sandra travelled to the bathroom. Daniel travelled to the bathroom. John discarded the milk. Sandra journeyed to the hallway. John got the apple there. Sandra journeyed to the kitchen. John journeyed to the hallway. Sandra grabbed the milk. Sandra went back to the hallway. Daniel went back to the hallway. John discarded the apple there. Daniel went to the office. John moved to the office. John went back to the bedroom. Sandra picked up the apple. Daniel journeyed to the kitchen. Daniel travelled to the bedroom. Daniel travelled to the garden. Daniel went back to the hallway. Sandra left the apple. John travelled to the garden. Mary travelled to the garden. Daniel journeyed to the bathroom. Daniel went to the hallway. Sandra went back to the kitchen. Mary went to the bathroom. John journeyed to the office. Sandra left the football. Sandra moved to the garden. Mary went to the garden. Daniel grabbed the apple. Sandra put down the milk.
|
babilong_0k_qa3_sample_95
| 302 | 257 |
|
414 |
Write a python function to check whether the value exists in a sequence or not.
|
def overlapping(list1,list2):
c=0
d=0
for i in list1:
c+=1
for i in list2:
d+=1
for i in range(0,c):
for j in range(0,d):
if(list1[i]==list2[j]):
return 1
return 0
|
[
"assert overlapping([1,2,3,4,5],[6,7,8,9]) == False",
"assert overlapping([1,2,3],[4,5,6]) == False",
"assert overlapping([1,4,5],[1,4,5]) == True"
] |
[] |
The bedroom is west of the kitchen. The office is west of the bedroom.
|
babilong_0k_qa4_sample_59
| 17 | 257 |
|
325 |
Write a python function to find the minimum number of squares whose sum is equal to a given number.
|
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(6) == 3",
"assert get_Min_Squares(2) == 2",
"assert get_Min_Squares(4) == 1"
] |
[] |
John travelled to the kitchen. Sandra moved to the bathroom. Daniel moved to the kitchen. Sandra moved to the kitchen. Daniel went to the hallway. John went to the office. Sandra went back to the garden. Sandra went to the bedroom. John went to the bedroom. John journeyed to the bathroom.
|
babilong_0k_qa1_sample_47
| 63 | 258 |
|
387 |
Write a python function to check whether the hexadecimal number is 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(\"AB3454D\") ==\"Odd\"",
"assert even_or_odd(\"ABC\") == \"Even\"",
"assert even_or_odd(\"AAD\") == \"Odd\""
] |
[] |
Mary moved to the garden. Mary picked up the apple. Sandra moved to the kitchen. Daniel travelled to the hallway. Daniel moved to the office. Mary moved to the bedroom. John journeyed to the garden. Sandra picked up the milk. Mary left the apple. Sandra dropped the milk. Mary went back to the kitchen. Mary went back to the bathroom. John went back to the kitchen. Daniel journeyed to the kitchen. John travelled to the hallway. Sandra travelled to the bathroom. John went to the bedroom. Mary moved to the kitchen. Daniel grabbed the milk. Daniel travelled to the garden. Daniel journeyed to the bedroom. John went back to the bathroom. John travelled to the hallway. Mary journeyed to the garden. John went to the garden. Daniel dropped the milk. Sandra went to the office. Mary moved to the kitchen.
|
babilong_0k_qa3_sample_52
| 173 | 260 |
|
395 |
Write a python function to find the first non-repeated character in a given string.
|
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(\"abcabc\") == None",
"assert first_non_repeating_character(\"abc\") == \"a\"",
"assert first_non_repeating_character(\"ababc\") == \"c\""
] |
[] |
John picked up the football. John dropped the football there. Sandra travelled to the office. Daniel moved to the kitchen. Daniel travelled to the garden. John journeyed to the office. Sandra travelled to the garden. Sandra travelled to the office. Daniel travelled to the kitchen. Sandra took the milk. Mary went back to the office. Mary got the apple. Daniel went to the office. John went to the bedroom. John took the football. Daniel went back to the hallway. Sandra went back to the bedroom. Sandra dropped the milk. Sandra got the milk. Mary discarded the apple. Sandra discarded the milk. John put down the football. Sandra went to the kitchen. John moved to the kitchen. Mary picked up the apple. Daniel moved to the bathroom. Daniel travelled to the garden. Mary left the apple. Mary journeyed to the bedroom. Mary went back to the bathroom. Sandra journeyed to the hallway. Sandra travelled to the bathroom. Daniel went to the hallway. Sandra travelled to the bedroom. Sandra grabbed the football there. John journeyed to the office. Sandra put down the football there. John took the apple. John journeyed to the kitchen. John dropped the apple there. Mary went back to the office. John went back to the hallway. Daniel moved to the garden. Sandra got the milk. Sandra moved to the bathroom. Sandra travelled to the office. Sandra left the milk. Sandra went back to the bathroom. Daniel went to the bathroom. Mary travelled to the bathroom. John went to the garden. Daniel travelled to the kitchen. Daniel went back to the hallway. John journeyed to the kitchen. John journeyed to the office. John went back to the bathroom. John moved to the office. Sandra moved to the bedroom. Sandra grabbed the football. Mary moved to the kitchen. John travelled to the garden. John journeyed to the bathroom. Sandra went to the garden. Sandra went to the bedroom. Sandra travelled to the hallway. Mary went to the office. John travelled to the bedroom. Sandra went back to the bathroom. Sandra left the football. Daniel moved to the office. Mary picked up the milk. Sandra took the football. Daniel went back to the bedroom. Mary went back to the garden. Sandra discarded the football. Mary dropped the milk. Mary went back to the bathroom. Mary picked up the football there. Mary discarded the football there. Mary went back to the hallway. Mary went to the kitchen. Sandra took the football. Sandra moved to the kitchen. Sandra went back to the bathroom.
|
babilong_0k_qa3_sample_4
| 513 | 260 |
|
236 |
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;
|
[
"assert No_of_Triangle(4,2) == 7",
"assert No_of_Triangle(4,3) == 3",
"assert No_of_Triangle(1,3) == -1"
] |
[] |
The hallway is south of the office. The garden is north of the office.
|
babilong_0k_qa4_sample_2
| 17 | 263 |
|
47 |
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
|
[
"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"
] |
Daniel grabbed the apple. Sandra travelled to the bedroom. Sandra moved to the office. Mary journeyed to the office. Daniel put down the apple. John moved to the bathroom. Sandra travelled to the bedroom. Daniel went to the bathroom. Mary went back to the bathroom. Sandra took the apple. Mary took the milk. Mary put down the milk. Daniel got the milk. Sandra dropped the apple there. Daniel left the milk. Mary journeyed to the kitchen. John grabbed the milk there. John journeyed to the kitchen. John grabbed the football. John dropped the football there. John dropped the milk. John grabbed the football. Sandra grabbed the apple. John got the milk. Sandra moved to the hallway. Sandra moved to the office. Mary moved to the bathroom. Sandra left the apple. Daniel went to the office. Daniel moved to the hallway.
|
babilong_0k_qa3_sample_72
| 174 | 264 |
|
110 |
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)
|
[
"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, 19), (38, 50)], 1, 52) == [(1, 7), (2, 52), (2, 15), (19, 52), (19, 38), (50, 52)]"
] |
[] |
Mary went to the bedroom. Mary went back to the office. Jeff got the milk there. Bill journeyed to the kitchen. Mary went to the bathroom. Mary got the football there. Jeff discarded the milk there. Bill went back to the garden. Jeff took the milk there. Jeff handed the milk to Bill. Mary journeyed to the bedroom. Fred journeyed to the bedroom.
|
babilong_0k_qa5_sample_24
| 79 | 264 |
|
467 |
Write a python function to convert decimal number to octal number.
|
def decimal_to_Octal(deciNum):
octalNum = 0
countval = 1;
dNo = deciNum;
while (deciNum!= 0):
remainder= deciNum % 8;
octalNum+= remainder*countval;
countval= countval*10;
deciNum //= 8;
return (octalNum)
|
[
"assert decimal_to_Octal(10) == 12",
"assert decimal_to_Octal(2) == 2",
"assert decimal_to_Octal(33) == 41"
] |
[] |
The bedroom is west of the bathroom. The kitchen is west of the bedroom.
|
babilong_0k_qa4_sample_40
| 17 | 266 |
|
121 |
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)
|
[
"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"
] |
[] |
Daniel went to the hallway. Sandra went back to the bedroom. Sandra got the football. Sandra discarded the football there. Daniel moved to the garden. Mary went to the office. Sandra went to the kitchen. Mary took the milk there. Daniel travelled to the kitchen. Sandra journeyed to the garden. Mary took the apple. Daniel went back to the hallway. Mary travelled to the bathroom. Sandra went back to the office. Mary discarded the apple there. Mary took the apple. John journeyed to the bedroom. Mary journeyed to the kitchen. Mary went to the bedroom. Mary went back to the garden. Sandra travelled to the bedroom. John journeyed to the kitchen. Sandra took the football. John went to the garden. Mary discarded the milk there. John grabbed the milk. Mary discarded the apple. Daniel moved to the office.
|
babilong_0k_qa3_sample_43
| 171 | 268 |
|
397 |
Write a function to find the median of three specific 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(25,55,65)==55.0",
"assert median_numbers(20,10,30)==20.0",
"assert median_numbers(15,45,75)==45.0"
] |
[] |
Mary went back to the bedroom. Daniel got the apple. Sandra went back to the office. Daniel put down the apple. Sandra picked up the apple. Mary journeyed to the office. John went back to the office. John travelled to the kitchen. Mary travelled to the bedroom. John travelled to the garden. Daniel went to the garden. Daniel took the milk. Sandra put down the apple. Daniel journeyed to the bathroom. Daniel dropped the milk. Sandra got the apple. Sandra left the apple. John travelled to the hallway. Daniel picked up the milk. John moved to the kitchen. Mary went back to the kitchen. Sandra took the apple. Sandra dropped the apple. John journeyed to the bathroom. Daniel dropped the milk. Sandra moved to the kitchen. John picked up the milk there. John discarded the milk. John went to the kitchen. Sandra travelled to the bedroom. Daniel grabbed the milk. Daniel travelled to the bedroom. Daniel journeyed to the garden. Daniel put down the milk. Daniel moved to the bathroom. John went back to the garden. Mary travelled to the bathroom. Mary journeyed to the hallway. Sandra went to the kitchen. John went back to the bedroom. Mary went back to the office. Mary picked up the apple. Daniel travelled to the kitchen. Sandra travelled to the bathroom. Sandra travelled to the garden. Sandra picked up the milk. Daniel went to the garden. Mary journeyed to the garden. Sandra discarded the milk. Mary put down the apple there. Mary grabbed the milk. Daniel took the apple. Mary dropped the milk. Daniel went to the bathroom. Daniel left the apple. Daniel travelled to the garden. Daniel got the milk there. John travelled to the garden. Mary moved to the office. Daniel discarded the milk. Sandra moved to the hallway. Sandra moved to the garden. Daniel picked up the milk. Sandra went to the hallway. Mary journeyed to the hallway. Sandra got the football there. Daniel moved to the office. Daniel left the milk. Daniel got the milk. Daniel left the milk. Sandra went back to the kitchen. Daniel moved to the hallway. Sandra discarded the football. Sandra grabbed the football. Daniel travelled to the bedroom. Daniel travelled to the office. John moved to the office. John got the milk. John discarded the milk. Daniel grabbed the milk. Sandra discarded the football. Mary went back to the bedroom. Daniel travelled to the bedroom. Daniel went back to the office. Daniel discarded the milk there. Daniel went to the bedroom.
|
babilong_0k_qa3_sample_22
| 511 | 268 |
|
164 |
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);
|
[
"assert areEquivalent(36,57) == False",
"assert areEquivalent(2,4) == False",
"assert areEquivalent(23,47) == True"
] |
[] |
Mary moved to the hallway. Mary journeyed to the kitchen. Sandra moved to the office. Daniel journeyed to the office. Mary travelled to the bedroom. Mary went back to the garden. Sandra moved to the kitchen. Daniel went back to the bedroom. Mary went to the office. Mary moved to the garden. John moved to the hallway. John travelled to the bedroom. John moved to the office. Daniel journeyed to the bathroom. Sandra picked up the milk there. Sandra moved to the office. John travelled to the bedroom. John travelled to the bathroom. Sandra went back to the garden. John went to the hallway. Sandra put down the milk. Mary picked up the milk there. John went back to the kitchen. John went to the garden. Mary put down the milk. Sandra picked up the milk there. Sandra went back to the hallway. John journeyed to the hallway. John moved to the bedroom. Sandra went back to the garden.
|
babilong_0k_qa2_sample_22
| 194 | 270 |
|
438 |
Write a function to count bidirectional tuple pairs.
|
def count_bidirectional(test_list):
res = 0
for idx in range(0, len(test_list)):
for iidx in range(idx + 1, len(test_list)):
if test_list[iidx][0] == test_list[idx][1] and test_list[idx][1] == test_list[iidx][0]:
res += 1
return (str(res))
|
[
"assert count_bidirectional([(5, 6), (1, 2), (6, 5), (9, 1), (6, 5), (2, 1)] ) == '3'",
"assert count_bidirectional([(5, 6), (1, 3), (6, 5), (9, 1), (6, 5), (2, 1)] ) == '2'",
"assert count_bidirectional([(5, 6), (1, 2), (6, 5), (9, 2), (6, 5), (2, 1)] ) == '4'"
] |
[] |
The garden is north of the bedroom. The office is south of the bedroom.
|
babilong_0k_qa4_sample_19
| 17 | 270 |
|
141 |
Write a function to sort a list of elements using pancake sort.
|
def pancake_sort(nums):
arr_len = len(nums)
while arr_len > 1:
mi = nums.index(max(nums[0:arr_len]))
nums = nums[mi::-1] + nums[mi+1:len(nums)]
nums = nums[arr_len-1::-1] + nums[arr_len:len(nums)]
arr_len -= 1
return nums
|
[
"assert pancake_sort([15, 79, 25, 38, 69]) == [15, 25, 38, 69, 79]",
"assert pancake_sort([98, 12, 54, 36, 85]) == [12, 36, 54, 85, 98]",
"assert pancake_sort([41, 42, 32, 12, 23]) == [12, 23, 32, 41, 42]"
] |
[] |
The kitchen is west of the bathroom. The hallway is east of the bathroom.
|
babilong_0k_qa4_sample_50
| 17 | 272 |
|
194 |
Write a python function to convert octal number to decimal number.
|
def octal_To_Decimal(n):
num = n;
dec_value = 0;
base = 1;
temp = num;
while (temp):
last_digit = temp % 10;
temp = int(temp / 10);
dec_value += last_digit*base;
base = base * 8;
return dec_value;
|
[
"assert octal_To_Decimal(25) == 21",
"assert octal_To_Decimal(30) == 24",
"assert octal_To_Decimal(40) == 32"
] |
[] |
Mary went to the garden. Sandra journeyed to the garden. Mary journeyed to the bathroom. Daniel went to the office.
|
babilong_0k_qa1_sample_89
| 27 | 274 |
|
29 |
Write a python function to find the element occurring odd number of times.
|
def get_Odd_Occurrence(arr,arr_size):
for i in range(0,arr_size):
count = 0
for j in range(0,arr_size):
if arr[i] == arr[j]:
count+=1
if (count % 2 != 0):
return arr[i]
return -1
|
[
"assert get_Odd_Occurrence([1,2,3,1,2,3,1],7) == 1",
"assert get_Odd_Occurrence([1,2,3,2,3,1,3],7) == 3",
"assert get_Odd_Occurrence([2,3,5,4,5,2,4,3,5,2,4,4,2],13) == 5"
] |
[] |
The bathroom is north of the garden. The bathroom is south of the kitchen.
|
babilong_0k_qa4_sample_90
| 17 | 275 |
|
283 |
Write a python function to check whether the frequency of each digit is less than or equal to the digit itself.
|
def validate(n):
for i in range(10):
temp = n;
count = 0;
while (temp):
if (temp % 10 == i):
count+=1;
if (count > i):
return False
temp //= 10;
return True
|
[
"assert validate(1234) == True",
"assert validate(51241) == False",
"assert validate(321) == True"
] |
[] |
Bill moved to the office. Jeff moved to the hallway. Mary went to the office. Mary went to the kitchen. Fred grabbed the football there. Mary journeyed to the office. Fred dropped the football. Mary took the milk there. Fred went back to the hallway. Mary handed the milk to Bill. Fred went back to the bathroom. Bill handed the milk to Mary. Bill went to the bathroom. Mary went back to the hallway. Mary gave the milk to Jeff. Fred grabbed the football there.
|
babilong_0k_qa5_sample_96
| 103 | 277 |
|
11 |
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
|
[
"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\") == \"\""
] |
John went back to the office. Daniel went to the office. Sandra grabbed the football. Daniel travelled to the bedroom. Sandra went back to the kitchen. Sandra dropped the football. Sandra picked up the milk. John went to the bathroom. Daniel moved to the office. Sandra dropped the milk there. Daniel journeyed to the bathroom. John went to the kitchen. John grabbed the football. John left the football. Sandra picked up the milk. Daniel moved to the kitchen. Mary went to the bedroom. Sandra took the football. Sandra dropped the milk there. Sandra discarded the football there. Daniel grabbed the football there. John grabbed the milk. John travelled to the bathroom. Daniel journeyed to the bathroom. Daniel went to the bedroom. John moved to the kitchen. Sandra moved to the hallway. Mary travelled to the kitchen. Mary moved to the bathroom. Daniel discarded the football there. John put down the milk. Daniel picked up the football.
|
babilong_0k_qa3_sample_65
| 191 | 278 |
|
275 |
Write a python function to find the position of the last removed element from the given array.
|
import math as mt
def get_Position(a,n,m):
for i in range(n):
a[i] = (a[i] // m + (a[i] % m != 0))
result,maxx = -1,-1
for i in range(n - 1,-1,-1):
if (maxx < a[i]):
maxx = a[i]
result = i
return result + 1
|
[
"assert get_Position([2,5,4],3,2) == 2",
"assert get_Position([4,3],2,2) == 2",
"assert get_Position([1,2,3,4],4,1) == 4"
] |
[] |
Daniel went to the hallway. Daniel got the football there. John went back to the garden. Mary went back to the office. John went to the bathroom. Daniel went back to the bathroom. John travelled to the office. Mary went to the bathroom. Daniel travelled to the office. Sandra went back to the bedroom. Mary travelled to the kitchen. Mary travelled to the hallway. Sandra travelled to the garden. Sandra travelled to the bedroom. Sandra journeyed to the bathroom. Sandra moved to the office. Mary moved to the bathroom. Mary travelled to the hallway. Daniel left the football. Daniel took the football. Daniel put down the football. Daniel journeyed to the hallway. John went back to the bedroom. Mary travelled to the bedroom. Mary picked up the apple. Mary travelled to the garden. Mary went back to the hallway. Mary moved to the bedroom. Sandra took the football there. Mary dropped the apple.
|
babilong_0k_qa3_sample_92
| 186 | 280 |
|
61 |
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
|
[
"assert count_Substrings('112112',6) == 6",
"assert count_Substrings('111',3) == 6",
"assert count_Substrings('1101112',7) == 12"
] |
[] |
The kitchen is north of the hallway. The garden is south of the hallway.
|
babilong_0k_qa4_sample_17
| 17 | 281 |
|
67 |
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]
|
[
"assert bell_number(2)==2",
"assert bell_number(10)==115975",
"assert bell_number(56)==6775685320645824322581483068371419745979053216268760300"
] |
[] |
Bill journeyed to the bedroom. Jeff went to the bathroom. Bill went to the bathroom. Fred went back to the office. Mary went to the kitchen. Jeff went back to the kitchen. Bill moved to the garden. Mary moved to the hallway. Bill grabbed the apple there. Fred got the football there. Bill got the milk there. Mary moved to the bathroom. Bill went back to the kitchen. Bill handed the apple to Jeff. Bill left the milk. Jeff gave the apple to Bill.
|
babilong_0k_qa5_sample_93
| 102 | 287 |
|
131 |
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
|
[
"assert reverse_vowels(\"Python\") == \"Python\"",
"assert reverse_vowels(\"USA\") == \"ASU\"",
"assert reverse_vowels(\"ab\") == \"ab\""
] |
[] |
Bill moved to the kitchen. Bill moved to the hallway. Jeff journeyed to the bathroom. Fred went to the office. Bill moved to the office. Fred went to the bedroom. Mary went to the hallway. Jeff went back to the garden. Fred went back to the bathroom. Jeff went back to the kitchen. Bill journeyed to the garden. Mary travelled to the bedroom. Jeff travelled to the bathroom. Jeff journeyed to the kitchen. Bill took the apple there. Bill put down the apple. Bill grabbed the apple there. Mary went to the hallway. Bill discarded the apple. Mary moved to the garden. Bill went to the hallway. Fred journeyed to the bedroom. Mary moved to the kitchen. Bill moved to the bathroom. Fred went back to the office. Mary moved to the hallway. Mary went back to the bedroom. Bill went back to the office. Jeff took the football there. Mary went back to the bathroom. Jeff went back to the hallway. Fred went back to the bathroom. Bill went to the kitchen. Jeff put down the football. Bill went to the bathroom. Jeff moved to the garden. Jeff went back to the bathroom. Bill went back to the garden. Bill journeyed to the kitchen. Fred went to the office. Mary travelled to the bedroom. Fred went back to the bathroom. Fred journeyed to the kitchen. Fred went back to the garden. Bill journeyed to the bedroom. Bill moved to the garden. Fred picked up the apple there. Mary went to the office. Fred gave the apple to Bill. Fred went to the bedroom. Mary travelled to the kitchen. Fred went to the bathroom. Bill travelled to the bathroom. Bill handed the apple to Fred.
|
babilong_0k_qa5_sample_46
| 347 | 290 |
|
60 |
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
|
[
"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"
] |
[] |
The bedroom is west of the garden. The bathroom is west of the bedroom.
|
babilong_0k_qa4_sample_78
| 17 | 293 |
|
225 |
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];
|
[
"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"
] |
[] |
Fred travelled to the bedroom. Bill journeyed to the bedroom. Bill got the football there. Mary went back to the bathroom. Mary went back to the garden. Jeff went back to the office. Jeff moved to the bedroom. Bill passed the football to Fred. Fred passed the football to Bill. Bill handed the football to Fred.
|
babilong_0k_qa5_sample_56
| 68 | 294 |
|
187 |
Write a function to find the longest common subsequence for the given two sequences.
|
def longest_common_subsequence(X, Y, m, n):
if m == 0 or n == 0:
return 0
elif X[m-1] == Y[n-1]:
return 1 + longest_common_subsequence(X, Y, m-1, n-1)
else:
return max(longest_common_subsequence(X, Y, m, n-1), longest_common_subsequence(X, Y, m-1, n))
|
[
"assert longest_common_subsequence(\"AGGTAB\" , \"GXTXAYB\", 6, 7) == 4",
"assert longest_common_subsequence(\"ABCDGH\" , \"AEDFHR\", 6, 6) == 3",
"assert longest_common_subsequence(\"AXYT\" , \"AYZX\", 4, 4) == 2"
] |
[] |
The bedroom is east of the office. The bedroom is west of the garden.
|
babilong_0k_qa4_sample_27
| 17 | 296 |
|
289 |
Write a python function to calculate the number of odd days in a given year.
|
def odd_Days(N):
hund1 = N // 100
hund4 = N // 400
leap = N >> 2
ordd = N - leap
if (hund1):
ordd += hund1
leap -= hund1
if (hund4):
ordd -= hund4
leap += hund4
days = ordd + leap * 2
odd = days % 7
return odd
|
[
"assert odd_Days(100) == 5",
"assert odd_Days(50) ==6",
"assert odd_Days(75) == 2"
] |
[] |
Sandra went to the bathroom. Mary journeyed to the bathroom. Sandra went back to the kitchen. Daniel went back to the hallway.
|
babilong_0k_qa1_sample_31
| 29 | 299 |
|
149 |
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
|
[
"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"
] |
[] |
Sandra travelled to the hallway. Mary went back to the hallway. Mary moved to the office. Sandra journeyed to the kitchen.
|
babilong_0k_qa1_sample_18
| 28 | 303 |
|
338 |
Write a python function to count the number of substrings with same first and last 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;
|
[
"assert count_Substring_With_Equal_Ends('aba') == 4",
"assert count_Substring_With_Equal_Ends('abcab') == 7",
"assert count_Substring_With_Equal_Ends('abc') == 3"
] |
[] |
John took the football there. John left the football. Mary went back to the bathroom. Sandra got the football there. Daniel journeyed to the kitchen. John journeyed to the bedroom. Sandra dropped the football. Mary moved to the kitchen. Daniel grabbed the apple there. Mary went to the bathroom. Mary moved to the bedroom. John went back to the bathroom. Daniel discarded the apple there. Mary travelled to the kitchen. Sandra picked up the football there. Sandra left the football there.
|
babilong_0k_qa2_sample_99
| 100 | 303 |
|
70 |
Write a function to find whether all the given tuples have equal length or not.
|
def find_equal_tuple(Input, k):
flag = 1
for tuple in Input:
if len(tuple) != k:
flag = 0
break
return flag
def get_equal(Input, k):
if find_equal_tuple(Input, k) == 1:
return ("All tuples have same length")
else:
return ("All tuples do not have same length")
|
[
"assert get_equal([(11, 22, 33), (44, 55, 66)], 3) == 'All tuples have same length'",
"assert get_equal([(1, 2, 3), (4, 5, 6, 7)], 3) == 'All tuples do not have same length'",
"assert get_equal([(1, 2), (3, 4)], 2) == 'All tuples have same length'"
] |
[] |
Sandra took the football there. Mary travelled to the kitchen. John went to the office. Daniel travelled to the bedroom. Daniel journeyed to the bathroom. Mary went back to the bedroom. Sandra travelled to the kitchen. Mary went to the bathroom. Sandra went back to the bathroom. Sandra discarded the football. Mary journeyed to the bedroom. Sandra picked up the football there. Mary grabbed the milk there. Mary discarded the milk.
|
babilong_0k_qa2_sample_11
| 89 | 304 |
|
239 |
Write a function to find the number of possible sequences of length n such that each of the next element is greater than or equal to twice of the previous element but less than or equal to m.
|
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]
|
[
"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"
] |
[] |
Mary journeyed to the bedroom. Mary went to the office. Sandra journeyed to the bathroom. Daniel journeyed to the bedroom. John travelled to the garden. Daniel journeyed to the kitchen. Daniel went to the office. Daniel moved to the kitchen. Sandra travelled to the bedroom. Sandra journeyed to the kitchen. John went back to the office. John moved to the bathroom. Sandra went back to the garden. Daniel took the apple. Sandra travelled to the office. John travelled to the bedroom. John travelled to the kitchen. Daniel discarded the apple. Sandra went to the garden. Mary went to the bedroom. Daniel grabbed the apple. John went to the bedroom. John went back to the hallway. Daniel went to the bedroom. John travelled to the office. Daniel travelled to the kitchen. Daniel dropped the apple. John moved to the garden. Sandra went to the kitchen. Sandra picked up the apple. Sandra went back to the bathroom. Sandra went to the hallway. John travelled to the office. Sandra put down the apple. Sandra went back to the kitchen. Sandra travelled to the bathroom. Mary went to the kitchen. John went back to the hallway.
|
babilong_0k_qa3_sample_25
| 236 | 304 |
|
30 |
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;
|
[
"assert count_Substring_With_Equal_Ends(\"abc\") == 3",
"assert count_Substring_With_Equal_Ends(\"abcda\") == 6",
"assert count_Substring_With_Equal_Ends(\"ab\") == 2"
] |
[] |
Mary went back to the office. Daniel went to the bedroom.
|
babilong_0k_qa1_sample_26
| 14 | 305 |
|
492 |
Write a function to search an element in the given array by using binary search.
|
def binary_search(item_list,item):
first = 0
last = len(item_list)-1
found = False
while( first<=last and not found):
mid = (first + last)//2
if item_list[mid] == item :
found = True
else:
if item < item_list[mid]:
last = mid - 1
else:
first = mid + 1
return found
|
[
"assert binary_search([1,2,3,5,8], 6) == False",
"assert binary_search([7, 8, 9, 10, 13], 10) == True",
"assert binary_search([11, 13, 14, 19, 22, 36], 23) == False"
] |
[] |
Bill travelled to the garden. Mary travelled to the bedroom. Jeff went to the hallway. Jeff journeyed to the office. Mary went to the hallway. Jeff grabbed the milk there. Fred moved to the hallway. Bill went to the bathroom. Jeff dropped the milk. Fred picked up the football there. Fred put down the football. Fred took the football there. Fred discarded the football. Jeff picked up the milk there. Bill got the apple there. Fred journeyed to the bathroom. Bill handed the apple to Fred. Mary picked up the football there. Fred passed the apple to Bill. Jeff journeyed to the kitchen. Bill handed the apple to Fred. Mary dropped the football. Bill travelled to the kitchen. Mary moved to the kitchen. Fred dropped the apple there. Jeff went to the garden. Mary journeyed to the office. Mary went to the kitchen. Fred grabbed the apple there. Jeff travelled to the hallway. Mary went back to the bedroom. Jeff put down the milk there. Fred left the apple. Bill travelled to the bathroom. Jeff went to the bathroom. Bill took the apple there. Fred went back to the office. Bill passed the apple to Jeff.
|
babilong_0k_qa5_sample_63
| 239 | 306 |
|
286 |
Write a function to find the largest sum of contiguous array in the modified array which is formed by repeating the given array k times.
|
def max_sub_array_sum_repeated(a, n, k):
max_so_far = -2147483648
max_ending_here = 0
for i in range(n*k):
max_ending_here = max_ending_here + a[i%n]
if (max_so_far < max_ending_here):
max_so_far = max_ending_here
if (max_ending_here < 0):
max_ending_here = 0
return max_so_far
|
[
"assert max_sub_array_sum_repeated([10, 20, -30, -1], 4, 3) == 30",
"assert max_sub_array_sum_repeated([-1, 10, 20], 3, 2) == 59",
"assert max_sub_array_sum_repeated([-1, -2, -3], 3, 3) == -1"
] |
[] |
The bathroom is north of the hallway. The kitchen is north of the bathroom.
|
babilong_0k_qa4_sample_61
| 17 | 308 |
|
510 |
Write a function to find the number of subsequences having product smaller than k for the given non negative array.
|
def no_of_subsequences(arr, k):
n = len(arr)
dp = [[0 for i in range(n + 1)]
for j in range(k + 1)]
for i in range(1, k + 1):
for j in range(1, n + 1):
dp[i][j] = dp[i][j - 1]
if arr[j - 1] <= i and arr[j - 1] > 0:
dp[i][j] += dp[i // arr[j - 1]][j - 1] + 1
return dp[k][n]
|
[
"assert no_of_subsequences([1,2,3,4], 10) == 11",
"assert no_of_subsequences([4,8,7,2], 50) == 9",
"assert no_of_subsequences([5,6,7,8], 15) == 4"
] |
[] |
Sandra travelled to the bedroom. John travelled to the garden. Mary went to the hallway. Mary went back to the bedroom.
|
babilong_0k_qa1_sample_37
| 27 | 309 |
|
403 |
Write a function to check if a url is valid or not using regex.
|
import re
def is_valid_URL(str):
regex = ("((http|https)://)(www.)?" +
"[a-zA-Z0-9@:%._\\+~#?&//=]" +
"{2,256}\\.[a-z]" +
"{2,6}\\b([-a-zA-Z0-9@:%" +
"._\\+~#?&//=]*)")
p = re.compile(regex)
if (str == None):
return False
if(re.search(p, str)):
return True
else:
return False
|
[
"assert is_valid_URL(\"https://www.google.com\") == True",
"assert is_valid_URL(\"https:/www.gmail.com\") == False",
"assert is_valid_URL(\"https:// www.redit.com\") == False"
] |
[] |
Jeff went back to the garden. Mary travelled to the office. Bill went back to the bedroom. Mary moved to the hallway. Bill went back to the garden. Mary went back to the bedroom. Jeff journeyed to the office. Mary went to the kitchen. Bill travelled to the hallway. Mary moved to the hallway. Fred went to the hallway. Bill picked up the football there. Bill picked up the apple there. Bill passed the apple to Mary.
|
babilong_0k_qa5_sample_49
| 93 | 311 |
|
122 |
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]
|
[
"assert smartNumber(1) == 30",
"assert smartNumber(50) == 273",
"assert smartNumber(1000) == 2664"
] |
[] |
Bill went to the kitchen. Fred moved to the bedroom. Jeff went to the kitchen. Jeff moved to the bedroom. Mary went to the bathroom. Jeff went to the garden. Fred moved to the bathroom. Mary travelled to the garden. Mary grabbed the milk there. Mary passed the milk to Jeff. Jeff moved to the kitchen. Bill travelled to the garden. Jeff went back to the bathroom. Jeff handed the milk to Fred.
|
babilong_0k_qa5_sample_36
| 88 | 314 |
|
207 |
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]
|
[
"assert find_longest_repeating_subseq(\"AABEBCDD\") == 3",
"assert find_longest_repeating_subseq(\"aabb\") == 2",
"assert find_longest_repeating_subseq(\"aab\") == 1"
] |
[] |
The kitchen is west of the garden. The kitchen is east of the office.
|
babilong_0k_qa4_sample_65
| 17 | 316 |
|
97 |
Write a function to find frequency count of list of lists.
|
def frequency_lists(list1):
list1 = [item for sublist in list1 for item in sublist]
dic_data = {}
for num in list1:
if num in dic_data.keys():
dic_data[num] += 1
else:
key = num
value = 1
dic_data[key] = value
return dic_data
|
[
"assert frequency_lists([[1, 2, 3, 2], [4, 5, 6, 2], [7, 8, 9, 5]])=={1: 1, 2: 3, 3: 1, 4: 1, 5: 2, 6: 1, 7: 1, 8: 1, 9: 1}",
"assert frequency_lists([[1,2,3,4],[5,6,7,8],[9,10,11,12]])=={1: 1, 2: 1, 3: 1, 4: 1, 5: 1, 6: 1, 7: 1, 8: 1, 9: 1,10:1,11:1,12:1}",
"assert frequency_lists([[20,30,40,17],[18,16,14,13],[10,20,30,40]])=={20:2,30:2,40:2,17: 1,18:1, 16: 1,14: 1,13: 1, 10: 1}"
] |
[] |
Mary took the apple there. Bill went to the garden. Bill went to the bathroom. Jeff moved to the office. Bill travelled to the bedroom. Jeff travelled to the hallway. Mary gave the apple to Fred. Mary travelled to the office.
|
babilong_0k_qa5_sample_67
| 50 | 317 |
|
32 |
Write a python function to find the largest prime factor of a given number.
|
import math
def max_Prime_Factors (n):
maxPrime = -1
while n%2 == 0:
maxPrime = 2
n >>= 1
for i in range(3,int(math.sqrt(n))+1,2):
while n % i == 0:
maxPrime = i
n = n / i
if n > 2:
maxPrime = n
return int(maxPrime)
|
[
"assert max_Prime_Factors(15) == 5",
"assert max_Prime_Factors(6) == 3",
"assert max_Prime_Factors(2) == 2"
] |
[] |
Mary moved to the kitchen. Mary travelled to the office. Daniel grabbed the football there. Mary moved to the hallway. Sandra moved to the bedroom. Mary went back to the bedroom. John grabbed the milk there. John put down the milk. Daniel journeyed to the bathroom. Sandra journeyed to the bathroom. John got the milk there. Mary took the apple there. Mary left the apple. John journeyed to the bedroom. Mary travelled to the office. Daniel put down the football.
|
babilong_0k_qa2_sample_3
| 100 | 318 |
|
195 |
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
|
[
"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"
] |
[] |
Mary travelled to the office. Daniel went to the bathroom. John went back to the bedroom. John went to the hallway. Mary journeyed to the bathroom. Sandra picked up the apple there. John moved to the bathroom. John got the milk there. Daniel moved to the bedroom. John moved to the garden.
|
babilong_0k_qa2_sample_50
| 64 | 318 |
|
506 |
Write a function to calculate the permutation coefficient of given p(n, k).
|
def permutation_coefficient(n, k):
P = [[0 for i in range(k + 1)]
for j in range(n + 1)]
for i in range(n + 1):
for j in range(min(i, k) + 1):
if (j == 0):
P[i][j] = 1
else:
P[i][j] = P[i - 1][j] + (
j * P[i - 1][j - 1])
if (j < k):
P[i][j + 1] = 0
return P[n][k]
|
[
"assert permutation_coefficient(10, 2) == 90",
"assert permutation_coefficient(10, 3) == 720",
"assert permutation_coefficient(10, 1) == 10"
] |
[] |
Sandra went back to the kitchen. John picked up the milk there. John left the milk. Sandra went to the garden. Mary went to the bathroom. Daniel journeyed to the garden. Sandra took the football there. Daniel moved to the kitchen. John took the milk there. John put down the milk there. John went to the bathroom. Sandra put down the football. Daniel journeyed to the bedroom. Sandra travelled to the bathroom. John journeyed to the office. John grabbed the apple there. John travelled to the bathroom. John left the apple there. Daniel went to the bathroom. Daniel grabbed the apple there. Sandra moved to the hallway. Daniel journeyed to the hallway.
|
babilong_0k_qa2_sample_32
| 140 | 321 |
|
415 |
Write a python function to find a pair with highest product from a given array of integers.
|
def max_Product(arr):
arr_len = len(arr)
if (arr_len < 2):
return ("No pairs exists")
x = arr[0]; y = arr[1]
for i in range(0,arr_len):
for j in range(i + 1,arr_len):
if (arr[i] * arr[j] > x * y):
x = arr[i]; y = arr[j]
return x,y
|
[
"assert max_Product([1,2,3,4,7,0,8,4]) == (7,8)",
"assert max_Product([0,-1,-2,-4,5,0,-6]) == (-4,-6)",
"assert max_Product([1,2,3]) == (2,3)"
] |
[] |
Daniel went to the hallway. Daniel got the football there. John went back to the garden. Mary went back to the office. John went to the bathroom. Daniel went back to the bathroom. John travelled to the office. Mary went to the bathroom. Daniel travelled to the office. Sandra went back to the bedroom. Mary travelled to the kitchen. Mary travelled to the hallway. Sandra travelled to the garden. Sandra travelled to the bedroom. Sandra journeyed to the bathroom. Sandra moved to the office. Mary moved to the bathroom. Mary travelled to the hallway. Daniel left the football. Daniel took the football. Daniel put down the football. Daniel journeyed to the hallway. John went back to the bedroom. Mary travelled to the bedroom. Mary picked up the apple. Mary travelled to the garden. Mary went back to the hallway. Mary moved to the bedroom. Sandra took the football there. Mary dropped the apple. Mary took the apple. John went back to the bathroom. Sandra left the football. Mary put down the apple there. John went back to the kitchen. Sandra travelled to the hallway. John moved to the office. John grabbed the football. Mary travelled to the bathroom. John left the football. Daniel travelled to the kitchen. John went to the bathroom. Sandra moved to the bedroom. Sandra picked up the apple. Sandra discarded the apple. Daniel journeyed to the bathroom. Sandra picked up the apple. Sandra discarded the apple. Sandra grabbed the apple there. Sandra travelled to the garden. Sandra dropped the apple there. Daniel travelled to the bedroom. John went back to the garden. Sandra travelled to the office. John got the apple. Daniel journeyed to the hallway. Sandra moved to the bedroom. John put down the apple. John went back to the bathroom. Sandra journeyed to the bathroom. Sandra journeyed to the garden. Sandra picked up the apple. Mary journeyed to the bedroom. Sandra travelled to the office. Sandra discarded the apple. Sandra moved to the kitchen. Daniel journeyed to the bathroom. Sandra went back to the bedroom. Mary moved to the garden. John moved to the kitchen. John journeyed to the garden. Daniel travelled to the hallway. Sandra moved to the kitchen. John travelled to the bedroom. Sandra grabbed the milk. Mary journeyed to the hallway. Sandra travelled to the garden. Mary went back to the bathroom. Sandra went to the office. John moved to the garden. Sandra went back to the bathroom. Sandra journeyed to the bedroom. Sandra left the milk there. John journeyed to the office.
|
babilong_0k_qa3_sample_93
| 519 | 331 |
|
175 |
Write a function to verify validity of a string of parentheses.
|
def is_valid_parenthese( str1):
stack, pchar = [], {"(": ")", "{": "}", "[": "]"}
for parenthese in str1:
if parenthese in pchar:
stack.append(parenthese)
elif len(stack) == 0 or pchar[stack.pop()] != parenthese:
return False
return len(stack) == 0
|
[
"assert is_valid_parenthese(\"(){}[]\")==True",
"assert is_valid_parenthese(\"()[{)}\")==False",
"assert is_valid_parenthese(\"()\")==True"
] |
[] |
The garden is west of the bedroom. The office is east of the bedroom.
|
babilong_0k_qa4_sample_21
| 17 | 335 |
|
371 |
Write a function to find the smallest missing element in a sorted array.
|
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([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"
] |
[] |
Daniel journeyed to the garden. Mary moved to the hallway. Daniel journeyed to the bedroom. John picked up the football there. John discarded the football. Daniel went to the hallway. Sandra went back to the bathroom. John picked up the football there. John journeyed to the garden. Sandra went back to the bedroom. John journeyed to the bathroom. Daniel journeyed to the bedroom. Sandra moved to the garden. Daniel moved to the garden. John journeyed to the office. Daniel went to the kitchen. Mary travelled to the kitchen. John travelled to the bathroom. Mary went to the bedroom. John picked up the apple there. Sandra went back to the kitchen. Daniel moved to the bathroom. Sandra travelled to the office. Daniel travelled to the kitchen. Sandra went back to the bathroom. Sandra travelled to the kitchen. Daniel picked up the milk there. Daniel moved to the office.
|
babilong_0k_qa2_sample_85
| 182 | 335 |
|
69 |
Write a function to check whether a list contains the given sublist or not.
|
def is_sublist(l, s):
sub_set = False
if s == []:
sub_set = True
elif s == l:
sub_set = True
elif len(s) > len(l):
sub_set = False
else:
for i in range(len(l)):
if l[i] == s[0]:
n = 1
while (n < len(s)) and (l[i+n] == s[n]):
n += 1
if n == len(s):
sub_set = True
return sub_set
|
[
"assert is_sublist([2,4,3,5,7],[3,7])==False",
"assert is_sublist([2,4,3,5,7],[4,3])==True",
"assert is_sublist([2,4,3,5,7],[1,6])==False"
] |
[] |
John moved to the bathroom. John travelled to the garden. Sandra travelled to the hallway. Daniel moved to the kitchen. Sandra journeyed to the office. Mary moved to the bathroom. Daniel went back to the hallway. Mary journeyed to the kitchen.
|
babilong_0k_qa1_sample_78
| 52 | 336 |
|
386 |
Write a function to find out the minimum no of swaps required for bracket balancing in the given string.
|
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(\"[]][][\") == 2",
"assert swap_count(\"[[][]]\") == 0",
"assert swap_count(\"[[][]]][\") == 1"
] |
[] |
Bill got the apple there. Mary travelled to the bedroom. Mary picked up the football there. Mary moved to the bathroom. Mary handed the football to Fred. Fred passed the football to Mary. Jeff went to the bathroom. Mary travelled to the hallway. Mary went to the bedroom. Bill discarded the apple. Bill journeyed to the bathroom. Jeff journeyed to the hallway. Fred travelled to the garden. Fred grabbed the apple there. Jeff travelled to the garden. Fred gave the apple to Jeff.
|
babilong_0k_qa5_sample_65
| 102 | 336 |
|
407 |
Write a function to create the next bigger number by rearranging the digits of a given number.
|
def rearrange_bigger(n):
nums = list(str(n))
for i in range(len(nums)-2,-1,-1):
if nums[i] < nums[i+1]:
z = nums[i:]
y = min(filter(lambda x: x > z[0], z))
z.remove(y)
z.sort()
nums[i:] = [y] + z
return int("".join(nums))
return False
|
[
"assert rearrange_bigger(12)==21",
"assert rearrange_bigger(10)==False",
"assert rearrange_bigger(102)==120"
] |
[] |
The garden is east of the kitchen. The garden is west of the hallway.
|
babilong_0k_qa4_sample_34
| 17 | 336 |
|
34 |
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
return (-1)
|
[
"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"
] |
[] |
John went to the office. Daniel grabbed the apple there. Mary took the football there. Mary discarded the football. Mary picked up the football. Daniel travelled to the garden. Mary put down the football there. Daniel dropped the apple there. Sandra went to the office. Mary got the milk. Sandra journeyed to the kitchen. Mary picked up the football. Sandra went to the bedroom. John journeyed to the hallway. Mary put down the milk. Daniel got the apple. Mary discarded the football. John journeyed to the bathroom. Daniel journeyed to the hallway. Mary got the milk. Mary left the milk. Daniel picked up the football. Mary grabbed the milk. Sandra travelled to the office. Sandra travelled to the garden. Mary discarded the milk. Sandra journeyed to the office. Mary got the milk. Mary discarded the milk. Daniel journeyed to the bathroom. Sandra went to the hallway. Daniel put down the apple. Daniel discarded the football. Mary took the milk.
|
babilong_0k_qa3_sample_35
| 200 | 337 |
|
113 |
Write a function to check if a string represents an integer or not.
|
def check_integer(text):
text = text.strip()
if len(text) < 1:
return None
else:
if all(text[i] in "0123456789" for i in range(len(text))):
return True
elif (text[0] in "+-") and \
all(text[i] in "0123456789" for i in range(1,len(text))):
return True
else:
return False
|
[
"assert check_integer(\"python\")==False",
"assert check_integer(\"1\")==True",
"assert check_integer(\"12345\")==True"
] |
[] |
Jeff took the milk there. Jeff put down the milk. Fred took the milk there. Fred handed the milk to Jeff.
|
babilong_0k_qa5_sample_20
| 26 | 338 |
|
316 |
Write a function to find the index of the last occurrence of a given number in a sorted array.
|
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, 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"
] |
[] |
Mary took the apple. Sandra journeyed to the bathroom. Sandra went back to the bedroom. Mary put down the apple. John went to the garden. John took the apple. John left the apple. Mary picked up the apple. Mary left the apple. Mary grabbed the apple. Mary journeyed to the kitchen. Mary dropped the apple there. Mary picked up the apple. Sandra went back to the hallway. Mary travelled to the bathroom. John went to the hallway. Mary went to the hallway. John went back to the kitchen. Mary took the football there. Sandra travelled to the bathroom. John travelled to the bathroom. Sandra travelled to the garden. Mary went back to the office. Mary journeyed to the kitchen. Daniel went to the hallway. Mary dropped the football. Sandra journeyed to the kitchen. John went back to the hallway. John travelled to the bathroom. Sandra picked up the football. Daniel went to the garden. Sandra left the football. John journeyed to the kitchen. John picked up the football. John went back to the bedroom. Mary dropped the apple. Mary moved to the bedroom. Mary travelled to the office.
|
babilong_0k_qa3_sample_63
| 232 | 343 |
|
501 |
Write a python function to find common divisor between two numbers in a given pair.
|
def ngcd(x,y):
i=1
while(i<=x and i<=y):
if(x%i==0 and y%i == 0):
gcd=i;
i+=1
return gcd;
def num_comm_div(x,y):
n = ngcd(x,y)
result = 0
z = int(n**0.5)
i = 1
while(i <= z):
if(n % i == 0):
result += 2
if(i == n/i):
result-=1
i+=1
return result
|
[
"assert num_comm_div(2,4) == 2",
"assert num_comm_div(2,8) == 2",
"assert num_comm_div(12,24) == 6"
] |
[] |
Bill grabbed the apple there. Jeff went back to the kitchen. Fred went to the garden. Bill dropped the apple. Jeff went to the garden. Bill moved to the bathroom. Bill journeyed to the office. Fred travelled to the hallway. Bill went to the hallway. Fred travelled to the kitchen. Jeff journeyed to the hallway. Jeff went back to the office. Fred moved to the hallway. Bill travelled to the office. Jeff grabbed the apple there. Jeff went back to the kitchen. Mary went back to the hallway. Jeff went back to the hallway. Jeff passed the apple to Mary. Mary gave the apple to Fred. Fred handed the apple to Mary. Fred moved to the bathroom. Mary dropped the apple. Mary took the apple there. Mary handed the apple to Jeff. Bill travelled to the hallway. Jeff put down the apple. Fred journeyed to the garden.
|
babilong_0k_qa5_sample_6
| 179 | 344 |
|
148 |
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) + sum_digits_single(N - A)
|
[
"assert sum_digits_twoparts(35)==17",
"assert sum_digits_twoparts(7)==7",
"assert sum_digits_twoparts(100)==19"
] |
[] |
Sandra moved to the hallway. Daniel went to the office. Sandra travelled to the kitchen. John moved to the office.
|
babilong_0k_qa1_sample_5
| 26 | 345 |
|
107 |
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 // 16;
return count;
|
[
"assert count_Hexadecimal(10,15) == 6",
"assert count_Hexadecimal(2,4) == 0",
"assert count_Hexadecimal(15,16) == 1"
] |
[] |
John went back to the kitchen. John journeyed to the bedroom.
|
babilong_0k_qa1_sample_97
| 15 | 350 |
|
179 |
Write a function to find if the given number is a keith number or not.
|
def is_num_keith(x):
terms = []
temp = x
n = 0
while (temp > 0):
terms.append(temp % 10)
temp = int(temp / 10)
n+=1
terms.reverse()
next_term = 0
i = n
while (next_term < x):
next_term = 0
for j in range(1,n+1):
next_term += terms[i - j]
terms.append(next_term)
i+=1
return (next_term == x)
|
[
"assert is_num_keith(14) == True",
"assert is_num_keith(12) == False",
"assert is_num_keith(197) == True"
] |
[] |
Sandra went to the garden. John travelled to the office. Sandra went back to the hallway. Mary went back to the office.
|
babilong_0k_qa1_sample_77
| 28 | 351 |
|
351 |
Write a python function to find the first element occurring k times in a given array.
|
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([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"
] |
[] |
John went back to the bedroom. John journeyed to the garden. Daniel journeyed to the bathroom. Sandra went back to the kitchen. Daniel travelled to the kitchen. Sandra went to the hallway.
|
babilong_0k_qa1_sample_93
| 41 | 351 |
|
304 |
Write a python function to find element at a given index after number of rotations.
|
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([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"
] |
[] |
The hallway is east of the garden. The kitchen is west of the garden.
|
babilong_0k_qa4_sample_85
| 17 | 352 |
|
182 |
Write a function to find uppercase, lowercase, special character and numeric values using regex.
|
import re
def find_character(string):
uppercase_characters = re.findall(r"[A-Z]", string)
lowercase_characters = re.findall(r"[a-z]", string)
numerical_characters = re.findall(r"[0-9]", string)
special_characters = re.findall(r"[, .!?]", string)
return uppercase_characters, lowercase_characters, numerical_characters, special_characters
|
[
"assert find_character(\"ThisIsGeeksforGeeks\") == (['T', 'I', 'G', 'G'], ['h', 'i', 's', 's', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'e', 'e', 'k', 's'], [], [])",
"assert find_character(\"Hithere2\") == (['H'], ['i', 't', 'h', 'e', 'r', 'e'], ['2'], [])",
"assert find_character(\"HeyFolks32\") == (['H', 'F'], ['e', 'y', 'o', 'l', 'k', 's'], ['3', '2'], [])"
] |
[] |
Mary moved to the office. Jeff took the apple there. Fred went to the hallway. Bill grabbed the football there. Jeff went back to the kitchen. Mary picked up the milk there. Bill went to the bedroom. Fred travelled to the garden. Fred travelled to the bathroom. Bill went back to the hallway. Mary dropped the milk. Bill dropped the football. Mary went to the garden. Bill went back to the office. Jeff moved to the bedroom. Bill got the milk there. Bill travelled to the bathroom. Bill handed the milk to Fred. Fred gave the milk to Bill. Jeff travelled to the garden. Mary moved to the office. Bill gave the milk to Fred.
|
babilong_0k_qa5_sample_89
| 138 | 357 |
|
355 |
Write a python function to count the number of rectangles in a circle of radius r.
|
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(2) == 8",
"assert count_Rectangles(1) == 1",
"assert count_Rectangles(0) == 0"
] |
[] |
Daniel went back to the garden. Mary got the apple. Sandra travelled to the bedroom. Daniel travelled to the office. Mary went back to the office. Mary left the apple. Mary moved to the bathroom. Mary moved to the bedroom. Sandra journeyed to the office. Sandra grabbed the apple. John went back to the hallway. John went back to the bedroom. Sandra discarded the apple. Sandra got the apple. John went back to the bathroom. Mary travelled to the bathroom. Daniel went to the hallway. Sandra travelled to the bathroom. Mary journeyed to the garden. John went back to the hallway. Mary moved to the bedroom. John journeyed to the garden. John moved to the bedroom. Sandra travelled to the office. Mary moved to the bathroom. Daniel moved to the bedroom. Sandra moved to the bathroom. Sandra put down the apple there. John journeyed to the office. Sandra went back to the bedroom. John moved to the bathroom. John grabbed the apple. John left the apple. Mary went to the bedroom. John took the apple. Daniel moved to the office. Mary went to the kitchen. John journeyed to the bedroom. Mary took the football. Daniel went to the bathroom. Daniel journeyed to the kitchen. John went to the bathroom. Sandra travelled to the hallway. John left the apple. Mary put down the football. Daniel took the football there.
|
babilong_0k_qa3_sample_14
| 281 | 372 |
|
247 |
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[i][j] = max(L[i][j-1], L[i+1][j]);
return L[0][n-1]
|
[
"assert lps(\"TENS FOR TENS\") == 5 ",
"assert lps(\"CARDIO FOR CARDS\") == 7",
"assert lps(\"PART OF THE JOURNEY IS PART\") == 9 "
] |
[] |
Mary went to the bathroom. Sandra went back to the bathroom.
|
babilong_0k_qa1_sample_64
| 14 | 374 |
|
181 |
Write a function to find the longest common prefix in the given set of strings.
|
def common_prefix_util(str1, str2):
result = "";
n1 = len(str1)
n2 = len(str2)
i = 0
j = 0
while i <= n1 - 1 and j <= n2 - 1:
if (str1[i] != str2[j]):
break
result += str1[i]
i += 1
j += 1
return (result)
def common_prefix (arr, n):
prefix = arr[0]
for i in range (1, n):
prefix = common_prefix_util(prefix, arr[i])
return (prefix)
|
[
"assert common_prefix([\"tablets\", \"tables\", \"taxi\", \"tamarind\"], 4) == 'ta'",
"assert common_prefix([\"apples\", \"ape\", \"april\"], 3) == 'ap'",
"assert common_prefix([\"teens\", \"teenager\", \"teenmar\"], 3) == 'teen'"
] |
[] |
Mary went back to the office. Mary went back to the bathroom. Mary went back to the hallway. Mary went back to the bedroom. Mary journeyed to the kitchen. Daniel moved to the bedroom. Mary picked up the football. Daniel travelled to the hallway. Daniel journeyed to the bedroom. Sandra travelled to the hallway. Mary moved to the garden. Mary put down the football there. Mary travelled to the kitchen. Daniel moved to the hallway. Sandra moved to the garden. Mary went to the bathroom. Mary picked up the apple. Mary moved to the garden. Sandra picked up the football. Daniel went back to the office. Sandra left the football. Mary put down the apple. John journeyed to the bathroom. John grabbed the milk. Daniel travelled to the kitchen. Sandra got the apple there. Mary moved to the office. Sandra journeyed to the hallway. Sandra left the apple. Sandra moved to the bathroom. Sandra went to the kitchen. Sandra went to the hallway. Sandra took the apple. Mary went back to the hallway. Sandra travelled to the garden. Sandra dropped the apple. Mary journeyed to the bathroom. Mary travelled to the office. Sandra travelled to the kitchen. Sandra travelled to the bedroom. Daniel journeyed to the bathroom. John went back to the office. John left the milk. Mary went back to the bathroom. John grabbed the milk. John went back to the hallway. John moved to the garden. Sandra went to the bathroom. Sandra moved to the hallway. John grabbed the football there. Daniel travelled to the kitchen. John put down the football there. Mary travelled to the garden. Mary got the football. Daniel went to the garden. Daniel travelled to the kitchen. John discarded the milk. John got the apple there. John picked up the milk. John dropped the apple. John picked up the apple. Mary travelled to the kitchen. Mary went back to the office. John journeyed to the hallway. John discarded the milk. Mary went to the bathroom. Mary moved to the hallway. Sandra went to the bedroom. Sandra went to the bathroom. Mary dropped the football there.
|
babilong_0k_qa3_sample_86
| 429 | 384 |
|
54 |
Write a function to sort the given array by using counting sort.
|
def counting_sort(my_list):
max_value = 0
for i in range(len(my_list)):
if my_list[i] > max_value:
max_value = my_list[i]
buckets = [0] * (max_value + 1)
for i in my_list:
buckets[i] += 1
i = 0
for j in range(max_value + 1):
for a in range(buckets[j]):
my_list[i] = j
i += 1
return my_list
|
[
"assert counting_sort([1,23,4,5,6,7,8]) == [1, 4, 5, 6, 7, 8, 23]",
"assert counting_sort([12, 9, 28, 33, 69, 45]) == [9, 12, 28, 33, 45, 69]",
"assert counting_sort([8, 4, 14, 3, 2, 1]) == [1, 2, 3, 4, 8, 14]"
] |
[] |
Mary moved to the kitchen. John got the milk there. Mary went to the garden. Sandra went back to the office. Daniel picked up the football there. John went back to the kitchen. Daniel went to the kitchen. John discarded the milk. Mary journeyed to the hallway. Daniel got the milk. Daniel left the milk there. Daniel travelled to the office. Daniel went to the garden. John took the milk there. Daniel dropped the football. Sandra moved to the garden. Sandra got the football. John went to the garden. John moved to the hallway. Sandra went back to the bedroom. Sandra dropped the football. Daniel went to the bedroom. John got the apple. John moved to the garden. Sandra travelled to the hallway. Sandra journeyed to the office. Daniel got the football. Daniel moved to the garden. John left the milk. Daniel picked up the milk there. Sandra went to the bedroom. Mary travelled to the kitchen. John discarded the apple. Mary moved to the garden. John journeyed to the bedroom. Sandra went back to the hallway. Daniel took the apple. Daniel discarded the milk. Mary grabbed the milk. Mary moved to the hallway. Sandra journeyed to the bedroom. Daniel put down the apple there. Daniel went back to the hallway. Daniel dropped the football. John went back to the bathroom. John went back to the hallway.
|
babilong_0k_qa3_sample_11
| 278 | 393 |
|
428 |
Write a function to sort the given array by using shell sort.
|
def shell_sort(my_list):
gap = len(my_list) // 2
while gap > 0:
for i in range(gap, len(my_list)):
current_item = my_list[i]
j = i
while j >= gap and my_list[j - gap] > current_item:
my_list[j] = my_list[j - gap]
j -= gap
my_list[j] = current_item
gap //= 2
return my_list
|
[
"assert shell_sort([12, 23, 4, 5, 3, 2, 12, 81, 56, 95]) == [2, 3, 4, 5, 12, 12, 23, 56, 81, 95]",
"assert shell_sort([24, 22, 39, 34, 87, 73, 68]) == [22, 24, 34, 39, 68, 73, 87]",
"assert shell_sort([32, 30, 16, 96, 82, 83, 74]) == [16, 30, 32, 74, 82, 83, 96]"
] |
[] |
John went back to the bathroom. John went back to the bedroom. Daniel went to the office. Mary took the milk. Mary left the milk. John went to the hallway. Mary took the milk. Mary left the milk. Sandra travelled to the bedroom. Mary went to the bathroom. Sandra went to the garden. Mary moved to the kitchen. Daniel moved to the bedroom. Sandra moved to the kitchen. Sandra got the milk. Daniel grabbed the football. John journeyed to the kitchen. Sandra moved to the office. Daniel took the apple there. Daniel put down the apple. John went back to the bedroom. John travelled to the office. Daniel discarded the football. Sandra dropped the milk. Sandra got the milk. Daniel picked up the football. Daniel got the apple. Daniel dropped the football. Daniel moved to the office. Sandra put down the milk. Daniel journeyed to the garden. Daniel went to the hallway. Sandra grabbed the milk. Mary went to the bedroom. Daniel left the apple. Daniel moved to the office. Daniel travelled to the bedroom. Daniel journeyed to the garden.
|
babilong_0k_qa3_sample_81
| 222 | 393 |
|
374 |
Write a function to print all permutations of a given string including duplicates.
|
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('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']"
] |
[] |
John journeyed to the garden. John went back to the bedroom. Daniel went back to the office. Daniel went to the bedroom.
|
babilong_0k_qa1_sample_94
| 28 | 395 |
|
136 |
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 - 200) * 8.45)
surcharge = 75
total = amount + surcharge
return total
|
[
"assert cal_electbill(75)==246.25",
"assert cal_electbill(265)==1442.75",
"assert cal_electbill(100)==327.5"
] |
[] |
The bathroom is north of the kitchen. The bathroom is south of the hallway.
|
babilong_0k_qa4_sample_31
| 17 | 398 |
|
297 |
Write a function to flatten a given nested list structure.
|
def flatten_list(list1):
result_list = []
if not list1: return result_list
stack = [list(list1)]
while stack:
c_num = stack.pop()
next = c_num.pop()
if c_num: stack.append(c_num)
if isinstance(next, list):
if next: stack.append(list(next))
else: result_list.append(next)
result_list.reverse()
return result_list
|
[
"assert flatten_list([0, 10, [20, 30], 40, 50, [60, 70, 80], [90, 100, 110, 120]])==[0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120]",
"assert flatten_list([[10, 20], [40], [30, 56, 25], [10, 20], [33], [40]])==[10, 20, 40, 30, 56, 25, 10, 20, 33, 40]",
"assert flatten_list([[1,2,3], [4,5,6], [10,11,12], [7,8,9]])==[1, 2, 3, 4, 5, 6, 10, 11, 12, 7, 8, 9]"
] |
[] |
Mary journeyed to the office. Mary moved to the hallway.
|
babilong_0k_qa1_sample_15
| 14 | 400 |
|
364 |
Write a function to find the number of flips required to make the given binary string a sequence of alternate characters.
|
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(\"0001010111\") == 2",
"assert min_flip_to_make_string_alternate(\"001\") == 1",
"assert min_flip_to_make_string_alternate(\"010111011\") == 2 "
] |
[] |
John travelled to the kitchen. John went to the bedroom. Sandra got the milk. Sandra discarded the milk. Sandra got the milk. Sandra journeyed to the garden. John went to the hallway. John travelled to the kitchen. Sandra travelled to the office. John went back to the bedroom. Sandra dropped the milk. John went to the kitchen.
|
babilong_0k_qa3_sample_60
| 71 | 407 |
|
485 |
Write a function to find the largest palindromic number in the given array.
|
def is_palindrome(n) :
divisor = 1
while (n / divisor >= 10) :
divisor *= 10
while (n != 0) :
leading = n // divisor
trailing = n % 10
if (leading != trailing) :
return False
n = (n % divisor) // 10
divisor = divisor // 100
return True
def largest_palindrome(A, n) :
A.sort()
for i in range(n - 1, -1, -1) :
if (is_palindrome(A[i])) :
return A[i]
return -1
|
[
"assert largest_palindrome([1, 232, 54545, 999991], 4) == 54545",
"assert largest_palindrome([1, 2, 3, 4, 5, 50], 6) == 5",
"assert largest_palindrome([1, 3, 7, 9, 45], 5) == 9"
] |
[] |
John journeyed to the garden. John travelled to the bathroom. Mary moved to the kitchen. Mary went back to the bedroom. John went to the hallway. John went to the kitchen.
|
babilong_0k_qa1_sample_67
| 39 | 410 |
|
189 |
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] += n
for i in range(n):
if arr[i] <= n:
return(i + 1)
return(n + 1)
|
[
"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"
] |
[] |
Sandra moved to the kitchen. John travelled to the office. Sandra went back to the garden. John went to the garden. Daniel travelled to the garden. Sandra moved to the hallway.
|
babilong_0k_qa1_sample_95
| 39 | 416 |
|
231 |
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][j] + tri[i-1][j-1]
else:
tri[i][j] = tri[i][j]+tri[i-1][j]
return (max(tri[n-1]))
|
[
"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"
] |
[] |
The bedroom is east of the bathroom. The hallway is west of the bathroom.
|
babilong_0k_qa4_sample_25
| 17 | 417 |
|
71 |
Write a function to sort a list of elements using comb sort.
|
def comb_sort(nums):
shrink_fact = 1.3
gaps = len(nums)
swapped = True
i = 0
while gaps > 1 or swapped:
gaps = int(float(gaps) / shrink_fact)
swapped = False
i = 0
while gaps + i < len(nums):
if nums[i] > nums[i+gaps]:
nums[i], nums[i+gaps] = nums[i+gaps], nums[i]
swapped = True
i += 1
return nums
|
[
"assert comb_sort([5, 15, 37, 25, 79]) == [5, 15, 25, 37, 79]",
"assert comb_sort([41, 32, 15, 19, 22]) == [15, 19, 22, 32, 41]",
"assert comb_sort([99, 15, 13, 47]) == [13, 15, 47, 99]"
] |
[] |
Fred journeyed to the bedroom. Bill moved to the bedroom. Fred went to the office. Fred picked up the football there. Bill journeyed to the kitchen. Bill moved to the garden. Jeff went to the bathroom. Fred discarded the football there. Mary journeyed to the hallway. Fred grabbed the football there. Bill travelled to the bathroom. Bill journeyed to the office. Fred handed the football to Bill. Fred went back to the bathroom. Bill discarded the football. Jeff went back to the kitchen. Mary went back to the bedroom. Mary picked up the milk there. Mary travelled to the garden. Fred went to the garden. Mary discarded the milk. Jeff travelled to the bathroom. Bill went to the hallway. Mary grabbed the milk there. Mary discarded the milk. Fred went back to the bedroom. Fred picked up the apple there. Fred moved to the garden. Fred discarded the apple. Mary went back to the office. Fred moved to the kitchen. Mary got the football there. Bill went back to the office. Jeff moved to the office. Mary handed the football to Bill. Fred journeyed to the office.
|
babilong_0k_qa5_sample_99
| 229 | 424 |
|
466 |
Write a function to find the peak element in the given array.
|
def find_peak_util(arr, low, high, n):
mid = low + (high - low)/2
mid = int(mid)
if ((mid == 0 or arr[mid - 1] <= arr[mid]) and
(mid == n - 1 or arr[mid + 1] <= arr[mid])):
return mid
elif (mid > 0 and arr[mid - 1] > arr[mid]):
return find_peak_util(arr, low, (mid - 1), n)
else:
return find_peak_util(arr, (mid + 1), high, n)
def find_peak(arr, n):
return find_peak_util(arr, 0, n - 1, n)
|
[
"assert find_peak([1, 3, 20, 4, 1, 0], 6) == 2",
"assert find_peak([2, 3, 4, 5, 6], 5) == 4",
"assert find_peak([8, 9, 11, 12, 14, 15], 6) == 5 "
] |
[] |
John travelled to the garden. Sandra journeyed to the kitchen. Daniel went to the bedroom. Mary went to the bathroom. Sandra took the milk there. Sandra went back to the bedroom. Daniel journeyed to the kitchen. Mary went to the bedroom. Mary moved to the garden. Mary went to the hallway. Sandra dropped the milk there. John travelled to the bathroom.
|
babilong_0k_qa2_sample_87
| 76 | 424 |
|
408 |
Write a function to find k number of pairs which consist of one element from the first array and one element from the second array.
|
import heapq
def k_smallest_pairs(nums1, nums2, k):
queue = []
def push(i, j):
if i < len(nums1) and j < len(nums2):
heapq.heappush(queue, [nums1[i] + nums2[j], i, j])
push(0, 0)
pairs = []
while queue and len(pairs) < k:
_, i, j = heapq.heappop(queue)
pairs.append([nums1[i], nums2[j]])
push(i, j + 1)
if j == 0:
push(i + 1, 0)
return pairs
|
[
"assert k_smallest_pairs([1,3,7],[2,4,6],2)==[[1, 2], [1, 4]]",
"assert k_smallest_pairs([1,3,7],[2,4,6],1)==[[1, 2]]",
"assert k_smallest_pairs([1,3,7],[2,4,6],7)==[[1, 2], [1, 4], [3, 2], [1, 6], [3, 4], [3, 6], [7, 2]]"
] |
[] |
Sandra moved to the bathroom. Sandra moved to the kitchen. Sandra went to the bedroom. Daniel picked up the apple. Mary went back to the bathroom. Mary grabbed the football. John travelled to the bathroom. Mary left the football. Sandra went back to the garden. Mary travelled to the office. John journeyed to the bedroom. Daniel moved to the hallway. Daniel put down the apple. Mary travelled to the bedroom. Sandra picked up the milk there. Sandra journeyed to the bedroom. John travelled to the office. John moved to the garden. Sandra left the milk there. Mary picked up the milk. John went back to the hallway. Daniel went to the bathroom. Sandra went back to the garden. John moved to the office. Sandra travelled to the kitchen. John went back to the kitchen. Daniel took the football. John travelled to the office. Sandra travelled to the hallway. Daniel moved to the hallway. Daniel got the apple. Mary journeyed to the hallway. Mary went back to the kitchen. John journeyed to the bedroom. Mary discarded the milk. John travelled to the garden. Sandra went to the office. Daniel discarded the apple there.
|
babilong_0k_qa3_sample_97
| 236 | 430 |
|
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 .
|
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([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"
] |
[] |
Bill grabbed the football there. Bill got the milk there. Bill discarded the milk. Fred went back to the office. Bill took the milk there. Bill dropped the milk there. Jeff went back to the hallway. Jeff went back to the bathroom. Mary went to the hallway. Bill put down the football. Bill journeyed to the bedroom. Jeff travelled to the office. Mary moved to the garden. Mary went back to the kitchen. Bill went to the hallway. Jeff journeyed to the kitchen. Mary got the apple there. Mary passed the apple to Jeff. Jeff passed the apple to Mary. Mary passed the apple to Jeff.
|
babilong_0k_qa5_sample_18
| 129 | 455 |
|
245 |
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]:
MSDBS[-i] = MSDBS[-j] + arr[-i]
max_sum = float("-Inf")
for i, j, k in zip(MSIBS, MSDBS, arr):
max_sum = max(max_sum, i + j - k)
return max_sum
|
[
"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"
] |
[] |
Sandra travelled to the office. Mary grabbed the football there. Mary put down the football. Daniel picked up the football there. John travelled to the garden. Mary moved to the garden. John went to the office. Mary got the milk there. Mary left the milk there. Daniel put down the football. John went to the bedroom. Mary got the milk there. Daniel journeyed to the garden. Mary discarded the milk.
|
babilong_0k_qa2_sample_96
| 87 | 478 |
|
382 |
Write a function to find the number of rotations in a circularly sorted array.
|
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([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"
] |
[] |
The bathroom is north of the bedroom. The bedroom is north of the kitchen.
|
babilong_0k_qa4_sample_56
| 17 | 478 |
|
223 |
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] == x):
return mid
elif x > arr[mid]:
return binary_search(arr, (mid + 1), high, x)
else:
return binary_search(arr, low, (mid -1), x)
return -1
|
[
"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"
] |
[] |
John travelled to the hallway. John travelled to the bathroom. Sandra moved to the kitchen. John journeyed to the bedroom. Daniel journeyed to the hallway. John journeyed to the bathroom. Daniel moved to the bedroom. Mary went to the bathroom.
|
babilong_0k_qa1_sample_62
| 52 | 479 |
|
367 |
Write a function to check if a binary tree is balanced or not.
|
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 "
] |
root = Node(1)
root.left = Node(2)
root.right = Node(3)
root.left.left = Node(4)
root.left.right = Node(5)
root.left.left.left = Node(8)
root1 = Node(1)
root1.left = Node(2)
root1.right = Node(3)
root1.left.left = Node(4)
root1.left.right = Node(5)
root1.right.left = Node(6)
root1.left.left.left = Node(7)
root2 = Node(1)
root2.left = Node(2)
root2.right = Node(3)
root2.left.left = Node(4)
root2.left.right = Node(5)
root2.left.left.left = Node(7)
|
[] |
Sandra moved to the bathroom. Sandra moved to the kitchen. Sandra went to the bedroom. Daniel picked up the apple. Mary went back to the bathroom. Mary grabbed the football. John travelled to the bathroom. Mary left the football. Sandra went back to the garden. Mary travelled to the office. John journeyed to the bedroom. Daniel moved to the hallway. Daniel put down the apple. Mary travelled to the bedroom. Sandra picked up the milk there. Sandra journeyed to the bedroom. John travelled to the office. John moved to the garden. Sandra left the milk there. Mary picked up the milk. John went back to the hallway. Daniel went to the bathroom. Sandra went back to the garden. John moved to the office. Sandra travelled to the kitchen. John went back to the kitchen. Daniel took the football. John travelled to the office. Sandra travelled to the hallway. Daniel moved to the hallway. Daniel got the apple. Mary journeyed to the hallway. Mary went back to the kitchen. John journeyed to the bedroom. Mary discarded the milk. John travelled to the garden. Sandra went to the office. Daniel discarded the apple there. Mary went to the bathroom. John went to the bathroom. Daniel journeyed to the bedroom. Mary travelled to the bedroom. Mary went to the hallway. Mary journeyed to the office. John went to the hallway. Mary moved to the bathroom. Daniel dropped the football there. Daniel grabbed the football. Daniel went to the bathroom. Sandra travelled to the hallway. Sandra picked up the apple there. Daniel went to the office. John journeyed to the garden. Sandra journeyed to the bathroom. Mary travelled to the office. Sandra dropped the apple. Daniel went back to the hallway. Mary journeyed to the bedroom. Daniel went back to the office. Mary journeyed to the bathroom. Mary grabbed the apple. John went back to the hallway. Daniel went to the bedroom. Mary dropped the apple. John moved to the bathroom. Daniel went to the bathroom. Mary took the apple. Daniel discarded the football.
|
babilong_0k_qa3_sample_98
| 420 | 492 |
152 |
Write a function to sort the given array by using merge sort.
|
def merge(a,b):
c = []
while len(a) != 0 and len(b) != 0:
if a[0] < b[0]:
c.append(a[0])
a.remove(a[0])
else:
c.append(b[0])
b.remove(b[0])
if len(a) == 0:
c += b
else:
c += a
return c
def merge_sort(x):
if len(x) == 0 or len(x) == 1:
return x
else:
middle = len(x)//2
a = merge_sort(x[:middle])
b = merge_sort(x[middle:])
return merge(a,b)
|
[
"assert merge_sort([3, 4, 2, 6, 5, 7, 1, 9]) == [1, 2, 3, 4, 5, 6, 7, 9]",
"assert merge_sort([7, 25, 45, 78, 11, 33, 19]) == [7, 11, 19, 25, 33, 45, 78]",
"assert merge_sort([3, 1, 4, 9, 8]) == [1, 3, 4, 8, 9]"
] |
[] |
Daniel moved to the kitchen. Mary went to the office. John went to the office. Daniel picked up the milk there. Daniel left the milk. Sandra went back to the kitchen. Mary travelled to the hallway. Mary went back to the bedroom. Daniel moved to the office. John moved to the kitchen. John took the milk. John went back to the office. Daniel moved to the kitchen. Sandra moved to the bedroom. John went back to the bathroom. Mary picked up the apple. Mary went back to the office. John went to the office. Mary discarded the apple. John got the apple. Daniel went back to the bedroom. John discarded the milk.
|
babilong_0k_qa3_sample_57
| 135 | 511 |
|
129 |
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]
sum_list.append(result1)
result2 = 0
for i in range(iSize-1,-1,-1):
result2 +=my_matrix[i][i]
sum_list.append(result2)
if len(set(sum_list))>1:
return False
return True
|
[
"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"
] |
[] |
Mary travelled to the office. Daniel grabbed the football there. Mary journeyed to the garden. Daniel dropped the football. Sandra moved to the office. Daniel grabbed the football there. Daniel travelled to the office. John went to the garden.
|
babilong_0k_qa2_sample_80
| 49 | 541 |
|
453 |
Write a python function to find the sum of even factors of a number.
|
import math
def sumofFactors(n) :
if (n % 2 != 0) :
return 0
res = 1
for i in range(2, (int)(math.sqrt(n)) + 1) :
count = 0
curr_sum = 1
curr_term = 1
while (n % i == 0) :
count= count + 1
n = n // i
if (i == 2 and count == 1) :
curr_sum = 0
curr_term = curr_term * i
curr_sum = curr_sum + curr_term
res = res * curr_sum
if (n >= 2) :
res = res * (1 + n)
return res
|
[
"assert sumofFactors(18) == 26",
"assert sumofFactors(30) == 48",
"assert sumofFactors(6) == 8"
] |
[] |
Daniel took the apple. John journeyed to the bedroom. Sandra picked up the football. Sandra discarded the football. Mary went back to the office. Sandra took the football. Sandra discarded the football. Sandra journeyed to the kitchen. Sandra picked up the milk. Daniel travelled to the hallway. Daniel discarded the apple. Daniel went to the office. John moved to the garden. Mary journeyed to the kitchen. Sandra left the milk there. Sandra grabbed the milk. Mary journeyed to the garden. Daniel went to the garden. Sandra put down the milk. John travelled to the bedroom. Sandra travelled to the bedroom. Mary travelled to the kitchen. John went to the bathroom. Sandra moved to the garden. John grabbed the football. Sandra moved to the office. John went to the bedroom. John left the football. John picked up the football. Mary grabbed the milk there. Mary put down the milk. John discarded the football. Mary travelled to the bedroom. John grabbed the football. John put down the football. John took the football. Sandra journeyed to the hallway. Sandra took the apple. Sandra discarded the apple. Mary travelled to the office. Daniel went to the bedroom. Sandra picked up the apple. Daniel went to the bathroom. John dropped the football there. John got the football. John dropped the football. Sandra put down the apple. Sandra went to the office. Mary travelled to the bathroom. John got the football. Sandra journeyed to the kitchen. Daniel moved to the office. Sandra picked up the milk there. John dropped the football there. Daniel went to the bathroom. Sandra left the milk there. Mary moved to the bedroom. John grabbed the football. Mary went to the garden. Mary went back to the office. Sandra took the milk. John left the football. John got the football. Sandra went to the garden. Mary journeyed to the garden. Mary went back to the hallway. Daniel moved to the office. Sandra went back to the hallway. Sandra picked up the apple. Mary moved to the office. Daniel went back to the garden. Sandra went back to the kitchen. Mary moved to the hallway. Mary went back to the bathroom. John left the football. Mary moved to the garden. Mary travelled to the kitchen. Sandra left the apple there. Sandra moved to the bedroom. John went to the garden. John travelled to the kitchen. Sandra went to the bathroom. Sandra travelled to the office. Sandra journeyed to the garden. John moved to the garden. Mary journeyed to the bedroom. Mary grabbed the football there. Mary travelled to the hallway. Sandra journeyed to the bathroom. John went to the bathroom. Sandra discarded the milk. Daniel travelled to the hallway.
|
babilong_0k_qa3_sample_32
| 549 | 553 |
|
39 |
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)
nct2, char2 = heapq.heappop(heap)
ans.extend([char1, char2])
if nct1 + 1: heapq.heappush(heap, (nct1 + 1, char1))
if nct2 + 1: heapq.heappush(heap, (nct2 + 1, char2))
return "".join(ans) + (heap[0][1] if heap else "")
|
[
"assert rearange_string(\"aab\")==('aba')",
"assert rearange_string(\"aabb\")==('abab')",
"assert rearange_string(\"abccdd\")==('cdabcd')"
] |
[] |
The bathroom is east of the kitchen. The hallway is west of the kitchen.
|
babilong_0k_qa4_sample_36
| 17 | 578 |
|
31 |
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:
heapq.heapify(temp)
else:
if v > temp[0][0]:
heapq.heappop(temp)
heapq.heappush(temp, (v, key))
result = []
while temp:
v, key = heapq.heappop(temp)
result.append(key)
return result
|
[
"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], [2, 5, 7, 11], [1, 4, 7, 8, 12]],5)==[6, 5, 7, 8, 1]"
] |
[] |
Mary travelled to the garden. Daniel took the football. Daniel journeyed to the hallway. John went to the bathroom. Daniel travelled to the bathroom. Sandra moved to the office. Daniel moved to the hallway. John went to the garden. John moved to the bedroom. Daniel went to the garden. Sandra travelled to the bathroom. Mary went back to the hallway. Daniel travelled to the hallway. Sandra went back to the bedroom. John travelled to the garden. John moved to the kitchen. Daniel discarded the football. Daniel moved to the kitchen. Sandra went to the office. John journeyed to the hallway. Sandra picked up the apple there. Mary moved to the bathroom. Daniel moved to the hallway. Mary got the milk. Sandra moved to the hallway. Sandra grabbed the football there. Mary put down the milk. Daniel went back to the bathroom. Sandra dropped the football there. Sandra took the football. Mary took the milk there. Sandra went back to the bathroom. Mary went to the office. Mary discarded the milk there. Sandra put down the football. Daniel took the football. John went back to the garden. Daniel moved to the kitchen. Daniel journeyed to the bedroom. Sandra put down the apple. John went back to the bedroom. Mary went to the kitchen.
|
babilong_0k_qa3_sample_8
| 258 | 593 |
|
315 |
Write a python function to find the first maximum length of even word.
|
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(\"python language\") == \"language\"",
"assert find_Max_Len_Even(\"maximum even length\") == \"length\"",
"assert find_Max_Len_Even(\"eve\") == \"-1\""
] |
[] |
Sandra moved to the hallway. John travelled to the office. Sandra took the milk there. Sandra put down the milk. Mary went to the bedroom. Sandra went back to the kitchen. Mary went to the kitchen. Sandra got the apple there.
|
babilong_0k_qa2_sample_34
| 51 | 597 |
|
123 |
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 for fact in range(1, num) if num % fact == 0])
sum_fact2 = sum([fact for fact in range(1, sum_fact) if sum_fact % fact == 0])
if num == sum_fact2 and num != sum_fact:
amicables.add(num)
amicables.add(sum_fact2)
return sum(amicables)
|
[
"assert amicable_numbers_sum(999)==504",
"assert amicable_numbers_sum(9999)==31626",
"assert amicable_numbers_sum(99)==0"
] |
[] |
Fred journeyed to the kitchen. Jeff went to the garden. Mary travelled to the office. Bill journeyed to the office. Mary took the football there. Mary handed the football to Bill. Bill journeyed to the bedroom. Mary moved to the bathroom.
|
babilong_0k_qa5_sample_19
| 53 | 599 |
|
463 |
Write a function to find the maximum product subarray of the given array.
|
def max_subarray_product(arr):
n = len(arr)
max_ending_here = 1
min_ending_here = 1
max_so_far = 0
flag = 0
for i in range(0, n):
if arr[i] > 0:
max_ending_here = max_ending_here * arr[i]
min_ending_here = min (min_ending_here * arr[i], 1)
flag = 1
elif arr[i] == 0:
max_ending_here = 1
min_ending_here = 1
else:
temp = max_ending_here
max_ending_here = max (min_ending_here * arr[i], 1)
min_ending_here = temp * arr[i]
if (max_so_far < max_ending_here):
max_so_far = max_ending_here
if flag == 0 and max_so_far == 0:
return 0
return max_so_far
|
[
"assert max_subarray_product([1, -2, -3, 0, 7, -8, -2]) == 112",
"assert max_subarray_product([6, -3, -10, 0, 2]) == 180 ",
"assert max_subarray_product([-2, -40, 0, -2, -3]) == 80"
] |
[] |
Jeff took the milk there. Jeff put down the milk. Fred took the milk there. Fred handed the milk to Jeff. Mary went to the office. Jeff gave the milk to Mary. Mary gave the milk to Fred. Fred passed the milk to Mary. Bill journeyed to the kitchen. Mary handed the milk to Fred.
|
babilong_0k_qa5_sample_22
| 67 | 611 |
|
469 |
Write a function to find the maximum profit earned from a maximum of k stock transactions
|
def max_profit(price, k):
n = len(price)
final_profit = [[None for x in range(n)] for y in range(k + 1)]
for i in range(k + 1):
for j in range(n):
if i == 0 or j == 0:
final_profit[i][j] = 0
else:
max_so_far = 0
for x in range(j):
curr_price = price[j] - price[x] + final_profit[i-1][x]
if max_so_far < curr_price:
max_so_far = curr_price
final_profit[i][j] = max(final_profit[i][j-1], max_so_far)
return final_profit[k][n-1]
|
[
"assert max_profit([1, 5, 2, 3, 7, 6, 4, 5], 3) == 10",
"assert max_profit([2, 4, 7, 5, 4, 3, 5], 2) == 7",
"assert max_profit([10, 6, 8, 4, 2], 2) == 2"
] |
[] |
Jeff got the football there. Jeff passed the football to Fred. Fred gave the football to Jeff. Fred journeyed to the bedroom. Fred went to the office. Jeff picked up the milk there.
|
babilong_0k_qa5_sample_60
| 41 | 615 |
|
18 |
Write a function to remove characters from the first string which are present in the second string.
|
NO_OF_CHARS = 256
def str_to_list(string):
temp = []
for x in string:
temp.append(x)
return temp
def lst_to_string(List):
return ''.join(List)
def get_char_count_array(string):
count = [0] * NO_OF_CHARS
for i in string:
count[ord(i)] += 1
return count
def remove_dirty_chars(string, second_string):
count = get_char_count_array(second_string)
ip_ind = 0
res_ind = 0
temp = ''
str_list = str_to_list(string)
while ip_ind != len(str_list):
temp = str_list[ip_ind]
if count[ord(temp)] == 0:
str_list[res_ind] = str_list[ip_ind]
res_ind += 1
ip_ind+=1
return lst_to_string(str_list[0:res_ind])
|
[
"assert remove_dirty_chars(\"probasscurve\", \"pros\") == 'bacuve'",
"assert remove_dirty_chars(\"digitalindia\", \"talent\") == 'digiidi'",
"assert remove_dirty_chars(\"exoticmiles\", \"toxic\") == 'emles' "
] |
[] |
The bathroom is east of the hallway. The office is west of the hallway.
|
babilong_0k_qa4_sample_52
| 17 | 664 |
|
159 |
Write a function to print the season for the given month and day.
|
def month_season(month,days):
if month in ('January', 'February', 'March'):
season = 'winter'
elif month in ('April', 'May', 'June'):
season = 'spring'
elif month in ('July', 'August', 'September'):
season = 'summer'
else:
season = 'autumn'
if (month == 'March') and (days > 19):
season = 'spring'
elif (month == 'June') and (days > 20):
season = 'summer'
elif (month == 'September') and (days > 21):
season = 'autumn'
elif (month == 'October') and (days > 21):
season = 'autumn'
elif (month == 'November') and (days > 21):
season = 'autumn'
elif (month == 'December') and (days > 20):
season = 'winter'
return season
|
[
"assert month_season('January',4)==('winter')",
"assert month_season('October',28)==('autumn')",
"assert month_season('June',6)==('spring')"
] |
[] |
Daniel picked up the apple there. Sandra travelled to the hallway. Daniel put down the apple there. Mary went back to the bathroom. John moved to the bathroom. John travelled to the garden. Daniel journeyed to the hallway. Mary went back to the bedroom. Daniel moved to the kitchen. Daniel journeyed to the bedroom. Mary moved to the hallway. Daniel went back to the kitchen. Daniel moved to the garden. John went back to the hallway. Mary moved to the office. Mary got the apple there. Sandra went to the bathroom. Mary left the apple. Mary moved to the bathroom. Mary went back to the office. Sandra travelled to the garden. Daniel journeyed to the bedroom. Daniel got the football there. Daniel went to the hallway. John went back to the kitchen. Daniel moved to the garden.
|
babilong_0k_qa2_sample_59
| 167 | 669 |
|
323 |
Write a function to re-arrange the given array in alternating positive and negative items.
|
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([-5, -2, 5, 2, 4,\t7, 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]"
] |
[] |
Mary journeyed to the bathroom. Sandra went to the garden. Daniel went back to the garden. Daniel went to the office. Sandra grabbed the milk there. Sandra put down the milk there. Daniel went to the hallway. Sandra got the milk there. Daniel went to the garden. Daniel journeyed to the kitchen. Daniel journeyed to the bedroom. Mary journeyed to the garden. Daniel took the football there. Mary moved to the office. Sandra travelled to the bedroom. Daniel dropped the football. Sandra left the milk there. Daniel grabbed the football there. Sandra grabbed the milk there. Daniel went to the kitchen.
|
babilong_0k_qa2_sample_0
| 126 | 673 |
|
74 |
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():
sdict[patterns[i]] = []
keys = sdict[patterns[i]]
keys.append(colors[i])
sdict[patterns[i]] = keys
if len(pset) != len(sset):
return False
for values in sdict.values():
for i in range(len(values) - 1):
if values[i] != values[i+1]:
return False
return True
|
[
"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 "
] |
[] |
Mary travelled to the bathroom. Daniel went back to the hallway. Sandra went back to the office. Sandra went back to the hallway. John went back to the bathroom. Daniel went to the kitchen. John moved to the kitchen. Daniel went to the bedroom. Sandra journeyed to the kitchen. John moved to the bedroom.
|
babilong_0k_qa1_sample_22
| 66 | 675 |
|
342 |
Write a function to find the smallest range that includes at-least one element from each of the given arrays.
|
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, 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)"
] |
[] |
Mary moved to the bedroom. Daniel grabbed the milk. John went back to the office. John went to the hallway. John picked up the apple. Daniel journeyed to the bathroom. John put down the apple. Mary moved to the kitchen. Daniel put down the milk there. Daniel travelled to the kitchen. John journeyed to the kitchen. Sandra travelled to the bedroom. Mary went to the bedroom. John journeyed to the bathroom. Daniel went to the garden. John grabbed the milk there. John went back to the kitchen. Mary went back to the bathroom. Mary went back to the hallway. Mary moved to the garden. Mary journeyed to the hallway. Mary went to the garden. Daniel went to the kitchen. John discarded the milk there. Daniel went back to the hallway. Mary went to the kitchen. Mary picked up the milk. Sandra travelled to the office. John travelled to the bedroom. John moved to the office. Daniel grabbed the apple there. Daniel put down the apple. Mary journeyed to the garden. Mary went to the office. Mary put down the milk. Daniel got the apple. Daniel discarded the apple. Daniel picked up the apple. Mary grabbed the football. Mary journeyed to the garden. John travelled to the bathroom. Daniel went back to the bathroom. Mary dropped the football there. Sandra moved to the kitchen. Sandra went back to the garden. Mary picked up the football. Mary moved to the bathroom. Daniel left the apple. John moved to the hallway. Sandra went to the hallway. Mary left the football. Daniel got the football. Mary picked up the apple. Mary dropped the apple. Mary went back to the bedroom. Daniel travelled to the bedroom. Daniel left the football. Sandra moved to the garden. Mary got the football. Mary dropped the football. Mary went back to the garden. Daniel grabbed the football. Sandra went to the bathroom. Daniel put down the football. John moved to the kitchen. Sandra grabbed the apple. Sandra dropped the apple. Mary moved to the bathroom. Sandra took the apple. Daniel took the football. Mary moved to the kitchen. Mary travelled to the garden. Mary went to the bathroom. Daniel journeyed to the hallway. Mary went to the bedroom. Sandra journeyed to the garden. Mary went back to the bathroom. Daniel discarded the football there. Sandra journeyed to the kitchen. Daniel picked up the football. Mary went to the bedroom. Sandra left the apple. Daniel dropped the football. Sandra got the apple. Sandra put down the apple there. John moved to the garden. Daniel moved to the office. Sandra got the apple. Daniel took the milk. Sandra discarded the apple. John moved to the hallway. Sandra went back to the office. Daniel left the milk. John picked up the football. Mary travelled to the kitchen. John went to the bathroom. Mary travelled to the bathroom. John left the football. Sandra got the milk. John went to the bedroom. Daniel journeyed to the bathroom. Daniel moved to the garden. Mary picked up the football. Sandra discarded the milk. Sandra went to the bedroom. Daniel travelled to the bathroom. John went to the garden. John travelled to the kitchen. Mary moved to the office. Mary went to the kitchen. Mary picked up the apple. Sandra moved to the office. Sandra moved to the bathroom. Mary journeyed to the bedroom. Daniel journeyed to the kitchen. Mary journeyed to the bathroom. Sandra travelled to the bedroom. Daniel went back to the office. Mary moved to the hallway. John journeyed to the bathroom. Sandra went back to the kitchen. Sandra went back to the office. Daniel grabbed the milk. Daniel put down the milk. Mary discarded the apple there. Daniel went to the bathroom. Sandra moved to the garden. John moved to the garden.
|
babilong_0k_qa3_sample_78
| 772 | 809 |
|
423 |
Write a function to solve gold mine problem.
|
def get_maxgold(gold, m, n):
goldTable = [[0 for i in range(n)]
for j in range(m)]
for col in range(n-1, -1, -1):
for row in range(m):
if (col == n-1):
right = 0
else:
right = goldTable[row][col+1]
if (row == 0 or col == n-1):
right_up = 0
else:
right_up = goldTable[row-1][col+1]
if (row == m-1 or col == n-1):
right_down = 0
else:
right_down = goldTable[row+1][col+1]
goldTable[row][col] = gold[row][col] + max(right, right_up, right_down)
res = goldTable[0][0]
for i in range(1, m):
res = max(res, goldTable[i][0])
return res
|
[
"assert get_maxgold([[1, 3, 1, 5],[2, 2, 4, 1],[5, 0, 2, 3],[0, 6, 1, 2]],4,4)==16",
"assert get_maxgold([[10,20],[30,40]],2,2)==70",
"assert get_maxgold([[4,9],[3,7]],2,2)==13"
] |
[] |
Jeff went back to the hallway. Fred journeyed to the bathroom. Mary moved to the hallway. Jeff went to the bedroom. Jeff went to the garden. Fred went to the garden. Jeff got the milk there. Jeff got the apple there. Jeff gave the apple to Fred. Fred gave the apple to Jeff. Jeff passed the apple to Fred. Fred handed the apple to Jeff. Jeff put down the milk. Jeff discarded the apple. Fred got the milk there. Bill went back to the kitchen. Bill grabbed the football there. Bill dropped the football there. Fred travelled to the kitchen. Fred took the football there. Jeff journeyed to the office. Bill went to the bedroom. Fred went back to the hallway. Fred passed the football to Mary.
|
babilong_0k_qa5_sample_48
| 154 | 812 |
|
170 |
Write a function to find sum of the numbers in a list between the indices of a specified range.
|
def sum_range_list(list1, m, n):
sum_range = 0
for i in range(m, n+1, 1):
sum_range += list1[i]
return sum_range
|
[
"assert sum_range_list( [2,1,5,6,8,3,4,9,10,11,8,12],8,10)==29",
"assert sum_range_list( [2,1,5,6,8,3,4,9,10,11,8,12],5,7)==16",
"assert sum_range_list( [2,1,5,6,8,3,4,9,10,11,8,12],7,10)==38"
] |
[] |
Mary travelled to the office. Daniel went to the bathroom. John went back to the bedroom. John went to the hallway. Mary journeyed to the bathroom. Sandra picked up the apple there. John moved to the bathroom. John got the milk there. Daniel moved to the bedroom. John moved to the garden. Sandra put down the apple. John got the football there. Sandra journeyed to the office. Daniel picked up the apple there. Mary journeyed to the kitchen. Daniel left the apple there. Daniel got the apple there. John went back to the bathroom. Daniel put down the apple. John moved to the garden.
|
babilong_0k_qa2_sample_51
| 128 | 910 |
|
493 |
Write a function to calculate a grid of hexagon coordinates where function returns a list of lists containing 6 tuples of x, y point coordinates.
|
import math
def calculate_polygons(startx, starty, endx, endy, radius):
sl = (2 * radius) * math.tan(math.pi / 6)
p = sl * 0.5
b = sl * math.cos(math.radians(30))
w = b * 2
h = 2 * sl
startx = startx - w
starty = starty - h
endx = endx + w
endy = endy + h
origx = startx
origy = starty
xoffset = b
yoffset = 3 * p
polygons = []
row = 1
counter = 0
while starty < endy:
if row % 2 == 0:
startx = origx + xoffset
else:
startx = origx
while startx < endx:
p1x = startx
p1y = starty + p
p2x = startx
p2y = starty + (3 * p)
p3x = startx + b
p3y = starty + h
p4x = startx + w
p4y = starty + (3 * p)
p5x = startx + w
p5y = starty + p
p6x = startx + b
p6y = starty
poly = [
(p1x, p1y),
(p2x, p2y),
(p3x, p3y),
(p4x, p4y),
(p5x, p5y),
(p6x, p6y),
(p1x, p1y)]
polygons.append(poly)
counter += 1
startx += w
starty += yoffset
row += 1
return polygons
|
[
"assert calculate_polygons(1,1, 4, 4, 3)==[[(-5.0, -4.196152422706632), (-5.0, -0.7320508075688767), (-2.0, 1.0), (1.0, -0.7320508075688767), (1.0, -4.196152422706632), (-2.0, -5.928203230275509), (-5.0, -4.196152422706632)], [(1.0, -4.196152422706632), (1.0, -0.7320508075688767), (4.0, 1.0), (7.0, -0.7320508075688767), (7.0, -4.196152422706632), (4.0, -5.928203230275509), (1.0, -4.196152422706632)], [(7.0, -4.196152422706632), (7.0, -0.7320508075688767), (10.0, 1.0), (13.0, -0.7320508075688767), (13.0, -4.196152422706632), (10.0, -5.928203230275509), (7.0, -4.196152422706632)], [(-2.0, 1.0000000000000004), (-2.0, 4.464101615137755), (1.0, 6.196152422706632), (4.0, 4.464101615137755), (4.0, 1.0000000000000004), (1.0, -0.7320508075688767), (-2.0, 1.0000000000000004)], [(4.0, 1.0000000000000004), (4.0, 4.464101615137755), (7.0, 6.196152422706632), (10.0, 4.464101615137755), (10.0, 1.0000000000000004), (7.0, -0.7320508075688767), (4.0, 1.0000000000000004)], [(-5.0, 6.196152422706632), (-5.0, 9.660254037844387), (-2.0, 11.392304845413264), (1.0, 9.660254037844387), (1.0, 6.196152422706632), (-2.0, 4.464101615137755), (-5.0, 6.196152422706632)], [(1.0, 6.196152422706632), (1.0, 9.660254037844387), (4.0, 11.392304845413264), (7.0, 9.660254037844387), (7.0, 6.196152422706632), (4.0, 4.464101615137755), (1.0, 6.196152422706632)], [(7.0, 6.196152422706632), (7.0, 9.660254037844387), (10.0, 11.392304845413264), (13.0, 9.660254037844387), (13.0, 6.196152422706632), (10.0, 4.464101615137755), (7.0, 6.196152422706632)], [(-2.0, 11.392304845413264), (-2.0, 14.85640646055102), (1.0, 16.588457268119896), (4.0, 14.85640646055102), (4.0, 11.392304845413264), (1.0, 9.660254037844387), (-2.0, 11.392304845413264)], [(4.0, 11.392304845413264), (4.0, 14.85640646055102), (7.0, 16.588457268119896), (10.0, 14.85640646055102), (10.0, 11.392304845413264), (7.0, 9.660254037844387), (4.0, 11.392304845413264)]]",
"assert calculate_polygons(5,4,7,9,8)==[[(-11.0, -9.856406460551018), (-11.0, -0.6188021535170058), (-3.0, 4.0), (5.0, -0.6188021535170058), (5.0, -9.856406460551018), (-3.0, -14.475208614068023), (-11.0, -9.856406460551018)], [(5.0, -9.856406460551018), (5.0, -0.6188021535170058), (13.0, 4.0), (21.0, -0.6188021535170058), (21.0, -9.856406460551018), (13.0, -14.475208614068023), (5.0, -9.856406460551018)], [(21.0, -9.856406460551018), (21.0, -0.6188021535170058), (29.0, 4.0), (37.0, -0.6188021535170058), (37.0, -9.856406460551018), (29.0, -14.475208614068023), (21.0, -9.856406460551018)], [(-3.0, 4.0), (-3.0, 13.237604307034012), (5.0, 17.856406460551018), (13.0, 13.237604307034012), (13.0, 4.0), (5.0, -0.6188021535170058), (-3.0, 4.0)], [(13.0, 4.0), (13.0, 13.237604307034012), (21.0, 17.856406460551018), (29.0, 13.237604307034012), (29.0, 4.0), (21.0, -0.6188021535170058), (13.0, 4.0)], [(-11.0, 17.856406460551018), (-11.0, 27.09401076758503), (-3.0, 31.712812921102035), (5.0, 27.09401076758503), (5.0, 17.856406460551018), (-3.0, 13.237604307034012), (-11.0, 17.856406460551018)], [(5.0, 17.856406460551018), (5.0, 27.09401076758503), (13.0, 31.712812921102035), (21.0, 27.09401076758503), (21.0, 17.856406460551018), (13.0, 13.237604307034012), (5.0, 17.856406460551018)], [(21.0, 17.856406460551018), (21.0, 27.09401076758503), (29.0, 31.712812921102035), (37.0, 27.09401076758503), (37.0, 17.856406460551018), (29.0, 13.237604307034012), (21.0, 17.856406460551018)], [(-3.0, 31.712812921102035), (-3.0, 40.95041722813605), (5.0, 45.569219381653056), (13.0, 40.95041722813605), (13.0, 31.712812921102035), (5.0, 27.09401076758503), (-3.0, 31.712812921102035)], [(13.0, 31.712812921102035), (13.0, 40.95041722813605), (21.0, 45.569219381653056), (29.0, 40.95041722813605), (29.0, 31.712812921102035), (21.0, 27.09401076758503), (13.0, 31.712812921102035)]]",
"assert calculate_polygons(9,6,4,3,2)==[[(5.0, 2.5358983848622456), (5.0, 4.8452994616207485), (7.0, 6.0), (9.0, 4.8452994616207485), (9.0, 2.5358983848622456), (7.0, 1.3811978464829942), (5.0, 2.5358983848622456)], [(7.0, 6.0), (7.0, 8.309401076758503), (9.0, 9.464101615137753), (11.0, 8.309401076758503), (11.0, 6.0), (9.0, 4.8452994616207485), (7.0, 6.0)]]"
] |
[] |
John moved to the kitchen. Daniel picked up the football. John journeyed to the garden. Mary moved to the bedroom. Mary went back to the garden. Sandra travelled to the hallway. Daniel left the football. Daniel took the football there. Sandra got the apple. John moved to the bedroom. Sandra took the milk. John moved to the kitchen. John went back to the office. Daniel journeyed to the garden. Mary travelled to the hallway. John went to the hallway. Daniel dropped the football. Mary went back to the kitchen. Mary moved to the garden. Sandra discarded the milk there. Mary took the football there. Sandra put down the apple. John journeyed to the garden. Sandra went back to the bathroom. John travelled to the bedroom. Mary dropped the football. Daniel got the football. Mary moved to the hallway. Mary journeyed to the bathroom. John went back to the hallway. Daniel dropped the football there. Sandra moved to the kitchen. Daniel travelled to the hallway. Daniel took the milk. Mary travelled to the kitchen. Daniel put down the milk. Daniel went back to the office. Daniel went to the garden. Sandra journeyed to the office. John grabbed the milk there. Daniel travelled to the office. John took the apple. Daniel moved to the hallway. John journeyed to the garden. Daniel went back to the kitchen. John moved to the bathroom. Daniel travelled to the garden. Daniel travelled to the hallway. John went back to the kitchen. John put down the apple.
|
babilong_0k_qa3_sample_45
| 307 | 1,331 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.