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#... |
End of preview. Expand in Data Studio
No dataset card yet
- Downloads last month
- 23