name stringlengths 2 111 ⌀ | Python stringlengths 3 6.97k ⌀ | C++ stringlengths 6 8.69k ⌀ | id int64 0 15.2k | Go stringlengths 1 8.88k ⌀ |
|---|---|---|---|---|
LCS_FORMED_CONSECUTIVE_SEGMENTS_LEAST_LENGTH_K | def f_gold ( k , s1 , s2 ) :
n = len ( s1 )
m = len ( s2 )
lcs = [ [ 0 for x in range ( m + 1 ) ] for y in range ( n + 1 ) ]
cnt = [ [ 0 for x in range ( m + 1 ) ] for y in range ( n + 1 ) ]
for i in range ( 1 , n + 1 ) :
for j in range ( 1 , m + 1 ) :
lcs [ i ] [ j ] = ma... |
using namespace std;
int f_gold ( int k, string s1, string s2 ) {
int n = s1 . length ( );
int m = s2 . length ( );
int lcs [ n + 1 ] [ m + 1 ];
int cnt [ n + 1 ] [ m + 1 ];
memset ( lcs, 0, sizeof ( lcs ) );
memset ( cnt, 0, sizeof ( cnt ) );
for ( int i = 1;
i <= n;
i ++ ) {
for ( i... | 0 | null |
COUNT_CHARACTERS_STRING_DISTANCE_ENGLISH_ALPHABETS | def f_gold ( 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 ;
|
using namespace std;
int f_gold ( 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;
}
| 1 | null |
RECURSIVE_PROGRAM_PRIME_NUMBER | null |
using namespace std;
bool f_gold ( int n, int i = 2 ) {
if ( n <= 2 ) return ( n == 2 ) ? true : false;
if ( n % i == 0 ) return false;
if ( i * i > n ) return true;
return f_gold ( n, i + 1 );
}
| 2 | null |
COUNT_DISTINCT_OCCURRENCES_AS_A_SUBSEQUENCE | def f_gold ( 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... |
using namespace std;
int f_gold ( 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;
... | 3 | null |
CHECK_WHETHER_TWO_STRINGS_ARE_ANAGRAM_OF_EACH_OTHER | def f_gold ( str1 , str2 ) :
n1 = len ( str1 )
n2 = len ( str2 )
if n1 != n2 :
return 0
str1 = sorted ( str1 )
str2 = sorted ( str2 )
for i in range ( 0 , n1 ) :
if str1 [ i ] != str2 [ i ] :
return 0
return 1
| null | 4 | null |
COUNT_NUMBERS_CAN_CONSTRUCTED_USING_TWO_NUMBERS | def f_gold ( 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... |
using namespace std;
int f_gold ( 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;
... | 5 | null |
SUM_PAIRWISE_PRODUCTS | def f_gold ( n ) :
sm = 0
for i in range ( 1 , n + 1 ) :
for j in range ( i , n + 1 ) :
sm = sm + i * j
return sm
|
using namespace std;
long long int f_gold ( int n ) {
long long int sum = 0;
for ( int i = 1;
i <= n;
i ++ ) for ( int j = i;
j <= n;
j ++ ) sum = sum + i * j;
return sum;
}
| 6 | null |
COUNT_SET_BITS_IN_AN_INTEGER | def f_gold ( n ) :
count = 0
while ( n ) :
count += n & 1
n >>= 1
return count
|
using namespace std;
unsigned int f_gold ( unsigned int n ) {
unsigned int count = 0;
while ( n ) {
count += n & 1;
n >>= 1;
}
return count;
}
| 7 | null |
LONGEST_PALINDROME_SUBSEQUENCE_SPACE | def f_gold ( s ) :
n = len ( s )
a = [ 0 ] * n
for i in range ( n - 1 , - 1 , - 1 ) :
back_up = 0
for j in range ( i , n ) :
if j == i :
a [ j ] = 1
elif s [ i ] == s [ j ] :
temp = a [ j ]
a [ j ] = back_up + ... |
using namespace std;
int f_gold ( string & s ) {
int n = s . length ( );
int a [ n ];
for ( int i = n - 1;
i >= 0;
i -- ) {
int back_up = 0;
for ( int j = i;
j < n;
j ++ ) {
if ( j == i ) a [ j ] = 1;
else if ( s [ i ] == s [ j ] ) {
int temp = a [ j ];
... | 8 | null |
DYCK_PATH | def f_gold ( n ) :
res = 1
for i in range ( 0 , n ) :
res *= ( 2 * n - i )
res /= ( i + 1 )
return res / ( n + 1 )
|
using namespace std;
int f_gold ( unsigned int n ) {
int res = 1;
for ( int i = 0;
i < n;
++ i ) {
res *= ( 2 * n - i );
res /= ( i + 1 );
}
return res / ( n + 1 );
}
| 10 | null |
PRINT_A_CLOSEST_STRING_THAT_DOES_NOT_CONTAIN_ADJACENT_DUPLICATES | null |
using namespace std;
string f_gold ( string s ) {
int n = s . length ( );
for ( int i = 1;
i < n;
i ++ ) {
if ( s [ i ] == s [ i - 1 ] ) {
s [ i ] = 'a';
while ( s [ i ] == s [ i - 1 ] || ( i + 1 < n && s [ i ] == s [ i + 1 ] ) ) s [ i ] ++;
i ++;
}
}
return s;
}
... | 11 | null |
OVERLAPPING_SUM_TWO_ARRAY | null |
using namespace std;
int f_gold ( int A [ ], int B [ ], int n ) {
unordered_map < int, int > hash;
for ( int i = 0;
i < n;
i ++ ) {
hash [ A [ i ] ] ++;
hash [ B [ i ] ] ++;
}
int sum = 0;
for ( auto x : hash ) if ( x . second == 1 ) sum += x . first;
return sum;
}
| 12 | null |
MOBILE_NUMERIC_KEYPAD_PROBLEM | def f_gold ( keypad , n ) :
if ( not keypad or n <= 0 ) :
return 0
if ( n == 1 ) :
return 10
odd = [ 0 ] * 10
even = [ 0 ] * 10
i = 0
j = 0
useOdd = 0
totalCount = 0
for i in range ( 10 ) :
odd [ i ] = 1
for j in range ( 2 , n + 1 ) :
... | null | 13 | null |
CHECK_VALID_SEQUENCE_DIVISIBLE_M_1 | def f_gold ( n , index , modulo , M , arr , dp ) :
modulo = ( ( modulo % M ) + M ) % M
if ( index == n ) :
if ( modulo == 0 ) :
return 1
return 0
if ( dp [ index ] [ modulo ] != - 1 ) :
return dp [ index ] [ modulo ]
placeAdd = f_gold ( n , index + 1 , modulo ... | null | 14 | null |
DIFFERENCE_BETWEEN_HIGHEST_AND_LEAST_FREQUENCIES_IN_AN_ARRAY_1 | null |
using namespace std;
int f_gold ( int arr [ ], int n ) {
unordered_map < int, int > hm;
for ( int i = 0;
i < n;
i ++ ) hm [ arr [ i ] ] ++;
int max_count = 0, min_count = n;
for ( auto x : hm ) {
max_count = max ( max_count, x . second );
min_count = min ( min_count, x . second );
}
... | 15 | null |
WAYS_TRANSFORMING_ONE_STRING_REMOVING_0_CHARACTERS | def f_gold ( a , b ) :
n = len ( a )
m = len ( b )
if m == 0 :
return 1
dp = [ [ 0 ] * ( n + 1 ) for _ in range ( m + 1 ) ]
for i in range ( m ) :
for j in range ( i , n ) :
if i == 0 :
if j == 0 :
if a [ j ] == b [ i ] :
... |
using namespace std;
int f_gold ( string a, string b ) {
int n = a . size ( ), m = b . size ( );
if ( m == 0 ) return 1;
int dp [ m + 1 ] [ n + 1 ];
memset ( dp, 0, sizeof ( dp ) );
for ( int i = 0;
i < m;
i ++ ) {
for ( int j = i;
j < n;
j ++ ) {
if ( i == 0 ) {
i... | 16 | null |
MARKOV_MATRIX | def f_gold ( m ) :
for i in range ( 0 , len ( m ) ) :
sm = 0
for j in range ( 0 , len ( m [ i ] ) ) :
sm = sm + m [ i ] [ j ]
if ( sm != 1 ) :
return False
return True
| null | 17 | null |
CHOCOLATE_DISTRIBUTION_PROBLEM | import sys
def f_gold ( 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_... |
using namespace std;
int f_gold ( int arr [ ], int n, int m ) {
if ( m == 0 || n == 0 ) return 0;
sort ( arr, arr + n );
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 ( ... | 18 | null |
FIND_DIFFERENCE_BETWEEN_SUMS_OF_TWO_DIAGONALS_1 | def f_gold ( arr , n ) :
d1 = 0
d2 = 0
for i in range ( 0 , n ) :
d1 = d1 + arr [ i ] [ i ]
d2 = d2 + arr [ i ] [ n - i - 1 ]
return abs ( d1 - d2 )
| null | 19 | null |
ROW_WISE_COMMON_ELEMENTS_TWO_DIAGONALS_SQUARE_MATRIX | def f_gold ( mat , n ) :
res = 0
for i in range ( n ) :
if mat [ i ] [ i ] == mat [ i ] [ n - i - 1 ] :
res = res + 1
return res
| null | 20 | null |
FIND_SUBARRAY_WITH_GIVEN_SUM_1 | def f_gold ( arr , n , sum ) :
curr_sum = arr [ 0 ]
start = 0
i = 1
while i <= n :
while curr_sum > sum and start < i - 1 :
curr_sum = curr_sum - arr [ start ]
start += 1
if curr_sum == sum :
print ( "Sum found between indexes" )
... |
using namespace std;
int f_gold ( int arr [ ], int n, int sum ) {
int curr_sum = arr [ 0 ], start = 0, i;
for ( i = 1;
i <= n;
i ++ ) {
while ( curr_sum > sum && start < i - 1 ) {
curr_sum = curr_sum - arr [ start ];
start ++;
}
if ( curr_sum == sum ) {
cout << "Sum fo... | 21 | null |
HYPERCUBE_GRAPH | def f_gold ( n ) :
if n == 1 :
return 2
return 2 * f_gold ( n - 1 )
|
using namespace std;
int f_gold ( int n ) {
if ( n == 1 ) return 2;
return 2 * f_gold ( n - 1 );
}
| 22 | null |
HEXAGONAL_NUMBER | def f_gold ( n ) :
return n * ( 2 * n - 1 )
|
using namespace std;
int f_gold ( int n ) {
return n * ( 2 * n - 1 );
}
| 23 | null |
LEXICOGRAPHICALLY_NEXT_STRING | def f_gold ( s ) :
if ( s == " " ) :
return "a"
i = len ( s ) - 1
while ( s [ i ] == 'z' and i >= 0 ) :
i -= 1
if ( i == - 1 ) :
s = s + 'a'
else :
s = s.replace ( s [ i ] , chr ( ord ( s [ i ] ) + 1 ) , 1 )
return s
|
using namespace std;
string f_gold ( string s ) {
if ( s == "" ) return "a";
int i = s . length ( ) - 1;
while ( s [ i ] == 'z' && i >= 0 ) i --;
if ( i == - 1 ) s = s + 'a';
else s [ i ] ++;
return s;
}
| 24 | null |
CHECK_LARGE_NUMBER_DIVISIBLE_9_NOT | null |
using namespace std;
int f_gold ( string str ) {
int n = str . length ( );
int digitSum = 0;
for ( int i = 0;
i < n;
i ++ ) digitSum += ( str [ i ] - '0' );
return ( digitSum % 9 == 0 );
}
| 25 | null |
FIND_THE_LARGEST_SUBARRAY_WITH_0_SUM | null |
using namespace std;
int f_gold ( int arr [ ], int n ) {
int max_len = 0;
for ( int i = 0;
i < n;
i ++ ) {
int curr_sum = 0;
for ( int j = i;
j < n;
j ++ ) {
curr_sum += arr [ j ];
if ( curr_sum == 0 ) max_len = max ( max_len, j - i + 1 );
}
}
return max_len;
... | 26 | null |
SUM_BINOMIAL_COEFFICIENTS_1 | def f_gold ( n ) :
return ( 1 << n ) ;
|
using namespace std;
int f_gold ( int n ) {
return ( 1 << n );
}
| 27 | null |
NUMBER_SUBSEQUENCES_STRING_DIVISIBLE_N | null |
using namespace std;
int f_gold ( string str, int n ) {
int len = str . length ( );
int dp [ len ] [ n ];
memset ( dp, 0, sizeof ( dp ) );
dp [ 0 ] [ ( str [ 0 ] - '0' ) % n ] ++;
for ( int i = 1;
i < len;
i ++ ) {
dp [ i ] [ ( str [ i ] - '0' ) % n ] ++;
for ( int j = 0;
j < n;
... | 28 | null |
ADD_TWO_NUMBERS_WITHOUT_USING_ARITHMETIC_OPERATORS | def f_gold ( x , y ) :
while ( y != 0 ) :
carry = x & y
x = x ^ y
y = carry << 1
return x
|
using namespace std;
int f_gold ( int x, int y ) {
while ( y != 0 ) {
int carry = x & y;
x = x ^ y;
y = carry << 1;
}
return x;
}
| 29 | null |
COUNT_OPERATIONS_MAKE_STRINGAB_FREE | def f_gold ( s ) :
b_count = 0
res = 0
for i in range ( len ( s ) ) :
if s [ ~ i ] == 'a' :
res = ( res + b_count )
b_count = ( b_count * 2 )
else :
b_count += 1
return res
| null | 30 | null |
SCHEDULE_JOBS_SERVER_GETS_EQUAL_LOAD | def f_gold ( a , b , n ) :
s = 0
for i in range ( 0 , n ) :
s += a [ i ] + b [ i ]
if n == 1 :
return a [ 0 ] + b [ 0 ]
if s % n != 0 :
return - 1
x = s // n
for i in range ( 0 , n ) :
if a [ i ] > x :
return - 1
if i > 0 :
... |
using namespace std;
int f_gold ( int a [ ], int b [ ], int n ) {
int i;
long long int s = 0;
for ( i = 0;
i < n;
i ++ ) s += ( a [ i ] + b [ i ] );
if ( n == 1 ) return a [ 0 ] + b [ 0 ];
if ( s % n != 0 ) return - 1;
int x = s / n;
for ( i = 0;
i < n;
i ++ ) {
if ( a [ i ] > x... | 31 | null |
HOW_TO_CHECK_IF_A_GIVEN_ARRAY_REPRESENTS_A_BINARY_HEAP_1 | def f_gold ( arr , n ) :
for i in range ( int ( ( n - 2 ) / 2 ) + 1 ) :
if arr [ 2 * i + 1 ] > arr [ i ] :
return False
if ( 2 * i + 2 < n and arr [ 2 * i + 2 ] > arr [ i ] ) :
return False
return True
|
using namespace std;
bool f_gold ( int arr [ ], int n ) {
for ( int i = 0;
i <= ( n - 2 ) / 2;
i ++ ) {
if ( arr [ 2 * i + 1 ] > arr [ i ] ) return false;
if ( 2 * i + 2 < n && arr [ 2 * i + 2 ] > arr [ i ] ) return false;
}
return true;
}
| 32 | null |
NUMBER_DIGITS_REMOVED_MAKE_NUMBER_DIVISIBLE_3 | null |
using namespace std;
int f_gold ( string num ) {
int n = num . length ( );
int sum = accumulate ( begin ( num ), end ( num ), 0 ) - '0' * 1;
if ( sum % 3 == 0 ) return 0;
if ( n == 1 ) return - 1;
for ( int i = 0;
i < n;
i ++ ) if ( sum % 3 == ( num [ i ] - '0' ) % 3 ) return 1;
if ( n == 2 )... | 33 | null |
MAXIMIZE_SUM_ARRII | def f_gold ( arr , n ) :
arr.sort ( )
sum = 0
for i in range ( n ) :
sum += arr [ i ] * i
return sum
|
using namespace std;
int f_gold ( int arr [ ], int n ) {
sort ( arr, arr + n );
int sum = 0;
for ( int i = 0;
i < n;
i ++ ) sum += ( arr [ i ] * i );
return sum;
}
| 34 | null |
CHECK_WHETHER_GIVEN_DEGREES_VERTICES_REPRESENT_GRAPH_TREE | def f_gold ( degree , n ) :
deg_sum = sum ( degree )
if ( 2 * ( n - 1 ) == deg_sum ) :
return True
else :
return False
|
using namespace std;
bool f_gold ( 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 );
}
| 35 | null |
MAXIMUM_POINTS_INTERSECTION_N_CIRCLES | def f_gold ( n ) :
return n * ( n - 1 ) ;
|
using namespace std;
int f_gold ( int n ) {
return n * ( n - 1 );
}
| 36 | null |
SUBSEQUENCES_SIZE_THREE_ARRAY_WHOSE_SUM_DIVISIBLE_M | def f_gold ( A , N , M ) :
sum = 0
ans = 0
for i in range ( 0 , N ) :
for j in range ( i + 1 , N ) :
for k in range ( j + 1 , N ) :
sum = A [ i ] + A [ j ] + A [ k ]
if ( sum % M == 0 ) :
ans = ans + 1
return ans
|
using namespace std;
int f_gold ( int A [ ], int N, int M ) {
int sum = 0;
int ans = 0;
for ( int i = 0;
i < N;
i ++ ) {
for ( int j = i + 1;
j < N;
j ++ ) {
for ( int k = j + 1;
k < N;
k ++ ) {
sum = A [ i ] + A [ j ] + A [ k ];
if ( sum % M == 0 ... | 37 | null |
COUNT_NUMBER_OF_WAYS_TO_PARTITION_A_SET_INTO_K_SUBSETS_1 | def f_gold ( n , k ) :
dp = [ [ 0 for i in range ( k + 1 ) ] for j in range ( n + 1 ) ]
for i in range ( n + 1 ) :
dp [ i ] [ 0 ] = 0
for i in range ( k + 1 ) :
dp [ 0 ] [ k ] = 0
for i in range ( 1 , n + 1 ) :
for j in range ( 1 , k + 1 ) :
if ( j == 1 or i =... | null | 38 | null |
LEONARDO_NUMBER_1 | def f_gold ( n ) :
dp = [ ] ;
dp.append ( 1 ) ;
dp.append ( 1 ) ;
for i in range ( 2 , n + 1 ) :
dp.append ( dp [ i - 1 ] + dp [ i - 2 ] + 1 ) ;
return dp [ n ] ;
|
using namespace std;
int f_gold ( int n ) {
int dp [ n + 1 ];
dp [ 0 ] = dp [ 1 ] = 1;
for ( int i = 2;
i <= n;
i ++ ) dp [ i ] = dp [ i - 1 ] + dp [ i - 2 ] + 1;
return dp [ n ];
}
| 39 | null |
FIND_MAXIMUM_HEIGHT_PYRAMID_FROM_THE_GIVEN_ARRAY_OF_OBJECTS | def f_gold ( boxes , n ) :
boxes.sort ( )
ans = 1
prev_width = boxes [ 0 ]
prev_count = 1
curr_count = 0
curr_width = 0
for i in range ( 1 , n ) :
curr_width += boxes [ i ]
curr_count += 1
if ( curr_width > prev_width and curr_count > prev_count ) :
... |
using namespace std;
int f_gold ( int boxes [ ], int n ) {
sort ( boxes, boxes + n );
int ans = 1;
int prev_width = boxes [ 0 ];
int prev_count = 1;
int curr_count = 0;
int curr_width = 0;
for ( int i = 1;
i < n;
i ++ ) {
curr_width += boxes [ i ];
curr_count += 1;
if ( curr... | 40 | null |
MAXIMUM_NUMBER_CHOCOLATES_DISTRIBUTED_EQUALLY_AMONG_K_STUDENTS | def f_gold ( arr , n , k ) :
um , curr_rem , maxSum = { } , 0 , 0
sm = [ 0 ] * n
sm [ 0 ] = arr [ 0 ]
for i in range ( 1 , n ) :
sm [ i ] = sm [ i - 1 ] + arr [ i ]
for i in range ( n ) :
curr_rem = sm [ i ] % k
if ( not curr_rem and maxSum < sm [ i ] ) :
... |
using namespace std;
int f_gold ( int arr [ ], int n, int k ) {
unordered_map < int, int > um;
int sum [ n ], curr_rem;
int maxSum = 0;
sum [ 0 ] = arr [ 0 ];
for ( int i = 1;
i < n;
i ++ ) sum [ i ] = sum [ i - 1 ] + arr [ i ];
for ( int i = 0;
i < n;
i ++ ) {
curr_rem = sum [ i ]... | 41 | null |
ELEMENTS_TO_BE_ADDED_SO_THAT_ALL_ELEMENTS_OF_A_RANGE_ARE_PRESENT_IN_ARRAY | def f_gold ( arr , n ) :
count = 0
arr.sort ( )
for i in range ( 0 , n - 1 ) :
if ( arr [ i ] != arr [ i + 1 ] and arr [ i ] != arr [ i + 1 ] - 1 ) :
count += arr [ i + 1 ] - arr [ i ] - 1 ;
return count
|
using namespace std;
int f_gold ( int arr [ ], int n ) {
int count = 0;
sort ( arr, arr + n );
for ( int i = 0;
i < n - 1;
i ++ ) if ( arr [ i ] != arr [ i + 1 ] && arr [ i ] != arr [ i + 1 ] - 1 ) count += arr [ i + 1 ] - arr [ i ] - 1;
return count;
}
| 42 | null |
FIND_THE_MAXIMUM_ELEMENT_IN_AN_ARRAY_WHICH_IS_FIRST_INCREASING_AND_THEN_DECREASING | def f_gold ( arr , low , high ) :
max = arr [ low ]
i = low
for i in range ( high + 1 ) :
if arr [ i ] > max :
max = arr [ i ]
return max
|
using namespace std;
int f_gold ( int arr [ ], int low, int high ) {
int max = arr [ low ];
int i;
for ( i = low + 1;
i <= high;
i ++ ) {
if ( arr [ i ] > max ) max = arr [ i ];
else break;
}
return max;
}
| 43 | null |
MAXIMUM_LENGTH_SUBSEQUENCE_DIFFERENCE_ADJACENT_ELEMENTS_EITHER_0_1 | def f_gold(arr, n):
mls = []
max = 0
for i in range(n):
mls.append(1)
for i in range(n):
for j in range(i):
if (abs(arr[i] - arr[j]) <= 1 and mls[i] < mls[j] + 1):
mls[i] = mls[j] + 1
for i in range(n):
if (max < mls[i]):
max... |
using namespace std;
int f_gold ( int arr [ ], int n ) {
int mls [ n ], max = 0;
for ( int i = 0;
i < n;
i ++ ) mls [ i ] = 1;
for ( int i = 1;
i < n;
i ++ ) for ( int j = 0;
j < i;
j ++ ) if ( abs ( arr [ i ] - arr [ j ] ) <= 1 && mls [ i ] < mls [ j ] + 1 ) mls [ i ] = mls [ j ] + 1;
... | 44 | null |
CASSINIS_IDENTITY | def f_gold ( n ) :
return - 1 if ( n & 1 ) else 1
|
using namespace std;
int f_gold ( int n ) {
return ( n & 1 ) ? - 1 : 1;
}
| 45 | null |
PROGRAM_CALCULATE_VOLUME_ELLIPSOID | import math
def f_gold(r1, r2, r3):
return 1.33 * math.pi * r1 * r2 * r3
|
using namespace std;
float f_gold ( float r1, float r2, float r3 ) {
float pi = 3.14;
return 1.33 * pi * r1 * r2 * r3;
}
| 46 | null |
MAXIMUM_XOR_VALUE_MATRIX | def f_gold(mat, N):
max_xor = 0
for i in range(N):
r_xor = 0
c_xor = 0
for j in range(N):
r_xor = r_xor ^ mat[i][j]
c_xor = c_xor ^ mat[j][i]
if (max_xor < max(r_xor, c_xor)):
max_xor = max(r_xor, c_xor)
return max_xor
| null | 47 | null |
CHECK_ARRAY_REPRESENTS_INORDER_BINARY_SEARCH_TREE_NOT | def f_gold ( 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
|
using namespace std;
bool f_gold ( 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;
}
| 48 | null |
COUNT_SUBARRAYS_EQUAL_NUMBER_1S_0S_1 | def f_gold ( arr , n ) :
mp = dict ( )
Sum = 0
count = 0
for i in range ( n ) :
if ( arr [ i ] == 0 ) :
arr [ i ] = - 1
Sum += arr [ i ]
if ( Sum == 0 ) :
count += 1
if ( Sum in mp.keys ( ) ) :
count += mp [ Sum ]
mp... |
using namespace std;
int f_gold ( int arr [ ], int n ) {
map < int, int > mp;
int sum = 0;
int count = 0;
for ( int i = 0;
i < n;
i ++ ) {
if ( arr [ i ] == 0 ) arr [ i ] = - 1;
sum += arr [ i ];
if ( sum == 0 ) count ++;
if ( mp [ sum ] ) count += mp [ sum ];
if ( mp [ sum... | 49 | null |
FIND_SUM_NODES_GIVEN_PERFECT_BINARY_TREE_1 | import math
def f_gold ( l ) :
leafNodeCount = math.pow ( 2 , l - 1 ) ;
sumLastLevel = 0 ;
sumLastLevel = ( ( leafNodeCount * ( leafNodeCount + 1 ) ) / 2 ) ;
sum = sumLastLevel * l ;
return int ( sum ) ;
| null | 50 | null |
PROGRAM_CIRCUMFERENCE_PARALLELOGRAM | def f_gold ( a , b ) :
return ( ( 2 * a ) + ( 2 * b ) )
|
using namespace std;
float f_gold ( float a, float b ) {
return ( ( 2 * a ) + ( 2 * b ) );
}
| 51 | null |
CHECK_NUMBER_IS_PERFECT_SQUARE_USING_ADDITIONSUBTRACTION | def f_gold ( n ) :
i = 1
the_sum = 0
while the_sum < n :
the_sum += i
if the_sum == n :
return True
i += 2
return False
|
using namespace std;
bool f_gold ( int n ) {
for ( int sum = 0, i = 1;
sum < n;
i += 2 ) {
sum += i;
if ( sum == n ) return true;
}
return false;
}
| 52 | null |
SUM_FACTORS_NUMBER | import math
def f_gold ( n ) :
result = 0
for i in range ( 2 , ( int ) ( math.sqrt ( n ) ) + 1 ) :
if ( n % i == 0 ) :
if ( i == ( n / i ) ) :
result = result + i
else :
result = result + ( i + n // i )
return ( result + n + 1 )
... |
using namespace std;
int f_gold ( int n ) {
int result = 0;
for ( int i = 2;
i <= sqrt ( n );
i ++ ) {
if ( n % i == 0 ) {
if ( i == ( n / i ) ) result += i;
else result += ( i + n / i );
}
}
return ( result + n + 1 );
}
| 53 | null |
CHECK_GIVEN_STRING_ROTATION_PALINDROME | def f_gold ( 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
|
using namespace std;
bool f_gold ( string str ) {
int l = 0;
int h = str . length ( ) - 1;
while ( h > l ) if ( str [ l ++ ] != str [ h -- ] ) return false;
return true;
}
| 54 | null |
TOTAL_NUMBER_OF_NON_DECREASING_NUMBERS_WITH_N_DIGITS_1 | def f_gold ( n ) :
N = 10
count = 1
for i in range ( 1 , n + 1 ) :
count = int ( count * ( N + i - 1 ) )
count = int ( count / i )
return count
|
using namespace std;
long long int f_gold ( int n ) {
int N = 10;
long long count = 1;
for ( int i = 1;
i <= n;
i ++ ) {
count *= ( N + i - 1 );
count /= i;
}
return count;
}
| 55 | null |
LEXICOGRAPHICALLY_MINIMUM_STRING_ROTATION | def f_gold ( str_ ) :
n = len ( str_ )
arr = [ 0 ] * n
concat = str_ + str_
for i in range ( n ) :
arr [ i ] = concat [ i : n + i ]
arr.sort ( )
return arr [ 0 ]
|
using namespace std;
string f_gold ( string str ) {
int n = str . length ( );
string arr [ n ];
string concat = str + str;
for ( int i = 0;
i < n;
i ++ ) arr [ i ] = concat . substr ( i, n );
sort ( arr, arr + n );
return arr [ 0 ];
}
| 56 | null |
CHECK_NUMBER_POWER_K_USING_BASE_CHANGING_METHOD | def f_gold ( 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
|
using namespace std;
bool f_gold ( 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;
}
| 57 | null |
MINIMUM_NUMBER_OF_JUMPS_TO_REACH_END_OF_A_GIVEN_ARRAY_1 | def f_gold ( arr , n ) :
jumps = [ 0 for i in range ( n ) ]
if ( n == 0 ) or ( arr [ 0 ] == 0 ) :
return float ( 'inf' )
jumps [ 0 ] = 0
for i in range ( 1 , n ) :
jumps [ i ] = float ( 'inf' )
for j in range ( i ) :
if ( i <= j + arr [ j ] ) and ( jumps [ j ]... |
using namespace std;
int f_gold ( int arr [ ], int n ) {
int * jumps = new int [ n ];
int i, j;
if ( n == 0 || arr [ 0 ] == 0 ) return INT_MAX;
jumps [ 0 ] = 0;
for ( i = 1;
i < n;
i ++ ) {
jumps [ i ] = INT_MAX;
for ( j = 0;
j < i;
j ++ ) {
if ( i <= j + arr [ j ] && ... | 58 | null |
SORT_EVEN_NUMBERS_ASCENDING_ORDER_SORT_ODD_NUMBERS_DESCENDING_ORDER_1 | def f_gold ( arr , n ) :
for i in range ( 0 , n ) :
if ( arr [ i ] & 1 ) :
arr [ i ] *= - 1
arr.sort ( )
for i in range ( 0 , n ) :
if ( arr [ i ] & 1 ) :
arr [ i ] *= - 1
|
using namespace std;
void f_gold ( int arr [ ], int n ) {
for ( int i = 0;
i < n;
i ++ ) if ( arr [ i ] & 1 ) arr [ i ] *= - 1;
sort ( arr, arr + n );
for ( int i = 0;
i < n;
i ++ ) if ( arr [ i ] & 1 ) arr [ i ] *= - 1;
}
| 59 | null |
SEARCH_AN_ELEMENT_IN_AN_ARRAY_WHERE_DIFFERENCE_BETWEEN_ADJACENT_ELEMENTS_IS_1 | def f_gold ( arr , n , x ) :
i = 0
while ( i < n ) :
if ( arr [ i ] == x ) :
return i
i = i + abs ( arr [ i ] - x )
print ( "number is not present!" )
return - 1
|
using namespace std;
int f_gold ( int arr [ ], int n, int x ) {
int i = 0;
while ( i < n ) {
if ( arr [ i ] == x ) return i;
i = i + abs ( arr [ i ] - x );
}
cout << "number is not present!";
return - 1;
}
| 60 | null |
SUM_SEQUENCE_2_22_222 | import math
def f_gold ( n ) :
return 0.0246 * ( math.pow ( 10 , n ) - 1 - ( 9 * n ) )
| null | 61 | null |
MAXIMUM_PRODUCT_SUBARRAY_ADDED_NEGATIVE_PRODUCT_CASE | def f_gold ( arr , n ) :
ans = - float ( 'inf' )
maxval = 1
minval = 1
for i in range ( 0 , n ) :
if arr [ i ] > 0 :
maxval = maxval * arr [ i ]
minval = min ( 1 , minval * arr [ i ] )
elif arr [ i ] == 0 :
minval = 1
maxval = 0
... |
using namespace std;
int f_gold ( int arr [ ], int n ) {
int i;
int ans = INT_MIN;
int maxval = 1;
int minval = 1;
int prevMax;
for ( i = 0;
i < n;
i ++ ) {
if ( arr [ i ] > 0 ) {
maxval = maxval * arr [ i ];
minval = min ( 1, minval * arr [ i ] );
}
else if ( arr... | 62 | null |
CHECK_IF_X_CAN_GIVE_CHANGE_TO_EVERY_PERSON_IN_THE_QUEUE | def f_gold ( 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
else :
... |
using namespace std;
int f_gold ( 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 ++;
}
el... | 63 | null |
MINIMUM_LENGTH_SUBARRAY_SUM_GREATER_GIVEN_VALUE | def f_gold ( arr , n , x ) :
curr_sum = 0
min_len = n + 1
start = 0
end = 0
while ( end < n ) :
while ( curr_sum <= x and end < n ) :
curr_sum += arr [ end ]
end += 1
while ( curr_sum > x and start < n ) :
if ( end - start < min_len ) :
... |
using namespace std;
int f_gold ( int arr [ ], int n, int x ) {
int curr_sum = 0, min_len = n + 1;
int start = 0, end = 0;
while ( end < n ) {
while ( curr_sum <= x && end < n ) curr_sum += arr [ end ++ ];
while ( curr_sum > x && start < n ) {
if ( end - start < min_len ) min_len = end - st... | 64 | null |
NEXT_HIGHER_NUMBER_WITH_SAME_NUMBER_OF_SET_BITS | def f_gold ( x ) :
next = 0
if ( x ) :
rightOne = x & - ( x )
nextHigherOneBit = x + int ( rightOne )
rightOnesPattern = x ^ int ( nextHigherOneBit )
rightOnesPattern = ( int ( rightOnesPattern ) / int ( rightOne ) )
rightOnesPattern = int ( rightOnesPattern ) >> 2... | null | 65 | null |
SEARCH_INSERT_AND_DELETE_IN_A_SORTED_ARRAY_1 | def f_gold ( arr , n , key , capacity ) :
if ( n >= capacity ) :
return n
i = n - 1
while i >= 0 and arr [ i ] > key :
arr [ i + 1 ] = arr [ i ]
i -= 1
arr [ i + 1 ] = key
return ( n + 1 )
|
using namespace std;
int f_gold ( int arr [ ], int n, int key, int capacity ) {
if ( n >= capacity ) return n;
int i;
for ( i = n - 1;
( i >= 0 && arr [ i ] > key );
i -- ) arr [ i + 1 ] = arr [ i ];
arr [ i + 1 ] = key;
return ( n + 1 );
}
| 66 | null |
CONVERT_STRICTLY_INCREASING_ARRAY_MINIMUM_CHANGES | def f_gold ( 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... |
using namespace std;
int f_gold ( 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 ] ) ) {
... | 67 | null |
C_PROGRAM_FACTORIAL_NUMBER_1 | def f_gold ( n ) :
return 1 if ( n == 1 or n == 0 ) else n * f_gold ( n - 1 ) ;
|
using namespace std;
unsigned int f_gold ( unsigned int n ) {
int res = 1, i;
for ( i = 2;
i <= n;
i ++ ) res *= i;
return res;
}
| 68 | null |
EQUILIBRIUM_INDEX_OF_AN_ARRAY_1 | null |
using namespace std;
int f_gold ( int arr [ ], int n ) {
int sum = 0;
int leftsum = 0;
for ( int i = 0;
i < n;
++ i ) sum += arr [ i ];
for ( int i = 0;
i < n;
++ i ) {
sum -= arr [ i ];
if ( leftsum == sum ) return i;
leftsum += arr [ i ];
}
return - 1;
}
| 69 | null |
HOW_CAN_WE_SUM_THE_DIGITS_OF_A_GIVEN_NUMBER_IN_SINGLE_STATEMENT | def f_gold(n):
sum = 0
while (n != 0):
sum = sum + int(n % 10)
n = int(n / 10)
return sum
| null | 70 | null |
MAXIMUM_DIFFERENCE_SUM_ELEMENTS_TWO_ROWS_MATRIX | def f_gold(mat, m, n):
rowSum = [0] * m
for i in range(0, m):
sum = 0
for j in range(0, n):
sum += mat[i][j]
rowSum[i] = sum
max_diff = rowSum[1] - rowSum[0]
min_element = rowSum[0]
for i in range(1, m):
if (rowSum[i] - min_element > max_diff):
... | null | 71 | null |
ADD_1_TO_A_GIVEN_NUMBER_1 | def f_gold ( x ) :
return ( - ( ~ x ) )
|
using namespace std;
int f_gold ( int x ) {
return ( - ( ~ x ) );
}
| 72 | null |
FIND_THE_NUMBER_OCCURRING_ODD_NUMBER_OF_TIMES | def f_gold ( arr , arr_size ) :
for i in range ( 0 , arr_size ) :
count = 0
for j in range ( 0 , arr_size ) :
if arr [ i ] == arr [ j ] :
count += 1
if ( count % 2 != 0 ) :
return arr [ i ]
return - 1
|
using namespace std;
int f_gold ( int arr [ ], int arr_size ) {
for ( int i = 0;
i < arr_size;
i ++ ) {
int count = 0;
for ( int j = 0;
j < arr_size;
j ++ ) {
if ( arr [ i ] == arr [ j ] ) count ++;
}
if ( count % 2 != 0 ) return arr [ i ];
}
return - 1;
}
| 73 | null |
FIND_HARMONIC_MEAN_USING_ARITHMETIC_MEAN_GEOMETRIC_MEAN | import math
def f_gold ( a , b ) :
AM = ( a + b ) / 2
GM = math.sqrt ( a * b )
HM = ( GM * GM ) / AM
return HM
|
using namespace std;
double f_gold ( int a, int b ) {
double AM, GM, HM;
AM = ( a + b ) / 2;
GM = sqrt ( a * b );
HM = ( GM * GM ) / AM;
return HM;
}
| 74 | null |
COUNT_ARRAYS_CONSECUTIVE_ELEMENT_DIFFERENT_VALUES | def f_gold ( n , k , x ) :
dp = list ( )
dp.append ( 0 )
dp.append ( 1 )
i = 2
while i < n :
dp.append ( ( k - 2 ) * dp [ i - 1 ] + ( k - 1 ) * dp [ i - 2 ] )
i = i + 1
return ( ( k - 1 ) * dp [ n - 2 ] if x == 1 else dp [ n - 1 ] )
| null | 75 | null |
SUM_TWO_LARGE_NUMBERS | def f_gold(str1, str2):
if (len(str1) > len(str2)):
t = str1
str1 = str2
str2 = t
str = ""
n1 = len(str1)
n2 = len(str2)
str1 = str1[:: - 1]
str2 = str2[:: - 1]
carry = 0
for i in range(n1):
sum = ((ord(str1[i]) - 48) + ((ord(str2[i]) - 48) + c... |
using namespace std;
string f_gold ( string str1, string str2 ) {
if ( str1 . length ( ) > str2 . length ( ) ) swap ( str1, str2 );
string str = "";
int n1 = str1 . length ( ), n2 = str2 . length ( );
reverse ( str1 . begin ( ), str1 . end ( ) );
reverse ( str2 . begin ( ), str2 . end ( ) );
int ca... | 76 | null |
COUNT_NUMBER_OF_SOLUTIONS_OF_X2_1_MOD_P_IN_GIVEN_RANGE | def f_gold ( n , p ) :
ans = 0 ;
for x in range ( 1 , p ) :
if ( ( x * x ) % p == 1 ) :
last = x + p * ( n / p ) ;
if ( last > n ) :
last -= p ;
ans += ( ( last - x ) / p + 1 ) ;
return int ( ans ) ;
| null | 77 | null |
MAXIMUM_SUM_2_X_N_GRID_NO_TWO_ELEMENTS_ADJACENT | def f_gold ( grid , n ) :
incl = max ( grid [ 0 ] [ 0 ] , grid [ 1 ] [ 0 ] )
excl = 0
for i in range ( 1 , n ) :
excl_new = max ( excl , incl )
incl = excl + max ( grid [ 0 ] [ i ] , grid [ 1 ] [ i ] )
excl = excl_new
return max ( excl , incl )
| null | 78 | null |
SUM_OF_ALL_ELEMENTS_UP_TO_NTH_ROW_IN_A_PASCALS_TRIANGLE_1 | def f_gold ( n ) :
sum = 0
sum = 1 << n ;
return ( sum - 1 )
|
using namespace std;
long long int f_gold ( int n ) {
long long int sum = 0;
sum = 1 << n;
return ( sum - 1 );
}
| 79 | null |
FUNCTION_COPY_STRING_ITERATIVE_RECURSIVE_1 | def f_gold ( s1 , s2 , index ) :
s2 [ index ] = s1 [ index ] ;
if ( index == len ( s1 ) - 1 ) :
return ;
f_gold ( s1 , s2 , index + 1 ) ;
|
using namespace std;
void f_gold ( char s1 [ ], char s2 [ ], int index = 0 ) {
s2 [ index ] = s1 [ index ];
if ( s1 [ index ] == '\0' ) return;
f_gold ( s1, s2, index + 1 );
}
| 80 | null |
PROGRAM_FOR_FACTORIAL_OF_A_NUMBER | def f_gold ( n ) :
return 1 if ( n == 1 or n == 0 ) else n * f_gold ( n - 1 ) ;
|
using namespace std;
unsigned int f_gold ( unsigned int n ) {
if ( n == 0 ) return 1;
return n * f_gold ( n - 1 );
}
| 81 | null |
COUNT_NUMBERS_THAT_DONT_CONTAIN_3 | def f_gold ( 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 f_gold ( msd ) * f_gold ( po - 1 ) + f_gold ( msd ) + f_gold ( n % po )
else :
return f_go... |
using namespace std;
int f_gold ( 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 f_gold ( msd ) * f_gold ( po - 1 ) + f_gold ( msd ) + f_gold ( n % po );
else return f_gold ( msd * po ... | 82 | null |
FIND_INDEX_OF_AN_EXTRA_ELEMENT_PRESENT_IN_ONE_SORTED_ARRAY_1 | def f_gold ( arr1 , arr2 , n ) :
index = n
left = 0
right = n - 1
while ( left <= right ) :
mid = ( int ) ( ( left + right ) / 2 )
if ( arr2 [ mid ] == arr1 [ mid ] ) :
left = mid + 1
else :
index = mid
right = mid - 1
return ind... |
using namespace std;
int f_gold ( int arr1 [ ], int arr2 [ ], int n ) {
int index = n;
int left = 0, right = n - 1;
while ( left <= right ) {
int mid = ( left + right ) / 2;
if ( arr2 [ mid ] == arr1 [ mid ] ) left = mid + 1;
else {
index = mid;
right = mid - 1;
}
}
r... | 84 | null |
PAIR_WITH_GIVEN_PRODUCT_SET_1_FIND_IF_ANY_PAIR_EXISTS_1 | def f_gold(arr, n, x):
if n < 2:
return False
s = set()
for i in range(0, n):
if arr[i] == 0:
if x == 0:
return True
else:
continue
if x % arr[i] == 0:
if x // arr[i] in s:
return True
... |
using namespace std;
bool f_gold ( int arr [ ], int n, int x ) {
if ( n < 2 ) return false;
unordered_set < int > s;
for ( int i = 0;
i < n;
i ++ ) {
if ( arr [ i ] == 0 ) {
if ( x == 0 ) return true;
else continue;
}
if ( x % arr [ i ] == 0 ) {
if ( s . find ( x / ... | 85 | null |
FIND_MINIMUM_DIFFERENCE_PAIR_1 | def f_gold ( arr , n ) :
arr = sorted ( arr )
diff = 10 ** 20
for i in range ( n - 1 ) :
if arr [ i + 1 ] - arr [ i ] < diff :
diff = arr [ i + 1 ] - arr [ i ]
return diff
|
using namespace std;
int f_gold ( int arr [ ], int n ) {
sort ( arr, arr + n );
int diff = INT_MAX;
for ( int i = 0;
i < n - 1;
i ++ ) if ( arr [ i + 1 ] - arr [ i ] < diff ) diff = arr [ i + 1 ] - arr [ i ];
return diff;
}
| 86 | null |
FIND_MAXIMUM_PRODUCT_OF_A_TRIPLET_IN_ARRAY | import sys
def f_gold ( arr , n ) :
if n < 3 :
return - 1
max_product = - ( sys.maxsize - 1 )
for i in range ( 0 , n - 2 ) :
for j in range ( i + 1 , n - 1 ) :
for k in range ( j + 1 , n ) :
max_product = max ( max_product , arr [ i ] * arr [ j ] * arr [... |
using namespace std;
int f_gold ( int arr [ ], int n ) {
if ( n < 3 ) return - 1;
int max_product = INT_MIN;
for ( int i = 0;
i < n - 2;
i ++ ) for ( int j = i + 1;
j < n - 1;
j ++ ) for ( int k = j + 1;
k < n;
k ++ ) max_product = max ( max_product, arr [ i ] * arr [ j ] * arr [ k ] );
... | 87 | null |
COUNT_SET_BITS_IN_AN_INTEGER_1 | def f_gold ( n ) :
if ( n == 0 ) :
return 0
else :
return ( n & 1 ) + f_gold ( n >> 1 )
|
using namespace std;
int f_gold ( int n ) {
if ( n == 0 ) return 0;
else return ( n & 1 ) + f_gold ( n >> 1 );
}
| 88 | null |
COUNT_SUM_OF_DIGITS_IN_NUMBERS_FROM_1_TO_N | import math
def f_gold ( n ) :
if ( n < 10 ) :
return ( n * ( n + 1 ) / 2 )
d = ( int ) ( math.log10 ( n ) )
a = [ 0 ] * ( d + 1 )
a [ 0 ] = 0
a [ 1 ] = 45
for i in range ( 2 , d + 1 ) :
a [ i ] = a [ i - 1 ] * 10 + 45 * ( int ) ( math.ceil ( math.pow ( 10 , i - 1 ) ) ... |
using namespace std;
int f_gold ( int n ) {
if ( n < 10 ) return n * ( n + 1 ) / 2;
int d = log10 ( n );
int * a = new int [ d + 1 ];
a [ 0 ] = 0, a [ 1 ] = 45;
for ( int i = 2;
i <= d;
i ++ ) a [ i ] = a [ i - 1 ] * 10 + 45 * ceil ( pow ( 10, i - 1 ) );
int p = ceil ( pow ( 10, d ) );
int... | 89 | null |
FIND_FIRST_NATURAL_NUMBER_WHOSE_FACTORIAL_DIVISIBLE_X | def f_gold ( x ) :
i = 1 ;
fact = 1 ;
for i in range ( 1 , x ) :
fact = fact * i
if ( fact % x == 0 ) :
break
return i
|
using namespace std;
int f_gold ( int x ) {
int i = 1;
int fact = 1;
for ( i = 1;
i < x;
i ++ ) {
fact = fact * i;
if ( fact % x == 0 ) break;
}
return i;
}
| 90 | null |
MAXIMUM_SUBSEQUENCE_SUM_SUCH_THAT_NO_THREE_ARE_CONSECUTIVE | def f_gold ( arr , n ) :
sum = [ 0 for k in range ( n ) ]
if n >= 1 :
sum [ 0 ] = arr [ 0 ]
if n >= 2 :
sum [ 1 ] = arr [ 0 ] + arr [ 1 ]
if n > 2 :
sum [ 2 ] = max ( sum [ 1 ] , max ( arr [ 1 ] + arr [ 2 ] , arr [ 0 ] + arr [ 2 ] ) )
for i in range ( 3 , n ) :
... |
using namespace std;
int f_gold ( int arr [ ], int n ) {
int sum [ n ];
if ( n >= 1 ) sum [ 0 ] = arr [ 0 ];
if ( n >= 2 ) sum [ 1 ] = arr [ 0 ] + arr [ 1 ];
if ( n > 2 ) sum [ 2 ] = max ( sum [ 1 ], max ( arr [ 1 ] + arr [ 2 ], arr [ 0 ] + arr [ 2 ] ) );
for ( int i = 3;
i < n;
i ++ ) sum [ i ]... | 91 | null |
K_TH_PRIME_FACTOR_GIVEN_NUMBER | import math
def f_gold ( n , k ) :
while ( n % 2 == 0 ) :
k = k - 1
n = n / 2
if ( k == 0 ) :
return 2
i = 3
while i <= math.sqrt ( n ) :
while ( n % i == 0 ) :
if ( k == 1 ) :
return i
k = k - 1
n... |
using namespace std;
int f_gold ( int n, int k ) {
while ( n % 2 == 0 ) {
k --;
n = n / 2;
if ( k == 0 ) return 2;
}
for ( int i = 3;
i <= sqrt ( n );
i = i + 2 ) {
while ( n % i == 0 ) {
if ( k == 1 ) return i;
k --;
n = n / i;
}
}
if ( n > 2 && k =... | 92 | null |
MAXIMUM_SUM_PAIRS_SPECIFIC_DIFFERENCE_1 | def f_gold ( arr , N , k ) :
maxSum = 0 ;
arr.sort ( ) ;
i = N - 1 ;
while ( i >= 0 ) :
if ( arr [ i ] - arr [ i - 1 ] < k ) :
maxSum += arr [ i ] ;
maxSum += arr [ i - 1 ] ;
i -= 1 ;
i -= 1 ;
return maxSum ;
|
using namespace std;
int f_gold ( int arr [ ], int N, int k ) {
int maxSum = 0;
sort ( arr, arr + N );
for ( int i = N - 1;
i > 0;
-- i ) {
if ( arr [ i ] - arr [ i - 1 ] < k ) {
maxSum += arr [ i ];
maxSum += arr [ i - 1 ];
-- i;
}
}
return maxSum;
}
| 93 | null |
COUNT_PALINDROMIC_SUBSEQUENCE_GIVEN_STRING | def f_gold ( 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 [... |
using namespace std;
int f_gold ( 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 ... | 94 | null |
SUM_MATRIX_ELEMENT_ABSOLUTE_DIFFERENCE_ROW_COLUMN_NUMBERS_2 | def f_gold ( n ) :
n -= 1
sum = 0
sum += ( n * ( n + 1 ) ) / 2
sum += ( n * ( n + 1 ) * ( 2 * n + 1 ) ) / 6
return int ( sum )
|
using namespace std;
int f_gold ( int n ) {
n --;
int sum = 0;
sum += ( n * ( n + 1 ) ) / 2;
sum += ( n * ( n + 1 ) * ( 2 * n + 1 ) ) / 6;
return sum;
}
| 95 | null |
CHECK_LARGE_NUMBER_DIVISIBLE_3_NOT | null |
using namespace std;
int f_gold ( string str ) {
int n = str . length ( );
int digitSum = 0;
for ( int i = 0;
i < n;
i ++ ) digitSum += ( str [ i ] - '0' );
return ( digitSum % 3 == 0 );
}
| 96 | null |
SORT_ARRAY_TWO_HALVES_SORTED | def f_gold ( A , n ) :
A.sort ( )
|
using namespace std;
void f_gold ( int A [ ], int n ) {
sort ( A, A + n );
}
| 97 | null |
FIND_THE_MINIMUM_DISTANCE_BETWEEN_TWO_NUMBERS | def f_gold ( arr , n , x , y ) :
min_dist = 99999999
for i in range ( n ) :
for j in range ( i + 1 , n ) :
if ( x == arr [ i ] and y == arr [ j ] or y == arr [ i ] and x == arr [ j ] ) and min_dist > abs ( i - j ) :
min_dist = abs ( i - j )
return min_dist
|
using namespace std;
int f_gold ( int arr [ ], int n, int x, int y ) {
int i, j;
int min_dist = INT_MAX;
for ( i = 0;
i < n;
i ++ ) {
for ( j = i + 1;
j < n;
j ++ ) {
if ( ( x == arr [ i ] && y == arr [ j ] || y == arr [ i ] && x == arr [ j ] ) && min_dist > abs ( i - j ) ) {
... | 98 | null |
WRITE_ONE_LINE_C_FUNCTION_TO_FIND_WHETHER_A_NO_IS_POWER_OF_TWO | def f_gold(n):
if (n == 0):
return False
while (n != 1):
if (n % 2 != 0):
return False
n = n // 2
return True
|
using namespace std;
bool f_gold ( int n ) {
if ( n == 0 ) return 0;
while ( n != 1 ) {
if ( n % 2 != 0 ) return 0;
n = n / 2;
}
return 1;
}
| 99 | null |
MINIMUM_XOR_VALUE_PAIR | def f_gold ( arr , n ) :
arr.sort ( ) ;
min_xor = 999999
val = 0
for i in range ( 0 , n - 1 ) :
for j in range ( i + 1 , n - 1 ) :
val = arr [ i ] ^ arr [ j ]
min_xor = min ( min_xor , val )
return min_xor
|
using namespace std;
int f_gold ( int arr [ ], int n ) {
int min_xor = INT_MAX;
for ( int i = 0;
i < n;
i ++ ) for ( int j = i + 1;
j < n;
j ++ ) min_xor = min ( min_xor, arr [ i ] ^ arr [ j ] );
return min_xor;
}
| 100 | null |
SUM_DIVISORS_1_N_1 | def f_gold ( n ) :
sum = 0
for i in range ( 1 , n + 1 ) :
sum += int ( n / i ) * i
return int ( sum )
|
using namespace std;
int f_gold ( int n ) {
int sum = 0;
for ( int i = 1;
i <= n;
++ i ) sum += ( n / i ) * i;
return sum;
}
| 101 | null |
End of preview. Expand in Data Studio
YAML Metadata Warning:empty or missing yaml metadata in repo card
Check out the documentation for more information.
Bienvenue sur la base de données Translation_go_into_cpp.
Ce dataset regroupe des traductions de code en trois languages : Go, Python, et C++. Une autre colonne "name" donne le thème des codes de chaque lignes. Chaque ligne contient au minimum deux traductions de code, donc deux languages différents.
L'objectif de ce dataset est de fournir une base d'entrainement de LLM en fine-tuning dans le but de faire de la traduction Go/c++.
📊 Data Source
🧱 Structure Data
🏷️ Champs du dataset
| Field name | Type | Description |
|---|---|---|
id |
int32 | Index of the sample |
Go |
string | The Go version of the code |
C++ |
string | The C++ version of the code |
Python |
string | The Python version of the code |
💻 Exemple de ligne (id = 0)
```json { "name": "LCS_FORMED_CONSECUTIVE_SEGMENTS_LEAST_LENGTH_K", "Python": "def f_gold ( k , s1 , s2 ) :\r\n n = len ( s1 )\r\n m = len ( s2 )\r\n lcs = [ [ 0 for x in range ( m + 1 ) ] for y in range ( n + 1 ) ]\r\n cnt = [ [ 0 for x in range ( m + 1 ) ] for y in range ( n + 1 ) ]\r\n for i in range ( 1 , n + 1 ) :\r\n for j in range ( 1 , m + 1 ) :\r\n lcs [ i ] [ j ] = max ( lcs [ i - 1 ] [ j ] , lcs [ i ] [ j - 1 ] )\r\n if ( s1 [ i - 1 ] == s2 [ j - 1 ] ) :\r\n cnt [ i ] [ j ] = cnt [ i - 1 ] [ j - 1 ] + 1 ;\r\n if ( cnt [ i ] [ j ] >= k ) :\r\n for a in range ( k , cnt [ i ] [ j ] + 1 ) :\r\n lcs [ i ] [ j ] = max ( lcs [ i ] [ j ] , lcs [ i - a ] [ j - a ] + a )\r\n return lcs [ n ] [ m ]", "C++": "using namespace std;\r\nint f_gold ( int k, string s1, string s2 ) {\r\n int n = s1 . length ( );\r\n int m = s2 . length ( );\r\n int lcs [ n + 1 ] [ m + 1 ];\r\n int cnt [ n + 1 ] [ m + 1 ];\r\n memset ( lcs, 0, sizeof ( lcs ) );\r\n memset ( cnt, 0, sizeof ( cnt ) );\r\n for ( int i = 1; i <= n; i ++ ) {\r\n for ( int j = 1; j <= m; j ++ ) {\r\n lcs [ i ] [ j ] = max ( lcs [ i - 1 ] [ j ], lcs [ i ] [ j - 1 ] );\r\n if ( s1 [ i - 1 ] == s2 [ j - 1 ] ) cnt [ i ] [ j ] = cnt [ i - 1 ] [ j - 1 ] + 1;\r\n if ( cnt [ i ] [ j ] >= k ) {\r\n for ( int a = k; a <= cnt [ i ] [ j ]; a ++ ) lcs [ i ] [ j ] = max ( lcs [ i ] [ j ], lcs [ i - a ] [ j - a ] + a );\r\n }\r\n }\r\n }\r\n return lcs [ n ] [ m ];\r\n}", "id": 0, "Go": null } ```
📄 Data Splits
- Downloads last month
- 7