qid int64 602 974 | title stringclasses 332
values | language stringclasses 16
values | text stringlengths 38 251 | signature_with_docstring stringlengths 61 354 | signature stringlengths 8 162 | arguments stringclasses 150
values | solution stringclasses 332
values | question_info stringlengths 1.14k 4.26k |
|---|---|---|---|---|---|---|---|---|
602 | MBPP/602 | C++ | Write a c++ function to find the first repeated character in a given string. | /**
* Write a c++ function to find the first repeated character in a given string.
*/
string firstRepeatedChar(string str1) { | string firstRepeatedChar(string str1) { | ['str1'] | def first_repeated_char(str1):
for index,c in enumerate(str1):
if str1[:index+1].count(c) > 1:
return c
return "None" | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'firstRepeatedChar', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\... |
603 | MBPP/603 | C++ | Write a function to get a lucid number smaller than or equal to n. | /**
* Write a function to get a lucid number smaller than or equal to n.
*/
vector<int> getLudic(int n) { | vector<int> getLudic(int n) { | ['n'] | def get_ludic(n):
ludics = []
for i in range(1, n + 1):
ludics.append(i)
index = 1
while(index != len(ludics)):
first_ludic = ludics[index]
remove_index = index + first_ludic
while(remove_index < len(ludics)):
ludics.remove(ludics[remove_index])
remove_index = remove_index + first_ludic - 1
... | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'getLudic', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include... |
604 | MBPP/604 | C++ | Write a function to reverse words in a given string. | /**
* Write a function to reverse words in a given string.
*/
string reverseWords(string s) { | string reverseWords(string s) { | ['s'] | def reverse_words(s):
return ' '.join(reversed(s.split())) | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'reverseWords', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#inc... |
605 | MBPP/605 | C++ | Write a function to check if the given integer is a prime number. | /**
* Write a function to check if the given integer is a prime number.
*/
bool primeNum(int num) { | bool primeNum(int num) { | ['num'] | def prime_num(num):
if num >=1:
for i in range(2, num//2):
if (num % i) == 0:
return False
else:
return True
else:
return False | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'primeNum', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include... |
606 | MBPP/606 | C++ | Write a function to convert degrees to radians. | /**
* Write a function to convert degrees to radians.
*/
double radianDegree(int degree) { | double radianDegree(int degree) { | ['degree'] | import math
def radian_degree(degree):
radian = degree*(math.pi/180)
return radian | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'radianDegree', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#inc... |
608 | MBPP/608 | C++ | Write a c++ function to find nth bell number. | /**
* Write a c++ function to find nth bell number.
*/
int bellNumber(int n) { | int bellNumber(int n) { | ['n'] | 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] | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'bellNumber', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#inclu... |
609 | MBPP/609 | C++ | Write a c++ function to find minimum possible value for the given periodic function. | /**
* Write a c++ function to find minimum possible value for the given periodic function.
*/
int floorMin(int a, int b, int n) { | int floorMin(int a, int b, int n) { | ['a', 'b', 'n'] | def floor_Min(A,B,N):
x = max(B - 1,N)
return (A*x) // B | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'floorMin', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include... |
610 | MBPP/610 | C++ | Write a c++ function to remove the k'th element from a given vector. | /**
* Write a c++ function to remove the k'th element from a given vector.
*/
vector<int> removeKthElement(vector<int> list1, int l) { | vector<int> removeKthElement(vector<int> list1, int l) { | ['list1', 'l'] | def remove_kth_element(list1, L):
return list1[:L-1] + list1[L:] | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'removeKthElement', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n... |
611 | MBPP/611 | C++ | Write a function to find the maximum of nth column from the given tuple vector. | /**
* Write a function to find the maximum of nth column from the given tuple vector.
*/
int maxOfNth(vector<vector<int>> test_list, int n) { | int maxOfNth(vector<vector<int>> test_list, int n) { | ['test_list', 'n'] | def max_of_nth(test_list, N):
res = max([sub[N] for sub in test_list])
return (res) | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'maxOfNth', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include... |
614 | MBPP/614 | C++ | Write a function to find the cumulative sum of all the values that are present in the given tuple vector. | /**
* Write a function to find the cumulative sum of all the values that are present in the given tuple vector.
*/
int cummulativeSum(vector<vector<int>> test_list) { | int cummulativeSum(vector<vector<int>> test_list) { | ['test_list'] | def cummulative_sum(test_list):
res = sum(map(sum, test_list))
return (res) | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'cummulativeSum', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#i... |
615 | MBPP/615 | C++ | Write a function to find average value of the numbers in a given tuple of tuples. | /**
* Write a function to find average value of the numbers in a given tuple of tuples.
*/
vector<float> averageTuple(vector<vector<int>> nums) { | vector<float> averageTuple(vector<vector<int>> nums) { | ['nums'] | def average_tuple(nums):
result = [sum(x) / len(x) for x in zip(*nums)]
return result | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'averageTuple', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#inc... |
616 | MBPP/616 | C++ | Write a function to perfom the modulo of tuple elements in the given two tuples. | /**
* Write a function to perfom the modulo of tuple elements in the given two tuples.
*/
vector<int> tupleModulo(vector<int> test_tup1, vector<int> test_tup2) { | vector<int> tupleModulo(vector<int> test_tup1, vector<int> test_tup2) { | ['test_tup1', 'test_tup2'] | def tuple_modulo(test_tup1, test_tup2):
res = tuple(ele1 % ele2 for ele1, ele2 in zip(test_tup1, test_tup2))
return (res) | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'tupleModulo', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#incl... |
617 | MBPP/617 | C++ | Write a function to check for the number of jumps required of given length to reach a point of form (d, 0) from origin in a 2d plane. | /**
* Write a function to check for the number of jumps required of given length to reach a point of form (d, 0) from origin in a 2d plane.
*/
float minJumps(int a, int b, int d) { | float minJumps(int a, int b, int d) { | ['a', 'b', 'd'] | def min_Jumps(a, b, d):
temp = a
a = min(a, b)
b = max(temp, b)
if (d >= b):
return (d + b - 1) / b
if (d == 0):
return 0
if (d == a):
return 1
else:
return 2 | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'minJumps', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include... |
618 | MBPP/618 | C++ | Write a function to divide two vectors using map and lambda function. | /**
* Write a function to divide two vectors using map and lambda function.
*/
vector<double> divList(vector<int> nums1, vector<int> nums2) { | vector<double> divList(vector<int> nums1, vector<int> nums2) { | ['nums1', 'nums2'] | def div_list(nums1,nums2):
result = map(lambda x, y: x / y, nums1, nums2)
return list(result) | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'divList', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include ... |
619 | MBPP/619 | C++ | Write a function to move all the numbers in it to the given string. | /**
* Write a function to move all the numbers in it to the given string.
*/
string moveNum(string test_str) { | string moveNum(string test_str) { | ['test_str'] | def move_num(test_str):
res = ''
dig = ''
for ele in test_str:
if ele.isdigit():
dig += ele
else:
res += ele
res += dig
return (res) | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'moveNum', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include ... |
620 | MBPP/620 | C++ | Write a function to find the largest subset where each pair is divisible. | /**
* Write a function to find the largest subset where each pair is divisible.
*/
int largestSubset(vector<int> a, int n) { | int largestSubset(vector<int> a, int n) { | ['a', 'n'] | def largest_subset(a, n):
dp = [0 for i in range(n)]
dp[n - 1] = 1;
for i in range(n - 2, -1, -1):
mxm = 0;
for j in range(i + 1, n):
if a[j] % a[i] == 0 or a[i] % a[j] == 0:
mxm = max(mxm, dp[j])
dp[i] = 1 + mxm
return max(dp) | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'largestSubset', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#in... |
621 | MBPP/621 | C++ | Write a function to increment the numeric values in the given strings by k. | /**
* Write a function to increment the numeric values in the given strings by k.
*/
vector<string> incrementNumerics(vector<string> test_list, int k) { | vector<string> incrementNumerics(vector<string> test_list, int k) { | ['test_list', 'k'] | def increment_numerics(test_list, K):
res = [str(int(ele) + K) if ele.isdigit() else ele for ele in test_list]
return res | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'incrementNumerics', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\... |
622 | MBPP/622 | C++ | Write a function to find the median of two sorted vectors of same size. | /**
* Write a function to find the median of two sorted vectors of same size.
*/
float getMedian(vector<int> arr1, vector<int> arr2, int n) { | float getMedian(vector<int> arr1, vector<int> arr2, int n) { | ['arr1', 'arr2', 'n'] | def get_median(arr1, arr2, n):
i = 0
j = 0
m1 = -1
m2 = -1
count = 0
while count < n + 1:
count += 1
if i == n:
m1 = m2
m2 = arr2[0]
break
elif j == n:
m1 = m2
m2 = arr1[0]
break
if arr1[i] <= arr2[j]:
m1 = m2
m2 = arr1[i]
... | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'getMedian', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#includ... |
623 | MBPP/623 | C++ | Write a function to find the n-th power of individual elements in vector using lambda function. | /**
* Write a function to find the n-th power of individual elements in vector using lambda function.
*/
vector<int> nthNums(vector<int> nums, int n) { | vector<int> nthNums(vector<int> nums, int n) { | ['nums', 'n'] | def nth_nums(nums,n):
nth_nums = list(map(lambda x: x ** n, nums))
return nth_nums | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'nthNums', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include ... |
624 | MBPP/624 | C++ | Write a c++ function to convert the given string to upper case. | /**
* Write a c++ function to convert the given string to upper case.
*/
string isUpper(string string_arg0) { | string isUpper(string string_arg0) { | ['string_arg0'] | def is_upper(string):
return (string.upper()) | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'isUpper', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include ... |
625 | MBPP/625 | C++ | Write a c++ function to interchange first and last elements in a given vector. | /**
* Write a c++ function to interchange first and last elements in a given vector.
*/
vector<int> swapList(vector<int> newlist) { | vector<int> swapList(vector<int> newlist) { | ['newlist'] | def swap_List(newList):
size = len(newList)
temp = newList[0]
newList[0] = newList[size - 1]
newList[size - 1] = temp
return newList | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'swapList', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include... |
626 | MBPP/626 | C++ | Write a c++ function to find the largest triangle that can be inscribed in the semicircle. | /**
* Write a c++ function to find the largest triangle that can be inscribed in the semicircle.
*/
int triangleArea(int r) { | int triangleArea(int r) { | ['r'] | def triangle_area(r) :
if r < 0 :
return -1
return r * r | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'triangleArea', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#inc... |
627 | MBPP/627 | C++ | Write a c++ function to find the smallest missing number from the given vector. | /**
* Write a c++ function to find the smallest missing number from the given vector.
*/
int findFirstMissing(vector<int> array, int start, int end_arg2) { | int findFirstMissing(vector<int> array, int start, int end_arg2) { | ['array', 'start', 'end_arg2'] | def find_First_Missing(array,start,end):
if (start > end):
return end + 1
if (start != array[start]):
return start;
mid = int((start + end) / 2)
if (array[mid] == mid):
return find_First_Missing(array,mid+1,end)
return find_First_Missing(array,start,mid) | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'findFirstMissing', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n... |
628 | MBPP/628 | C++ | Write a function to replace all spaces in the given string with character * vector item * vector item * vector item * vector item '%20'. | /**
* Write a function to replace all spaces in the given string with character * vector item * vector item * vector item * vector item '%20'.
*/
string replaceSpaces(string string_arg0) { | string replaceSpaces(string string_arg0) { | ['string_arg0'] | MAX=1000;
def replace_spaces(string):
string=string.strip()
i=len(string)
space_count=string.count(' ')
new_length = i + space_count*2
if new_length > MAX:
return -1
index = new_length-1
string=list(string)
for f in range(i-2, new_length-2):
string.append('0')
for j in range(i-1, 0... | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'replaceSpaces', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#in... |
629 | MBPP/629 | C++ | Write a c++ function to find even numbers from a mixed vector. | /**
* Write a c++ function to find even numbers from a mixed vector.
*/
vector<int> split(vector<int> list) { | vector<int> split(vector<int> list) { | ['list'] | def Split(list):
ev_li = []
for i in list:
if (i % 2 == 0):
ev_li.append(i)
return ev_li | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'split', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <c... |
630 | MBPP/630 | C++ | Write a function to extract all the adjacent coordinates of the given coordinate tuple. | /**
* Write a function to extract all the adjacent coordinates of the given coordinate tuple.
*/
vector<vector<int>> getCoordinates(vector<int> test_tup) { | vector<vector<int>> getCoordinates(vector<int> test_tup) { | ['test_tup'] | def adjac(ele, sub = []):
if not ele:
yield sub
else:
yield from [idx for j in range(ele[0] - 1, ele[0] + 2)
for idx in adjac(ele[1:], sub + [j])]
def get_coordinates(test_tup):
res = list(adjac(test_tup))
return (res) | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'getCoordinates', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#i... |
631 | MBPP/631 | C++ | Write a function to replace whitespaces with an underscore and vice versa in a given string by using regex. | /**
* Write a function to replace whitespaces with an underscore and vice versa in a given string by using regex.
*/
string replaceSpaces(string text) { | string replaceSpaces(string text) { | ['text'] | import re
text = 'Python Exercises'
def replace_spaces(text):
text =text.replace (" ", "_")
return (text)
text =text.replace ("_", " ")
return (text) | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'replaceSpaces', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#in... |
632 | MBPP/632 | C++ | Write a c++ function to move all zeroes to the end of the given vector. | /**
* Write a c++ function to move all zeroes to the end of the given vector.
*/
vector<int> moveZero(vector<int> num_list) { | vector<int> moveZero(vector<int> num_list) { | ['num_list'] | def move_zero(num_list):
a = [0 for i in range(num_list.count(0))]
x = [ i for i in num_list if i != 0]
x.extend(a)
return (x) | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'moveZero', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include... |
633 | MBPP/633 | C++ | Write a c++ function to find the sum of xor of all pairs of numbers in the given vector. | /**
* Write a c++ function to find the sum of xor of all pairs of numbers in the given vector.
*/
int pairOrSum(vector<int> arr, int n) { | int pairOrSum(vector<int> arr, int n) { | ['arr', 'n'] | def pair_OR_Sum(arr,n) :
ans = 0
for i in range(0,n) :
for j in range(i + 1,n) :
ans = ans + (arr[i] ^ arr[j])
return ans | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'pairOrSum', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#includ... |
634 | MBPP/634 | C++ | Write a c++ function to find the sum of fourth power of first n even natural numbers. | /**
* Write a c++ function to find the sum of fourth power of first n even natural numbers.
*/
int evenPowerSum(int n) { | int evenPowerSum(int n) { | ['n'] | def even_Power_Sum(n):
sum = 0;
for i in range(1,n + 1):
j = 2*i;
sum = sum + (j*j*j*j);
return sum; | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'evenPowerSum', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#inc... |
635 | MBPP/635 | C++ | Write a function to push all values into a heap and then pop off the smallest values one at a time. | /**
* Write a function to push all values into a heap and then pop off the smallest values one at a time.
*/
vector<int> heapSort(vector<int> iterable) { | vector<int> heapSort(vector<int> iterable) { | ['iterable'] | import heapq as hq
def heap_sort(iterable):
h = []
for value in iterable:
hq.heappush(h, value)
return [hq.heappop(h) for i in range(len(h))] | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'heapSort', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include... |
636 | MBPP/636 | C++ | Write a c++ function to check if roots of a quadratic equation are reciprocal of each other or not. | /**
* Write a c++ function to check if roots of a quadratic equation are reciprocal of each other or not.
*/
string checkSolution(int a, int b, int c) { | string checkSolution(int a, int b, int c) { | ['a', 'b', 'c'] | def Check_Solution(a,b,c):
if (a == c):
return ("Yes");
else:
return ("No"); | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'checkSolution', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#in... |
637 | MBPP/637 | C++ | Write a function to check whether the given amount has no profit and no loss | /**
* Write a function to check whether the given amount has no profit and no loss
*/
bool noprofitNoloss(int actual_cost, int sale_amount) { | bool noprofitNoloss(int actual_cost, int sale_amount) { | ['actual_cost', 'sale_amount'] | def noprofit_noloss(actual_cost,sale_amount):
if(sale_amount == actual_cost):
return True
else:
return False | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'noprofitNoloss', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#i... |
638 | MBPP/638 | C++ | Write a function to calculate wind chill index. | /**
* Write a function to calculate wind chill index.
*/
int windChill(int v, int t) { | int windChill(int v, int t) { | ['v', 't'] | import math
def wind_chill(v,t):
windchill = 13.12 + 0.6215*t - 11.37*math.pow(v, 0.16) + 0.3965*t*math.pow(v, 0.16)
return int(round(windchill, 0)) | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'windChill', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#includ... |
639 | MBPP/639 | C++ | Write a function to sum the length of the names of a given vector of names after removing the names that start with a lowercase letter. | /**
* Write a function to sum the length of the names of a given vector of names after removing the names that start with a lowercase letter.
*/
int sampleNam(vector<string> sample_names) { | int sampleNam(vector<string> sample_names) { | ['sample_names'] | def sample_nam(sample_names):
sample_names=list(filter(lambda el:el[0].isupper() and el[1:].islower(),sample_names))
return len(''.join(sample_names)) | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'sampleNam', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#includ... |
640 | MBPP/640 | C++ | Write a function to remove the parenthesis area in a string. | /**
* Write a function to remove the parenthesis area in a string.
*/
string removeParenthesis(vector<string> items) { | string removeParenthesis(vector<string> items) { | ['items'] | import re
def remove_parenthesis(items):
for item in items:
return (re.sub(r" ?\([^)]+\)", "", item)) | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'removeParenthesis', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\... |
641 | MBPP/641 | C++ | Write a function to find the nth nonagonal number. | /**
* Write a function to find the nth nonagonal number.
*/
int isNonagonal(int n) { | int isNonagonal(int n) { | ['n'] | def is_nonagonal(n):
return int(n * (7 * n - 5) / 2) | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'isNonagonal', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#incl... |
643 | MBPP/643 | C++ | Write a function that matches a word containing 'z', not at the start or end of the word. | /**
* Write a function that matches a word containing 'z', not at the start or end of the word.
*/
string textMatchWordzMiddle(string text) { | string textMatchWordzMiddle(string text) { | ['text'] | import re
def text_match_wordz_middle(text):
patterns = '\Bz\B'
if re.search(patterns, text):
return 'Found a match!'
else:
return('Not matched!') | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'textMatchWordzMiddle', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.... |
644 | MBPP/644 | C++ | Write a c++ function to reverse vector upto a given position. | /**
* Write a c++ function to reverse vector upto a given position.
*/
vector<int> reverseArrayUptoK(vector<int> input, int k) { | vector<int> reverseArrayUptoK(vector<int> input, int k) { | ['input', 'k'] | def reverse_Array_Upto_K(input, k):
return (input[k-1::-1] + input[k:]) | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'reverseArrayUptoK', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\... |
645 | MBPP/645 | C++ | Write a function to find the product of it’s kth index in the given tuples. | /**
* Write a function to find the product of it’s kth index in the given tuples.
*/
int findKProduct(vector<vector<int>> test_list, int k) { | int findKProduct(vector<vector<int>> test_list, int k) { | ['test_list', 'k'] | def get_product(val) :
res = 1
for ele in val:
res *= ele
return res
def find_k_product(test_list, K):
res = get_product([sub[K] for sub in test_list])
return (res) | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'findKProduct', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#inc... |
646 | MBPP/646 | C++ | Write a c++ function to count number of cubes of size k in a cube of size n. | /**
* Write a c++ function to count number of cubes of size k in a cube of size n.
*/
int noOfCubes(int n, int k) { | int noOfCubes(int n, int k) { | ['n', 'k'] | def No_of_cubes(N,K):
No = 0
No = (N - K + 1)
No = pow(No, 3)
return No | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'noOfCubes', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#includ... |
647 | MBPP/647 | C++ | Write a function to split a string at uppercase letters. | /**
* Write a function to split a string at uppercase letters.
*/
vector<string> splitUpperstring(string text) { | vector<string> splitUpperstring(string text) { | ['text'] | import re
def split_upperstring(text):
return (re.findall('[A-Z][^A-Z]*', text)) | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'splitUpperstring', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n... |
648 | MBPP/648 | C++ | Write a function to exchange the position of every n-th value with (n+1)th value and (n+1)th value with n-th value in a given vector. | /**
* Write a function to exchange the position of every n-th value with (n+1)th value and (n+1)th value with n-th value in a given vector.
*/
vector<int> exchangeElements(vector<int> lst) { | vector<int> exchangeElements(vector<int> lst) { | ['lst'] | from itertools import zip_longest, chain, tee
def exchange_elements(lst):
lst1, lst2 = tee(iter(lst), 2)
return list(chain.from_iterable(zip_longest(lst[1::2], lst[::2]))) | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'exchangeElements', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n... |
649 | MBPP/649 | C++ | Write a c++ function to calculate the sum of the numbers in vector between the indices of a specified range. | /**
* Write a c++ function to calculate the sum of the numbers in vector between the indices of a specified range.
*/
int sumRangeList(vector<int> nums, int m, int n) { | int sumRangeList(vector<int> nums, int m, int n) { | ['nums', 'm', 'n'] | def sum_Range_list(nums, m, n):
sum_range = 0 ... | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'sumRangeList', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#inc... |
650 | MBPP/650 | C++ | Write a c++ function to check whether the given two vectors are equal or not. | /**
* Write a c++ function to check whether the given two vectors are equal or not.
*/
bool areEqual(vector<int> arr1, vector<int> arr2, int n, int m) { | bool areEqual(vector<int> arr1, vector<int> arr2, int n, int m) { | ['arr1', 'arr2', 'n', 'm'] | def are_Equal(arr1,arr2,n,m):
if (n != m):
return False
arr1.sort()
arr2.sort()
for i in range(0,n - 1):
if (arr1[i] != arr2[i]):
return False
return True | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'areEqual', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include... |
651 | MBPP/651 | C++ | Write a function to check if one tuple is a subset of another tuple. | /**
* Write a function to check if one tuple is a subset of another tuple.
*/
bool checkSubset(vector<int> test_tup1, vector<int> test_tup2) { | bool checkSubset(vector<int> test_tup1, vector<int> test_tup2) { | ['test_tup1', 'test_tup2'] | def check_subset(test_tup1, test_tup2):
res = set(test_tup2).issubset(test_tup1)
return (res) | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'checkSubset', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#incl... |
652 | MBPP/652 | C++ | Write a function to flatten the given tuple matrix into the tuple vector with each tuple representing each column. | /**
* Write a function to flatten the given tuple matrix into the tuple vector with each tuple representing each column.
*/
string matrixToList(vector<vector<vector<int>>> test_list) { | string matrixToList(vector<vector<vector<int>>> test_list) { | ['test_list'] | def matrix_to_list(test_list):
temp = [ele for sub in test_list for ele in sub]
res = list(zip(*temp))
return (str(res)) | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'matrixToList', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#inc... |
654 | MBPP/654 | C++ | Write a function to find the perimeter of a rectangle. | /**
* Write a function to find the perimeter of a rectangle.
*/
int rectanglePerimeter(int l, int b) { | int rectanglePerimeter(int l, int b) { | ['l', 'b'] | def rectangle_perimeter(l,b):
perimeter=2*(l+b)
return perimeter | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'rectanglePerimeter', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>... |
655 | MBPP/655 | C++ | Write a c++ function to find the sum of fifth power of n natural numbers. | /**
* Write a c++ function to find the sum of fifth power of n natural numbers.
*/
int fifthPowerSum(int n) { | int fifthPowerSum(int n) { | ['n'] | def fifth_Power_Sum(n) :
sm = 0
for i in range(1,n+1) :
sm = sm + (i*i*i*i*i)
return sm | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'fifthPowerSum', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#in... |
656 | MBPP/656 | C++ | Write a c++ function to find the minimum sum of absolute differences of two vectors. | /**
* Write a c++ function to find the minimum sum of absolute differences of two vectors.
*/
int findMinSum(vector<int> a, vector<int> b, int n) { | int findMinSum(vector<int> a, vector<int> b, int n) { | ['a', 'b', 'n'] | def find_Min_Sum(a,b,n):
a.sort()
b.sort()
sum = 0
for i in range(n):
sum = sum + abs(a[i] - b[i])
return sum | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'findMinSum', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#inclu... |
657 | MBPP/657 | C++ | Write a c++ function to find the first digit in factorial of a given number. | /**
* Write a c++ function to find the first digit in factorial of a given number.
*/
int firstDigit(int n) { | int firstDigit(int n) { | ['n'] | import math
def first_Digit(n) :
fact = 1
for i in range(2,n + 1) :
fact = fact * i
while (fact % 10 == 0) :
fact = int(fact / 10)
while (fact >= 10) :
fact = int(fact / 10)
return math.floor(fact) | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'firstDigit', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#inclu... |
658 | MBPP/658 | C++ | Write a function to find the item with maximum occurrences in a given vector. | /**
* Write a function to find the item with maximum occurrences in a given vector.
*/
int maxOccurrences(vector<int> list1) { | int maxOccurrences(vector<int> list1) { | ['list1'] | def max_occurrences(list1):
max_val = 0
result = list1[0]
for i in list1:
occu = list1.count(i)
if occu > max_val:
max_val = occu
result = i
return result | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'maxOccurrences', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#i... |
659 | MBPP/659 | C++ | Write a c++ function to print duplicants from vector of integers. | /**
* Write a c++ function to print duplicants from vector of integers.
*/
vector<int> repeat(vector<int> x) { | vector<int> repeat(vector<int> x) { | ['x'] | def Repeat(x):
_size = len(x)
repeated = []
for i in range(_size):
k = i + 1
for j in range(k, _size):
if x[i] == x[j] and x[i] not in repeated:
repeated.append(x[i])
return repeated | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'repeat', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <... |
660 | MBPP/660 | C++ | Write a c++ function to choose points from two ranges such that no point lies in both the ranges. | /**
* Write a c++ function to choose points from two ranges such that no point lies in both the ranges.
*/
vector<int> findPoints(int l1, int r1, int l2, int r2) { | vector<int> findPoints(int l1, int r1, int l2, int r2) { | ['l1', 'r1', 'l2', 'r2'] | def find_Points(l1,r1,l2,r2):
x = min(l1,l2) if (l1 != l2) else -1
y = max(r1,r2) if (r1 != r2) else -1
return (x,y) | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'findPoints', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#inclu... |
661 | MBPP/661 | C++ | Write a function to find the maximum sum that can be formed which has no three consecutive elements present. | /**
* Write a function to find the maximum sum that can be formed which has no three consecutive elements present.
*/
int maxSumOfThreeConsecutive(vector<int> arr, int n) { | int maxSumOfThreeConsecutive(vector<int> arr, int n) { | ['arr', 'n'] | def max_sum_of_three_consecutive(arr, n):
sum = [0 for k in range(n)]
if n >= 1:
sum[0] = arr[0]
if n >= 2:
sum[1] = arr[0] + arr[1]
if n > 2:
sum[2] = max(sum[1], max(arr[1] + arr[2], arr[0] + arr[2]))
for i in range(3, n):
sum[i] = max(max(sum[i-1], sum[i-2] + arr[i]), arr[i] + arr[i-1]... | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'maxSumOfThreeConsecutive', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <m... |
662 | MBPP/662 | C++ | Write a function to sort vector in map. | /**
* Write a function to sort vector in map.
*/
map<string,vector<int>> sortedDict(map<string,vector<int>> dict1) { | map<string,vector<int>> sortedDict(map<string,vector<int>> dict1) { | ['dict1'] | def sorted_dict(dict1):
sorted_dict = {x: sorted(y) for x, y in dict1.items()}
return sorted_dict | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'sortedDict', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#inclu... |
663 | MBPP/663 | C++ | Write a function to find the largest possible value of k such that k modulo x is y. | /**
* Write a function to find the largest possible value of k such that k modulo x is y.
*/
int findMaxVal(int n, int x, int y) { | int findMaxVal(int n, int x, int y) { | ['n', 'x', 'y'] | import sys
def find_max_val(n, x, y):
ans = -sys.maxsize
for k in range(n + 1):
if (k % x == y):
ans = max(ans, k)
return (ans if (ans >= 0 and
ans <= n) else -1) | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'findMaxVal', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#inclu... |
664 | MBPP/664 | C++ | Write a c++ function to find the average of even numbers till a given even number. | /**
* Write a c++ function to find the average of even numbers till a given even number.
*/
int averageEven(int n) { | int averageEven(int n) { | ['n'] | def average_Even(n) :
if (n% 2!= 0) :
return ("Invalid Input")
return -1
sm = 0
count = 0
while (n>= 2) :
count = count+1
sm = sm+n
n = n-2
return sm // count | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'averageEven', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#incl... |
665 | MBPP/665 | C++ | Write a c++ function to shift first element to the end of given vector. | /**
* Write a c++ function to shift first element to the end of given vector.
*/
vector<int> moveLast(vector<int> num_list) { | vector<int> moveLast(vector<int> num_list) { | ['num_list'] | def move_last(num_list):
a = [num_list[0] for i in range(num_list.count(num_list[0]))]
x = [ i for i in num_list if i != num_list[0]]
x.extend(a)
return (x) | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'moveLast', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include... |
666 | MBPP/666 | C++ | Write a function to count occurrence of a character in a string. | /**
* Write a function to count occurrence of a character in a string.
*/
int countChar(string string_arg0, char char_arg1) { | int countChar(string string_arg0, char char_arg1) { | ['string_arg0', 'char_arg1'] | def count_char(string,char):
count = 0
for i in range(len(string)):
if(string[i] == char):
count = count + 1
return count | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'countChar', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#includ... |
667 | MBPP/667 | C++ | Write a c++ function to count number of vowels in the string. | /**
* Write a c++ function to count number of vowels in the string.
*/
int checkVow(string string_arg0, string vowels) { | int checkVow(string string_arg0, string vowels) { | ['string_arg0', 'vowels'] | def Check_Vow(string, vowels):
final = [each for each in string if each in vowels]
return(len(final))
| {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'checkVow', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include... |
668 | MBPP/668 | C++ | Write a c++ function to replace multiple occurence of character by single. | /**
* Write a c++ function to replace multiple occurence of character by single.
*/
string replace(string string_arg0, char char_arg1) { | string replace(string string_arg0, char char_arg1) { | ['string_arg0', 'char_arg1'] | import re
def replace(string, char):
pattern = char + '{2,}'
string = re.sub(pattern, char, string)
return string | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'replace', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include ... |
669 | MBPP/669 | C++ | Write a function to check whether the given ip address is valid or not using regex. | /**
* Write a function to check whether the given ip address is valid or not using regex.
*/
string checkIp(string ip) { | string checkIp(string ip) { | ['ip'] | import re
regex = '''^(25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?)\.(
25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?)\.(
25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?)\.(
25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?)$'''
def check_IP(Ip):
if(re.search(regex, Ip)):
return ("Valid IP address")
else:
return ("Invalid I... | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'checkIp', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include ... |
670 | MBPP/670 | C++ | Write a c++ function to check whether a sequence of numbers has a decreasing trend or not. | /**
* Write a c++ function to check whether a sequence of numbers has a decreasing trend or not.
*/
bool decreasingTrend(vector<int> nums) { | bool decreasingTrend(vector<int> nums) { | ['nums'] | def decreasing_trend(nums):
if (sorted(nums)== nums):
return True
else:
return False | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'decreasingTrend', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#... |
671 | MBPP/671 | C++ | Write a c++ function to set the right most unset bit. | /**
* Write a c++ function to set the right most unset bit.
*/
int setRightMostUnsetBit(int n) { | int setRightMostUnsetBit(int n) { | ['n'] | import math
def get_Pos_Of_Right_most_Set_Bit(n):
return int(math.log2(n&-n)+1)
def set_Right_most_Unset_Bit(n):
if (n == 0):
return 1
if ((n & (n + 1)) == 0):
return n
pos = get_Pos_Of_Right_most_Set_Bit(~n)
return ((1 << (pos - 1)) | n) | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'setRightMostUnsetBit', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.... |
672 | MBPP/672 | C++ | Write a function to find maximum of three numbers. | /**
* Write a function to find maximum of three numbers.
*/
int maxOfThree(int num1, int num2, int num3) { | int maxOfThree(int num1, int num2, int num3) { | ['num1', 'num2', 'num3'] | def max_of_three(num1,num2,num3):
if (num1 >= num2) and (num1 >= num3):
lnum = num1
elif (num2 >= num1) and (num2 >= num3):
lnum = num2
else:
lnum = num3
return lnum | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'maxOfThree', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#inclu... |
673 | MBPP/673 | C++ | Write a c++ function to convert vector of multiple integers into a single integer. | /**
* Write a c++ function to convert vector of multiple integers into a single integer.
*/
int convert(vector<int> list) { | int convert(vector<int> list) { | ['list'] | def convert(list):
s = [str(i) for i in list]
res = int("".join(s))
return (res) | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'convert', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include ... |
674 | MBPP/674 | C++ | Write a function to remove duplicate words from a given string using collections module. | /**
* Write a function to remove duplicate words from a given string using collections module.
*/
string removeDuplicate(string string_arg0) { | string removeDuplicate(string string_arg0) { | ['string_arg0'] | from collections import OrderedDict
def remove_duplicate(string):
result = ' '.join(OrderedDict((w,w) for w in string.split()).keys())
return result | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'removeDuplicate', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#... |
675 | MBPP/675 | C++ | Write a function to add two integers. however, if the sum is between the given range it will return 20. | /**
* Write a function to add two integers. however, if the sum is between the given range it will return 20.
*/
int sumNums(int x, int y, int m, int n) { | int sumNums(int x, int y, int m, int n) { | ['x', 'y', 'm', 'n'] | def sum_nums(x, y,m,n):
sum_nums= x + y
if sum_nums in range(m, n):
return 20
else:
return sum_nums | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'sumNums', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include ... |
676 | MBPP/676 | C++ | Write a function to remove everything except alphanumeric characters from the given string by using regex. | /**
* Write a function to remove everything except alphanumeric characters from the given string by using regex.
*/
string removeExtraChar(string text1) { | string removeExtraChar(string text1) { | ['text1'] | import re
def remove_extra_char(text1):
pattern = re.compile('[\W_]+')
return (pattern.sub('', text1)) | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'removeExtraChar', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#... |
677 | MBPP/677 | C++ | Write a function to check if the triangle is valid or not. | /**
* Write a function to check if the triangle is valid or not.
*/
bool validityTriangle(int a, int b, int c) { | bool validityTriangle(int a, int b, int c) { | ['a', 'b', 'c'] | def validity_triangle(a,b,c):
total = a + b + c
if total == 180:
return True
else:
return False | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'validityTriangle', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n... |
678 | MBPP/678 | C++ | Write a c++ function to remove spaces from a given string. | /**
* Write a c++ function to remove spaces from a given string.
*/
string removeSpaces(string str1) { | string removeSpaces(string str1) { | ['str1'] | def remove_spaces(str1):
str1 = str1.replace(' ','')
return str1 | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'removeSpaces', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#inc... |
679 | MBPP/679 | C++ | Write a function to access map key’s element by index. | /**
* Write a function to access map key’s element by index.
*/
string accessKey(map<string,int> ditionary, int key) { | string accessKey(map<string,int> ditionary, int key) { | ['ditionary', 'key'] | def access_key(ditionary,key):
return list(ditionary)[key] | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'accessKey', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#includ... |
680 | MBPP/680 | C++ | Write a c++ function to check whether a sequence of numbers has an increasing trend or not. | /**
* Write a c++ function to check whether a sequence of numbers has an increasing trend or not.
*/
bool increasingTrend(vector<int> nums) { | bool increasingTrend(vector<int> nums) { | ['nums'] | def increasing_trend(nums):
if (sorted(nums)== nums):
return True
else:
return False | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'increasingTrend', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#... |
681 | MBPP/681 | C++ | Write a c++ function to find the smallest prime divisor of a number. | /**
* Write a c++ function to find the smallest prime divisor of a number.
*/
int smallestDivisor(int n) { | int smallestDivisor(int n) { | ['n'] | def smallest_Divisor(n):
if (n % 2 == 0):
return 2;
i = 3;
while (i*i <= n):
if (n % i == 0):
return i;
i += 2;
return n; | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'smallestDivisor', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#... |
682 | MBPP/682 | C++ | Write a function to multiply two vectors using map and lambda function. | /**
* Write a function to multiply two vectors using map and lambda function.
*/
vector<int> mulList(vector<int> nums1, vector<int> nums2) { | vector<int> mulList(vector<int> nums1, vector<int> nums2) { | ['nums1', 'nums2'] | def mul_list(nums1,nums2):
result = map(lambda x, y: x * y, nums1, nums2)
return list(result) | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'mulList', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include ... |
683 | MBPP/683 | C++ | Write a c++ function to check whether the given number can be represented by sum of two squares or not. | /**
* Write a c++ function to check whether the given number can be represented by sum of two squares or not.
*/
bool sumSquare(int n) { | bool sumSquare(int n) { | ['n'] | def sum_Square(n) :
i = 1
while i*i <= n :
j = 1
while (j*j <= n) :
if (i*i+j*j == n) :
return True
j = j+1
i = i+1
return False | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'sumSquare', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#includ... |
684 | MBPP/684 | C++ | Write a c++ function to count occurences of a character in a repeated string. | /**
* Write a c++ function to count occurences of a character in a repeated string.
*/
int countChar(string str, char x) { | int countChar(string str, char x) { | ['str', 'x'] | def count_Char(str,x):
count = 0
for i in range(len(str)):
if (str[i] == x) :
count += 1
n = 10
repititions = n // len(str)
count = count * repititions
l = n % len(str)
for i in range(l):
if (str[i] == x):
count += 1
return... | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'countChar', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#includ... |
685 | MBPP/685 | C++ | Write a c++ function to find sum of prime numbers between 1 to n. | /**
* Write a c++ function to find sum of prime numbers between 1 to n.
*/
int sumOfPrimes(int n) { | int sumOfPrimes(int n) { | ['n'] | def sum_Of_Primes(n):
prime = [True] * (n + 1)
p = 2
while p * p <= n:
if prime[p] == True:
i = p * 2
while i <= n:
prime[i] = False
i += p
p += 1
sum = 0
for i in range (2,n + 1):
if(prime[i]): ... | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'sumOfPrimes', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#incl... |
686 | MBPP/686 | C++ | Write a function to find the frequency of each element in the given vector. | /**
* Write a function to find the frequency of each element in the given vector.
*/
string freqElement(vector<int> test_tup) { | string freqElement(vector<int> test_tup) { | ['test_tup'] | from collections import defaultdict
def freq_element(test_tup):
res = defaultdict(int)
for ele in test_tup:
res[ele] += 1
return (str(dict(res))) | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'freqElement', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#incl... |
687 | MBPP/687 | C++ | Write a function to find the greatest common divisor (gcd) of two integers by using recursion. | /**
* Write a function to find the greatest common divisor (gcd) of two integers by using recursion.
*/
int recurGcd(int a, int b) { | int recurGcd(int a, int b) { | ['a', 'b'] | def recur_gcd(a, b):
low = min(a, b)
high = max(a, b)
if low == 0:
return high
elif low == 1:
return 1
else:
return recur_gcd(low, high%low) | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'recurGcd', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include... |
688 | MBPP/688 | C++ | Write a function to get the length of a complex number. | /**
* Write a function to get the length of a complex number.
*/
double lenComplex(int a, int b) { | double lenComplex(int a, int b) { | ['a', 'b'] | import cmath
def len_complex(a,b):
cn=complex(a,b)
length=abs(cn)
return length | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'lenComplex', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#inclu... |
689 | MBPP/689 | C++ | ## write a function to find the minimum number of jumps to reach the end of the vector for the given vector of integers where each element represents the max number of steps that can be made forward from that element. > indented block > indented block | /**
* ## write a function to find the minimum number of jumps to reach the end of the vector for the given vector of integers where each element represents the max number of steps that can be made forward from that element. > indented block > indented block
*/
int minJumps(vector<int> arr, int n) { | int minJumps(vector<int> arr, int n) { | ['arr', 'n'] | def min_jumps(arr, n):
jumps = [0 for i in range(n)]
if (n == 0) or (arr[0] == 0):
return float('inf')
jumps[0] = 0
for i in range(1, n):
jumps[i] = float('inf')
for j in range(i):
if (i <= j + arr[j]) and (jumps[j] != float('inf')):
jumps[i] = min(jumps[i], jumps[j] + 1)
break
return j... | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'minJumps', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include... |
690 | MBPP/690 | C++ | Write a function to multiply consecutive numbers of a given vector. | /**
* Write a function to multiply consecutive numbers of a given vector.
*/
vector<int> mulConsecutiveNums(vector<int> nums) { | vector<int> mulConsecutiveNums(vector<int> nums) { | ['nums'] | def mul_consecutive_nums(nums):
result = [b*a for a, b in zip(nums[:-1], nums[1:])]
return result | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'mulConsecutiveNums', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>... |
691 | MBPP/691 | C++ | Write a function to group the 1st elements on the basis of 2nd elements in the given tuple vector. | /**
* Write a function to group the 1st elements on the basis of 2nd elements in the given tuple vector.
*/
map<int,vector<int>> groupElement(vector<vector<int>> test_list) { | map<int,vector<int>> groupElement(vector<vector<int>> test_list) { | ['test_list'] | from itertools import groupby
def group_element(test_list):
res = dict()
for key, val in groupby(sorted(test_list, key = lambda ele: ele[1]), key = lambda ele: ele[1]):
res[key] = [ele[0] for ele in val]
return (res)
| {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'groupElement', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#inc... |
692 | MBPP/692 | C++ | Write a c++ function to find the last two digits in factorial of a given number. | /**
* Write a c++ function to find the last two digits in factorial of a given number.
*/
int lastTwoDigits(int n) { | int lastTwoDigits(int n) { | ['n'] | def last_Two_Digits(N):
if (N >= 10):
return
fac = 1
for i in range(1,N + 1):
fac = (fac * i) % 100
return (fac) | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'lastTwoDigits', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#in... |
693 | MBPP/693 | C++ | Write a function to remove multiple spaces in a string by using regex. | /**
* Write a function to remove multiple spaces in a string by using regex.
*/
string removeMultipleSpaces(string text1) { | string removeMultipleSpaces(string text1) { | ['text1'] | import re
def remove_multiple_spaces(text1):
return (re.sub(' +',' ',text1)) | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'removeMultipleSpaces', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.... |
694 | MBPP/694 | C++ | Write a function to extract unique values from the given map values. | /**
* Write a function to extract unique values from the given map values.
*/
vector<int> extractUnique(map<string,vector<int>> test_dict) { | vector<int> extractUnique(map<string,vector<int>> test_dict) { | ['test_dict'] | def extract_unique(test_dict):
res = list(sorted({ele for val in test_dict.values() for ele in val}))
return res | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'extractUnique', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#in... |
695 | MBPP/695 | C++ | Write a function to check if each element of the second tuple is greater than its corresponding index in the first tuple. | /**
* Write a function to check if each element of the second tuple is greater than its corresponding index in the first tuple.
*/
bool checkGreater(vector<int> test_tup1, vector<int> test_tup2) { | bool checkGreater(vector<int> test_tup1, vector<int> test_tup2) { | ['test_tup1', 'test_tup2'] | def check_greater(test_tup1, test_tup2):
res = all(x < y for x, y in zip(test_tup1, test_tup2))
return (res) | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'checkGreater', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#inc... |
697 | MBPP/697 | C++ | Write a function to find number of even elements in the given vector using lambda function. | /**
* Write a function to find number of even elements in the given vector using lambda function.
*/
int countEven(vector<int> array_nums) { | int countEven(vector<int> array_nums) { | ['array_nums'] | def count_even(array_nums):
count_even = len(list(filter(lambda x: (x%2 == 0) , array_nums)))
return count_even | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'countEven', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#includ... |
701 | MBPP/701 | C++ | Write a function to find the equilibrium index of the given vector. | /**
* Write a function to find the equilibrium index of the given vector.
*/
int equilibriumIndex(vector<int> arr) { | int equilibriumIndex(vector<int> arr) { | ['arr'] | def equilibrium_index(arr):
total_sum = sum(arr)
left_sum=0
for i, num in enumerate(arr):
total_sum -= num
if left_sum == total_sum:
return i
left_sum += num
return -1 | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'equilibriumIndex', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n... |
702 | MBPP/702 | C++ | Write a function to find the minimum number of elements that should be removed such that amax-amin<=k. | /**
* Write a function to find the minimum number of elements that should be removed such that amax-amin<=k.
*/
int removals(vector<int> arr, int n, int k) { | int removals(vector<int> arr, int n, int k) { | ['arr', 'n', 'k'] | def find_ind(key, i, n,
k, arr):
ind = -1
start = i + 1
end = n - 1;
while (start < end):
mid = int(start +
(end - start) / 2)
if (arr[mid] - key <= k):
ind = mid
start = mid + 1
else:
end = mid
return ind
def removals(arr, n, k):
ans = n - 1
arr.sort()
for i in range(0, ... | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'removals', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include... |
703 | MBPP/703 | C++ | Write a function to check whether the given key is present in the map or not. | /**
* Write a function to check whether the given key is present in the map or not.
*/
bool isKeyPresent(map<int,int> d, int x) { | bool isKeyPresent(map<int,int> d, int x) { | ['d', 'x'] | def is_key_present(d,x):
if x in d:
return True
else:
return False | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'isKeyPresent', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#inc... |
704 | MBPP/704 | C++ | Write a function to calculate the harmonic sum of n-1. | /**
* Write a function to calculate the harmonic sum of n-1.
*/
double harmonicSum(int n) { | double harmonicSum(int n) { | ['n'] | def harmonic_sum(n):
if n < 2:
return 1
else:
return 1 / n + (harmonic_sum(n - 1)) | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'harmonicSum', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#incl... |
706 | MBPP/706 | C++ | Write a function to find whether vector is subset of another vector. | /**
* Write a function to find whether vector is subset of another vector.
*/
bool isSubset(vector<int> arr1, int m, vector<int> arr2, int n) { | bool isSubset(vector<int> arr1, int m, vector<int> arr2, int n) { | ['arr1', 'm', 'arr2', 'n'] | def is_subset(arr1, m, arr2, n):
hashset = set()
for i in range(0, m):
hashset.add(arr1[i])
for i in range(0, n):
if arr2[i] in hashset:
continue
else:
return False
return True | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'isSubset', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include... |
707 | MBPP/707 | C++ | Write a c++ function to count the total set bits from 1 to n. | /**
* Write a c++ function to count the total set bits from 1 to n.
*/
int countSetBits(int n) { | int countSetBits(int n) { | ['n'] | def count_Set_Bits(n) :
n += 1;
powerOf2 = 2;
cnt = n // 2;
while (powerOf2 <= n) :
totalPairs = n // powerOf2;
cnt += (totalPairs // 2) * powerOf2;
if (totalPairs & 1) :
cnt += (n % powerOf2)
else :
cnt += 0
powe... | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'countSetBits', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#inc... |
708 | MBPP/708 | C++ | Write a c++ function to convert a string to vector. | /**
* Write a c++ function to convert a string to vector.
*/
vector<string> convert(string string_arg0) { | vector<string> convert(string string_arg0) { | ['string_arg0'] | def Convert(string):
li = list(string.split(" "))
return li | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'convert', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include ... |
709 | MBPP/709 | C++ | Write a function to count unique keys for each value present in the tuple. | /**
* Write a function to count unique keys for each value present in the tuple.
*/
string getUnique(vector<vector<int>> test_list) { | string getUnique(vector<vector<int>> test_list) { | ['test_list'] | from collections import defaultdict
def get_unique(test_list):
res = defaultdict(list)
for sub in test_list:
res[sub[1]].append(sub[0])
res = dict(res)
res_dict = dict()
for key in res:
res_dict[key] = len(list(set(res[key])))
return (str(res_dict)) | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'getUnique', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#includ... |
710 | MBPP/710 | C++ | Write a function to access the initial and last data of the given tuple record. | /**
* Write a function to access the initial and last data of the given tuple record.
*/
vector<int> frontAndRear(vector<int> test_tup) { | vector<int> frontAndRear(vector<int> test_tup) { | ['test_tup'] | def front_and_rear(test_tup):
res = (test_tup[0], test_tup[-1])
return (res) | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'frontAndRear', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#inc... |
711 | MBPP/711 | C++ | Write a c++ function to check whether the product of digits of a number at even and odd places is equal or not. | /**
* Write a c++ function to check whether the product of digits of a number at even and odd places is equal or not.
*/
bool productEqual(int n) { | bool productEqual(int n) { | ['n'] | def product_Equal(n):
if n < 10:
return False
prodOdd = 1; prodEven = 1
while n > 0:
digit = n % 10
prodOdd *= digit
n = n//10
if n == 0:
break;
digit = n % 10
prodEven *= digit
n = n//10
if prodOdd == prodEv... | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'productEqual', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#inc... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.