Datasets:
qid stringlengths 1 3 | title stringlengths 9 106 | language stringclasses 1
value | signature stringlengths 24 145 | arguments sequence | source_py stringlengths 54 989 | source_cpp stringlengths 59 951 | question_info dict |
|---|---|---|---|---|---|---|---|
1 | Add 1 To A Given Number 1 | C++ | int add1ToAGivenNumber1(int x) { | [
"x"
] | def add_1_to_a_given_number_1(x):
return (- (~ x)) | int add_1_to_a_given_number_1(int x) {
return ( - ( ~ x ) );
} | {
"entry_fn_name": "add1ToAGivenNumber1",
"extension": "cpp",
"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 <cmath>\n#i... |
2 | Add Two Numbers Without Using Arithmetic Operators | C++ | int addTwoNumbersWithoutUsingArithmeticOperators(int x, int y) { | [
"x",
"y"
] | def add_two_numbers_without_using_arithmetic_operators(x, y):
while (y != 0):
carry = (x & y)
x = (x ^ y)
y = (carry << 1)
return x | int add_two_numbers_without_using_arithmetic_operators(int x, int y) {
while ( y != 0 ) {
int carry = x & y;
x = x ^ y;
y = carry << 1;
}
return x;
} | {
"entry_fn_name": "addTwoNumbersWithoutUsingArithmeticOperators",
"extension": "cpp",
"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... |
3 | Analysis Of Algorithms Set 2 Asymptotic Analysis | C++ | int analysisOfAlgorithmsSet2AsymptoticAnalysis(vector<int> arr, int n, int x) { | [
"arr",
"n",
"x"
] | def analysis_of_algorithms_set_2_asymptotic_analysis(arr, n, x):
i = 0
for i in range(i, n):
if (arr[i] == x):
return i
return (- 1) | int analysis_of_algorithms_set_2_asymptotic_analysis(vector<int> arr, int n, int x) {
int i;
for ( i = 0;
i < n;
i ++ ) {
if ( arr [ i ] == x ) return i;
}
return - 1;
} | {
"entry_fn_name": "analysisOfAlgorithmsSet2AsymptoticAnalysis",
"extension": "cpp",
"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... |
4 | Area Of A Hexagon | C++ | double areaOfAHexagon(double s) { | [
"s"
] | def area_of_a_hexagon(s):
return (((3 * math.sqrt(3)) * (s * s)) / 2) | double area_of_a_hexagon(double s) {
return ( ( 3 * sqrt ( 3 ) * ( s * s ) ) / 2 );
} | {
"entry_fn_name": "areaOfAHexagon",
"extension": "cpp",
"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 <cmath>\n#includ... |
5 | Area Of The Circle That Has A Square And A Circle Inscribed In It | C++ | double areaOfTheCircleThatHasASquareAndACircleInscribedInIt(int a) { | [
"a"
] | def area_of_the_circle_that_has_a_square_and_a_circle_inscribed_in_it(a):
area = (((math.pi * a) * a) / 4)
return area | float area_of_the_circle_that_has_a_square_and_a_circle_inscribed_in_it(int a) {
float area = ( M_PI * a * a ) / 4.0;
return area;
} | {
"entry_fn_name": "areaOfTheCircleThatHasASquareAndACircleInscribedInIt",
"extension": "cpp",
"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#inclu... |
6 | Area Square Circumscribed Circle | C++ | int areaSquareCircumscribedCircle(int r) { | [
"r"
] | def area_square_circumscribed_circle(r):
return ((2 * r) * r) | int area_square_circumscribed_circle(int r) {
return ( 2 * r * r );
} | {
"entry_fn_name": "areaSquareCircumscribedCircle",
"extension": "cpp",
"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 <... |
7 | Array Element Moved K Using Single Moves | C++ | int arrayElementMovedKUsingSingleMoves(vector<int> a, int n, int k) { | [
"a",
"n",
"k"
] | def array_element_moved_k_using_single_moves(a, n, k):
if (k >= (n - 1)):
return n
best = 0
times = 0
for i in range(n):
if (a[i] > best):
best = a[i]
if (i == True):
times = 1
else:
times += 1
if (times >= k):
... | int array_element_moved_k_using_single_moves(vector<int> a, int n, int k) {
if ( k >= n - 1 ) return n;
int best = 0, times = 0;
for ( int i = 0;
i < n;
i ++ ) {
if ( a [ i ] > best ) {
best = a [ i ];
if ( i ) times = 1;
}
else times += 1;
if ( times >= k ) return best;
}
retu... | {
"entry_fn_name": "arrayElementMovedKUsingSingleMoves",
"extension": "cpp",
"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... |
8 | Array Range Queries Elements Frequency Value | C++ | int arrayRangeQueriesElementsFrequencyValue(int start, int end_arg1, vector<int> arr) { | [
"start",
"end_arg1",
"arr"
] | def array_range_queries_elements_frequency_value(start, end, arr):
frequency = dict()
for i in range(start, (end + 1)):
if (arr[i] in frequency.keys()):
frequency[arr[i]] += 1
else:
frequency[arr[i]] = 1
count = 0
for x in frequency:
if (x == frequency[x])... | int array_range_queries_elements_frequency_value(int start, int end, vector<int> arr) {
unordered_map < int, int > frequency;
for ( int i = start;
i <= end;
i ++ ) frequency [ arr [ i ] ] ++;
int count = 0;
for ( auto x : frequency ) if ( x . first == x . second ) count ++;
return count;
} | {
"entry_fn_name": "arrayRangeQueriesElementsFrequencyValue",
"extension": "cpp",
"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... |
9 | Basic And Extended Euclidean Algorithms | C++ | int basicAndExtendedEuclideanAlgorithms(int a, int b) { | [
"a",
"b"
] | def basic_and_extended_euclidean_algorithms(a, b):
if (a == 0):
return b
return basic_and_extended_euclidean_algorithms((b % a), a) | int basic_and_extended_euclidean_algorithms(int a, int b) {
if ( a == 0 ) return b;
return basic_and_extended_euclidean_algorithms ( b % a, a );
} | {
"entry_fn_name": "basicAndExtendedEuclideanAlgorithms",
"extension": "cpp",
"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... |
10 | Bell Numbers Number Of Ways To Partition A Set | C++ | int bellNumbersNumberOfWaysToPartitionASet(int n) { | [
"n"
] | def bell_numbers_number_of_ways_to_partition_a_set(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)])
... | int bell_numbers_number_of_ways_to_partition_a_set(int n) {
int bell [ n + 1 ] [ n + 1 ];
bell [ 0 ] [ 0 ] = 1;
for ( int i = 1;
i <= n;
i ++ ) {
bell [ i ] [ 0 ] = bell [ i - 1 ] [ i - 1 ];
for ( int j = 1;
j <= i;
j ++ ) bell [ i ] [ j ] = bell [ i - 1 ] [ j - 1 ] + bell [ i ] [ j - 1 ];
}... | {
"entry_fn_name": "bellNumbersNumberOfWaysToPartitionASet",
"extension": "cpp",
"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#... |
11 | Binary Search | C++ | int binarySearch(vector<int> arr, int l, int r, int x) { | [
"arr",
"l",
"r",
"x"
] | def binary_search(arr, l, r, x):
if (r >= l):
mid = (l + ((r - l) // 2))
if (arr[mid] == x):
return mid
elif (arr[mid] > x):
return binary_search(arr, l, (mid - 1), x)
else:
return binary_search(arr, (mid + 1), r, x)
else:
return (- 1) | int binary_search(vector<int> arr, int l, int r, int x) {
if ( r >= l ) {
int mid = l + ( r - l ) / 2;
if ( arr [ mid ] == x ) return mid;
if ( arr [ mid ] > x ) return binary_search ( arr, l, mid - 1, x );
return binary_search ( arr, mid + 1, r, x );
}
return - 1;
} | {
"entry_fn_name": "binarySearch",
"extension": "cpp",
"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 <cmath>\n#include ... |
12 | Breaking Number First Part Integral Division Second Power 10 | C++ | int breakingNumberFirstPartIntegralDivisionSecondPower10(string n) { | [
"n"
] | def breaking_number_first_part_integral_division_second_power_10(N):
length = len(N)
l = int((length / 2))
count = 0
for i in range((l + 1)):
s = N[0:(0 + i)]
l1 = len(s)
t = N[i:(l1 + i)]
try:
if ((s[0] == '0') or (t[0] == '0')):
continue
... | int breaking_number_first_part_integral_division_second_power_10(string N) {
int len = N . length ( );
int l = ( len ) / 2;
int count = 0;
for ( int i = 1;
i <= l;
i ++ ) {
string s = N . substr ( 0, i );
int l1 = s . length ( );
string t = N . substr ( i, l1 );
if ( s [ 0 ] == '0' || t [ 0 ... | {
"entry_fn_name": "breakingNumberFirstPartIntegralDivisionSecondPower10",
"extension": "cpp",
"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#inclu... |
15 | Calculate Area Tetrahedron | C++ | float calculateAreaTetrahedron(int side) { | [
"side"
] | def calculate_area_tetrahedron(side):
volume = ((side ** 3) / (6 * math.sqrt(2)))
return round(volume, 2) | double calculate_area_tetrahedron(int side) {
double volume = ( pow ( side, 3 ) / ( 6 * sqrt ( 2 ) ) );
return volume;
} | {
"entry_fn_name": "calculateAreaTetrahedron",
"extension": "cpp",
"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 <cmath... |
16 | Calculate Maximum Value Using Sign Two Numbers String | C++ | int calculateMaximumValueUsingSignTwoNumbersString(string str) { | [
"str"
] | def calculate_maximum_value_using_sign_two_numbers_string(str):
res = (ord(str[0]) - 48)
for i in range(1, len(str)):
if ((str[i] == '0') or (str[i] == '1') or (res < 2)):
res += (ord(str[i]) - 48)
else:
res *= (ord(str[i]) - 48)
return res | int calculate_maximum_value_using_sign_two_numbers_string(string str) {
int res = str [ 0 ] - '0';
for ( int i = 1;
i < str . length ( );
i ++ ) {
if ( str [ i ] == '0' || str [ i ] == '1' || res < 2 ) res += ( str [ i ] - '0' );
else res *= ( str [ i ] - '0' );
}
return res;
} | {
"entry_fn_name": "calculateMaximumValueUsingSignTwoNumbersString",
"extension": "cpp",
"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 <ma... |
17 | Calculate Volume Dodecahedron | C++ | double calculateVolumeDodecahedron(int side) { | [
"side"
] | def calculate_volume_dodecahedron(side):
return (((15 + (7 * math.sqrt(5))) / 4) * math.pow(side, 3)) | double calculate_volume_dodecahedron(int side) {
return ( ( ( 15 + ( 7 * ( sqrt ( 5 ) ) ) ) / 4 ) * ( pow ( side, 3 ) ) );
} | {
"entry_fn_name": "calculateVolumeDodecahedron",
"extension": "cpp",
"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 <cm... |
18 | Cassinis Identity | C++ | int cassinisIdentity(int n) { | [
"n"
] | def cassinis_identity(n):
return ((- 1) if (n & 1) else 1) | int cassinis_identity(int n) {
return ( n & 1 ) ? - 1 : 1;
} | {
"entry_fn_name": "cassinisIdentity",
"extension": "cpp",
"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 <cmath>\n#incl... |
19 | Ceiling In A Sorted Array | C++ | int ceilingInASortedArray(vector<int> arr, int low, int high, int x) { | [
"arr",
"low",
"high",
"x"
] | def ceiling_in_a_sorted_array(arr, low, high, x):
if (x <= arr[low]):
return low
i = low
for i in range(high):
if (arr[i] == x):
return i
if ((arr[i] < x) and (arr[(i + 1)] >= x)):
return (i + 1)
return (- 1) | int ceiling_in_a_sorted_array(vector<int> arr, int low, int high, int x) {
int i;
if ( x <= arr [ low ] ) return low;
for ( i = low;
i < high;
i ++ ) {
if ( arr [ i ] == x ) return i;
if ( arr [ i ] < x && arr [ i + 1 ] >= x ) return i + 1;
}
return - 1;
} | {
"entry_fn_name": "ceilingInASortedArray",
"extension": "cpp",
"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 <cmath>\n... |
20 | Ceiling In A Sorted Array 1 | C++ | int ceilingInASortedArray1(vector<int> arr, int low, int high, int x) { | [
"arr",
"low",
"high",
"x"
] | def ceiling_in_a_sorted_array_1(arr, low, high, x):
if (x <= arr[low]):
return low
if (x > arr[high]):
return (- 1)
mid = ((low + high) / 2)
if (arr[mid] == x):
return mid
elif (arr[mid] < x):
if (((mid + 1) <= high) and (x <= arr[(mid + 1)])):
return (mid... | int ceiling_in_a_sorted_array_1(vector<int> arr, int low, int high, int x) {
int mid;
if ( x <= arr [ low ] ) return low;
if ( x > arr [ high ] ) return - 1;
mid = ( low + high ) / 2;
if ( arr [ mid ] == x ) return mid;
else if ( arr [ mid ] < x ) {
if ( mid + 1 <= high && x <= arr [ mid + 1 ] ) return ... | {
"entry_fn_name": "ceilingInASortedArray1",
"extension": "cpp",
"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 <cmath>\... |
22 | Change Bits Can Made One Flip | C++ | bool changeBitsCanMadeOneFlip(string str) { | [
"str"
] | def change_bits_can_made_one_flip(str):
zeros = 0
ones = 0
for i in range(0, len(str)):
ch = str[i]
if (ch == '0'):
zeros = (zeros + 1)
else:
ones = (ones + 1)
return ((zeros == 1) or (ones == 1)) | bool change_bits_can_made_one_flip(string str) {
int zeros = 0, ones = 0;
for ( char ch : str ) ( ch == '0' ) ? ++ zeros : ++ ones;
return ( zeros == 1 || ones == 1 );
} | {
"entry_fn_name": "changeBitsCanMadeOneFlip",
"extension": "cpp",
"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 <cmath... |
23 | Check Array Contains Contiguous Integers Duplicates Allowed | C++ | bool checkArrayContainsContiguousIntegersDuplicatesAllowed(vector<int> arr, int n) { | [
"arr",
"n"
] | def check_array_contains_contiguous_integers_duplicates_allowed(arr, n):
max1 = max(arr)
min1 = min(arr)
m = ((max1 - min1) + 1)
if (m > n):
return False
visited = ([0] * m)
for i in range(0, n):
visited[(arr[i] - min1)] = True
for i in range(0, m):
if (visited[i] == ... | bool check_array_contains_contiguous_integers_duplicates_allowed(vector<int> arr, int n) {
int max = * max_element(arr.begin(), arr.end());
int min = * min_element(arr.begin(), arr.end());
int m = max - min + 1;
if ( m > n ) return false;
bool visited [ m ];
memset ( visited, false, sizeof ( visited ) );
... | {
"entry_fn_name": "checkArrayContainsContiguousIntegersDuplicatesAllowed",
"extension": "cpp",
"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#incl... |
24 | Check Array Represents Inorder Binary Search Tree Not | C++ | bool checkArrayRepresentsInorderBinarySearchTreeNot(vector<int> arr, int n) { | [
"arr",
"n"
] | def check_array_represents_inorder_binary_search_tree_not(arr, n):
if ((n == 0) or (n == 1)):
return True
for i in range(1, n, 1):
if (arr[(i - 1)] > arr[i]):
return False
return True | bool check_array_represents_inorder_binary_search_tree_not(vector<int> arr, int n) {
if ( n == 0 || n == 1 ) return true;
for ( int i = 1;
i < n;
i ++ ) if ( arr [ i - 1 ] > arr [ i ] ) return false;
return true;
} | {
"entry_fn_name": "checkArrayRepresentsInorderBinarySearchTreeNot",
"extension": "cpp",
"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 <ma... |
25 | Check Exist Two Elements Array Whose Sum Equal Sum Rest Array | C++ | bool checkExistTwoElementsArrayWhoseSumEqualSumRestArray(vector<int> arr, int n) { | [
"arr",
"n"
] | def check_exist_two_elements_array_whose_sum_equal_sum_rest_array(arr, n):
s = set()
sum = 0
for i in range(n):
sum += arr[i]
if ((sum % 2) != 0):
return False
sum = (sum / 2)
for i in range(n):
val = (sum - arr[i])
if (arr[i] not in s):
s.add(arr[i])
... | bool check_exist_two_elements_array_whose_sum_equal_sum_rest_array(vector<int> arr, int n) {
int sum = 0;
for ( int i = 0;
i < n;
i ++ ) sum += arr [ i ];
if ( sum % 2 != 0 ) return false;
sum = sum / 2;
unordered_set < int > s;
for ( int i = 0;
i < n;
i ++ ) {
int val = sum - arr [ i ];
if ... | {
"entry_fn_name": "checkExistTwoElementsArrayWhoseSumEqualSumRestArray",
"extension": "cpp",
"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#includ... |
26 | Check Given Circle Lies Completely Inside Ring Formed Two Concentric Circles | C++ | bool checkGivenCircleLiesCompletelyInsideRingFormedTwoConcentricCircles(int r0, int r10, int r11, int x1, int y1) { | [
"r0",
"r10",
"r11",
"x1",
"y1"
] | def check_given_circle_lies_completely_inside_ring_formed_two_concentric_circles(r, R, r1, x1, y1):
dis = int(math.sqrt(((x1 * x1) + (y1 * y1))))
return (((dis - r1) >= R) and ((dis + r1) <= r)) | bool check_given_circle_lies_completely_inside_ring_formed_two_concentric_circles(int r, int R, int r1, int x1, int y1) {
int dis = sqrt ( x1 * x1 + y1 * y1 );
return ( dis - r1 >= R && dis + r1 <= r );
} | {
"entry_fn_name": "checkGivenCircleLiesCompletelyInsideRingFormedTwoConcentricCircles",
"extension": "cpp",
"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 <v... |
27 | Check Given String Can Split Four Distinct Strings | C++ | bool checkGivenStringCanSplitFourDistinctStrings(string s) { | [
"s"
] | def check_given_string_can_split_four_distinct_strings(s):
if (len(s) >= 10):
return True
for i in range(1, len(s)):
for j in range((i + 1), len(s)):
for k in range((j + 1), len(s)):
s1 = s[0:i]
s2 = s[i:(j - i)]
s3 = s[j:(k - j)]
... | bool check_given_string_can_split_four_distinct_strings(string s) {
if ( s . size ( ) >= 10 ) return true;
for ( int i = 1;
i < s . size ( );
i ++ ) {
for ( int j = i + 1;
j < s . size ( );
j ++ ) {
for ( int k = j + 1;
k < s . size ( );
k ++ ) {
string s1 = s . substr ( 0,... | {
"entry_fn_name": "checkGivenStringCanSplitFourDistinctStrings",
"extension": "cpp",
"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.... |
28 | Check Given String Rotation Palindrome | C++ | bool checkGivenStringRotationPalindrome(string string_arg0) { | [
"string_arg0"
] | def check_given_string_rotation_palindrome(string):
l = 0
h = (len(string) - 1)
while (h > l):
l += 1
h -= 1
if (string[(l - 1)] != string[(h + 1)]):
return False
return True | bool check_given_string_rotation_palindrome(string str) {
int l = 0;
int h = str . length ( ) - 1;
while ( h > l ) if ( str [ l ++ ] != str [ h -- ] ) return false;
return true;
} | {
"entry_fn_name": "checkGivenStringRotationPalindrome",
"extension": "cpp",
"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... |
29 | Check If All The Elements Can Be Made Of Same Parity By Inverting Adjacent Elements | C++ | bool checkIfAllTheElementsCanBeMadeOfSameParityByInvertingAdjacentElements(vector<int> a, int n) { | [
"a",
"n"
] | def check_if_all_the_elements_can_be_made_of_same_parity_by_inverting_adjacent_elements(a, n):
count_odd = 0
count_even = 0
for i in range(n):
if (a[i] & 1):
count_odd += 1
else:
count_even += 1
if ((count_odd % 2) and (count_even % 2)):
return False
e... | bool check_if_all_the_elements_can_be_made_of_same_parity_by_inverting_adjacent_elements(vector<int> a, int n) {
int count_odd = 0, count_even = 0;
for ( int i = 0;
i < n;
i ++ ) {
if ( a [ i ] & 1 ) count_odd ++;
else count_even ++;
}
if ( count_odd % 2 && count_even % 2 ) return false;
else retu... | {
"entry_fn_name": "checkIfAllTheElementsCanBeMadeOfSameParityByInvertingAdjacentElements",
"extension": "cpp",
"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... |
30 | Check If A Number Is Jumbled Or Not | C++ | bool checkIfANumberIsJumbledOrNot(int num) { | [
"num"
] | def check_if_a_number_is_jumbled_or_not(num):
if ((num // 10) == 0):
return True
while (num != 0):
if ((num // 10) == 0):
return True
digit1 = (num % 10)
digit2 = ((num // 10) % 10)
if (abs((digit2 - digit1)) > 1):
return False
num = (num /... | bool check_if_a_number_is_jumbled_or_not(int num) {
if ( num / 10 == 0 ) return true;
while ( num != 0 ) {
if ( num / 10 == 0 ) return true;
int digit1 = num % 10;
int digit2 = ( num / 10 ) % 10;
if ( abs ( digit2 - digit1 ) > 1 ) return false;
num = num / 10;
}
return true;
} | {
"entry_fn_name": "checkIfANumberIsJumbledOrNot",
"extension": "cpp",
"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... |
31 | Check If A Number Is Power Of Another Number | C++ | bool checkIfANumberIsPowerOfAnotherNumber(int x, int y) { | [
"x",
"y"
] | def check_if_a_number_is_power_of_another_number(x, y):
if (x == 1):
return (y == 1)
pow = 1
while (pow < y):
pow = (pow * x)
return (pow == y) | bool check_if_a_number_is_power_of_another_number(int x, long int y) {
if ( x == 1 ) return ( y == 1 );
long int pow = 1;
while ( pow < y ) pow *= x;
return ( pow == y );
} | {
"entry_fn_name": "checkIfANumberIsPowerOfAnotherNumber",
"extension": "cpp",
"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... |
32 | Check If A Number Is Power Of Another Number 1 | C++ | int checkIfANumberIsPowerOfAnotherNumber1(int x, int y) { | [
"x",
"y"
] | def check_if_a_number_is_power_of_another_number_1(x, y):
res1 = (math.log(y) / math.log(x))
res2 = (math.log(y) / math.log(x))
return (1 if (res1 == res2) else 0) | bool check_if_a_number_is_power_of_another_number_1(int x, int y) {
int res1 = log ( y ) / log ( x );
double res2 = log ( y ) / log ( x );
return ( res1 == res2 );
} | {
"entry_fn_name": "checkIfANumberIsPowerOfAnotherNumber1",
"extension": "cpp",
"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... |
33 | Check If String Remains Palindrome After Removing Given Number Of Characters | C++ | bool checkIfStringRemainsPalindromeAfterRemovingGivenNumberOfCharacters(string str, int n) { | [
"str",
"n"
] | def check_if_string_remains_palindrome_after_removing_given_number_of_characters(str, n):
l = len(str)
if (l >= n):
return True
return False | bool check_if_string_remains_palindrome_after_removing_given_number_of_characters(string str, int n) {
int len = str . length ( );
if ( len >= n ) return true;
return false;
} | {
"entry_fn_name": "checkIfStringRemainsPalindromeAfterRemovingGivenNumberOfCharacters",
"extension": "cpp",
"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 <v... |
34 | Check If X Can Give Change To Every Person In The Queue | C++ | int checkIfXCanGiveChangeToEveryPersonInTheQueue(vector<int> notes, int n) { | [
"notes",
"n"
] | def check_if_x_can_give_change_to_every_person_in_the_queue(notes, n):
fiveCount = 0
tenCount = 0
for i in range(n):
if (notes[i] == 5):
fiveCount += 1
elif (notes[i] == 10):
if (fiveCount > 0):
fiveCount -= 1
tenCount += 1
... | int check_if_x_can_give_change_to_every_person_in_the_queue(vector<int> notes, int n) {
int fiveCount = 0;
int tenCount = 0;
for ( int i = 0;
i < n;
i ++ ) {
if ( notes [ i ] == 5 ) fiveCount ++;
else if ( notes [ i ] == 10 ) {
if ( fiveCount > 0 ) {
fiveCount --;
tenCount ++;
... | {
"entry_fn_name": "checkIfXCanGiveChangeToEveryPersonInTheQueue",
"extension": "cpp",
"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... |
35 | Check Integer Overflow Multiplication | C++ | bool checkIntegerOverflowMultiplication(long long a, long long b) { | [
"a",
"b"
] | def check_integer_overflow_multiplication(a, b):
if ((a == 0) or (b == 0)):
return False
result = (a * b)
if ((result >= 9223372036854775807) or (result <= (- 9223372036854775808))):
result = 0
if (a == (result // b)):
print((result // b))
return False
else:
r... | bool check_integer_overflow_multiplication(long long a, long long b) {
if ( a == 0 || b == 0 ) return false;
long long result = a * b;
if ( a == result / b ) return false;
else return true;
} | {
"entry_fn_name": "checkIntegerOverflowMultiplication",
"extension": "cpp",
"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... |
36 | Check Large Number Divisible 13 Not | C++ | bool checkLargeNumberDivisible13Not(string num) { | [
"num"
] | def check_large_number_divisible_13_not(num):
length = len(num)
if ((length == 1) and (num[0] == '0')):
return True
if ((length % 3) == 1):
num = (str(num) + '00')
length += 2
elif ((length % 3) == 2):
num = (str(num) + '0')
length += 1
sum = 0
p = 1
f... | bool check_large_number_divisible_13_not(string num) {
int length = num . size ( );
if ( length == 1 && num [ 0 ] == '0' ) return true;
if ( length % 3 == 1 ) {
num += "00";
length += 2;
}
else if ( length % 3 == 2 ) {
num += "0";
length += 1;
}
int sum = 0, p = 1;
for ( int i = length -... | {
"entry_fn_name": "checkLargeNumberDivisible13Not",
"extension": "cpp",
"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 ... |
37 | Check Line Passes Origin | C++ | bool checkLinePassesOrigin(int x1, int y1, int x2, int y2) { | [
"x1",
"y1",
"x2",
"y2"
] | def check_line_passes_origin(x1, y1, x2, y2):
return ((x1 * (y2 - y1)) == (y1 * (x2 - x1))) | bool check_line_passes_origin(int x1, int y1, int x2, int y2) {
return ( x1 * ( y2 - y1 ) == y1 * ( x2 - x1 ) );
} | {
"entry_fn_name": "checkLinePassesOrigin",
"extension": "cpp",
"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 <cmath>\n... |
38 | Check Number Is Perfect Square Using Additionsubtraction | C++ | bool checkNumberIsPerfectSquareUsingAdditionsubtraction(int n) { | [
"n"
] | def check_number_is_perfect_square_using_additionsubtraction(n):
i = 1
the_sum = 0
while (the_sum < n):
the_sum += i
if (the_sum == n):
return True
i += 2
return False | bool check_number_is_perfect_square_using_additionsubtraction(int n) {
for ( int sum = 0, i = 1;
sum < n;
i += 2 ) {
sum += i;
if ( sum == n ) return true;
}
return false;
} | {
"entry_fn_name": "checkNumberIsPerfectSquareUsingAdditionsubtraction",
"extension": "cpp",
"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... |
39 | Check Number Power K Using Base Changing Method | C++ | bool checkNumberPowerKUsingBaseChangingMethod(int n, int k) { | [
"n",
"k"
] | def check_number_power_k_using_base_changing_method(n, k):
oneSeen = False
while (n > 0):
digit = (n % k)
if (digit > 1):
return False
if (digit == 1):
if oneSeen:
return False
oneSeen = True
n //= k
return True | bool check_number_power_k_using_base_changing_method(unsigned int n, unsigned int k) {
bool oneSeen = false;
while ( n > 0 ) {
int digit = n % k;
if ( digit > 1 ) return false;
if ( digit == 1 ) {
if ( oneSeen ) return false;
oneSeen = true;
}
n /= k;
}
return true;
} | {
"entry_fn_name": "checkNumberPowerKUsingBaseChangingMethod",
"extension": "cpp",
"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>\... |
40 | Check Occurrences Character Appear Together | C++ | bool checkOccurrencesCharacterAppearTogether(string s, char c) { | [
"s",
"c"
] | def check_occurrences_character_appear_together(s, c):
oneSeen = False
i = 0
n = len(s)
while (i < n):
if (s[i] == c):
if (oneSeen == True):
return False
while ((i < n) and (s[i] == c)):
i = (i + 1)
oneSeen = True
else:
... | bool check_occurrences_character_appear_together(string s, char c) {
bool oneSeen = false;
int i = 0, n = s . length ( );
while ( i < n ) {
if ( s [ i ] == c ) {
if ( oneSeen == true ) return false;
while ( i < n && s [ i ] == c ) i ++;
oneSeen = true;
}
else i ++;
}
return true;... | {
"entry_fn_name": "checkOccurrencesCharacterAppearTogether",
"extension": "cpp",
"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... |
41 | Check Possible Sort Array Conditional Swapping Adjacent Allowed | C++ | bool checkPossibleSortArrayConditionalSwappingAdjacentAllowed(vector<int> arr, int n) { | [
"arr",
"n"
] | def check_possible_sort_array_conditional_swapping_adjacent_allowed(arr, n):
for i in range(0, (n - 1)):
if (arr[i] > arr[(i + 1)]):
if ((arr[i] - arr[(i + 1)]) == 1):
(arr[i], arr[(i + 1)]) = (arr[(i + 1)], arr[i])
else:
return False
return True | bool check_possible_sort_array_conditional_swapping_adjacent_allowed(vector<int> arr, int n) {
for ( int i = 0;
i < n - 1;
i ++ ) {
if ( arr [ i ] > arr [ i + 1 ] ) {
if ( arr [ i ] - arr [ i + 1 ] == 1 ) swap ( arr [ i ], arr [ i + 1 ] );
else return false;
}
}
return true;
} | {
"entry_fn_name": "checkPossibleSortArrayConditionalSwappingAdjacentAllowed",
"extension": "cpp",
"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#i... |
42 | Check Possible Transform One String Another | C++ | bool checkPossibleTransformOneStringAnother(string s1, string s2) { | [
"s1",
"s2"
] | def check_possible_transform_one_string_another(s1, s2):
n = len(s1)
m = len(s2)
dp = [[False for i in range((m + 1))] for i in range((n + 1))]
dp[0][0] = True
for i in range(len(s1)):
for j in range((len(s2) + 1)):
if dp[i][j]:
if ((j < len(s2)) and (s1[i].upper(... | bool check_possible_transform_one_string_another(string s1, string s2) {
int n = s1 . length ( );
int m = s2 . length ( );
bool dp [ n + 1 ] [ m + 1 ];
for ( int i = 0;
i <= n;
i ++ ) {
for ( int j = 0;
j <= m;
j ++ ) {
dp [ i ] [ j ] = false;
}
}
dp [ 0 ] [ 0 ] = true;
for ( int... | {
"entry_fn_name": "checkPossibleTransformOneStringAnother",
"extension": "cpp",
"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#... |
44 | Check Reversing Sub Array Make Array Sorted 1 | C++ | bool checkReversingSubArrayMakeArraySorted1(vector<int> arr, int n) { | [
"arr",
"n"
] | def check_reversing_sub_array_make_array_sorted_1(arr, n):
if (n == 1):
return True
i = 1
for i in range(1, n):
if (arr[(i - 1)] < arr[i]):
if (i == n):
return True
j = i
while (arr[j] < arr[(j - 1)]):
if ((i > 1) and (arr[j] < arr[(i - 2)])):
... | bool check_reversing_sub_array_make_array_sorted_1(vector<int> arr, int n) {
if ( n == 1 ) return true;
int i;
for ( i = 1;
i < n && arr [ i - 1 ] < arr [ i ];
i ++ );
if ( i == n ) return true;
int j = i;
while ( arr [ j ] < arr [ j - 1 ] ) {
if ( i > 1 && arr [ j ] < arr [ i - 2 ] ) return false;
... | {
"entry_fn_name": "checkReversingSubArrayMakeArraySorted1",
"extension": "cpp",
"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#... |
YAML Metadata Warning:The task_categories "text2text-generation" is not in the official list: text-classification, token-classification, table-question-answering, question-answering, zero-shot-classification, translation, summarization, feature-extraction, text-generation, fill-mask, sentence-similarity, text-to-speech, text-to-audio, automatic-speech-recognition, audio-to-audio, audio-classification, audio-text-to-text, voice-activity-detection, depth-estimation, image-classification, object-detection, image-segmentation, text-to-image, image-to-text, image-to-image, image-to-video, unconditional-image-generation, video-classification, reinforcement-learning, robotics, tabular-classification, tabular-regression, tabular-to-text, table-to-text, multiple-choice, text-ranking, text-retrieval, time-series-forecasting, text-to-video, image-text-to-text, image-text-to-image, image-text-to-video, visual-question-answering, document-question-answering, zero-shot-image-classification, graph-ml, mask-generation, zero-shot-object-detection, text-to-3d, image-to-3d, image-feature-extraction, video-text-to-text, keypoint-detection, visual-document-retrieval, any-to-any, video-to-video, other
Dataset Card for BabelCode Transcoder
How To Use This Dataset
To use this dataset, you can either use the original BabelCode Repo, or you can use the bc_eval Metric.
Dataset Summary
The Transcoder dataset in BabelCode format. Currently supports translation from C++ and Python.
Supported Tasks and Leaderboards
Languages
BC-Transcoder supports:
- C++
- C#
- Dart
- Go
- Haskell
- Java
- Javascript
- Julia
- Kotlin
- Lua
- PHP
- Python
- R
- Rust
- Scala
- TypeScript
Dataset Structure
>>> from datasets import load_dataset
>>> load_dataset("gabeorlanski/bc-transcoder")
DatasetDict({
test: Dataset({
features: ['qid', 'title', 'language', 'signature', 'arguments', 'source_py', 'source_cpp', 'question_info'],
num_rows: 8384
})
})
Data Fields
qid: The question ID used for running tests.title: The title of the question.language: The programming language of the example.signature: The signature for the problem.arguments: The arguments of the problem.source_py: The source solution in Python.source_cpp: The source in C++.question_info: The dict of information used for executing predictions. It has the keys:test_code: The raw testing script used in the language. If you want to use this, replacePLACEHOLDER_FN_NAME(andPLACEHOLDER_CLS_NAMEif needed) with the corresponding entry points. Next, replacePLACEHOLDER_CODE_BODYwith the postprocessed prediction.test_list: The raw json line of the list of tests for the problem. To load them, usejson.loadstest_case_ids: The list of test case ids for the problem. These are used to determine if a prediction passes or not.entry_fn_name: The function's name to use an entry point.entry_cls_name: The class name to use an entry point.commands: The commands used to execute the prediction. Includes a__FILENAME__hole that is replaced with the filename.timeouts: The default timeouts for each command.extension: The extension for the prediction file.
NOTE: If you want to use a different function name (or class name for languages that require class names) for the prediction, you must update the entry_fn_name and entry_cls_name accordingly. For example, if you have the original question with entry_fn_name of add, but want to change it to f, you must update ds["question_info"]["entry_fn_name"] to f:
>>> from datasets import load_dataset
>>> ds = load_dataset("gabeorlanski/bc-mbpp")['test']
>>> # The original entry_fn_name
>>> ds[0]['question_info']['entry_fn_name']
removeOcc
>>> # You MUST update the corresponding entry_fn_name
>>> ds[0]['question_info']['entry_fn_name'] = 'f'
>>> ds[0]['question_info']['entry_fn_name']
f
Dataset Creation
See section 2 of the BabelCode Paper to learn more about how the datasets are translated.
For information on the original curation of the Transcoder Dataset, please see Unsupervised Translation of Programming Languages by Roziere et. al.
Dataset Curators
Google Research
Licensing Information
CC-BY-4.0
Citation Information
@article{orlanski2023measuring,
title={Measuring The Impact Of Programming Language Distribution},
author={Orlanski, Gabriel and Xiao, Kefan and Garcia, Xavier and Hui, Jeffrey and Howland, Joshua and Malmaud, Jonathan and Austin, Jacob and Singh, Rishah and Catasta, Michele},
journal={arXiv preprint arXiv:2302.01973},
year={2023}
}
@article{roziere2020unsupervised,
title={Unsupervised translation of programming languages},
author={Roziere, Baptiste and Lachaux, Marie-Anne and Chanussot, Lowik and Lample, Guillaume},
journal={Advances in Neural Information Processing Systems},
volume={33},
year={2020}
}
- Downloads last month
- 125