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 ( mat , N ) :
dp = [ [ 0 for i in range ( N ) ] for j in range ( N ) ]
dp [ 0 ] [ 0 ] = mat [ 0 ] [ 0 ]
f... | CodeGen-main | data/transcoder_evaluation_gfg/python/MAXIMUM_WEIGHT_PATH_ENDING_ELEMENT_LAST_ROW_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 , x , y ) :
count = 0 ;
for i in range ( n ) :
if ( arr [ i ] >= x and arr [ i ] <= y ) :
... | CodeGen-main | data/transcoder_evaluation_gfg/python/QUERIES_COUNTS_ARRAY_ELEMENTS_VALUES_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 ( seq ) :
n = len ( seq )
if ( n >= 9 ) :
return "-1"
result = [ None ] * ( n + 1 )
count = 1... | CodeGen-main | data/transcoder_evaluation_gfg/python/FORM_MINIMUM_NUMBER_FROM_GIVEN_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 ( mat , N ) :
for i in range ( N ) :
for j in range ( N ) :
if ( mat [ i ] [ j ] != mat [ j ]... | CodeGen-main | data/transcoder_evaluation_gfg/python/PROGRAM_TO_CHECK_IF_A_MATRIX_IS_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 ( arr , N , K ) :
arr.sort ( )
dp = [ 0 ] * N
dp [ 0 ] = 0
for i in range ( 1 , N ) :
dp [ i ... | CodeGen-main | data/transcoder_evaluation_gfg/python/MAXIMUM_SUM_PAIRS_SPECIFIC_DIFFERENCE.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 ) :
ans = 0
for length in range ( 1 , int ( math.sqrt ( n ) ) + 1 ) :
height = lengt... | CodeGen-main | data/transcoder_evaluation_gfg/python/NUMBER_UNIQUE_RECTANGLES_FORMED_USING_N_UNIT_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 ) :
a = [ 0 ] * n
b = [ 0 ] * n
a [ 0 ] = b [ 0 ] = 1
for i in range ( 1 , n ) :
a [ i ] ... | CodeGen-main | data/transcoder_evaluation_gfg/python/COUNT_STRINGS_WITH_CONSECUTIVE_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.
#
import math
def f_gold ( n ) :
if ( n % 2 != 0 ) :
return 0
res = 1
for i in range ( 2 , ( int ) ( math.sqr... | CodeGen-main | data/transcoder_evaluation_gfg/python/FIND_SUM_EVEN_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 ( a , b ) :
result = 0
rem = 0
if ( a < b ) :
a , b = b , a
while ( b > 0 ) :
result ... | CodeGen-main | data/transcoder_evaluation_gfg/python/PAPER_CUT_MINIMUM_NUMBER_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 , index , modulo , M , arr , dp ) :
modulo = ( ( modulo % M ) + M ) % M
if ( index == n ) :
if ( ... | CodeGen-main | data/transcoder_evaluation_gfg/python/CHECK_VALID_SEQUENCE_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 ( s ) :
if ( len ( s ) == 0 ) :
print ( 0 )
ans = 0
o = 0
c = 0
for i in range ( len ( s ... | CodeGen-main | data/transcoder_evaluation_gfg/python/COST_BALANCE_PARANTHESES.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 , m ) :
count = 0
i = 0
j = m - 1
while j >= 0 and i < n :
if M [ i ] [ j ] < 0 :
... | CodeGen-main | data/transcoder_evaluation_gfg/python/COUNT_NEGATIVE_NUMBERS_IN_A_COLUMN_WISE_ROW_WISE_SORTED_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.
#
def f_gold ( str ) :
n = len ( str )
count = 0
res = str [ 0 ]
cur_count = 1
for i in range ( n ) :
... | CodeGen-main | data/transcoder_evaluation_gfg/python/MAXIMUM_CONSECUTIVE_REPEATING_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.
#
import itertools
def f_gold ( n ) :
count = 0
for curr in itertools.count ( ) :
sum = 0
x = curr
... | CodeGen-main | data/transcoder_evaluation_gfg/python/N_TH_NUMBER_WHOSE_SUM_OF_DIGITS_IS_TEN.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
return max ( ( f_gold ( n // 2 ) + f_gold ( n // 3 ) + f_g... | CodeGen-main | data/transcoder_evaluation_gfg/python/RECURSIVELY_BREAK_NUMBER_3_PARTS_GET_MAXIMUM_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 ) :
for i in range ( 0 , n ) :
if ( arr [ i ] & 1 ) :
arr [ i ] *= - 1
arr.sort... | CodeGen-main | data/transcoder_evaluation_gfg/python/SORT_EVEN_NUMBERS_ASCENDING_ORDER_SORT_ODD_NUMBERS_DESCENDING_ORDER_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 ( str , l , h ) :
if ( l > h ) :
return sys.maxsize
if ( l == h ) :
return 0
... | CodeGen-main | data/transcoder_evaluation_gfg/python/DYNAMIC_PROGRAMMING_SET_28_MINIMUM_INSERTIONS_TO_FORM_A_PALINDROME.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 )
L = [ [ 0 for x in range ( n ) ] for x in range ( n ) ]
for i in range ( n ) :
... | CodeGen-main | data/transcoder_evaluation_gfg/python/DYNAMIC_PROGRAMMING_SET_12_LONGEST_PALINDROMIC_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 ( N ) :
if ( N == 1 ) :
return 4
countB = 1
countS = 1
for i in range ( 2 , N + 1 ) :
... | CodeGen-main | data/transcoder_evaluation_gfg/python/COUNT_POSSIBLE_WAYS_TO_CONSTRUCT_BUILDINGS.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 , p ) :
res = 1
x = x % p
while ( y > 0 ) :
if ( ( y & 1 ) == 1 ) :
res = ( r... | CodeGen-main | data/transcoder_evaluation_gfg/python/MODULAR_EXPONENTIATION_POWER_IN_MODULAR_ARITHMETIC.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 ) :
res = 0 ;
count = 0 ;
count += 1 ;
if ( count == 1 ) :
res = x ;
else :
i... | CodeGen-main | data/transcoder_evaluation_gfg/python/SELECT_A_RANDOM_NUMBER_FROM_STREAM_WITH_O1_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 ( k , s1 , s2 ) :
n = len ( s1 )
m = len ( s2 )
lcs = [ [ 0 for x in range ( m + 1 ) ] for y in range ( n... | CodeGen-main | data/transcoder_evaluation_gfg/python/LCS_FORMED_CONSECUTIVE_SEGMENTS_LEAST_LENGTH_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 ( arr , n , x , y ) :
min_dist = 99999999
for i in range ( n ) :
for j in range ( i + 1 , n ) :
... | CodeGen-main | data/transcoder_evaluation_gfg/python/FIND_THE_MINIMUM_DISTANCE_BETWEEN_TWO_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 ( string , l ) :
string = list ( string )
i = - 1
j = l
while i < j :
i += 1
j -= 1
... | CodeGen-main | data/transcoder_evaluation_gfg/python/CONSTRUCT_LEXICOGRAPHICALLY_SMALLEST_PALINDROME.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 ) :
zero = 0
two = 0
for i in range ( n ) :
if a [ i ] == 0 :
zero += 1
... | CodeGen-main | data/transcoder_evaluation_gfg/python/NUMBER_OF_PAIRS_IN_AN_ARRAY_HAVING_SUM_EQUAL_TO_PRODUCT.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 ) :
return b
if ( b == 0 ) :
return a
k = 0
while ( ( ( a | b... | CodeGen-main | data/transcoder_evaluation_gfg/python/STEINS_ALGORITHM_FOR_FINDING_GCD.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 ( degree , n ) :
deg_sum = sum ( degree )
if ( 2 * ( n - 1 ) == deg_sum ) :
return True
else :
... | CodeGen-main | data/transcoder_evaluation_gfg/python/CHECK_WHETHER_GIVEN_DEGREES_VERTICES_REPRESENT_GRAPH_TREE.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 , p1 , p2 , n ) :
set1 = ( x >> p1 ) & ( ( 1 << n ) - 1 )
set2 = ( x >> p2 ) & ( ( 1 << n ) - 1 )
xor... | CodeGen-main | data/transcoder_evaluation_gfg/python/SWAP_BITS_IN_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(arr, n):
vis = dict()
for i in range(n):
vis[arr[i]] = 1
k = len(vis)
vid = dict()
ans = ... | CodeGen-main | data/transcoder_evaluation_gfg/python/COUNT_SUBARRAYS_TOTAL_DISTINCT_ELEMENTS_ORIGINAL_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 ) :
return 0
else :
return 1 + f_gold ( n & ( n - 1 ) )
#TOFILL
if __n... | CodeGen-main | data/transcoder_evaluation_gfg/python/COUNT_SET_BITS_IN_AN_INTEGER_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 ) :
if ( n < 0 ) :
return 0 ;
if ( n <= 1 ) :
return 1 ;
x = ( ( n * mat... | CodeGen-main | data/transcoder_evaluation_gfg/python/COUNT_DIGITS_FACTORIAL_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 , arr_size ) :
lo = 0
hi = arr_size - 1
mid = 0
while mid <= hi :
if a [ mid ] == 0 :
... | CodeGen-main | data/transcoder_evaluation_gfg/python/SORT_AN_ARRAY_OF_0S_1S_AND_2S.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 ) :
if ( k > n ) :
return - 1
sum = arr [ 0 ]
for i in range ( 1 , k ) :
su... | CodeGen-main | data/transcoder_evaluation_gfg/python/FIND_MAXIMUM_AVERAGE_SUBARRAY_OF_K_LENGTH_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 ) :
S = 0
for i in range ( 1 , n + 1 ) :
S += i * i - ( i - 1 ) * ( i - 1 )
return S
#TOFIL... | CodeGen-main | data/transcoder_evaluation_gfg/python/PROGRAM_PRINT_SUM_GIVEN_NTH_TERM.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 = ( n // 10 ) * 10
b = a + 10
return ( b if n - a > b - n else a )
#TOFILL
if __name__ == '_... | CodeGen-main | data/transcoder_evaluation_gfg/python/ROUND_THE_GIVEN_NUMBER_TO_NEAREST_MULTIPLE_OF_10.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 ) :
if ( arr [ i ] == x ) :
return i
i = i ... | CodeGen-main | data/transcoder_evaluation_gfg/python/SEARCH_AN_ELEMENT_IN_AN_ARRAY_WHERE_DIFFERENCE_BETWEEN_ADJACENT_ELEMENTS_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 ( a , b , k ) :
p = a ** b
count = 0
while ( p > 0 and count < k ) :
rem = p % 10
count =... | CodeGen-main | data/transcoder_evaluation_gfg/python/K_TH_DIGIT_RAISED_POWER_B.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):
maxvalue = 0
i = 1
for i in range(s - 1):
j = 1
for j in range(s):
k = s ... | CodeGen-main | data/transcoder_evaluation_gfg/python/MAXIMIZE_VOLUME_CUBOID_GIVEN_SUM_SIDES.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):
BT = [0] * (n + 1)
BT[0] = BT[1] = 1
for i in range(2, n + 1):
for j in range(i):
... | CodeGen-main | data/transcoder_evaluation_gfg/python/NUMBER_OF_BINARY_TREES_FOR_GIVEN_PREORDER_SEQUENCE_LENGTH.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 ( n , - 1 , - 2 ) :
if ( i == 0 or i == 1 ) :
return res... | CodeGen-main | data/transcoder_evaluation_gfg/python/DOUBLE_FACTORIAL_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 ) :
ans = 0 ; temp = 0 ;
for i in range ( 1 , n + 1 ) :
if temp < n :
temp = i - 1
... | CodeGen-main | data/transcoder_evaluation_gfg/python/SUM_MATRIX_ELEMENT_ELEMENT_INTEGER_DIVISION_ROW_COLUMN_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 ( coin , n , k ) :
coin.sort ( )
coins_needed = math.ceil ( 1.0 * n // ( k + 1 ) ) ;
ans = 0... | CodeGen-main | data/transcoder_evaluation_gfg/python/MINIMUM_COST_FOR_ACQUIRING_ALL_COINS_WITH_K_EXTRA_COINS_ALLOWED_WITH_EVERY_COIN.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 False
arr.sort ( )
for i in range ( N - 2 ) :
if arr [ i ... | CodeGen-main | data/transcoder_evaluation_gfg/python/POSSIBLE_FORM_TRIANGLE_ARRAY_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.
#
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_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 ) :
mp = dict ( )
for i in range ( n - 1 ) :
for j in range ( i + 1 , n ) :
mp ... | CodeGen-main | data/transcoder_evaluation_gfg/python/FIND_LARGEST_D_IN_ARRAY_SUCH_THAT_A_B_C_D_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 math import sqrt
def f_gold ( a ) :
area = ( sqrt ( 5 * ( 5 + 2 * ( sqrt ( 5 ) ) ) ) * a * a ) / 4
return area
#... | CodeGen-main | data/transcoder_evaluation_gfg/python/PROGRAM_TO_FIND_THE_AREA_OF_PENTAGON.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 ) :
if ( len ( str1 ) != len ( str2 ) ) :
return False
clock_rot = ""
anticlock_rot... | CodeGen-main | data/transcoder_evaluation_gfg/python/CHECK_STRING_CAN_OBTAINED_ROTATING_ANOTHER_STRING_2_PLACES.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
i = 5
while ( n / i >= 1 ) :
count += int ( n / i )
i *= 5
return i... | CodeGen-main | data/transcoder_evaluation_gfg/python/COUNT_TRAILING_ZEROES_FACTORIAL_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 ) :
a , b , c = 1 , 2 , 0 ;
if ( n <= 2 ) :
return n ;
for i in range ( 3 , n + 1 ) :
... | CodeGen-main | data/transcoder_evaluation_gfg/python/FRIENDS_PAIRING_PROBLEM_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 ( blockSize , m , processSize , n ) :
allocation = [ - 1 ] * n
for i in range ( n ) :
bestIdx = - 1
... | CodeGen-main | data/transcoder_evaluation_gfg/python/PROGRAM_BEST_FIT_ALGORITHM_MEMORY_MANAGEMENT.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 , corner ) :
n = len ( str )
cl = len ( corner )
if ( n < cl ) :
return False
return ( ... | CodeGen-main | data/transcoder_evaluation_gfg/python/PROGRAM_FIND_STRING_START_END_GEEKS.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/NEXT_POWER_OF_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 ) :
return ( 1 << ( n - 1 ) )
#TOFILL
if __name__ == '__main__':
param = [
(56,),
(28,),
(... | CodeGen-main | data/transcoder_evaluation_gfg/python/FIND_SUM_EVEN_INDEX_BINOMIAL_COEFFICIENTS_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 % 15 == 0 )
#TOFILL
if __name__ == '__main__':
param = [
(30,),
(-30,),
(60... | CodeGen-main | data/transcoder_evaluation_gfg/python/EFFICIENT_WAY_CHECK_WHETHER_N_TH_FIBONACCI_NUMBER_MULTIPLE_10.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 ) :
variable = 1
if ( A == B ) :
return 1
elif ( ( B - A ) >= 5 ) :
return 0
... | CodeGen-main | data/transcoder_evaluation_gfg/python/FIND_LAST_DIGIT_FACTORIAL_DIVIDES_FACTORIAL_B.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 ) :
diff = 10 ** 20
for i in range ( n - 1 ) :
for j in range ( i + 1 , n ) :
i... | CodeGen-main | data/transcoder_evaluation_gfg/python/FIND_MINIMUM_DIFFERENCE_PAIR.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 ( )
return ( arr [ n - 1 ] + arr [ n - 2 ] + arr [ n - 3 ] )
#TOFILL
if __name__ ==... | CodeGen-main | data/transcoder_evaluation_gfg/python/MAXIMUM_TRIPLET_SUM_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 ( arr , n ) :
i = - 1
for j in range ( n ) :
if ( arr [ j ] < 0 ) :
i += 1
ar... | CodeGen-main | data/transcoder_evaluation_gfg/python/REARRANGE_POSITIVE_AND_NEGATIVE_NUMBERS_PUBLISH.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 ) :
dp = [ [ 0 for x in range ( m + 1 ) ] for y in range ( n + 1 ) ]
for i in range ( 1 , n + 1 ) :
... | CodeGen-main | data/transcoder_evaluation_gfg/python/EULERIAN_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 ) :
evenArr = [ ]
oddArr = [ ]
for i in range ( n ) :
if ( ( i % 2 ) == 0 ) :
... | CodeGen-main | data/transcoder_evaluation_gfg/python/SORT_EVEN_PLACED_ELEMENTS_INCREASING_ODD_PLACED_DECREASING_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 ( str ) :
n = len ( str )
dp = [ [ 0 ] * ( n + 1 ) ] * ( n + 1 )
for i in range ( 1 , n + 1 ) :
f... | CodeGen-main | data/transcoder_evaluation_gfg/python/LONGEST_REPEATING_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 ( mat , n , x ) :
i = 0
j = n - 1
while ( i < n and j >= 0 ) :
if ( mat [ i ] [ j ] == x ) :
... | CodeGen-main | data/transcoder_evaluation_gfg/python/SEARCH_IN_ROW_WISE_AND_COLUMN_WISE_SORTED_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 ( x ) :
return ( x and ( not ( x & ( x - 1 ) ) ) )
#TOFILL
if __name__ == '__main__':
param = [
(1,),
... | CodeGen-main | data/transcoder_evaluation_gfg/python/WRITE_ONE_LINE_C_FUNCTION_TO_FIND_WHETHER_A_NO_IS_POWER_OF_TWO_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 ) :
l = len ( str )
count = 0
res = str [ 0 ]
for i in range ( l ) :
cur_count = 1
... | CodeGen-main | data/transcoder_evaluation_gfg/python/MAXIMUM_CONSECUTIVE_REPEATING_CHARACTER_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 sys
def f_gold ( arr , n ) :
arr.sort ( )
minXor = int ( sys.float_info.max )
val = 0
for i in range ( 0... | CodeGen-main | data/transcoder_evaluation_gfg/python/MINIMUM_XOR_VALUE_PAIR_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 , size ) :
positive = 0
negative = 1
while ( True ) :
while ( positive < size and a [ positiv... | CodeGen-main | data/transcoder_evaluation_gfg/python/POSITIVE_ELEMENTS_EVEN_NEGATIVE_ODD_POSITIONS.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 , x , y ) :
min_dist = sys.maxsize
for i in range ( n ) :
if arr [ i ] == x or ... | CodeGen-main | data/transcoder_evaluation_gfg/python/FIND_THE_MINIMUM_DISTANCE_BETWEEN_TWO_NUMBERS_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 ( C , l ) :
if ( l >= C ) : return C
eq_root = ( math.sqrt ( 1 + 8 * ( C - l ) ) - 1 ) / 2
r... | CodeGen-main | data/transcoder_evaluation_gfg/python/NUMBER_DAYS_TANK_WILL_BECOME_EMPTY.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 ) :
result = 1
for i in range ( 1 , n ) :
y = ( i * ( i + 1 ) ) / 2
if ( y < n ) :
... | CodeGen-main | data/transcoder_evaluation_gfg/python/MAXIMUM_HEIGHT_OF_TRIANGULAR_ARRANGEMENT_OF_ARRAY_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 ( s , c1 , c2 ) :
l = len ( s )
for i in range ( l ) :
if ( s [ i ] == c1 ) :
s = s [ 0 :... | CodeGen-main | data/transcoder_evaluation_gfg/python/REPLACE_CHARACTER_C1_C2_C2_C1_STRING_S.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 ( stri , n ) :
m = dict ( )
for i in range ( n ) :
m [ stri [ i ] ] = m.get ( stri [ i ] , 0 ) + 1
... | CodeGen-main | data/transcoder_evaluation_gfg/python/COUNT_WORDS_APPEAR_EXACTLY_TWO_TIMES_ARRAY_WORDS.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 ) :
Len = len ( Str )
res = [ None ] * Len
index = 0
i = 0
s = [ ]
s.append ( 0 )
w... | CodeGen-main | data/transcoder_evaluation_gfg/python/REMOVE_BRACKETS_ALGEBRAIC_STRING_CONTAINING_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 ) :
if ( a == b ) :
return a
if ( a == 0 ) :
return b
if ( b == 0 ) :
ret... | CodeGen-main | data/transcoder_evaluation_gfg/python/STEINS_ALGORITHM_FOR_FINDING_GCD_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 ) / 2 ) * ( 1 << ( n - 1 ) )
#TOFILL
if __name__ == '__main__':
param = [
... | CodeGen-main | data/transcoder_evaluation_gfg/python/SUM_SUBSETS_SET_FORMED_FIRST_N_NATURAL_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 ( A , arr_size , sum ) :
for i in range ( 0 , arr_size - 1 ) :
s = set ( )
curr_sum = sum - A [ i... | CodeGen-main | data/transcoder_evaluation_gfg/python/FIND_A_TRIPLET_THAT_SUM_TO_A_GIVEN_VALUE_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 ( x , y ) :
if ( y == 0 ) : return 1
elif ( int ( y % 2 ) == 0 ) :
return ( f_gold ( x , int ( y / 2 ... | CodeGen-main | data/transcoder_evaluation_gfg/python/WRITE_A_C_PROGRAM_TO_CALCULATE_POWXN.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 1 ;
return n * f_gold ( n - 2 ) ;
#TOFILL
if __name__ == ... | CodeGen-main | data/transcoder_evaluation_gfg/python/DOUBLE_FACTORIAL.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 ( not ( n & 1 ) )
#TOFILL
if __name__ == '__main__':
param = [
(57,),
(73,),
(7... | CodeGen-main | data/transcoder_evaluation_gfg/python/CHECK_WHETHER_GIVEN_NUMBER_EVEN_ODD_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 ) :
return math.pow ( n , 2 )
#TOFILL
if __name__ == '__main__':
param = [
(42,),
... | CodeGen-main | data/transcoder_evaluation_gfg/python/PROGRAM_PRINT_SUM_GIVEN_NTH_TERM_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 ) :
prevPrev = 1
prev = 2
curr = 3
while n > 0 :
prevPrev = prev
prev = curr
... | CodeGen-main | data/transcoder_evaluation_gfg/python/NTH_NON_FIBONACCI_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 ( mat , n ) :
row_sum = 0
col_sum = 0
for i in range ( n ) :
row_sum += mat [ n // 2 ] [ i ]
... | CodeGen-main | data/transcoder_evaluation_gfg/python/SUM_MIDDLE_ROW_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 ( arr1 , arr2 , m , n ) :
i = 0
j = 0
for i in range ( n ) :
for j in range ( m ) :
i... | CodeGen-main | data/transcoder_evaluation_gfg/python/FIND_WHETHER_AN_ARRAY_IS_SUBSET_OF_ANOTHER_ARRAY_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(n):
k = n
imin = 1
ans = 0
while (imin <= n):
imax = n / k
ans += k * (imax - imin + ... | CodeGen-main | data/transcoder_evaluation_gfg/python/COUNT_NUMBER_PAIRS_N_B_N_GCD_B_B.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
sum = 0
sum += ( n * ( n + 1 ) ) / 2
sum += ( n * ( n + 1 ) * ( 2 * n + 1 ) ) / 6
... | CodeGen-main | data/transcoder_evaluation_gfg/python/SUM_MATRIX_ELEMENT_ABSOLUTE_DIFFERENCE_ROW_COLUMN_NUMBERS_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 ( num ) :
if ( num < 0 ) :
return False
sum , n = 0 , 1
while ( sum <= num ) :
sum = sum ... | CodeGen-main | data/transcoder_evaluation_gfg/python/TRIANGULAR_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 ( str ) :
NO_OF_CHARS = 256
count = [ 0 ] * NO_OF_CHARS
for i in range ( len ( str ) ) :
count [ ... | CodeGen-main | data/transcoder_evaluation_gfg/python/C_PROGRAM_FIND_SECOND_FREQUENT_CHARACTER.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 = len ( X )
n = len ( Y )
L = [ [ 0 for i in range ( n + 1 ) ] for j in range ( 2 ) ]
b... | CodeGen-main | data/transcoder_evaluation_gfg/python/SPACE_OPTIMIZED_SOLUTION_LCS.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 ) :
ans = 0 ;
for x in range ( 1 , p ) :
if ( ( x * x ) % p == 1 ) :
last = x + p... | CodeGen-main | data/transcoder_evaluation_gfg/python/COUNT_NUMBER_OF_SOLUTIONS_OF_X2_1_MOD_P_IN_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 math
def f_gold ( a , b ) :
if ( a == 0 or b == 0 ) :
return 1
return math.floor ( math.log10 ( abs ( a ... | CodeGen-main | data/transcoder_evaluation_gfg/python/NUMBER_DIGITS_PRODUCT_TWO_NUMBERS_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
while ( n ) :
count += n & 1
n >>= 1
return count
#TOFILL
if __name_... | CodeGen-main | data/transcoder_evaluation_gfg/python/COUNT_SET_BITS_IN_AN_INTEGER.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 ) :
s1 = s
for i in range ( 1 , n ) :
s += s1
return s
#TOFILL
if __name__ == '__main_... | CodeGen-main | data/transcoder_evaluation_gfg/python/C_PROGRAM_CONCATENATE_STRING_GIVEN_NUMBER_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 ( low , high ) :
f1 , f2 , f3 = 0 , 1 , 1
result = 0
while ( f1 <= high ) :
if ( f1 >= low ) :
... | CodeGen-main | data/transcoder_evaluation_gfg/python/COUNT_FIBONACCI_NUMBERS_GIVEN_RANGE_LOG_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 ( l , w ) :
return ( 2 * ( l + w ) )
#TOFILL
if __name__ == '__main__':
param = [
(58,39,),
(37,49... | CodeGen-main | data/transcoder_evaluation_gfg/python/PYTHON_PROGRAM_FIND_PERIMETER_CIRCUMFERENCE_SQUARE_RECTANGLE_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 * ( 2 * n - 1 )
#TOFILL
if __name__ == '__main__':
param = [
(38,),
(44,),
(5... | CodeGen-main | data/transcoder_evaluation_gfg/python/HEXAGONAL_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 , key ) :
for i in range ( n ) :
if ( arr [ i ] == key ) :
return i
return - 1
... | CodeGen-main | data/transcoder_evaluation_gfg/python/SEARCH_INSERT_AND_DELETE_IN_AN_UNSORTED_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 , k ) :
total = k
mod = 1000000007
same , diff = 0 , k
for i in range ( 2 , n + 1 ) :
sam... | CodeGen-main | data/transcoder_evaluation_gfg/python/PAINTING_FENCE_ALGORITHM.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 <= 6 ) :
return N
screen = [ 0 ] * N
for n in range ( 1 , 7 ) :
screen [ n... | CodeGen-main | data/transcoder_evaluation_gfg/python/HOW_TO_PRINT_MAXIMUM_NUMBER_OF_A_USING_GIVEN_FOUR_KEYS.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 , K ) :
n = len ( s )
c1 = 0
c2 = 0
C = 0
for i in range ( n ) :
if s [ i ] == 'a' :
... | CodeGen-main | data/transcoder_evaluation_gfg/python/NUMBER_SUBSEQUENCES_AB_STRING_REPEATED_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 ( A , N , M ) :
sum = 0
ans = 0
for i in range ( 0 , N ) :
for j in range ( i + 1 , N ) :
... | CodeGen-main | data/transcoder_evaluation_gfg/python/SUBSEQUENCES_SIZE_THREE_ARRAY_WHOSE_SUM_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 ( arr , n , k ) :
for i in range ( 0 , k ) :
x = arr [ 0 ]
for j in range ( 0 , n - 1 ) :
... | CodeGen-main | data/transcoder_evaluation_gfg/python/SPLIT_ARRAY_ADD_FIRST_PART_END.py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.