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.
#
import math
def f_gold ( n ) :
fibo = 2.078087 * math.log ( n ) + 1.672276
return round ( fibo )
#TOFILL
if __name__... | CodeGen-main | data/transcoder_evaluation_gfg/python/FIND_INDEX_GIVEN_FIBONACCI_NUMBER_CONSTANT_TIME_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 * ( n - 1 ) ;
#TOFILL
if __name__ == '__main__':
param = [
(30,),
(25,),
(69,... | CodeGen-main | data/transcoder_evaluation_gfg/python/MAXIMUM_POINTS_INTERSECTION_N_CIRCLES.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 ) :
i = 1
the_sum = 0
while the_sum < n :
the_sum += i
if the_sum == n :
... | CodeGen-main | data/transcoder_evaluation_gfg/python/CHECK_NUMBER_IS_PERFECT_SQUARE_USING_ADDITIONSUBTRACTION.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 ) :
mp = dict ( )
Sum = 0
count = 0
for i in range ( n ) :
if ( arr [ i ] == 0 ) :
... | CodeGen-main | data/transcoder_evaluation_gfg/python/COUNT_SUBARRAYS_EQUAL_NUMBER_1S_0S_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.
#
import math
def f_gold ( side ) :
return ( ( side * side * side ) * ( math.sqrt ( 2 ) / 3 ) )
#TOFILL
if __name__ == '__... | CodeGen-main | data/transcoder_evaluation_gfg/python/PROGRAM_CALCULATE_VOLUME_OCTAHEDRON.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 ) :
i = len ( str ) - 1
start = end = i + 1
result = ''
while i >= 0 :
if str [ i ] == ... | CodeGen-main | data/transcoder_evaluation_gfg/python/PRINT_WORDS_STRING_REVERSE_ORDER.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 , size ) :
max_so_far = a [ 0 ]
curr_max = a [ 0 ]
for i in range ( 1 , size ) :
curr_max = m... | CodeGen-main | data/transcoder_evaluation_gfg/python/LARGEST_SUM_CONTIGUOUS_SUBARRAY_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 , low , high , x ) :
if x <= arr [ low ] :
return low
i = low
for i in range ( high ) :
... | CodeGen-main | data/transcoder_evaluation_gfg/python/CEILING_IN_A_SORTED_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 ) :
C = [ [ 0 for i in range ( n + 1 ) ] for j in range ( n + 1 ) ]
for i in range ( 0 , n + 1 ) :
... | CodeGen-main | data/transcoder_evaluation_gfg/python/SUM_SQUARES_BINOMIAL_COEFFICIENTS.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 ) :
temp = [ 0 for k in range ( n ) ]
j = 0
for i in range ( n ) :
if ( arr [ i ] >= 0 ... | CodeGen-main | data/transcoder_evaluation_gfg/python/MOVE_VE_ELEMENTS_END_ORDER_EXTRA_SPACE_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 ( A ) :
n = 2 * A
dpArray = [ 0 ] * ( n + 1 )
dpArray [ 0 ] = 1
dpArray [ 2 ] = 1
for i in range ... | CodeGen-main | data/transcoder_evaluation_gfg/python/COUNT_WAYS_DIVIDE_CIRCLE_USING_N_NON_INTERSECTING_CHORDS.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 ( text , word ) :
word_list = text.split ( )
result = ''
stars = '*' * len ( word )
count = 0
ind... | CodeGen-main | data/transcoder_evaluation_gfg/python/PROGRAM_CENSOR_WORD_ASTERISKS_SENTENCE.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 ) :
count = 0 ;
curr = 19 ;
while ( True ) :
sum = 0 ;
x = curr ;
while ( x >... | CodeGen-main | data/transcoder_evaluation_gfg/python/N_TH_NUMBER_WHOSE_SUM_OF_DIGITS_IS_TEN_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.
#
import math
def f_gold ( n ) :
ar = [ 0 ] * 10
while ( n > 0 ) :
digit = math.floor ( n % 10 )
if ( ar ... | CodeGen-main | data/transcoder_evaluation_gfg/python/PROGRAM_TO_CHECK_IF_A_GIVEN_NUMBER_IS_LUCKY_ALL_DIGITS_ARE_DIFFERENT.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 ) :
C = [ [ 0 ] * ( n + 2 ) for i in range ( 0 , n + 2 ) ]
for i in range ( 0 , n + 1 ) :
for j i... | CodeGen-main | data/transcoder_evaluation_gfg/python/SUM_BINOMIAL_COEFFICIENTS.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 ) :
dp = [ ] ;
dp.append ( 1 ) ;
dp.append ( 1 ) ;
for i in range ( 2 , n + 1 ) :
dp.appe... | CodeGen-main | data/transcoder_evaluation_gfg/python/LEONARDO_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, x):
i = 0
while (i <= n - 1):
if (arr[i] == x):
return i
i += abs(arr[i] ... | CodeGen-main | data/transcoder_evaluation_gfg/python/EFFICIENT_SEARCH_IN_AN_ARRAY_WHERE_DIFFERENCE_BETWEEN_ADJACENT_IS_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 ( r ) :
PI = 3.142
return PI * ( r * r ) ;
#TOFILL
if __name__ == '__main__':
param = [
(93,),
... | CodeGen-main | data/transcoder_evaluation_gfg/python/C_PROGRAM_FIND_AREA_CIRCLE.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 , x ) :
cnt = 0
for i in range ( 1 , n + 1 ) :
if i <= x :
if x // i <= n and x % i =... | CodeGen-main | data/transcoder_evaluation_gfg/python/COUNT_ENTRIES_EQUAL_TO_X_IN_A_SPECIAL_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 ( arr , n ) :
s = [ ]
first = 0
second = 0
for i in range ( n ) :
if arr [ i ] not in s :
... | CodeGen-main | data/transcoder_evaluation_gfg/python/MAXIMUM_AREA_RECTANGLE_PICKING_FOUR_SIDES_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 ) :
DP = [ 0 for i in range ( 0 , n + 1 ) ]
DP [ 0 ] = DP [ 1 ] = DP [ 2 ] = 1
DP [ 3 ] = 2
for i... | CodeGen-main | data/transcoder_evaluation_gfg/python/COUNT_OFDIFFERENT_WAYS_EXPRESS_N_SUM_1_3_4.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 ) :
p = 1
if ( k % 2 ) :
p = - 1
return ( pow ( n - 1 , k ) + p * ( n - 1 ) ) / n
#TOFI... | CodeGen-main | data/transcoder_evaluation_gfg/python/NUMBER_WAYS_NODE_MAKE_LOOP_SIZE_K_UNDIRECTED_COMPLETE_CONNECTED_GRAPH_N_NODES.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 = - 2147483648
for i in range ( n ) :
curr_xor = 0
for j in range ( i , n )... | CodeGen-main | data/transcoder_evaluation_gfg/python/FIND_THE_MAXIMUM_SUBARRAY_XOR_IN_A_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 ( arr1 , arr2 , m , n ) :
i = 0
j = 0
if m < n :
return 0
arr1.sort ( )
arr2.sort ( )
... | CodeGen-main | data/transcoder_evaluation_gfg/python/FIND_WHETHER_AN_ARRAY_IS_SUBSET_OF_ANOTHER_ARRAY_SET_1_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 ( num1 , num2 ) :
len1 = len ( num1 )
len2 = len ( num2 )
if len1 == 0 or len2 == 0 :
return "0"
... | CodeGen-main | data/transcoder_evaluation_gfg/python/MULTIPLY_LARGE_NUMBERS_REPRESENTED_AS_STRINGS.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 = 1
if ( n and not ( n & ( n - 1 ) ) ) :
return n
while ( p < n ) :
p <<= 1
... | CodeGen-main | data/transcoder_evaluation_gfg/python/NEXT_POWER_OF_2_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 , arr_size , sum ) :
for i in range ( 0 , arr_size - 2 ) :
for j in range ( i + 1 , arr_size - 1 ) :
... | CodeGen-main | data/transcoder_evaluation_gfg/python/FIND_A_TRIPLET_THAT_SUM_TO_A_GIVEN_VALUE.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 != 0 and ( ( n & ( n - 1 ) ) == 0 ) and not ( n & 0xAAAAAAAA ) ) ;
#TOFILL
if __name__ == '... | CodeGen-main | data/transcoder_evaluation_gfg/python/FIND_WHETHER_A_GIVEN_NUMBER_IS_A_POWER_OF_4_OR_NOT_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 ) :
table = [ 0 for i in range ( n + 1 ) ]
table [ 0 ] = 1
for i in range ( 3 , n + 1 ) :
tab... | CodeGen-main | data/transcoder_evaluation_gfg/python/COUNT_NUMBER_WAYS_REACH_GIVEN_SCORE_GAME.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 == 1 :
return 2
return 2 * f_gold ( n - 1 )
#TOFILL
if __name__ == '__main__':
pa... | CodeGen-main | data/transcoder_evaluation_gfg/python/HYPERCUBE_GRAPH.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 ) :
if ( X < arr [ 0 ] ) :
return 0 ;
elif ( X > arr [ n - 1 ] ) :
return n
... | CodeGen-main | data/transcoder_evaluation_gfg/python/LOWER_INSERTION_POINT.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 ( grid , n ) :
incl = max ( grid [ 0 ] [ 0 ] , grid [ 1 ] [ 0 ] )
excl = 0
for i in range ( 1 , n ) :
... | CodeGen-main | data/transcoder_evaluation_gfg/python/MAXIMUM_SUM_2_X_N_GRID_NO_TWO_ELEMENTS_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 ( n ) :
ans = 2 * ( pow ( 3 , n ) ) - 1 ;
return ans ;
#TOFILL
if __name__ == '__main__':
param = [
... | CodeGen-main | data/transcoder_evaluation_gfg/python/NUMBER_TRIANGLES_N_MOVES_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 ) :
n = len ( a )
m = len ( b )
if m == 0 :
return 1
dp = [ [ 0 ] * ( n + 1 ) for _ i... | CodeGen-main | data/transcoder_evaluation_gfg/python/WAYS_TRANSFORMING_ONE_STRING_REMOVING_0_CHARACTERS.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 ) :
n -= 1
n |= n >> 1
n |= n >> 2
n |= n >> 4
n |= n >> 8
n |= n >> 16
n += 1
re... | CodeGen-main | data/transcoder_evaluation_gfg/python/SMALLEST_POWER_OF_2_GREATER_THAN_OR_EQUAL_TO_N_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 ( s ) :
_sum = 0
n = 1
while ( _sum < s ) :
_sum += n * n * n
n += 1
n -= 1
if _s... | CodeGen-main | data/transcoder_evaluation_gfg/python/SQUARED_TRIANGULAR_NUMBER_SUM_CUBES.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 ( m , n ) :
T = [ [ 0 for i in range ( n + 1 ) ] for i in range ( m + 1 ) ]
for i in range ( m + 1 ) :
... | CodeGen-main | data/transcoder_evaluation_gfg/python/SEQUENCES_GIVEN_LENGTH_EVERY_ELEMENT_EQUAL_TWICE_PREVIOUS_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 ( h , m ) :
if ( h < 0 or m < 0 or h > 12 or m > 60 ) :
print ( 'Wrong input' )
if ( h == 12 ) :
... | CodeGen-main | data/transcoder_evaluation_gfg/python/CALCULATE_ANGLE_HOUR_HAND_MINUTE_HAND.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 , b , c ) :
dp = [ - 1 ] * ( n + 10 )
dp [ 0 ] = 0
for i in range ( 0 , n ) :
if ( dp [ i... | CodeGen-main | data/transcoder_evaluation_gfg/python/MAXIMUM_NUMBER_SEGMENTS_LENGTHS_B_C.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 ( limit ) :
if ( limit < 2 ) :
return 0
ef1 = 0
ef2 = 2
sm = ef1 + ef2
while ( ef2 <= lim... | CodeGen-main | data/transcoder_evaluation_gfg/python/EVEN_FIBONACCI_NUMBERS_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 , m ) :
count = [ ]
for i in range ( n + 2 ) :
count.append ( 0 )
count [ 0 ] = 0
for i i... | CodeGen-main | data/transcoder_evaluation_gfg/python/COUNT_NUMBER_WAYS_TILE_FLOOR_SIZE_N_X_M_USING_1_X_M_SIZE_TILES.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 , r , b , g ) :
fact = [ 0 for i in range ( n + 1 ) ]
fact [ 0 ] = 1
for i in range ( 1 , n + 1 , 1 )... | CodeGen-main | data/transcoder_evaluation_gfg/python/COUNT_NUMBER_OF_STRINGS_MADE_OF_R_G_AND_B_USING_GIVEN_COMBINATION.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 :
if ( b > c ) :
return b
elif ( a > c ) :
retur... | CodeGen-main | data/transcoder_evaluation_gfg/python/MIDDLE_OF_THREE_USING_MINIMUM_COMPARISONS_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.
#
import math
def f_gold ( a ) :
area = ( math.pi * a * a ) / 4
return area
#TOFILL
if __name__ == '__main__':
par... | CodeGen-main | data/transcoder_evaluation_gfg/python/AREA_OF_THE_CIRCLE_THAT_HAS_A_SQUARE_AND_A_CIRCLE_INSCRIBED_IN_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 sys
def f_gold ( arr , arr_size ) :
if ( arr_size < 3 ) :
print ( " Invalid Input " )
return
fir... | CodeGen-main | data/transcoder_evaluation_gfg/python/THIRD_LARGEST_ELEMENT_ARRAY_DISTINCT_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.
#
def f_gold ( arr , n ) :
isSorted = 0
while isSorted == 0 :
isSorted = 1
temp = 0
for i in range... | CodeGen-main | data/transcoder_evaluation_gfg/python/ODD_EVEN_SORT_BRICK_SORT.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, n):
sum = 0
for i in range(n):
for j in range(i + 1, n):
sum += (abs(x[i] - x[j]) +... | CodeGen-main | data/transcoder_evaluation_gfg/python/SUM_MANHATTAN_DISTANCES_PAIRS_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 == 2 or n == 3):
return (n - 1)
res = 1
while (n > 4):
n -= 3
res *= 3
... | CodeGen-main | data/transcoder_evaluation_gfg/python/DYNAMIC_PROGRAMMING_SET_36_CUT_A_ROPE_TO_MAXIMIZE_PRODUCT_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 ( dist ) :
count = [ 0 ] * ( dist + 1 )
count [ 0 ] = 1
count [ 1 ] = 1
count [ 2 ] = 2
for i in ... | CodeGen-main | data/transcoder_evaluation_gfg/python/COUNT_NUMBER_OF_WAYS_TO_COVER_A_DISTANCE_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 ( n ) :
if arr [ i ] > arr [ i + 1 ] :
break
l = ( i + 1... | CodeGen-main | data/transcoder_evaluation_gfg/python/GIVEN_A_SORTED_AND_ROTATED_ARRAY_FIND_IF_THERE_IS_A_PAIR_WITH_A_GIVEN_SUM_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 ) :
zeros = 0
ones = 0
for i in range ( 0 , len ( str ) ) :
ch = str [ i ] ;
if ( c... | CodeGen-main | data/transcoder_evaluation_gfg/python/CHANGE_BITS_CAN_MADE_ONE_FLIP.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 ( str1 ) :
result = 0 ;
n = len ( str1 )
for i in range ( 0 , n ) :
for j in range ( i + 1 , n ) ... | CodeGen-main | data/transcoder_evaluation_gfg/python/COUNT_CHARACTERS_STRING_DISTANCE_ENGLISH_ALPHABETS.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 ( f , d , s ) :
mem = [ [ 0 for i in range ( s + 1 ) ] for j in range ( d + 1 ) ]
mem [ 0 ] [ 0 ] = 1
for... | CodeGen-main | data/transcoder_evaluation_gfg/python/DICE_THROW_PROBLEM_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 <= 1 ) :
return n
a = 0
b = 1
c = 1
res = 1
while ( c < n ) :
... | CodeGen-main | data/transcoder_evaluation_gfg/python/FIND_INDEX_GIVEN_FIBONACCI_NUMBER_CONSTANT_TIME.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 , mod ) :
res = 0 ;
a = a % mod ;
while ( b ) :
if ( b & 1 ) :
res = ( res + ... | CodeGen-main | data/transcoder_evaluation_gfg/python/MULTIPLY_LARGE_INTEGERS_UNDER_LARGE_MODULO.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 ( p ) :
checkNumber = 2 ** p - 1
nextval = 4 % checkNumber
for i in range ( 1 , p - 1 ) :
nextval... | CodeGen-main | data/transcoder_evaluation_gfg/python/PRIMALITY_TEST_SET_5USING_LUCAS_LEHMER_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 ( str ) :
n = len ( str )
LCSRe = [ [ 0 for x in range ( n + 1 ) ] for y in range ( n + 1 ) ]
res = ""
... | CodeGen-main | data/transcoder_evaluation_gfg/python/LONGEST_REPEATING_AND_NON_OVERLAPPING_SUBSTRING.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 ( len ( s ) >= 10 ) :
return True
for i in range ( 1 , len ( s ) ) :
for j in rang... | CodeGen-main | data/transcoder_evaluation_gfg/python/CHECK_GIVEN_STRING_CAN_SPLIT_FOUR_DISTINCT_STRINGS.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 , r , x ) :
if r >= l :
mid = l + ( r - l ) // 2
if arr [ mid ] == x :
retu... | CodeGen-main | data/transcoder_evaluation_gfg/python/BINARY_SEARCH.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 , m , k ) :
if ( m <= n - k + 1 ) :
return m + k - 1
m = m - ( n - k + 1 )
if ( m % n == 0 ) ... | CodeGen-main | data/transcoder_evaluation_gfg/python/DISTRIBUTING_M_ITEMS_CIRCLE_SIZE_N_STARTING_K_TH_POSITION.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 ( num ) :
result = 0
i = 2
while i <= ( math.sqrt ( num ) ) :
if ( num % i == 0 ) :
... | CodeGen-main | data/transcoder_evaluation_gfg/python/SUM_OF_ALL_PROPER_DIVISORS_OF_A_NATURAL_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 ( n ) :
dp = [ [ 0 for i in range ( n + 1 ) ] for i in range ( 10 ) ]
for i in range ( 10 ) :
dp [ i ... | CodeGen-main | data/transcoder_evaluation_gfg/python/TOTAL_NUMBER_OF_NON_DECREASING_NUMBERS_WITH_N_DIGITS.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 ) :
n = len ( s )
a = [ 0 ] * n
for i in range ( n - 1 , - 1 , - 1 ) :
back_up = 0
fo... | CodeGen-main | data/transcoder_evaluation_gfg/python/LONGEST_PALINDROME_SUBSEQUENCE_SPACE.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 ( a1 , a2 , a3 , n1 , n2 , n3 , sum ) :
s = set ( )
for i in range ( n1 ) :
s.add ( a1 [ i ] )
fo... | CodeGen-main | data/transcoder_evaluation_gfg/python/FIND_THREE_ELEMENT_FROM_DIFFERENT_THREE_ARRAYS_SUCH_THAT_THAT_A_B_C_K_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 ( s1 , s2 , index ) :
s2 [ index ] = s1 [ index ] ;
if ( index == len ( s1 ) - 1 ) :
return ;
f_g... | CodeGen-main | data/transcoder_evaluation_gfg/python/FUNCTION_COPY_STRING_ITERATIVE_RECURSIVE_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 ) :
count = 0 ;
if ( n and not ( n & ( n - 1 ) ) ) :
return n
while ( n != 0 ) :
n >>... | CodeGen-main | data/transcoder_evaluation_gfg/python/SMALLEST_POWER_OF_2_GREATER_THAN_OR_EQUAL_TO_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 ) :
if ( n <= 1 ) :
return False
if ( n <= 3 ) :
return False
if ( n % 2 == 0 or n % ... | CodeGen-main | data/transcoder_evaluation_gfg/python/COMPOSITE_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 , n , k ) :
i = 0
l = 0
r = 0
res = 0
thi = [ ]
pol = [ ]
while i < n :
if ... | CodeGen-main | data/transcoder_evaluation_gfg/python/POLICEMEN_CATCH_THIEVES.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 ) :
principal += mat [ i ] [ i ]... | CodeGen-main | data/transcoder_evaluation_gfg/python/EFFICIENTLY_COMPUTE_SUMS_OF_DIAGONALS_OF_A_MATRIX_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.
#
import sys
def f_gold ( arr , n , m ) :
if ( m == 0 or n == 0 ) :
return 0
arr.sort ( )
if ( n < m ) :
... | CodeGen-main | data/transcoder_evaluation_gfg/python/CHOCOLATE_DISTRIBUTION_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 ( arr , size , KthIndex ) :
dict = { }
vect = [ ]
for i in range ( size ) :
if ( arr [ i ] in dic... | CodeGen-main | data/transcoder_evaluation_gfg/python/K_TH_DISTINCT_OR_NON_REPEATING_ELEMENT_IN_AN_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.
#
import math
def f_gold ( n ) :
result = 0
for i in range ( 2 , ( int ) ( math.sqrt ( n ) ) + 1 ) :
if ( n % i =... | CodeGen-main | data/transcoder_evaluation_gfg/python/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(x1, y1, x2, y2, r1, r2):
distSq = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)
radSumSq = (r1 + r2) * (r1 + ... | CodeGen-main | data/transcoder_evaluation_gfg/python/CHECK_TWO_GIVEN_CIRCLES_TOUCH_INTERSECT.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 , key , capacity ) :
if ( n >= capacity ) :
return n
i = n - 1
while i >= 0 and arr [ i... | CodeGen-main | data/transcoder_evaluation_gfg/python/SEARCH_INSERT_AND_DELETE_IN_A_SORTED_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 ( x ) :
even_bits = x & 0xAAAAAAAA
odd_bits = x & 0x55555555
even_bits >>= 1
odd_bits <<= 1
retur... | CodeGen-main | data/transcoder_evaluation_gfg/python/SWAP_ALL_ODD_AND_EVEN_BITS.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 ) :
res = 1
for i in range ( 0 , n ) :
res *= ( 2 * n - i )
res /= ( i + 1 )
return r... | CodeGen-main | data/transcoder_evaluation_gfg/python/DYCK_PATH.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 ( input , unlock_code ) :
rotation = 0 ;
while ( input > 0 or unlock_code > 0 ) :
input_digit = input... | CodeGen-main | data/transcoder_evaluation_gfg/python/MINIMUM_ROTATIONS_UNLOCK_CIRCULAR_LOCK.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 ( strA , strB ) :
res = 0
for i in range ( 0 , len ( strA ) ) :
res = res ^ ( ord ) ( strA [ i ] )
... | CodeGen-main | data/transcoder_evaluation_gfg/python/FIND_ONE_EXTRA_CHARACTER_STRING_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 , k ) :
oneSeen = False
while ( n > 0 ) :
digit = n % k
if ( digit > 1 ) :
re... | CodeGen-main | data/transcoder_evaluation_gfg/python/CHECK_NUMBER_POWER_K_USING_BASE_CHANGING_METHOD.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
maxsize = - 1
for i in range(0, n - 1):
sum = - 1 if (arr[i] == 0) else 1
... | CodeGen-main | data/transcoder_evaluation_gfg/python/LARGEST_SUBARRAY_WITH_EQUAL_NUMBER_OF_0S_AND_1S.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 ) :
temp = n * [ None ]
small , large = 0 , n - 1
flag = True
for i in range ( n ) :
... | CodeGen-main | data/transcoder_evaluation_gfg/python/REARRANGE_ARRAY_MAXIMUM_MINIMUM_FORM.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 , low , high , x ) :
if x <= arr [ low ] :
return low
if x > arr [ high ] :
return - 1
... | CodeGen-main | data/transcoder_evaluation_gfg/python/CEILING_IN_A_SORTED_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 ( str1 , str2 ) :
n1 = len ( str1 )
n2 = len ( str2 )
if n1 != n2 :
return 0
str1 = sorted ( ... | CodeGen-main | data/transcoder_evaluation_gfg/python/CHECK_WHETHER_TWO_STRINGS_ARE_ANAGRAM_OF_EACH_OTHER.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
arr.sort ( )
for i in range ( 0 , int ( n / 2 ) ) :
sum -= ( 2 * arr [ i ] ... | CodeGen-main | data/transcoder_evaluation_gfg/python/MAXIMIZE_SUM_CONSECUTIVE_DIFFERENCES_CIRCULAR_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 ) :
s = [ ]
j = 0
ans = 0
for i in range ( n ) :
while ( j < n and ( arr [ j ] not ... | CodeGen-main | data/transcoder_evaluation_gfg/python/SUBARRAYS_DISTINCT_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.
#
def f_gold(m, n):
if m < n:
return 0
if n == 0:
return 1
res = (f_gold(m - 1, n) + f_gold(m // 2, n ... | CodeGen-main | data/transcoder_evaluation_gfg/python/SEQUENCES_GIVEN_LENGTH_EVERY_ELEMENT_EQUAL_TWICE_PREVIOUS.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 ( b == 0 ) :
return 1
answer = a
increment = a
for i in range ( 1 , b ) :
... | CodeGen-main | data/transcoder_evaluation_gfg/python/WRITE_YOU_OWN_POWER_WITHOUT_USING_MULTIPLICATION_AND_DIVISION.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 , r , x ) :
if r < l :
return - 1
if arr [ l ] == x :
return l
if arr [ r ] == ... | CodeGen-main | data/transcoder_evaluation_gfg/python/RECURSIVE_C_PROGRAM_LINEARLY_SEARCH_ELEMENT_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 ( mat , n , sum ) :
for i in range ( n ) :
mat [ i ].sort ( )
for i in range ( n - 1 ) :
for ... | CodeGen-main | data/transcoder_evaluation_gfg/python/FIND_PAIRS_GIVEN_SUM_ELEMENTS_PAIR_DIFFERENT_ROWS.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 ) :
dp = [ 0 for i in range ( n + 1 ) ]
for i in range ( n + 1 ) :
if ( i <= 2 ) :
dp... | CodeGen-main | data/transcoder_evaluation_gfg/python/FRIENDS_PAIRING_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(s):
n = len(s)
s1 = ""
s1 = s1 + s[0].lower()
i = 1
while i < n:
if (s[i] == ' ' and i <=... | CodeGen-main | data/transcoder_evaluation_gfg/python/GOOGLE_CASE_GIVEN_SENTENCE.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 ( expr ) :
lenn = len ( expr )
if ( lenn % 2 ) :
return - 1
s = [ ]
for i in range ( lenn ) :... | CodeGen-main | data/transcoder_evaluation_gfg/python/MINIMUM_NUMBER_OF_BRACKET_REVERSALS_NEEDED_TO_MAKE_AN_EXPRESSION_BALANCED.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 ) :
sm = 0
for i in range ( 1 , n + 1 ) :
for j in range ( i , n + 1 ) :
sm = sm + i ... | CodeGen-main | data/transcoder_evaluation_gfg/python/SUM_PAIRWISE_PRODUCTS.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 ) :
for i in range ( n ) :
count = 0
for j in range ( n ) :
if arr [ j ... | CodeGen-main | data/transcoder_evaluation_gfg/python/DISTRIBUTING_ITEMS_PERSON_CANNOT_TAKE_TWO_ITEMS_TYPE.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 ) :
c = [ 0 , 0 , 0 ]
res = 0
for i in range ( 0 , n ) :
c [ arr [ i ] % 3 ] += 1
r... | CodeGen-main | data/transcoder_evaluation_gfg/python/COUNT_POSSIBLE_GROUPS_SIZE_2_3_SUM_MULTIPLE_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.
#
import math
def f_gold(N):
return math.ceil(math.log2(N + 1)) - 1
#TOFILL
if __name__ == '__main__':
param = [
... | CodeGen-main | data/transcoder_evaluation_gfg/python/HEIGHT_COMPLETE_BINARY_TREE_HEAP_N_NODES.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 random
def f_gold ( arr , n ) :
for i in range ( n - 1 , 0 , - 1 ) :
j = random.randint ( 0 , i + 1 )
... | CodeGen-main | data/transcoder_evaluation_gfg/python/SHUFFLE_A_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.
#
import math
def f_gold ( a , n ) :
return ( - 1 + int ( math.sqrt ( 1 + ( 8 * n ) ) ) ) // 2
#TOFILL
if __name__ == '__m... | CodeGen-main | data/transcoder_evaluation_gfg/python/MAXIMUM_HEIGHT_OF_TRIANGULAR_ARRANGEMENT_OF_ARRAY_VALUES_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 ( dp , arr1 , n , arr2 , m , k ) :
if k < 0 :
return - ( 10 ** 7 )
if n < 0 or m < 0 :
return... | CodeGen-main | data/transcoder_evaluation_gfg/python/LONGEST_COMMON_SUBSEQUENCE_WITH_AT_MOST_K_CHANGES_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 ( n , x , y ) :
arr = [ False for i in range ( n + 2 ) ]
if ( x <= n ) :
arr [ x ] = True
if ( y ... | CodeGen-main | data/transcoder_evaluation_gfg/python/COUNT_NUMBERS_CAN_CONSTRUCTED_USING_TWO_NUMBERS.py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.