python_code stringlengths 0 4.04M | repo_name stringlengths 8 58 | file_path stringlengths 5 147 |
|---|---|---|
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( n ) :
der = [ 0 for i in range ( n + 1 ) ]
der [ 0 ] = 1
der [ 1 ] = 0
der [ 2 ] = 1
for i in r... | CodeGen-main | data/transcoder_evaluation_gfg/python/COUNT_DERANGEMENTS_PERMUTATION_SUCH_THAT_NO_ELEMENT_APPEARS_IN_ITS_ORIGINAL_POSITION_1.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( number ) :
n = len ( number )
d = [ 0 for i in range ( 9 ) ]
d [ 0 ] = 1
result = 0
mod_sum = 0... | CodeGen-main | data/transcoder_evaluation_gfg/python/GIVEN_NUMBER_STRING_FIND_NUMBER_CONTIGUOUS_SUBSEQUENCES_RECURSIVELY_ADD_9_SET_2.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( a , b ) :
if ( a == 0 or b == 0 ) :
return False
result = a * b
if ( result >= 9223372036854775... | CodeGen-main | data/transcoder_evaluation_gfg/python/CHECK_INTEGER_OVERFLOW_MULTIPLICATION.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( n , index , Sum , M , arr , dp ) :
global MAX
if index == n :
if ( Sum % M ) == 0 :
ret... | CodeGen-main | data/transcoder_evaluation_gfg/python/CHECK_VALID_SEQUENCE_DIVISIBLE_M.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( str ) :
mx = ""
for i in range ( len ( str ) ) :
mx = max ( mx , str [ i : ] )
return mx
#TOF... | CodeGen-main | data/transcoder_evaluation_gfg/python/LEXICOGRAPHICAL_MAXIMUM_SUBSTRING_STRING.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( s ) :
for i in range ( len ( s ) ) :
if s [ i ].isdigit ( ) != True :
return False
retu... | CodeGen-main | data/transcoder_evaluation_gfg/python/PROGRAM_CHECK_INPUT_INTEGER_STRING.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
import math
def f_gold ( n ) :
if ( n < 0 ) :
return 0 ;
if ( n <= 1 ) :
return 1 ;
digits = 0 ;
... | CodeGen-main | data/transcoder_evaluation_gfg/python/COUNT_DIGITS_FACTORIAL_SET_1.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( arr , n ) :
res = 1
for i in range ( 0 , n ) :
if arr [ i ] <= res :
res = res + arr [ ... | CodeGen-main | data/transcoder_evaluation_gfg/python/FIND_SMALLEST_VALUE_REPRESENTED_SUM_SUBSET_GIVEN_ARRAY.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( arr , n ) :
arr.sort ( )
i = 0
j = n - 1
while ( i < j ) :
print ( arr [ j ] , end = " " )
... | CodeGen-main | data/transcoder_evaluation_gfg/python/ALTERNATIVE_SORTING.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( arr , n ) :
um = dict ( )
curr_sum = 0
for i in range ( n ) :
curr_sum += ( - 1 if ( arr [ i ] ... | CodeGen-main | data/transcoder_evaluation_gfg/python/COUNT_SUBARRAYS_EQUAL_NUMBER_1S_0S.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( arr , n ) :
invcount = 0
for i in range ( 1 , n - 1 ) :
small = 0
for j in range ( i + 1 , ... | CodeGen-main | data/transcoder_evaluation_gfg/python/COUNT_INVERSIONS_OF_SIZE_THREE_IN_A_GIVE_ARRAY_1.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( str ) :
res = ord ( str [ 0 ] ) - 48
for i in range ( 1 , len ( str ) ) :
if ( str [ i ] == '0' or ... | CodeGen-main | data/transcoder_evaluation_gfg/python/CALCULATE_MAXIMUM_VALUE_USING_SIGN_TWO_NUMBERS_STRING.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( arr , n ) :
arr.sort ( )
for i in range ( 0 , n - 1 , 2 ) :
arr [ i ] , arr [ i + 1 ] = arr [ i + 1... | CodeGen-main | data/transcoder_evaluation_gfg/python/SORT_ARRAY_WAVE_FORM_2.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( arr , n ) :
i = - 1
j = 0
while ( j != n ) :
if ( arr [ j ] % 2 == 0 ) :
i = i + 1
... | CodeGen-main | data/transcoder_evaluation_gfg/python/SEGREGATE_EVEN_ODD_NUMBERS_SET_3.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( high , low , n ) :
if ( n <= 0 ) :
return 0
return max ( high [ n - 1 ] + f_gold ( high , low , ( n... | CodeGen-main | data/transcoder_evaluation_gfg/python/DYNAMIC_PROGRAMMING_HIGH_EFFORT_VS_LOW_EFFORT_TASKS_PROBLEM.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( n ) :
num = n ;
dec_value = 0 ;
base = 1 ;
temp = num ;
while ( temp ) :
last_digit = t... | CodeGen-main | data/transcoder_evaluation_gfg/python/PROGRAM_OCTAL_DECIMAL_CONVERSION.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( num ) :
l = len ( num )
count_zero = 0
i = 1
while i < l :
ch = num [ i ]
if ( ch =... | CodeGen-main | data/transcoder_evaluation_gfg/python/CHECK_WHETHER_NUMBER_DUCK_NUMBER_NOT.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( n ) :
return 1162261467 % n == 0
#TOFILL
if __name__ == '__main__':
param = [
(1,),
(3,),
(2... | CodeGen-main | data/transcoder_evaluation_gfg/python/FIND_WHETHER_GIVEN_INTEGER_POWER_3_NOT.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( arr , n , k ) :
count = 0
for i in range ( 0 , n ) :
if ( arr [ i ] <= k ) :
count = co... | CodeGen-main | data/transcoder_evaluation_gfg/python/MINIMUM_SWAPS_REQUIRED_BRING_ELEMENTS_LESS_EQUAL_K_TOGETHER.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( n ) :
return - 1 if ( n & 1 ) else 1
#TOFILL
if __name__ == '__main__':
param = [
(67,),
(2,),
... | CodeGen-main | data/transcoder_evaluation_gfg/python/CASSINIS_IDENTITY.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( arr , n , sum ) :
for i in range ( n ) :
curr_sum = arr [ i ]
j = i + 1
while j <= n :
... | CodeGen-main | data/transcoder_evaluation_gfg/python/FIND_SUBARRAY_WITH_GIVEN_SUM.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( arr , n ) :
if ( n == 1 ) :
return arr [ 0 ]
dec = [ 0 for i in range ( n + 1 ) ]
inc = [ 0 for... | CodeGen-main | data/transcoder_evaluation_gfg/python/MAXIMUM_SUM_ALTERNATING_SUBSEQUENCE_SUM.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( a , n ) :
count = dict ( )
for i in range ( n ) :
if count.get ( a [ i ] ) :
count [ a ... | CodeGen-main | data/transcoder_evaluation_gfg/python/CHANGE_ARRAY_PERMUTATION_NUMBERS_1_N.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( n , d ) :
return ( n & ( d - 1 ) )
#TOFILL
if __name__ == '__main__':
param = [
(54,59,),
(39,84... | CodeGen-main | data/transcoder_evaluation_gfg/python/COMPUTE_MODULUS_DIVISION_BY_A_POWER_OF_2_NUMBER.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold(arr, l, h, key):
if l > h:
return - 1
mid = (l + h) // 2
if arr[mid] == key:
return mid
... | CodeGen-main | data/transcoder_evaluation_gfg/python/SEARCH_AN_ELEMENT_IN_A_SORTED_AND_PIVOTED_ARRAY.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( n ) :
result = 0
for i in range ( 1 , 10 ) :
s = [ ]
if ( i <= n ) :
s.append (... | CodeGen-main | data/transcoder_evaluation_gfg/python/COUNT_NATURAL_NUMBERS_WHOSE_PERMUTATION_GREATER_NUMBER.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( x ) :
return ( x << 1 ) + x + ( x >> 1 )
#TOFILL
if __name__ == '__main__':
param = [
(58,),
(16... | CodeGen-main | data/transcoder_evaluation_gfg/python/MULTIPLY_AN_INTEGER_WITH_3_5.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( y , x ) :
return ( y % pow ( 2 , x ) )
#TOFILL
if __name__ == '__main__':
param = [
(57,76,),
(8... | CodeGen-main | data/transcoder_evaluation_gfg/python/FIND_VALUE_OF_Y_MOD_2_RAISED_TO_POWER_X.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
import math
def f_gold ( s ) :
return ( ( 3 * math.sqrt ( 3 ) * ( s * s ) ) / 2 ) ;
#TOFILL
if __name__ == '__main__':
... | CodeGen-main | data/transcoder_evaluation_gfg/python/AREA_OF_A_HEXAGON.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( mat , n ) :
transpose = [ [ 0 ] * n ] * n
for i in range ( n ) :
for j in range ( n ) :
... | CodeGen-main | data/transcoder_evaluation_gfg/python/MINIMUM_FLIP_REQUIRED_MAKE_BINARY_MATRIX_SYMMETRIC.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( x , y ) :
if ( y == 0 ) :
return 0
if ( y > 0 ) :
return ( x + f_gold ( x , y - 1 ) )
i... | CodeGen-main | data/transcoder_evaluation_gfg/python/MULTIPLY_TWO_NUMBERS_WITHOUT_USING_MULTIPLY_DIVISION_BITWISE_OPERATORS_AND_NO_LOOPS.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold(n, k):
if (n + 1 >= k):
return (k - 1)
else:
return (2 * n + 1 - k)
#TOFILL
if __name__ ==... | CodeGen-main | data/transcoder_evaluation_gfg/python/COUNT_FREQUENCY_K_MATRIX_SIZE_N_MATRIXI_J_IJ.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( arr , n , k ) :
max1 = max ( arr )
res = 0
for i in range ( 0 , n ) :
if ( ( max1 - arr [ i ] )... | CodeGen-main | data/transcoder_evaluation_gfg/python/MINIMUM_INCREMENT_K_OPERATIONS_MAKE_ELEMENTS_EQUAL.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( arr , n ) :
s = dict ( )
count , maxm , minm = 0 , - 10 ** 9 , 10 ** 9
for i in range ( n ) :
s... | CodeGen-main | data/transcoder_evaluation_gfg/python/ELEMENTS_TO_BE_ADDED_SO_THAT_ALL_ELEMENTS_OF_A_RANGE_ARE_PRESENT_IN_ARRAY_1.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( n ) :
if ( n <= 0 ) :
return 0
fibo = [ 0 ] * ( n + 1 )
fibo [ 1 ] = 1
sm = fibo [ 0 ] + fi... | CodeGen-main | data/transcoder_evaluation_gfg/python/SUM_FIBONACCI_NUMBERS.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( n ) :
return int ( 1 + n * ( n + 1 ) / 2 )
#TOFILL
if __name__ == '__main__':
param = [
(46,),
(... | CodeGen-main | data/transcoder_evaluation_gfg/python/PIZZA_CUT_PROBLEM_CIRCLE_DIVISION_LINES.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( A , N , M ) :
ans = 0
h = [ 0 ] * M
for i in range ( 0 , N ) :
A [ i ] = A [ i ] % M
h ... | CodeGen-main | data/transcoder_evaluation_gfg/python/SUBSEQUENCES_SIZE_THREE_ARRAY_WHOSE_SUM_DIVISIBLE_M_1.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( n ) :
return ( ( n << 3 ) - n )
#TOFILL
if __name__ == '__main__':
param = [
(41,),
(42,),
(... | CodeGen-main | data/transcoder_evaluation_gfg/python/EFFICIENT_WAY_TO_MULTIPLY_WITH_7.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( str ) :
one_count = 0
zero_count = 0
n = len ( str )
for i in range ( 0 , n , 1 ) :
if ( st... | CodeGen-main | data/transcoder_evaluation_gfg/python/WAYS_REMOVE_ONE_ELEMENT_BINARY_STRING_XOR_BECOMES_ZERO.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( n ) :
A = [ 0 ] * ( n + 1 )
B = [ 0 ] * ( n + 1 )
A [ 0 ] = 1
A [ 1 ] = 0
B [ 0 ] = 0
B [ 1... | CodeGen-main | data/transcoder_evaluation_gfg/python/TILING_WITH_DOMINOES.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( n ) :
table = [ 0 ] * ( n + 1 )
for i in range ( n + 1 ) :
table [ i ] = n - i
for i in range (... | CodeGen-main | data/transcoder_evaluation_gfg/python/MINIMUM_STEPS_MINIMIZE_N_PER_GIVEN_CONDITION.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( a , b , n ) :
s = 0
for i in range ( 0 , n ) :
s += a [ i ] + b [ i ]
if n == 1 :
retur... | CodeGen-main | data/transcoder_evaluation_gfg/python/SCHEDULE_JOBS_SERVER_GETS_EQUAL_LOAD.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( arr , dep , n ) :
arr.sort ( )
dep.sort ( )
plat_needed = 1
result = 1
i = 1
j = 0
whil... | CodeGen-main | data/transcoder_evaluation_gfg/python/MINIMUM_NUMBER_PLATFORMS_REQUIRED_RAILWAYBUS_STATION.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( arr , n ) :
jumps = [ 0 for i in range ( n ) ]
if ( n == 0 ) or ( arr [ 0 ] == 0 ) :
return float (... | CodeGen-main | data/transcoder_evaluation_gfg/python/MINIMUM_NUMBER_OF_JUMPS_TO_REACH_END_OF_A_GIVEN_ARRAY_1.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( n ) :
multiTerms = n * ( n + 1 ) // 2
sm = multiTerms
for i in range ( 2 , n + 1 ) :
multiTerms... | CodeGen-main | data/transcoder_evaluation_gfg/python/SUM_PAIRWISE_PRODUCTS_1.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( arr , n , x ) :
for i in range ( 0 , n - 1 ) :
if ( arr [ i ] > arr [ i + 1 ] ) :
break ;
... | CodeGen-main | data/transcoder_evaluation_gfg/python/GIVEN_A_SORTED_AND_ROTATED_ARRAY_FIND_IF_THERE_IS_A_PAIR_WITH_A_GIVEN_SUM.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( n ) :
if ( n == 0 ) :
return 0
else :
return ( n & 1 ) + f_gold ( n >> 1 )
#TOFILL
if __... | CodeGen-main | data/transcoder_evaluation_gfg/python/COUNT_SET_BITS_IN_AN_INTEGER_1.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( arr , n ) :
max1 = max ( arr )
min1 = min ( arr )
m = max1 - min1 + 1
if ( m > n ) :
return... | CodeGen-main | data/transcoder_evaluation_gfg/python/CHECK_ARRAY_CONTAINS_CONTIGUOUS_INTEGERS_DUPLICATES_ALLOWED.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( num ) :
sum = 0
i = 2
while ( i * i <= num ) :
while ( num % i == 0 ) :
sum += i
... | CodeGen-main | data/transcoder_evaluation_gfg/python/FIND_MINIMUM_SUM_FACTORS_NUMBER.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( num ) :
if num < 0 :
return f_gold ( - num )
if ( num == 0 or num == 7 ) :
return True
... | CodeGen-main | data/transcoder_evaluation_gfg/python/DIVISIBILITY_BY_7.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( n ) :
if ( n == 0 ) :
return 1
return n * f_gold ( n - 1 )
#TOFILL
if __name__ == '__main__':
... | CodeGen-main | data/transcoder_evaluation_gfg/python/TAIL_RECURSION.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( arr , n ) :
if ( n == 1 ) : return True
arr.sort ( )
d = arr [ 1 ] - arr [ 0 ]
for i in range ( 2 ,... | CodeGen-main | data/transcoder_evaluation_gfg/python/CHECK_WHETHER_ARITHMETIC_PROGRESSION_CAN_FORMED_GIVEN_ARRAY.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( n ) :
if ( n == 0 or n == 9 ) :
return True
if ( n < 9 ) :
return False
return f_gold (... | CodeGen-main | data/transcoder_evaluation_gfg/python/DIVISIBILITY_9_USING_BITWISE_OPERATORS.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( a , b , c ) :
if ( a + b <= c ) or ( a + c <= b ) or ( b + c <= a ) :
return False
else :
r... | CodeGen-main | data/transcoder_evaluation_gfg/python/CHECK_WHETHER_TRIANGLE_VALID_NOT_SIDES_GIVEN.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( arr , n ) :
ans = 0
for i in range ( 0 , n ) :
for j in range ( i + 1 , n ) :
if ( arr ... | CodeGen-main | data/transcoder_evaluation_gfg/python/COUNT_INDEX_PAIRS_EQUAL_ELEMENTS_ARRAY.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( A , B , n ) :
sorted ( A )
sorted ( B )
result = 0
for i in range ( n ) :
result += ( A [ i... | CodeGen-main | data/transcoder_evaluation_gfg/python/MINIMIZE_SUM_PRODUCT_TWO_ARRAYS_PERMUTATIONS_ALLOWED.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( x ) :
m = 1 ;
while ( x & m ) :
x = x ^ m
m <<= 1
x = x ^ m
return x
#TOFILL
if ... | CodeGen-main | data/transcoder_evaluation_gfg/python/ADD_1_TO_A_GIVEN_NUMBER.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( s ) :
if ( s == " " ) :
return "a"
i = len ( s ) - 1
while ( s [ i ] == 'z' and i >= 0 ) :
... | CodeGen-main | data/transcoder_evaluation_gfg/python/LEXICOGRAPHICALLY_NEXT_STRING.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( s , c ) :
oneSeen = False
i = 0
n = len ( s )
while ( i < n ) :
if ( s [ i ] == c ) :
... | CodeGen-main | data/transcoder_evaluation_gfg/python/CHECK_OCCURRENCES_CHARACTER_APPEAR_TOGETHER.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( n ) :
sum = 0 ;
while ( n > 0 ) :
sum += ( n % 10 ) ;
n //= 10 ;
if ( sum == 1 ) :
... | CodeGen-main | data/transcoder_evaluation_gfg/python/MINIMIZE_THE_SUM_OF_DIGITS_OF_A_AND_B_SUCH_THAT_A_B_N.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold(mat, m, n):
rowSum = [0] * m
for i in range(0, m):
sum = 0
for j in range(0, n):
... | CodeGen-main | data/transcoder_evaluation_gfg/python/MAXIMUM_DIFFERENCE_SUM_ELEMENTS_TWO_ROWS_MATRIX.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( a , n , l , r ) :
count = 0
for i in range ( l , r ) :
if ( a [ i ] == a [ i + 1 ] ) :
... | CodeGen-main | data/transcoder_evaluation_gfg/python/NUMBER_INDEXES_EQUAL_ELEMENTS_GIVEN_RANGE.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( arr , size ) :
Hash = dict ( )
for i in range ( size ) :
Hash [ arr [ i ] ] = Hash.get ( arr [ i ] ... | CodeGen-main | data/transcoder_evaluation_gfg/python/FIND_THE_NUMBER_OCCURRING_ODD_NUMBER_OF_TIMES_1.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( digits , n ) :
count = [ 0 ] * ( n + 1 ) ;
count [ 0 ] = 1 ;
count [ 1 ] = 1 ;
for i in range ( 2 ,... | CodeGen-main | data/transcoder_evaluation_gfg/python/COUNT_POSSIBLE_DECODINGS_GIVEN_DIGIT_SEQUENCE_1.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( low , high ) :
fact = 1
x = 1
while ( fact < low ) :
fact = fact * x
x += 1
res = 0... | CodeGen-main | data/transcoder_evaluation_gfg/python/COUNT_FACTORIAL_NUMBERS_IN_A_GIVEN_RANGE.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
import sys
def f_gold ( arr , n ) :
res = - sys.maxsize
for i in range ( 0 , n ) :
curr_sum = 0
for j i... | CodeGen-main | data/transcoder_evaluation_gfg/python/MAXIMUM_SUM_IARRI_AMONG_ROTATIONS_GIVEN_ARRAY.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( n ) :
sum = 0
while ( n > 0 ) :
sum += int ( n % 10 )
n = int ( n / 10 )
return sum
#... | CodeGen-main | data/transcoder_evaluation_gfg/python/HOW_CAN_WE_SUM_THE_DIGITS_OF_A_GIVEN_NUMBER_IN_SINGLE_STATEMENT_1.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
from queue import Queue
def f_gold ( pages , n , capacity ) :
s = set ( )
indexes = Queue ( )
page_faults = 0
f... | CodeGen-main | data/transcoder_evaluation_gfg/python/PROGRAM_PAGE_REPLACEMENT_ALGORITHMS_SET_2_FIFO.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( a , b , c , x1 , y1 ) :
temp = - 2 * ( a * x1 + b * y1 + c ) / ( a * a + b * b )
x = temp * a + x1
y = ... | CodeGen-main | data/transcoder_evaluation_gfg/python/FIND_MIRROR_IMAGE_POINT_2_D_PLANE.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( num ) :
num = list ( num )
n = len ( num )
rightMin = [ 0 ] * n
right = 0
rightMin [ n - 1 ] = ... | CodeGen-main | data/transcoder_evaluation_gfg/python/FORM_SMALLEST_NUMBER_USING_ONE_SWAP_OPERATION.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( rows , columns , numbers ) :
k = 0
arr = [ [ 0 for i in range ( columns ) ] for j in range ( rows ) ]
f... | CodeGen-main | data/transcoder_evaluation_gfg/python/GIVEN_1S_2S_3S_KS_PRINT_ZIG_ZAG_WAY.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( arr , n ) :
if n < 3 :
return - 1
arr.sort ( )
return max ( arr [ 0 ] * arr [ 1 ] * arr [ n - 1... | CodeGen-main | data/transcoder_evaluation_gfg/python/FIND_MAXIMUM_PRODUCT_OF_A_TRIPLET_IN_ARRAY_1.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( n ) :
return 1 if ( n == 1 or n == 0 ) else n * f_gold ( n - 1 ) ;
#TOFILL
if __name__ == '__main__':
pa... | CodeGen-main | data/transcoder_evaluation_gfg/python/PROGRAM_FOR_FACTORIAL_OF_A_NUMBER_1.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( arr , n ) :
leftMax = [ None ] * n
leftMax [ 0 ] = float ( '-inf' )
for i in range ( 1 , n ) :
... | CodeGen-main | data/transcoder_evaluation_gfg/python/FIND_THE_ELEMENT_BEFORE_WHICH_ALL_THE_ELEMENTS_ARE_SMALLER_THAN_IT_AND_AFTER_WHICH_ALL_ARE_GREATER_THAN_IT.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
import math
def f_gold ( r ) :
if ( r <= 0 ) :
return 0
result = 4
for x in range ( 1 , r ) :
ySqua... | CodeGen-main | data/transcoder_evaluation_gfg/python/CIRCLE_LATTICE_POINTS.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( n ) :
if ( n == 0 or n == 1 ) :
return n
f1 , f2 , f3 = 0 , 1 , 1
while ( f3 <= n ) :
f... | CodeGen-main | data/transcoder_evaluation_gfg/python/ZECKENDORFS_THEOREM_NON_NEIGHBOURING_FIBONACCI_REPRESENTATION.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( arr , n , k ) :
result = + 2147483647
arr.sort ( )
for i in range ( n - k + 1 ) :
result = int ... | CodeGen-main | data/transcoder_evaluation_gfg/python/K_NUMBERS_DIFFERENCE_MAXIMUM_MINIMUM_K_NUMBER_MINIMIZED.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( X , Y , m , n ) :
res = 0
X.sort ( reverse = True )
Y.sort ( reverse = True )
hzntl = 1 ; vert = 1
... | CodeGen-main | data/transcoder_evaluation_gfg/python/MINIMUM_COST_CUT_BOARD_SQUARES.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( n , p ) :
if n >= p :
return 0
result = 1
for i in range ( 1 , n + 1 ) :
result = ( res... | CodeGen-main | data/transcoder_evaluation_gfg/python/COMPUTE_N_UNDER_MODULO_P.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( h ) :
MOD = 1000000007
dp = [ 0 for i in range ( h + 1 ) ]
dp [ 0 ] = 1
dp [ 1 ] = 1
for i in r... | CodeGen-main | data/transcoder_evaluation_gfg/python/COUNT_BALANCED_BINARY_TREES_HEIGHT_H.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( arr , n ) :
ans = 0
maxele = max ( arr )
for i in range ( 2 , maxele + 1 ) :
count = 0
... | CodeGen-main | data/transcoder_evaluation_gfg/python/LARGEST_SUBSEQUENCE_GCD_GREATER_1.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( a , b ) :
s = str ( b )
i = 0
while i < ( len ( s ) ) :
if ( s [ i ] != '9' ) :
bre... | CodeGen-main | data/transcoder_evaluation_gfg/python/COUNT_OF_PAIRS_SATISFYING_THE_GIVEN_CONDITION.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( s ) :
b_count = 0
res = 0
for i in range ( len ( s ) ) :
if s [ ~ i ] == 'a' :
res ... | CodeGen-main | data/transcoder_evaluation_gfg/python/COUNT_OPERATIONS_MAKE_STRINGAB_FREE.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold(k, n):
f1 = 0
f2 = 1
i = 2
while i != 0:
f3 = f1 + f2
f1 = f2
f2 = f3
... | CodeGen-main | data/transcoder_evaluation_gfg/python/NTH_MULTIPLE_NUMBER_FIBONACCI_SERIES.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( arr , n ) :
for i in range ( n ) :
arr [ i ] = i + 1
#TOFILL
if __name__ == '__main__':
param = ... | CodeGen-main | data/transcoder_evaluation_gfg/python/SORT_ARRAY_CONTAIN_1_N_VALUES.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( num1 ) :
l = len ( num1 ) ;
num = list ( num1 ) ;
i = l - 1 ;
while ( i >= 0 ) :
if ( num [... | CodeGen-main | data/transcoder_evaluation_gfg/python/BINARY_REPRESENTATION_OF_NEXT_NUMBER.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( a , n , k ) :
result = 0
for i in range ( n ) :
if ( a [ i ] != 1 and a [ i ] > k ) :
r... | CodeGen-main | data/transcoder_evaluation_gfg/python/MINIMUM_OPERATIONS_MAKE_GCD_ARRAY_MULTIPLE_K.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( s , t , n , k ) :
last = 0
cnt = 0
new_last = 0
size = 0
string = 'zyxwvutsrqponmlkjihgfedcba'
... | CodeGen-main | data/transcoder_evaluation_gfg/python/LEXICOGRAPHICALLY_LARGEST_SUBSEQUENCE_EVERY_CHARACTER_OCCURS_LEAST_K_TIMES.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( mat , n ) :
principal = 0
secondary = 0 ;
for i in range ( 0 , n ) :
for j in range ( 0 , n ) :... | CodeGen-main | data/transcoder_evaluation_gfg/python/EFFICIENTLY_COMPUTE_SUMS_OF_DIAGONALS_OF_A_MATRIX.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( N ) :
B_Number = 0
cnt = 0
while ( N != 0 ) :
rem = N % 2
c = pow ( 10 , cnt )
... | CodeGen-main | data/transcoder_evaluation_gfg/python/PROGRAM_DECIMAL_BINARY_CONVERSION_2.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( n , k ) :
res = ""
for i in range ( k ) :
res = res + chr ( ord ( 'a' ) + i )
count = 0
for... | CodeGen-main | data/transcoder_evaluation_gfg/python/STRING_K_DISTINCT_CHARACTERS_NO_CHARACTERS_ADJACENT.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( arr , n ) :
sum = [ 0 for k in range ( n ) ]
if n >= 1 :
sum [ 0 ] = arr [ 0 ]
if n >= 2 :
... | CodeGen-main | data/transcoder_evaluation_gfg/python/MAXIMUM_SUBSEQUENCE_SUM_SUCH_THAT_NO_THREE_ARE_CONSECUTIVE.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( arr , n ) :
mpis = [ 0 ] * ( n )
for i in range ( n ) :
mpis [ i ] = arr [ i ]
for i in range (... | CodeGen-main | data/transcoder_evaluation_gfg/python/MAXIMUM_PRODUCT_INCREASING_SUBSEQUENCE.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( a , n ) :
count_odd = 0 ; count_even = 0 ;
for i in range ( n ) :
if ( a [ i ] & 1 ) :
... | CodeGen-main | data/transcoder_evaluation_gfg/python/CHECK_IF_ALL_THE_ELEMENTS_CAN_BE_MADE_OF_SAME_PARITY_BY_INVERTING_ADJACENT_ELEMENTS.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
import math
def f_gold ( arr , n ) :
min_prefix_sum = 0
res = - math.inf
prefix_sum = [ ]
prefix_sum.append ( a... | CodeGen-main | data/transcoder_evaluation_gfg/python/MAXIMUM_SUBARRAY_SUM_USING_PREFIX_SUM.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( n ) :
nCr = 1
res = 1
for r in range ( 1 , n + 1 ) :
nCr = ( nCr * ( n + 1 - r ) ) / r ;
... | CodeGen-main | data/transcoder_evaluation_gfg/python/COUNT_EVEN_LENGTH_BINARY_SEQUENCES_WITH_SAME_SUM_OF_FIRST_AND_SECOND_HALF_BITS_1.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( boxes , n ) :
boxes.sort ( )
ans = 1
prev_width = boxes [ 0 ]
prev_count = 1
curr_count = 0
... | CodeGen-main | data/transcoder_evaluation_gfg/python/FIND_MAXIMUM_HEIGHT_PYRAMID_FROM_THE_GIVEN_ARRAY_OF_OBJECTS.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( a , n , m ) :
sum1 = 0
sum2 = 0
for i in range ( 0 , n ) :
sum1 = 0
sum2 = 0
fo... | CodeGen-main | data/transcoder_evaluation_gfg/python/CHECK_SUMS_TH_ROW_TH_COLUMN_MATRIX.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( s ) :
aCount = 0
bCount = 0
cCount = 0
for i in range ( len ( s ) ) :
if ( s [ i ] == 'a' )... | CodeGen-main | data/transcoder_evaluation_gfg/python/NUMBER_SUBSEQUENCES_FORM_AI_BJ_CK.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( arr , n , x ) :
curr_sum = 0 ;
min_len = n + 1 ;
start = 0 ;
end = 0 ;
while ( end < n ) :
... | CodeGen-main | data/transcoder_evaluation_gfg/python/MINIMUM_LENGTH_SUBARRAY_SUM_GREATER_GIVEN_VALUE_1.py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.