qid
stringlengths
1
3
title
stringlengths
9
106
language
stringclasses
1 value
signature
stringlengths
24
145
arguments
list
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 ) ); }
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
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; }
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
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; }
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
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 ); }
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
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; }
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
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 ); }
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
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...
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
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; }
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
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 ); }
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
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 ]; }...
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
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; }
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
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 ...
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
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; }
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
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; }
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
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 ) ) ); }
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
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; }
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
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; }
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
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 ...
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
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 ); }
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
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 ) ); ...
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
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; }
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
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 ...
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
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 ); }
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
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,...
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
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; }
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
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...
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
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; }
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
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 ); }
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
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 ); }
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
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; }
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
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 ++; ...
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
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; }
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
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 -...
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
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 ) ); }
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
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; }
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
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; }
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
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;...
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
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; }
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
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...
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
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; ...
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
45
Check String Can Obtained Rotating Another String 2 Places
C++
bool checkStringCanObtainedRotatingAnotherString2Places(string str1, string str2) {
[ "str1", "str2" ]
def check_string_can_obtained_rotating_another_string_2_places(str1, str2): if (len(str1) != len(str2)): return False clock_rot = '' anticlock_rot = '' l = len(str2) anticlock_rot = ((anticlock_rot + str2[(l - 2):]) + str2[0:(l - 2)]) clock_rot = ((clock_rot + str2[2:]) + str2[0:2]) ...
bool check_string_can_obtained_rotating_another_string_2_places(string str1, string str2) { if ( str1 . length ( ) != str2 . length ( ) ) return false; string clock_rot = ""; string anticlock_rot = ""; int len = str2 . length ( ); anticlock_rot = anticlock_rot + str2 . substr ( len - 2, 2 ) + str2 . substr ( ...
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
46
Check String Follows Anbn Pattern Not
C++
bool checkStringFollowsAnbnPatternNot(string str) {
[ "str" ]
def check_string_follows_anbn_pattern_not(str): n = len(str) for i in range(n): if (str[i] != 'a'): break if ((i * 2) != n): return False for j in range(i, n): if (str[j] != 'b'): return False return True
bool check_string_follows_anbn_pattern_not(string str) { int n = str . length ( ); int i; for ( i = 0; i < n; i ++ ) if ( str [ i ] != 'a' ) break; if ( i * 2 != n ) return false; int j; for ( j = i; j < n; j ++ ) if ( str [ j ] != 'b' ) return false; return true; }
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
47
Check Two Given Circles Touch Intersect
C++
int checkTwoGivenCirclesTouchIntersect(int x1, int y1, int x2, int y2, int r1, int r2) {
[ "x1", "y1", "x2", "y2", "r1", "r2" ]
def check_two_given_circles_touch_intersect(x1, y1, x2, y2, r1, r2): distSq = (((x1 - x2) * (x1 - x2)) + ((y1 - y2) * (y1 - y2))) radSumSq = ((r1 + r2) * (r1 + r2)) if (distSq == radSumSq): return 1 elif (distSq > radSumSq): return (- 1) else: return 0
int check_two_given_circles_touch_intersect(int x1, int y1, int x2, int y2, int r1, int r2) { int distSq = ( x1 - x2 ) * ( x1 - x2 ) + ( y1 - y2 ) * ( y1 - y2 ); int radSumSq = ( r1 + r2 ) * ( r1 + r2 ); if ( distSq == radSumSq ) return 1; else if ( distSq > radSumSq ) return - 1; else return 0; }
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
48
Check Whether Arithmetic Progression Can Formed Given Array
C++
bool checkWhetherArithmeticProgressionCanFormedGivenArray(vector<int> arr, int n) {
[ "arr", "n" ]
def check_whether_arithmetic_progression_can_formed_given_array(arr, n): if (n == 1): return True arr.sort() d = (arr[1] - arr[0]) for i in range(2, n): if ((arr[i] - arr[(i - 1)]) != d): return False return True
bool check_whether_arithmetic_progression_can_formed_given_array(vector<int> arr, int n) { if ( n == 1 ) return true; sort(arr.begin(), arr.end()); int d = arr [ 1 ] - arr [ 0 ]; for ( int i = 2; i < n; i ++ ) if ( arr [ i ] - arr [ i - 1 ] != d ) return false; return true; }
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
49
Check Whether Given Degrees Vertices Represent Graph Tree
C++
bool checkWhetherGivenDegreesVerticesRepresentGraphTree(vector<int> degree, int n) {
[ "degree", "n" ]
def check_whether_given_degrees_vertices_represent_graph_tree(degree, n): deg_sum = sum(degree) if ((2 * (n - 1)) == deg_sum): return True else: return False
bool check_whether_given_degrees_vertices_represent_graph_tree(vector<int> degree, int n) { int deg_sum = 0; for ( int i = 0; i < n; i ++ ) deg_sum += degree [ i ]; return ( 2 * ( n - 1 ) == deg_sum ); }
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
50
Check Whether Given Number Even Odd
C++
bool checkWhetherGivenNumberEvenOdd(int n) {
[ "n" ]
def check_whether_given_number_even_odd(n): return ((n % 2) == 0)
bool check_whether_given_number_even_odd(int n) { return ( n % 2 == 0 ); }
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
51
Check Whether Given Number Even Odd 1
C++
bool checkWhetherGivenNumberEvenOdd1(int n) {
[ "n" ]
def check_whether_given_number_even_odd_1(n): return (not (n & 1))
bool check_whether_given_number_even_odd_1(int n) { return ( ! ( n & 1 ) ); }
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
52
Check Whether Triangle Valid Not Sides Given
C++
bool checkWhetherTriangleValidNotSidesGiven(int a, int b, int c) {
[ "a", "b", "c" ]
def check_whether_triangle_valid_not_sides_given(a, b, c): if (((a + b) <= c) or ((a + c) <= b) or ((b + c) <= a)): return False else: return True
bool check_whether_triangle_valid_not_sides_given(int a, int b, int c) { if ( a + b <= c || a + c <= b || b + c <= a ) return false; else return true; }
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
53
Chocolate Distribution Problem
C++
int chocolateDistributionProblem(vector<int> arr, int n, int m) {
[ "arr", "n", "m" ]
def chocolate_distribution_problem(arr, n, m): if ((m == 0) or (n == 0)): return 0 arr.sort() if (n < m): return (- 1) min_diff = sys.maxsize first = 0 last = 0 i = 0 while (((i + m) - 1) < n): diff = (arr[((i + m) - 1)] - arr[i]) if (diff < min_diff): ...
int chocolate_distribution_problem(vector<int> arr, int n, int m) { if ( m == 0 || n == 0 ) return 0; sort(arr.begin(), arr.end()); if ( n < m ) return - 1; int min_diff = INT_MAX; int first = 0, last = 0; for ( int i = 0; i + m - 1 < n; i ++ ) { int diff = arr [ i + m - 1 ] - arr [ i ]; if ( di...
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
54
Circle Lattice Points
C++
int circleLatticePoints(int r) {
[ "r" ]
def circle_lattice_points(r): if (r <= 0): return 0 result = 4 for x in range(1, r): ySquare = ((r * r) - (x * x)) y = int(math.sqrt(ySquare)) if ((y * y) == ySquare): result += 4 return result
int circle_lattice_points(int r) { if ( r <= 0 ) return 0; int result = 4; for ( int x = 1; x < r; x ++ ) { int ySquare = r * r - x * x; int y = sqrt ( ySquare ); if ( y * y == ySquare ) result += 4; } return result; }
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
55
Coin Game Winner Every Player Three Choices
C++
bool coinGameWinnerEveryPlayerThreeChoices(int x, int y, int n) {
[ "x", "y", "n" ]
def coin_game_winner_every_player_three_choices(x, y, n): dp = [0 for i in range((n + 1))] dp[0] = False dp[1] = True for i in range(2, (n + 1)): if (((i - 1) >= 0) and (not dp[(i - 1)])): dp[i] = True elif (((i - x) >= 0) and (not dp[(i - x)])): dp[i] = True ...
bool coin_game_winner_every_player_three_choices(int x, int y, int n) { int dp [ n + 1 ]; dp [ 0 ] = false; dp [ 1 ] = true; for ( int i = 2; i <= n; i ++ ) { if ( i - 1 >= 0 and ! dp [ i - 1 ] ) dp [ i ] = true; else if ( i - x >= 0 and ! dp [ i - x ] ) dp [ i ] = true; else if ( i - y >= 0 and...
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
56
Composite Number
C++
bool compositeNumber(int n) {
[ "n" ]
def composite_number(n): if (n <= 1): return False if (n <= 3): return False if (((n % 2) == 0) or ((n % 3) == 0)): return True i = 5 while ((i * i) <= n): if (((n % i) == 0) or ((n % (i + 2)) == 0)): return True i = (i + 6) return False
bool composite_number(int n) { if ( n <= 1 ) return false; if ( n <= 3 ) return false; if ( n % 2 == 0 || n % 3 == 0 ) return true; for ( int i = 5; i * i <= n; i = i + 6 ) if ( n % i == 0 || n % ( i + 2 ) == 0 ) return true; return false; }
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
57
Compute Average Two Numbers Without Overflow
C++
int computeAverageTwoNumbersWithoutOverflow(int a, int b) {
[ "a", "b" ]
def compute_average_two_numbers_without_overflow(a, b): return floor(((a + b) / 2))
int compute_average_two_numbers_without_overflow(int a, int b) { return ( a + b ) / 2; }
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
58
Compute Average Two Numbers Without Overflow 1
C++
int computeAverageTwoNumbersWithoutOverflow1(int a, int b) {
[ "a", "b" ]
def compute_average_two_numbers_without_overflow_1(a, b): return (((a // 2) + (b // 2)) + (((a % 2) + (b % 2)) // 2))
int compute_average_two_numbers_without_overflow_1(int a, int b) { return ( a / 2 ) + ( b / 2 ) + ( ( a % 2 + b % 2 ) / 2 ); }
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
59
Compute Modulus Division By A Power Of 2 Number
C++
int computeModulusDivisionByAPowerOf2Number(int n, int d) {
[ "n", "d" ]
def compute_modulus_division_by_a_power_of_2_number(n, d): return (n & (d - 1))
unsigned int compute_modulus_division_by_a_power_of_2_number(unsigned int n, unsigned int d) { return ( n & ( d - 1 ) ); }
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
60
Compute Ncr P Set 1 Introduction And Dynamic Programming Solution
C++
int computeNcrPSet1IntroductionAndDynamicProgrammingSolution(int n, int r, int p) {
[ "n", "r", "p" ]
def compute_ncr_p_set_1_introduction_and_dynamic_programming_solution(n, r, p): C = [0 for i in range((r + 1))] C[0] = 1 for i in range(1, (n + 1)): for j in range(min(i, r), 0, (- 1)): C[j] = ((C[j] + C[(j - 1)]) % p) return C[r]
int compute_ncr_p_set_1_introduction_and_dynamic_programming_solution(int n, int r, int p) { int C [ r + 1 ]; memset ( C, 0, sizeof ( C ) ); C [ 0 ] = 1; for ( int i = 1; i <= n; i ++ ) { for ( int j = min ( i, r ); j > 0; j -- ) C [ j ] = ( C [ j ] + C [ j - 1 ] ) % p; } return C [ r ]; }
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
61
Compute N Under Modulo P
C++
int computeNUnderModuloP(int n, int p) {
[ "n", "p" ]
def compute_n_under_modulo_p(n, p): if (n >= p): return 0 result = 1 for i in range(1, (n + 1)): result = ((result * i) % p) return result
int compute_n_under_modulo_p(int n, int p) { if ( n >= p ) return 0; int result = 1; for ( int i = 1; i <= n; i ++ ) result = ( result * i ) % p; return result; }
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
62
Converting One String Using Append Delete Last Operations
C++
bool convertingOneStringUsingAppendDeleteLastOperations(string str1, string str2, int k) {
[ "str1", "str2", "k" ]
def converting_one_string_using_append_delete_last_operations(str1, str2, k): if ((len(str1) + len(str2)) < k): return True commonLength = 0 for i in range(0, min(len(str1), len(str2)), 1): if (str1[i] == str2[i]): commonLength += 1 else: break if (((((k -...
bool converting_one_string_using_append_delete_last_operations(string str1, string str2, int k) { if ( ( str1 . length ( ) + str2 . length ( ) ) < k ) return true; int commonLength = 0; for ( int i = 0; i < min ( str1 . length ( ), str2 . length ( ) ); i ++ ) { if ( str1 [ i ] == str2 [ i ] ) commonLength...
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
63
Convert Strictly Increasing Array Minimum Changes
C++
int convertStrictlyIncreasingArrayMinimumChanges(vector<int> arr, int n) {
[ "arr", "n" ]
def convert_strictly_increasing_array_minimum_changes(arr, n): LIS = [0 for i in range(n)] len = 0 for i in range(n): LIS[i] = 1 for i in range(1, n): for j in range(i): if ((arr[i] > arr[j]) and ((i - j) <= (arr[i] - arr[j]))): LIS[i] = max(LIS[i], (LIS[j] + ...
int convert_strictly_increasing_array_minimum_changes(vector<int> arr, int n) { int LIS [ n ], len = 0; for ( int i = 0; i < n; i ++ ) LIS [ i ] = 1; for ( int i = 1; i < n; i ++ ) { for ( int j = 0; j < i; j ++ ) { if ( arr [ i ] > arr [ j ] && ( i - j ) <= ( arr [ i ] - arr [ j ] ) ) {...
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
65
Count Characters Position English Alphabets
C++
int countCharactersPositionEnglishAlphabets(string str) {
[ "str" ]
def count_characters_position_english_alphabets(str): result = 0 for i in range(len(str)): if ((i == (ord(str[i]) - ord('a'))) or (i == (ord(str[i]) - ord('A')))): result += 1 return result
int count_characters_position_english_alphabets(string str) { int result = 0; for ( int i = 0; i < str . size ( ); i ++ ) if ( i == ( str [ i ] - 'a' ) || i == ( str [ i ] - 'A' ) ) result ++; return result; }
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
66
Count Characters String Distance English Alphabets
C++
int countCharactersStringDistanceEnglishAlphabets(string str1) {
[ "str1" ]
def count_characters_string_distance_english_alphabets(str1): result = 0 n = len(str1) for i in range(0, n): for j in range((i + 1), n): if (abs((ord(str1[i]) - ord(str1[j]))) == abs((i - j))): result += 1 return result
int count_characters_string_distance_english_alphabets(string str) { int result = 0; int n = str . length ( ); for ( int i = 0; i < n; i ++ ) for ( int j = i + 1; j < n; j ++ ) if ( abs ( str [ i ] - str [ j ] ) == abs ( i - j ) ) result ++; return result; }
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
68
Count Digits Factorial Set 1
C++
int countDigitsFactorialSet1(int n) {
[ "n" ]
def count_digits_factorial_set_1(n): if (n < 0): return 0 if (n <= 1): return 1 digits = 0 for i in range(2, (n + 1)): digits += math.log10(i) return (math.floor(digits) + 1)
int count_digits_factorial_set_1(int n) { if ( n < 0 ) return 0; if ( n <= 1 ) return 1; double digits = 0; for ( int i = 2; i <= n; i ++ ) digits += log10 ( i ); return floor ( digits ) + 1; }
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
69
Count Digits Factorial Set 2
C++
int countDigitsFactorialSet2(int n) {
[ "n" ]
def count_digits_factorial_set_2(n): if (n < 0): return 0 if (n <= 1): return 1 x = ((n * math.log10((n / math.e))) + (math.log10(((2 * math.pi) * n)) / 2.0)) return (math.floor(x) + 1)
long long count_digits_factorial_set_2(int n) { if ( n < 0 ) return 0; if ( n <= 1 ) return 1; double x = ( ( n * log10 ( n / M_E ) + log10 ( 2 * M_PI * n ) / 2.0 ) ); return floor ( x ) + 1; }
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
70
Count Distinct Non Negative Pairs X Y Satisfy Inequality Xx Yy N 2
C++
int countDistinctNonNegativePairsXYSatisfyInequalityXxYyN2(int n) {
[ "n" ]
def count_distinct_non_negative_pairs_x_y_satisfy_inequality_xx_yy_n_2(n): res = 0 x = 0 while ((x * x) < n): y = 0 while (((x * x) + (y * y)) < n): res = (res + 1) y = (y + 1) x = (x + 1) return res
int count_distinct_non_negative_pairs_x_y_satisfy_inequality_xx_yy_n_2(int n) { int res = 0; for ( int x = 0; x * x < n; x ++ ) for ( int y = 0; x * x + y * y < n; y ++ ) res ++; return res; }
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
71
Count Distinct Non Negative Pairs X Y Satisfy Inequality Xx Yy N 2 1
C++
int countDistinctNonNegativePairsXYSatisfyInequalityXxYyN21(int n) {
[ "n" ]
def count_distinct_non_negative_pairs_x_y_satisfy_inequality_xx_yy_n_2_1(n): x = 0 res = 0 yCount = 0 while ((yCount * yCount) < n): yCount = (yCount + 1) while (yCount != 0): res = (res + yCount) x = (x + 1) while ((yCount != 0) and (((x * x) + ((yCount - 1) * (yCoun...
int count_distinct_non_negative_pairs_x_y_satisfy_inequality_xx_yy_n_2_1(int n) { int x = 0, yCount, res = 0; for ( yCount = 0; yCount * yCount < n; yCount ++ ); while ( yCount != 0 ) { res += yCount; x ++; while ( yCount != 0 && ( x * x + ( yCount - 1 ) * ( yCount - 1 ) >= n ) ) yCount --; } ...
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
72
Count Distinct Occurrences As A Subsequence
C++
int countDistinctOccurrencesAsASubsequence(string s, string t) {
[ "s", "t" ]
def count_distinct_occurrences_as_a_subsequence(S, T): m = len(T) n = len(S) if (m > n): return 0 mat = [[0 for _ in range((n + 1))] for __ in range((m + 1))] for i in range(1, (m + 1)): mat[i][0] = 0 for j in range((n + 1)): mat[0][j] = 1 for i in range(1, (m + 1)): ...
int count_distinct_occurrences_as_a_subsequence(string S, string T) { int m = T . length ( ), n = S . length ( ); if ( m > n ) return 0; int mat [ m + 1 ] [ n + 1 ]; for ( int i = 1; i <= m; i ++ ) mat [ i ] [ 0 ] = 0; for ( int j = 0; j <= n; j ++ ) mat [ 0 ] [ j ] = 1; for ( int i = 1; i <= m; ...
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
73
Count Even Length Binary Sequences With Same Sum Of First And Second Half Bits 1
C++
double countEvenLengthBinarySequencesWithSameSumOfFirstAndSecondHalfBits1(int n) {
[ "n" ]
def count_even_length_binary_sequences_with_same_sum_of_first_and_second_half_bits_1(n): nCr = 1 res = 1 for r in range(1, (n + 1)): nCr = ((nCr * ((n + 1) - r)) / r) res += (nCr * nCr) return res
int count_even_length_binary_sequences_with_same_sum_of_first_and_second_half_bits_1(int n) { int nCr = 1, res = 1; for ( int r = 1; r <= n; r ++ ) { nCr = ( nCr * ( n + 1 - r ) ) / r; res += nCr * nCr; } return res; }
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
74
Count Factorial Numbers In A Given Range
C++
int countFactorialNumbersInAGivenRange(int low, int high) {
[ "low", "high" ]
def count_factorial_numbers_in_a_given_range(low, high): fact = 1 x = 1 while (fact < low): fact = (fact * x) x += 1 res = 0 while (fact <= high): res += 1 fact = (fact * x) x += 1 return res
int count_factorial_numbers_in_a_given_range(int low, int high) { int fact = 1, x = 1; while ( fact < low ) { fact = fact * x; x ++; } int res = 0; while ( fact <= high ) { res ++; fact = fact * x; x ++; } return res; }
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
75
Count Fibonacci Numbers Given Range Log Time
C++
int countFibonacciNumbersGivenRangeLogTime(int low, int high) {
[ "low", "high" ]
def count_fibonacci_numbers_given_range_log_time(low, high): (f1, f2, f3) = (0, 1, 1) result = 0 while (f1 <= high): if (f1 >= low): result += 1 f1 = f2 f2 = f3 f3 = (f1 + f2) return result
int count_fibonacci_numbers_given_range_log_time(int low, int high) { int f1 = 0, f2 = 1, f3 = 1; int result = 0; while ( f1 <= high ) { if ( f1 >= low ) result ++; f1 = f2; f2 = f3; f3 = f1 + f2; } return result; }
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
76
Count Frequency K Matrix Size N Matrixi J Ij
C++
int countFrequencyKMatrixSizeNMatrixiJIj(int n, int k) {
[ "n", "k" ]
def count_frequency_k_matrix_size_n_matrixi_j_ij(n, k): if ((n + 1) >= k): return (k - 1) else: return (((2 * n) + 1) - k)
int count_frequency_k_matrix_size_n_matrixi_j_ij(int n, int k) { if ( n + 1 >= k ) return ( k - 1 ); else return ( 2 * n + 1 - k ); }
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
77
Count Index Pairs Equal Elements Array
C++
int countIndexPairsEqualElementsArray(vector<int> arr, int n) {
[ "arr", "n" ]
def count_index_pairs_equal_elements_array(arr, n): ans = 0 for i in range(0, n): for j in range((i + 1), n): if (arr[i] == arr[j]): ans += 1 return ans
int count_index_pairs_equal_elements_array(vector<int> arr, int n) { int ans = 0; for ( int i = 0; i < n; i ++ ) for ( int j = i + 1; j < n; j ++ ) if ( arr [ i ] == arr [ j ] ) ans ++; return ans; }
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
78
Count Index Pairs Equal Elements Array 1
C++
int countIndexPairsEqualElementsArray1(vector<int> arr, int n) {
[ "arr", "n" ]
def count_index_pairs_equal_elements_array_1(arr, n): mp = dict() for i in range(n): if (arr[i] in mp.keys()): mp[arr[i]] += 1 else: mp[arr[i]] = 1 ans = 0 for it in mp: count = mp[it] ans += ((count * (count - 1)) // 2) return ans
int count_index_pairs_equal_elements_array_1(vector<int> arr, int n) { unordered_map < int, int > mp; for ( int i = 0; i < n; i ++ ) mp [ arr [ i ] ] ++; int ans = 0; for ( auto it = mp . begin ( ); it != mp . end ( ); it ++ ) { int count = it -> second; ans += ( count * ( count - 1 ) ) / 2; }...
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
79
Count Inversions Of Size Three In A Give Array 1
C++
int countInversionsOfSizeThreeInAGiveArray1(vector<int> arr, int n) {
[ "arr", "n" ]
def count_inversions_of_size_three_in_a_give_array_1(arr, n): invcount = 0 for i in range(1, (n - 1)): small = 0 for j in range((i + 1), n): if (arr[i] > arr[j]): small += 1 great = 0 for j in range((i - 1), (- 1), (- 1)): if (arr[i] < arr[...
int count_inversions_of_size_three_in_a_give_array_1(vector<int> arr, int n) { int invcount = 0; for ( int i = 1; i < n - 1; i ++ ) { int small = 0; for ( int j = i + 1; j < n; j ++ ) if ( arr [ i ] > arr [ j ] ) small ++; int great = 0; for ( int j = i - 1; j >= 0; j -- ) if ( a...
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
80
Count Minimum Number Subsets Subsequences Consecutive Numbers
C++
int countMinimumNumberSubsetsSubsequencesConsecutiveNumbers(vector<int> arr, int n) {
[ "arr", "n" ]
def count_minimum_number_subsets_subsequences_consecutive_numbers(arr, n): x = sorted(arr) count = 1 for i in range(0, (n - 1)): if ((x[i] + 1) != x[(i + 1)]): count = (count + 1) return count
int count_minimum_number_subsets_subsequences_consecutive_numbers(vector<int> arr, int n) { sort(arr.begin(), arr.end()); int count = 1; for ( int i = 0; i < n - 1; i ++ ) { if ( arr [ i ] + 1 != arr [ i + 1 ] ) count ++; } return count; }
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
81
Count Natural Numbers Whose Permutation Greater Number
C++
int countNaturalNumbersWhosePermutationGreaterNumber(int n) {
[ "n" ]
def count_natural_numbers_whose_permutation_greater_number(n): result = 0 for i in range(1, 10): s = [] if (i <= n): s.append(i) result += 1 while (len(s) != 0): tp = s[(- 1)] s.pop() for j in range((tp % 10), 10): ...
int count_natural_numbers_whose_permutation_greater_number(int n) { int result = 0; for ( int i = 1; i <= 9; i ++ ) { stack < int > s; if ( i <= n ) { s . push ( i ); result ++; } while ( ! s . empty ( ) ) { int tp = s . top ( ); s . pop ( ); for ( int j = tp % 10; ...
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
82
Count Numbers Can Constructed Using Two Numbers
C++
int countNumbersCanConstructedUsingTwoNumbers(int n, int x, int y) {
[ "n", "x", "y" ]
def count_numbers_can_constructed_using_two_numbers(n, x, y): arr = [False for i in range((n + 2))] if (x <= n): arr[x] = True if (y <= n): arr[y] = True result = 0 for i in range(min(x, y), (n + 1)): if arr[i]: if ((i + x) <= n): arr[(i + x)] = Tr...
int count_numbers_can_constructed_using_two_numbers(int n, int x, int y) { vector < bool > arr ( n + 1, false ); if ( x <= n ) arr [ x ] = true; if ( y <= n ) arr [ y ] = true; int result = 0; for ( int i = min ( x, y ); i <= n; i ++ ) { if ( arr [ i ] ) { if ( i + x <= n ) arr [ i + x ] = true;...
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
83
Count Numbers That Dont Contain 3
C++
double countNumbersThatDontContain3(int n) {
[ "n" ]
def count_numbers_that_dont_contain_3(n): if (n < 3): return n elif ((n >= 3) and (n < 10)): return (n - 1) po = 1 while ((n / po) > 9): po = (po * 10) msd = (n / po) if (msd != 3): return (((count_numbers_that_dont_contain_3(msd) * count_numbers_that_dont_contain...
int count_numbers_that_dont_contain_3(int n) { if ( n < 3 ) return n; if ( n >= 3 && n < 10 ) return n - 1; int po = 1; while ( n / po > 9 ) po = po * 10; int msd = n / po; if ( msd != 3 ) return count_numbers_that_dont_contain_3 ( msd ) * count_numbers_that_dont_contain_3 ( po - 1 ) + count_numbers_that_do...
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
84
Count Number Binary Strings Without Consecutive 1S
C++
long long countNumberBinaryStringsWithoutConsecutive1S(int n) {
[ "n" ]
def count_number_binary_strings_without_consecutive_1s(n): a = [0 for i in range(n)] b = [0 for i in range(n)] a[0] = b[0] = 1 for i in range(1, n): a[i] = (a[(i - 1)] + b[(i - 1)]) b[i] = a[(i - 1)] return (a[(n - 1)] + b[(n - 1)])
int count_number_binary_strings_without_consecutive_1s(int n) { int a [ n ], b [ n ]; a [ 0 ] = b [ 0 ] = 1; for ( int i = 1; i < n; i ++ ) { a [ i ] = a [ i - 1 ] + b [ i - 1 ]; b [ i ] = a [ i - 1 ]; } return a [ n - 1 ] + b [ n - 1 ]; }
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
85
Count Number Of Occurrences Or Frequency In A Sorted Array
C++
int countNumberOfOccurrencesOrFrequencyInASortedArray(vector<int> arr, int n, int x) {
[ "arr", "n", "x" ]
def count_number_of_occurrences_or_frequency_in_a_sorted_array(arr, n, x): res = 0 for i in range(n): if (x == arr[i]): res += 1 return res
int count_number_of_occurrences_or_frequency_in_a_sorted_array(vector<int> arr, int n, int x) { int res = 0; for ( int i = 0; i < n; i ++ ) if ( x == arr [ i ] ) res ++; return res; }
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
86
Count Number Of Ways To Cover A Distance 1
C++
long long countNumberOfWaysToCoverADistance1(int dist) {
[ "dist" ]
def count_number_of_ways_to_cover_a_distance_1(dist): count = ([0] * (dist + 1)) count[0] = 1 count[1] = 1 count[2] = 2 for i in range(3, (dist + 1)): count[i] = ((count[(i - 1)] + count[(i - 2)]) + count[(i - 3)]) return count[dist]
int count_number_of_ways_to_cover_a_distance_1(int dist) { int count [ dist + 1 ]; count [ 0 ] = 1, count [ 1 ] = 1, count [ 2 ] = 2; for ( int i = 3; i <= dist; i ++ ) count [ i ] = count [ i - 1 ] + count [ i - 2 ] + count [ i - 3 ]; return count [ dist ]; }
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
87
Count Number Of Ways To Fill A N X 4 Grid Using 1 X 4 Tiles
C++
long long countNumberOfWaysToFillANX4GridUsing1X4Tiles(int n) {
[ "n" ]
def count_number_of_ways_to_fill_a_n_x_4_grid_using_1_x_4_tiles(n): dp = [0 for _ in range((n + 1))] for i in range(1, (n + 1)): if (i <= 3): dp[i] = 1 elif (i == 4): dp[i] = 2 else: dp[i] = (dp[(i - 1)] + dp[(i - 4)]) return dp[n]
int count_number_of_ways_to_fill_a_n_x_4_grid_using_1_x_4_tiles(int n) { int dp [ n + 1 ]; dp [ 0 ] = 0; for ( int i = 1; i <= n; i ++ ) { if ( i >= 1 && i <= 3 ) dp [ i ] = 1; else if ( i == 4 ) dp [ i ] = 2; else dp [ i ] = dp [ i - 1 ] + dp [ i - 4 ]; } return dp [ n ]; }
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
88
Count Number Pairs N B N Gcd B B
C++
double countNumberPairsNBNGcdBB(int n) {
[ "n" ]
def count_number_pairs_n_b_n_gcd_b_b(n): k = n imin = 1 ans = 0 while (imin <= n): imax = (n / k) ans += (k * ((imax - imin) + 1)) imin = (imax + 1) k = (n / imin) return ans
int count_number_pairs_n_b_n_gcd_b_b(int n) { int k = n; int imin = 1; int ans = 0; while ( imin <= n ) { int imax = n / k; ans += k * ( imax - imin + 1 ); imin = imax + 1; k = n / imin; } return ans; }
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
89
Count Number Ways Reach Given Score Game
C++
int countNumberWaysReachGivenScoreGame(int n) {
[ "n" ]
def count_number_ways_reach_given_score_game(n): table = [0 for i in range((n + 1))] table[0] = 1 for i in range(3, (n + 1)): table[i] += table[(i - 3)] for i in range(5, (n + 1)): table[i] += table[(i - 5)] for i in range(10, (n + 1)): table[i] += table[(i - 10)] return ...
int count_number_ways_reach_given_score_game(int n) { int table [ n + 1 ], i; for ( int j = 0; j < n + 1; j ++ ) table [ j ] = 0; table [ 0 ] = 1; for ( i = 3; i <= n; i ++ ) table [ i ] += table [ i - 3 ]; for ( i = 5; i <= n; i ++ ) table [ i ] += table [ i - 5 ]; for ( i = 10; i <= n; i +...
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
90
Count Number Ways Tile Floor Size N X M Using 1 X M Size Tiles
C++
long long countNumberWaysTileFloorSizeNXMUsing1XMSizeTiles(int n, int m) {
[ "n", "m" ]
def count_number_ways_tile_floor_size_n_x_m_using_1_x_m_size_tiles(n, m): count = [] for i in range((n + 2)): count.append(0) count[0] = 0 for i in range(1, (n + 1)): if (i > m): count[i] = (count[(i - 1)] + count[(i - m)]) elif (i < m): count[i] = 1 ...
int count_number_ways_tile_floor_size_n_x_m_using_1_x_m_size_tiles(int n, int m) { int count [ n + 1 ]; count [ 0 ] = 0; for ( int i = 1; i <= n; i ++ ) { if ( i > m ) count [ i ] = count [ i - 1 ] + count [ i - m ]; else if ( i < m ) count [ i ] = 1; else count [ i ] = 2; } return count [ n ]...
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
91
Count Obtuse Angles Circle K Equidistant Points 2 Given Points
C++
int countObtuseAnglesCircleKEquidistantPoints2GivenPoints(int a, int b, int k) {
[ "a", "b", "k" ]
def count_obtuse_angles_circle_k_equidistant_points_2_given_points(a, b, k): c1 = ((b - a) - 1) c2 = ((k - b) + (a - 1)) if (c1 == c2): return 0 return min(c1, c2)
int count_obtuse_angles_circle_k_equidistant_points_2_given_points(int a, int b, int k) { int c1 = ( b - a ) - 1; int c2 = ( k - b ) + ( a - 1 ); if ( c1 == c2 ) return 0; return min ( c1, c2 ); }
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
92
Count Ofdifferent Ways Express N Sum 1 3 4
C++
long long countOfdifferentWaysExpressNSum134(int n) {
[ "n" ]
def count_ofdifferent_ways_express_n_sum_1_3_4(n): DP = [0 for i in range(0, (n + 1))] DP[0] = DP[1] = DP[2] = 1 DP[3] = 2 for i in range(4, (n + 1)): DP[i] = ((DP[(i - 1)] + DP[(i - 3)]) + DP[(i - 4)]) return DP[n]
int count_ofdifferent_ways_express_n_sum_1_3_4(int n) { int DP [ n + 1 ]; DP [ 0 ] = DP [ 1 ] = DP [ 2 ] = 1; DP [ 3 ] = 2; for ( int i = 4; i <= n; i ++ ) DP [ i ] = DP [ i - 1 ] + DP [ i - 3 ] + DP [ i - 4 ]; return DP [ n ]; }
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
93
Count Of Occurrences Of A 101 Pattern In A String
C++
int countOfOccurrencesOfA101PatternInAString(string s) {
[ "s" ]
def count_of_occurrences_of_a_101_pattern_in_a_string(s): length = len(s) oneSeen = False count = 0 for i in range(length): if ((s[i] == '1') and oneSeen): if (s[(i - 1)] == '0'): count += 1 if ((s[i] == '1') and (oneSeen == 0)): oneSeen = True ...
int count_of_occurrences_of_a_101_pattern_in_a_string(string str) { int len = str . size ( ); bool oneSeen = 0; int count = 0; for ( int i = 0; i < len; i ++ ) { if ( str [ i ] == '1' && oneSeen == 1 ) if ( str [ i - 1 ] == '0' ) count ++; if ( str [ i ] == '1' && oneSeen == 0 ) { oneSeen = 1;...
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
94
Count Of Pairs Satisfying The Given Condition
C++
int countOfPairsSatisfyingTheGivenCondition(int a, int b) {
[ "a", "b" ]
def count_of_pairs_satisfying_the_given_condition(a, b): s = str(b) i = 0 while (i < len(s)): if (s[i] != '9'): break i += 1 result = 0 if (i == len(s)): result = (a * len(s)) else: result = (a * (len(s) - 1)) return result
int count_of_pairs_satisfying_the_given_condition(int a, int b) { string s = to_string ( b ); int i; for ( i = 0; i < s . length ( ); i ++ ) { if ( s [ i ] != '9' ) break; } int result; if ( i == s . length ( ) ) result = a * s . length ( ); else result = a * ( s . length ( ) - 1 ); return resul...
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
95
Count Pairs Difference Equal K
C++
int countPairsDifferenceEqualK(vector<int> arr, int n, int k) {
[ "arr", "n", "k" ]
def count_pairs_difference_equal_k(arr, n, k): count = 0 for i in range(0, n): for j in range((i + 1), n): if (((arr[i] - arr[j]) == k) or ((arr[j] - arr[i]) == k)): count += 1 return count
int count_pairs_difference_equal_k(vector<int> arr, int n, int k) { int count = 0; for ( int i = 0; i < n; i ++ ) { for ( int j = i + 1; j < n; j ++ ) if ( arr [ i ] - arr [ j ] == k || arr [ j ] - arr [ i ] == k ) count ++; } return count; }
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
96
Count Pairs Difference Equal K 1
C++
int countPairsDifferenceEqualK1(vector<int> arr, int n, int k) {
[ "arr", "n", "k" ]
def count_pairs_difference_equal_k_1(arr, n, k): count = 0 arr.sort() l = 0 r = 0 while (r < n): if ((arr[r] - arr[l]) == k): count += 1 l += 1 r += 1 elif ((arr[r] - arr[l]) > k): l += 1 else: r += 1 return coun...
int count_pairs_difference_equal_k_1(vector<int> arr, int n, int k) { int count = 0; sort(arr.begin(), arr.end()); int l = 0; int r = 0; while ( r < n ) { if ( arr [ r ] - arr [ l ] == k ) { count ++; l ++; r ++; } else if ( arr [ r ] - arr [ l ] > k ) l ++; else r ++; } ...
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
97
Count Pairs Two Sorted Arrays Whose Sum Equal Given Value X
C++
int countPairsTwoSortedArraysWhoseSumEqualGivenValueX(vector<int> arr1, vector<int> arr2, int m, int n, int x) {
[ "arr1", "arr2", "m", "n", "x" ]
def count_pairs_two_sorted_arrays_whose_sum_equal_given_value_x(arr1, arr2, m, n, x): count = 0 for i in range(m): for j in range(n): if ((arr1[i] + arr2[j]) == x): count = (count + 1) return count
int count_pairs_two_sorted_arrays_whose_sum_equal_given_value_x(vector<int> arr1, vector<int> arr2, int m, int n, int x) { int count = 0; for ( int i = 0; i < m; i ++ ) for ( int j = 0; j < n; j ++ ) if ( ( arr1 [ i ] + arr2 [ j ] ) == x ) count ++; return count; }
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
98
Count Pairs Two Sorted Arrays Whose Sum Equal Given Value X 1
C++
int countPairsTwoSortedArraysWhoseSumEqualGivenValueX1(vector<int> arr1, vector<int> arr2, int m, int n, int x) {
[ "arr1", "arr2", "m", "n", "x" ]
def count_pairs_two_sorted_arrays_whose_sum_equal_given_value_x_1(arr1, arr2, m, n, x): count = 0 us = set() for i in range(m): us.add(arr1[i]) for j in range(n): if ((x - arr2[j]) in us): count += 1 return count
int count_pairs_two_sorted_arrays_whose_sum_equal_given_value_x_1(vector<int> arr1, vector<int> arr2, int m, int n, int x) { int count = 0; unordered_set < int > us; for ( int i = 0; i < m; i ++ ) us . insert ( arr1 [ i ] ); for ( int j = 0; j < n; j ++ ) if ( us . find ( x - arr2 [ j ] ) != us . end ( ...
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
99
Count Pairs Two Sorted Arrays Whose Sum Equal Given Value X 2
C++
int countPairsTwoSortedArraysWhoseSumEqualGivenValueX2(vector<int> arr1, vector<int> arr2, int m, int n, int x) {
[ "arr1", "arr2", "m", "n", "x" ]
def count_pairs_two_sorted_arrays_whose_sum_equal_given_value_x_2(arr1, arr2, m, n, x): (count, l, r) = (0, 0, (n - 1)) while ((l < m) and (r >= 0)): if ((arr1[l] + arr2[r]) == x): l += 1 r -= 1 count += 1 elif ((arr1[l] + arr2[r]) < x): l += 1 ...
int count_pairs_two_sorted_arrays_whose_sum_equal_given_value_x_2(vector<int> arr1, vector<int> arr2, int m, int n, int x) { int count = 0; int l = 0, r = n - 1; while ( l < m && r >= 0 ) { if ( ( arr1 [ l ] + arr2 [ r ] ) == x ) { l ++; r --; count ++; } else if ( ( arr1 [ l ] + arr...
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
100
Count Pairs Whose Products Exist In Array
C++
int countPairsWhoseProductsExistInArray(vector<int> arr, int n) {
[ "arr", "n" ]
def count_pairs_whose_products_exist_in_array(arr, n): result = 0 for i in range(0, n): for j in range((i + 1), n): product = (arr[i] * arr[j]) for k in range(0, n): if (arr[k] == product): result = (result + 1) break re...
int count_pairs_whose_products_exist_in_array(vector<int> arr, int n) { int result = 0; for ( int i = 0; i < n; i ++ ) { for ( int j = i + 1; j < n; j ++ ) { int product = arr [ i ] * arr [ j ]; for ( int k = 0; k < n; k ++ ) { if ( arr [ k ] == product ) { ...
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
101
Count Pairs Whose Products Exist In Array 1
C++
int countPairsWhoseProductsExistInArray1(vector<int> arr, int n) {
[ "arr", "n" ]
def count_pairs_whose_products_exist_in_array_1(arr, n): result = 0 Hash = set() for i in range(n): Hash.add(arr[i]) for i in range(n): for j in range((i + 1), n): product = (arr[i] * arr[j]) if (product in Hash): result += 1 return result
int count_pairs_whose_products_exist_in_array_1(vector<int> arr, int n) { int result = 0; set < int > Hash; for ( int i = 0; i < n; i ++ ) Hash . insert ( arr [ i ] ); for ( int i = 0; i < n; i ++ ) { for ( int j = i + 1; j < n; j ++ ) { int product = arr [ i ] * arr [ j ]; if ( ...
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
102
Count Palindrome Sub Strings String
C++
int countPalindromeSubStringsString(vector<char> str, int n) {
[ "str", "n" ]
def count_palindrome_sub_strings_string(str, n): dp = [[0 for x in range(n)] for y in range(n)] P = [[False for x in range(n)] for y in range(n)] for i in range(n): P[i][i] = True for i in range((n - 1)): if (str[i] == str[(i + 1)]): P[i][(i + 1)] = True dp[i][(i ...
int count_palindrome_sub_strings_string(vector<char> str, int n) { int dp [ n ] [ n ]; memset ( dp, 0, sizeof ( dp ) ); bool P [ n ] [ n ]; memset ( P, false, sizeof ( P ) ); for ( int i = 0; i < n; i ++ ) P [ i ] [ i ] = true; for ( int i = 0; i < n - 1; i ++ ) { if ( str [ i ] == str [ i + 1 ]...
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
103
Count Palindromic Subsequence Given String
C++
int countPalindromicSubsequenceGivenString(string str) {
[ "str" ]
def count_palindromic_subsequence_given_string(str): N = len(str) cps = [[0 for i in range((N + 2))] for j in range((N + 2))] for i in range(N): cps[i][i] = 1 for L in range(2, (N + 1)): for i in range(N): k = ((L + i) - 1) if (k < N): if (str[i] =...
int count_palindromic_subsequence_given_string(string str) { int N = str . length ( ); int cps [ N + 1 ] [ N + 1 ]; memset ( cps, 0, sizeof ( cps ) ); for ( int i = 0; i < N; i ++ ) cps [ i ] [ i ] = 1; for ( int L = 2; L <= N; L ++ ) { for ( int i = 0; i < N; i ++ ) { int k = L + i ...
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
104
Count Possible Groups Size 2 3 Sum Multiple 3
C++
float countPossibleGroupsSize23SumMultiple3(vector<int> arr, int n) {
[ "arr", "n" ]
def count_possible_groups_size_2_3_sum_multiple_3(arr, n): c = [0, 0, 0] res = 0 for i in range(0, n): c[(arr[i] % 3)] += 1 res += ((c[0] * (c[0] - 1)) >> 1) res += (c[1] * c[2]) res += (((c[0] * (c[0] - 1)) * (c[0] - 2)) / 6) res += (((c[1] * (c[1] - 1)) * (c[1] - 2)) / 6) res +...
int count_possible_groups_size_2_3_sum_multiple_3(vector<int> arr, int n) { int c [ 3 ] = { 0 }, i; int res = 0; for ( i = 0; i < n; i ++ ) c [ arr [ i ] % 3 ] ++; res += ( ( c [ 0 ] * ( c [ 0 ] - 1 ) ) >> 1 ); res += c [ 1 ] * c [ 2 ]; res += ( c [ 0 ] * ( c [ 0 ] - 1 ) * ( c [ 0 ...
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
105
Count Possible Paths Top Left Bottom Right Nxm Matrix 2
C++
long long countPossiblePathsTopLeftBottomRightNxmMatrix2(int p, int q) {
[ "p", "q" ]
def count_possible_paths_top_left_bottom_right_nxm_matrix_2(p, q): dp = [1 for i in range(q)] for i in range((p - 1)): for j in range(1, q): dp[j] += dp[(j - 1)] return dp[(q - 1)]
int count_possible_paths_top_left_bottom_right_nxm_matrix_2(int m, int n) { int dp [ n ] = { 1 }; dp [ 0 ] = 1; for ( int i = 0; i < m; i ++ ) { for ( int j = 1; j < n; j ++ ) { dp [ j ] += dp [ j - 1 ]; } } return dp [ n - 1 ]; }
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...
106
Count Possible Ways To Construct Buildings
C++
long long countPossibleWaysToConstructBuildings(int n) {
[ "n" ]
def count_possible_ways_to_construct_buildings(N): if (N == 1): return 4 countB = 1 countS = 1 for i in range(2, (N + 1)): prev_countB = countB prev_countS = countS countS = (prev_countB + prev_countS) countB = prev_countS result = (countS + countB) return...
int count_possible_ways_to_construct_buildings(int N) { if ( N == 1 ) return 4; int countB = 1, countS = 1, prev_countB, prev_countS; for ( int i = 2; i <= N; i ++ ) { prev_countB = countB; prev_countS = countS; countS = prev_countB + prev_countS; countB = prev_countS; } int result = count...
{ "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 <bits/stdc++.h>\n#include <numeric>\n#include <functional...