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 , p ) :
n = n % p
for x in range ( 2 , p , 1 ) :
if ( ( x * x ) % p == n ) :
return T... | CodeGen-main | data/transcoder_evaluation_gfg/python/EULERS_CRITERION_CHECK_IF_SQUARE_ROOT_UNDER_MODULO_P_EXISTS.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# 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 ) :
max_count = 0
max_index = 0
prev_zero = - 1
prev_prev_zero = - 1
for curr in range ... | CodeGen-main | data/transcoder_evaluation_gfg/python/FIND_INDEX_0_REPLACED_1_GET_LONGEST_CONTINUOUS_SEQUENCE_1S_BINARY_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 ) :
dp = [ 1 for i in range ( n ) ]
for i in range ( n ) :
for j in range ( i ) :
... | CodeGen-main | data/transcoder_evaluation_gfg/python/LONGEST_SUBSEQUENCE_SUCH_THAT_DIFFERENCE_BETWEEN_ADJACENTS_IS_ONE.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# 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 ) :
i , total = 0 , 1
for i in range ( 2 , n + 2 ) :
total += i
total -= a [ i - 2 ]
... | CodeGen-main | data/transcoder_evaluation_gfg/python/FIND_THE_MISSING_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 , k ) :
count_map = { } ;
for i in range ( 0 , n ) :
if ( arr [ i ] in count_map.keys ( ) )... | CodeGen-main | data/transcoder_evaluation_gfg/python/FIRST_ELEMENT_OCCURRING_K_TIMES_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 ( side ) :
return ( 2 * ( 1 + ( math.sqrt ( 2 ) ) ) * side * side )
#TOFILL
if __name__ == '__mai... | CodeGen-main | data/transcoder_evaluation_gfg/python/PROGRAM_CALCULATE_AREA_OCTAGON.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# 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
for i in range ( 2 , n ) :
if ( n % i == 0 ) :
... | CodeGen-main | data/transcoder_evaluation_gfg/python/PRIME_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 ( arr , n , sum ) :
curr_sum = arr [ 0 ]
start = 0
i = 1
while i <= n :
while curr_sum > sum ... | CodeGen-main | data/transcoder_evaluation_gfg/python/FIND_SUBARRAY_WITH_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 ( arr , n ) :
difference = 0
ans = 0
hash_positive = [ 0 ] * ( n + 1 )
hash_negative = [ 0 ] * ( n + ... | CodeGen-main | data/transcoder_evaluation_gfg/python/COUNT_SUBARRAYS_WITH_SAME_EVEN_AND_ODD_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 ( mat , r , c ) :
result = 0
for i in range ( r ) :
j = 0
for j in range ( c - 1 ) :
... | CodeGen-main | data/transcoder_evaluation_gfg/python/COUNT_SORTED_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 ( arr , n ) :
cum_sum = 0
for i in range ( 0 , n ) :
cum_sum += arr [ i ]
curr_val = 0
for i ... | CodeGen-main | data/transcoder_evaluation_gfg/python/MAXIMUM_SUM_IARRI_AMONG_ROTATIONS_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 ( r ) :
return ( 2 * r * r )
#TOFILL
if __name__ == '__main__':
param = [
(14,),
(78,),
(45,),... | CodeGen-main | data/transcoder_evaluation_gfg/python/AREA_SQUARE_CIRCUMSCRIBED_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):
if (n <= 1):
return False
if (n <= 3):
return True
if (n % 2 == 0 or n % 3 == 0):
... | CodeGen-main | data/transcoder_evaluation_gfg/python/PRIMALITY_TEST_SET_1_INTRODUCTION_AND_SCHOOL_METHOD_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(price, n):
profit = [0] * n
max_price = price[n - 1]
for i in range(n - 2, 0, - 1):
if price[i] >... | CodeGen-main | data/transcoder_evaluation_gfg/python/MAXIMUM_PROFIT_BY_BUYING_AND_SELLING_A_SHARE_AT_MOST_TWICE.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# 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 ) :
cnt = 0
parent = [ None ] * ( n + 1 )
vis = [ None ] * ( n + 1 )
for i in range ( 0 , n +... | CodeGen-main | data/transcoder_evaluation_gfg/python/MAGICAL_INDICES_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 ( dp , a , low , high , turn ) :
if ( low == high ) :
return a [ low ] * turn
if ( dp [ low ] [ high ... | CodeGen-main | data/transcoder_evaluation_gfg/python/REMOVE_ARRAY_END_ELEMENT_MAXIMIZE_SUM_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 ( tree , k ) :
level = - 1
product = 1
n = len ( tree )
for i in range ( 0 , n ) :
if ( tree ... | CodeGen-main | data/transcoder_evaluation_gfg/python/PRODUCT_NODES_K_TH_LEVEL_TREE_REPRESENTED_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 ( gold , m , n ) :
goldTable = [ [ 0 for i in range ( n ) ] for j in range ( m ) ]
for col in range ( n - 1 ,... | CodeGen-main | data/transcoder_evaluation_gfg/python/GOLD_MINE_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, n):
x = sorted(arr)
count = 1
for i in range(0, n - 1):
if (x[i] + 1 != x[i + 1]):
... | CodeGen-main | data/transcoder_evaluation_gfg/python/COUNT_MINIMUM_NUMBER_SUBSETS_SUBSEQUENCES_CONSECUTIVE_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.
#
import math
def f_gold ( a , b ) :
AM = ( a + b ) / 2
GM = math.sqrt ( a * b )
HM = ( GM * GM ) / AM
return HM
... | CodeGen-main | data/transcoder_evaluation_gfg/python/FIND_HARMONIC_MEAN_USING_ARITHMETIC_MEAN_GEOMETRIC_MEAN.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# 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 for i in range ( n ) ]
b = [ 0 for i in range ( n ) ]
a [ 0 ] = b [ 0 ] = 1
for i in ... | CodeGen-main | data/transcoder_evaluation_gfg/python/COUNT_NUMBER_BINARY_STRINGS_WITHOUT_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.
#
def f_gold ( N ) :
length = len ( N )
l = int ( ( length ) / 2 )
count = 0
for i in range ( l + 1 ) :
s ... | CodeGen-main | data/transcoder_evaluation_gfg/python/BREAKING_NUMBER_FIRST_PART_INTEGRAL_DIVISION_SECOND_POWER_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 ( bin ) :
n = len ( bin )
if ( bin [ n - 1 ] == '1' ) :
return False
sum = 0
i = n - 2
wh... | CodeGen-main | data/transcoder_evaluation_gfg/python/DECIMAL_REPRESENTATION_GIVEN_BINARY_STRING_DIVISIBLE_10_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 , a = 0 , b = 1 ) :
if n == 0 :
return a
if n == 1 :
return b
return f_gold ( n - 1 ,... | CodeGen-main | data/transcoder_evaluation_gfg/python/TAIL_RECURSION_FIBONACCI.py |
# Copyright (c) 2019-present, Facebook, Inc.
# 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 ( str1 ) :
n = len ( str1 ) ;
C = [ 0 ] * ( n + 1 ) ;
P = [ [ False for x in range ( n + 1 ) ... | CodeGen-main | data/transcoder_evaluation_gfg/python/DYNAMIC_PROGRAMMING_SET_17_PALINDROME_PARTITIONING_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 x in range ( 10 ) ] for y in range ( n + 1 ) ] ;
if ( n == 1 ) :
return 10 ;
... | CodeGen-main | data/transcoder_evaluation_gfg/python/NUMBER_N_DIGIT_STEPPING_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 ( S , T ) :
m = len ( T )
n = len ( S )
if m > n :
return 0
mat = [ [ 0 for _ in range ( n + ... | CodeGen-main | data/transcoder_evaluation_gfg/python/COUNT_DISTINCT_OCCURRENCES_AS_A_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 ( arr , n ) :
count = 0
cummulative_sum = 0
arr.sort ( )
for i in range ( n ) :
if arr [ i ] ... | CodeGen-main | data/transcoder_evaluation_gfg/python/MAXIMUM_REMOVAL_FROM_ARRAY_WHEN_REMOVAL_TIME_WAITING_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.
#
import math
def f_gold ( n , k ) :
while ( n % 2 == 0 ) :
k = k - 1
n = n / 2
if ( k == 0 ) :
... | CodeGen-main | data/transcoder_evaluation_gfg/python/K_TH_PRIME_FACTOR_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 ( n , templeHeight ) :
sum = 0
for i in range ( n ) :
left = 0
right = 0
for j in ran... | CodeGen-main | data/transcoder_evaluation_gfg/python/TEMPLE_OFFERINGS.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# 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 ) :
for i in range ( 0 , n ) :
sum = 0
for j in range ( 0 , n ) :
sum = sum +... | CodeGen-main | data/transcoder_evaluation_gfg/python/DIAGONALLY_DOMINANT_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 ) :
length = len ( s )
oneSeen = False
count = 0
for i in range ( length ) :
if ( s [ i ]... | CodeGen-main | data/transcoder_evaluation_gfg/python/COUNT_OF_OCCURRENCES_OF_A_101_PATTERN_IN_A_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 ) :
sm = - 1000000
for i in range ( 0 , n ) :
for j in range ( i + 1 , n ) :
fo... | CodeGen-main | data/transcoder_evaluation_gfg/python/MAXIMUM_TRIPLET_SUM_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 ) :
arr = [ [ 0 for x in range ( n ) ] for y in range ( n ) ]
for i in range ( n ) :
for j in ran... | CodeGen-main | data/transcoder_evaluation_gfg/python/SUM_MATRIX_ELEMENT_ABSOLUTE_DIFFERENCE_ROW_COLUMN_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 ( mat , m , n , r ) :
s = set ( )
for j in range ( n ) :
s.add ( mat [ r ] [ j ] )
for i in range... | CodeGen-main | data/transcoder_evaluation_gfg/python/FIND_PERMUTED_ROWS_GIVEN_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 ( mat , n ) :
tot_energy = 0
for i in range ( n ) :
for j in range ( n ) :
q = mat [ i ] ... | CodeGen-main | data/transcoder_evaluation_gfg/python/MINIMUM_COST_SORT_MATRIX_NUMBERS_0_N2_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 ) :
n = len ( s1 )
m = len ( s2 )
dp = ( [ [ False for i in range ( m + 1 ) ] for i in range ( ... | CodeGen-main | data/transcoder_evaluation_gfg/python/CHECK_POSSIBLE_TRANSFORM_ONE_STRING_ANOTHER.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# 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 ) :
mp = set ( )
result = 0
curr_sum = curr_begin = 0
for i in range ( 0 , n ) :
... | CodeGen-main | data/transcoder_evaluation_gfg/python/MAXIMUM_POSSIBLE_SUM_WINDOW_ARRAY_ELEMENTS_WINDOW_ARRAY_UNIQUE.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# 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 - 1):
pos = i
for j in range(i + 1, n):
if (j - i > k):
... | CodeGen-main | data/transcoder_evaluation_gfg/python/LEXICOGRAPHICALLY_SMALLEST_ARRAY_K_CONSECUTIVE_SWAPS.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# 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 = 0
res = 0
yCount = 0
while ( yCount * yCount < n ) :
yCount = yCount + 1
whil... | CodeGen-main | data/transcoder_evaluation_gfg/python/COUNT_DISTINCT_NON_NEGATIVE_PAIRS_X_Y_SATISFY_INEQUALITY_XX_YY_N_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 ( n ) :
res = 0
x = 0
while ( x * x < n ) :
y = 0
while ( x * x + y * y < n ) :
... | CodeGen-main | data/transcoder_evaluation_gfg/python/COUNT_DISTINCT_NON_NEGATIVE_PAIRS_X_Y_SATISFY_INEQUALITY_XX_YY_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 ( arr , n ) :
max = 0
msis = [ 0 for x in range ( n ) ]
for i in range ( n ) :
msis [ i ] = arr [... | CodeGen-main | data/transcoder_evaluation_gfg/python/DYNAMIC_PROGRAMMING_SET_14_MAXIMUM_SUM_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 ( x , y ) :
if ( x == 1 ) :
return ( y == 1 )
pow = 1
while ( pow < y ) :
pow = pow * x
... | CodeGen-main | data/transcoder_evaluation_gfg/python/CHECK_IF_A_NUMBER_IS_POWER_OF_ANOTHER_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 , k ) :
dp = [ [ 0 for i in range ( k + 1 ) ] for j in range ( n + 1 ) ]
for i in range ( n + 1 ) :
... | CodeGen-main | data/transcoder_evaluation_gfg/python/COUNT_NUMBER_OF_WAYS_TO_PARTITION_A_SET_INTO_K_SUBSETS_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 , low , high ) :
max = arr [ low ]
i = low
for i in range ( high + 1 ) :
if arr [ i ] > max... | CodeGen-main | data/transcoder_evaluation_gfg/python/FIND_THE_MAXIMUM_ELEMENT_IN_AN_ARRAY_WHICH_IS_FIRST_INCREASING_AND_THEN_DECREASING.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# 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 ) :
Stack = [ ]
for ch in string :
if ch == ')' :
top = Stack.pop ( )
... | CodeGen-main | data/transcoder_evaluation_gfg/python/FIND_EXPRESSION_DUPLICATE_PARENTHESIS_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 ) :
dp = [ 0 ] * ( n + 1 )
dp [ 0 ] = 0
dp [ 1 ] = 1
for i in range ( 2 , n + 1 ) :
dp [ ... | CodeGen-main | data/transcoder_evaluation_gfg/python/RECURSIVELY_BREAK_NUMBER_3_PARTS_GET_MAXIMUM_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 ( arr , n , x ) :
curr_sum = 0
min_len = n + 1
start = 0
end = 0
while ( end < n ) :
whil... | CodeGen-main | data/transcoder_evaluation_gfg/python/MINIMUM_LENGTH_SUBARRAY_SUM_GREATER_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.
#
import sys
def f_gold ( arr , n ) :
if n < 3 :
return - 1
max_product = - ( sys.maxsize - 1 )
for i in rang... | CodeGen-main | data/transcoder_evaluation_gfg/python/FIND_MAXIMUM_PRODUCT_OF_A_TRIPLET_IN_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 ( m , n ) :
return math.factorial ( min ( m , n ) )
#TOFILL
if __name__ == '__main__':
param ... | CodeGen-main | data/transcoder_evaluation_gfg/python/GCD_FACTORIALS_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 ( a , b , d ) :
temp = a
a = min ( a , b )
b = max ( temp , b )
if ( d >= b ) :
return ( d + ... | CodeGen-main | data/transcoder_evaluation_gfg/python/NUMBER_JUMP_REQUIRED_GIVEN_LENGTH_REACH_POINT_FORM_D_0_ORIGIN_2D_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(n):
if (n < 4):
return - 1
rem = n % 4
if (rem == 0):
return n // 4
if (rem == 1):
... | CodeGen-main | data/transcoder_evaluation_gfg/python/SPLIT_N_MAXIMUM_COMPOSITE_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 ( m , n , arr ) :
k = 0 ; l = 0
cnt = 0
total = m * n
while ( k < m and l < n ) :
if ( cnt ==... | CodeGen-main | data/transcoder_evaluation_gfg/python/PRINT_GIVEN_MATRIX_COUNTER_CLOCK_WISE_SPIRAL_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 , n ) :
if ( n < 1 ) :
return False
Min = min ( arr )
Max = max ( arr )
if ( Max - Min ... | CodeGen-main | data/transcoder_evaluation_gfg/python/CHECK_IF_ARRAY_ELEMENTS_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 ( s ) :
n = len ( s )
count = 0 ;
for i in range ( 0 , n , 1 ) :
if ( s [ i ] == '4' or s [ i ] =... | CodeGen-main | data/transcoder_evaluation_gfg/python/NUMBER_SUBSTRINGS_DIVISIBLE_4_STRING_INTEGERS.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# 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 > 0 ) :
if ( b % 2 == 1 ) :
res =... | CodeGen-main | data/transcoder_evaluation_gfg/python/HOW_TO_AVOID_OVERFLOW_IN_MODULAR_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 ( arr , n , idx ) :
result = 0
for i in range ( n ) :
if ( arr [ i ] < arr [ idx ] ) :
re... | CodeGen-main | data/transcoder_evaluation_gfg/python/POSITION_ELEMENT_STABLE_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 ) :
return ( ( x & 0x0F ) << 4 | ( x & 0xF0 ) >> 4 )
#TOFILL
if __name__ == '__main__':
param = [
... | CodeGen-main | data/transcoder_evaluation_gfg/python/SWAP_TWO_NIBBLES_BYTE.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# 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 - 1 ) :
if ( arr [ i ] > arr [ i + 1 ] ) :
if ( arr [ i ... | CodeGen-main | data/transcoder_evaluation_gfg/python/CHECK_POSSIBLE_SORT_ARRAY_CONDITIONAL_SWAPPING_ADJACENT_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 ( str ) :
n = len ( str ) - 1
i = n
while ( i > 0 and str [ i - 1 ] <= str [ i ] ) :
i -= 1
i... | CodeGen-main | data/transcoder_evaluation_gfg/python/LEXICOGRAPHICALLY_PREVIOUS_PERMUTATION_IN_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.
#
import math
def f_gold ( n ) :
count = 0
ans = 1
while n % 2 == 0 :
count += 1
n //= 2
if count... | CodeGen-main | data/transcoder_evaluation_gfg/python/FIND_MINIMUM_NUMBER_DIVIDED_MAKE_NUMBER_PERFECT_SQUARE.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# 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 for i in range ( n + 1 ) ] for j in range ( n + 1 ) ]
for i in range... | CodeGen-main | data/transcoder_evaluation_gfg/python/LONGEST_REPEATED_SUBSEQUENCE_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 ( first , second ) :
if len ( first ) == 0 and len ( second ) == 0 :
return True
if len ( first ) > 1... | CodeGen-main | data/transcoder_evaluation_gfg/python/WILDCARD_CHARACTER_MATCHING.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# 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 ) :
b = dict ( )
for i in range ( n ) :
x = a [ i ]
d = min ( 1 + i , n - i )
... | CodeGen-main | data/transcoder_evaluation_gfg/python/PRINT_MAXIMUM_SHORTEST_DISTANCE.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# 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 ) :
stack = [ ]
for i in range ( len ( str ) ) :
stack.append ( str [ i ] )
for i in range ... | CodeGen-main | data/transcoder_evaluation_gfg/python/PROGRAM_REVERSE_STRING_ITERATIVE_RECURSIVE.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# 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 ) :
dp = [ 0 for i in range ( n + 1 ) ]
dp [ 0 ] = False
dp [ 1 ] = True
for i in range (... | CodeGen-main | data/transcoder_evaluation_gfg/python/COIN_GAME_WINNER_EVERY_PLAYER_THREE_CHOICES.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# 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 , k ) :
a.sort ( reverse = True )
b.sort ( )
for i in range ( n ) :
if ( a [ i ] + b ... | CodeGen-main | data/transcoder_evaluation_gfg/python/PERMUTE_TWO_ARRAYS_SUM_EVERY_PAIR_GREATER_EQUAL_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 ( mat , r , c ) :
a = 0
b = 2
low_row = 0 if ( 0 > a ) else a
low_column = 0 if ( 0 > b ) else b - 1
... | CodeGen-main | data/transcoder_evaluation_gfg/python/PRINT_MATRIX_SPIRAL_FORM_STARTING_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 ( str ) :
n = len ( str )
C = [ [ 0 for i in range ( n ) ] for i in range ( n ) ]
P = [ [ False for i in ... | CodeGen-main | data/transcoder_evaluation_gfg/python/DYNAMIC_PROGRAMMING_SET_17_PALINDROME_PARTITIONING.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# 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 ) :
brr = [ 0 ] * ( 2 * n + 1 )
for i in range ( n ) :
brr [ i ] = arr [ i ]
for i in r... | CodeGen-main | data/transcoder_evaluation_gfg/python/FIND_A_ROTATION_WITH_MAXIMUM_HAMMING_DISTANCE.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# 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 ) :
if arr [ i ] in mp.keys ( ) :
mp [ arr... | CodeGen-main | data/transcoder_evaluation_gfg/python/COUNT_INDEX_PAIRS_EQUAL_ELEMENTS_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 ( arr1 , arr2 , n ) :
index = n
left = 0
right = n - 1
while ( left <= right ) :
mid = ( int ... | CodeGen-main | data/transcoder_evaluation_gfg/python/FIND_INDEX_OF_AN_EXTRA_ELEMENT_PRESENT_IN_ONE_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 ( arr , n ) :
ans = - float ( 'inf' )
maxval = 1
minval = 1
for i in range ( 0 , n ) :
if arr... | CodeGen-main | data/transcoder_evaluation_gfg/python/MAXIMUM_PRODUCT_SUBARRAY_ADDED_NEGATIVE_PRODUCT_CASE.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# 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 ) :
parity = 0
while n :
parity = ~ parity
n = n & ( n - 1 )
return parity
#TOFILL
... | CodeGen-main | data/transcoder_evaluation_gfg/python/WRITE_A_C_PROGRAM_TO_FIND_THE_PARITY_OF_AN_UNSIGNED_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 ( arr , n ) :
arr.sort ( )
a = 0 ; b = 0
for i in range ( n ) :
if ( i % 2 != 0 ) :
a... | CodeGen-main | data/transcoder_evaluation_gfg/python/MINIMUM_SUM_TWO_NUMBERS_FORMED_DIGITS_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 False
while (n != 1):
if (n % 2 != 0):
return False
... | CodeGen-main | data/transcoder_evaluation_gfg/python/WRITE_ONE_LINE_C_FUNCTION_TO_FIND_WHETHER_A_NO_IS_POWER_OF_TWO.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# 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
temp = f_gold ( x , int ( y / 2 ) )
if ( y % 2 == 0 ) :
retu... | CodeGen-main | data/transcoder_evaluation_gfg/python/WRITE_A_C_PROGRAM_TO_CALCULATE_POWXN_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 ( b , m ) :
return ( b / m - 1 ) * ( b / m ) / 2
#TOFILL
if __name__ == '__main__':
param = [
(40,74,)... | CodeGen-main | data/transcoder_evaluation_gfg/python/MAXIMUM_NUMBER_OF_SQUARES_THAT_CAN_BE_FIT_IN_A_RIGHT_ANGLE_ISOSCELES_TRIANGLE.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# 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 , x ) :
count , l , r = 0 , 0 , n - 1
while ( l < m and r >= 0 ) :
if ( ( arr1 ... | CodeGen-main | data/transcoder_evaluation_gfg/python/COUNT_PAIRS_TWO_SORTED_ARRAYS_WHOSE_SUM_EQUAL_GIVEN_VALUE_X_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 ( ( 0.666 ) * ( 1 - 1 / pow ( 10 , n ) ) ) ;
#TOFILL
if __name__ == '__main__':
param = [
... | CodeGen-main | data/transcoder_evaluation_gfg/python/SUM_SERIES_0_6_0_06_0_006_0_0006_N_TERMS.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# 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 ) :
series = [ 1 , 3 , 2 , - 1 , - 3 , - 2 ] ;
series_index = 0 ;
result = 0 ;
for i in range (... | CodeGen-main | data/transcoder_evaluation_gfg/python/REMAINDER_7_LARGE_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 ( arr , n ) :
neg = 0
pos = 0
sum = 0
for i in range ( 0 , n ) :
sum += arr [ i ]
if ... | CodeGen-main | data/transcoder_evaluation_gfg/python/INTEGER_POSITIVE_VALUE_POSITIVE_NEGATIVE_VALUE_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 ( num , divisor ) :
return ( num - divisor * ( num // divisor ) )
#TOFILL
if __name__ == '__main__':
param... | CodeGen-main | data/transcoder_evaluation_gfg/python/PROGRAM_TO_FIND_REMAINDER_WITHOUT_USING_MODULO_OR_OPERATOR.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# 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 ) :
i = 1 ;
fact = 1 ;
for i in range ( 1 , x ) :
fact = fact * i
if ( fact % x == 0 ... | CodeGen-main | data/transcoder_evaluation_gfg/python/FIND_FIRST_NATURAL_NUMBER_WHOSE_FACTORIAL_DIVISIBLE_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.
#
def f_gold ( n ) :
dp = [ [ 0 for j in range ( 27 ) ] for i in range ( n + 1 ) ]
for i in range ( 0 , 26 ) :
dp ... | CodeGen-main | data/transcoder_evaluation_gfg/python/COUNT_STRINGS_ADJACENT_CHARACTERS_DIFFERENCE_ONE.py |
# Copyright (c) 2019-present, Facebook, Inc.
# 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 ( base , area ) :
return math.ceil ( ( 2 * area ) / base )
#TOFILL
if __name__ == '__main__':
... | CodeGen-main | data/transcoder_evaluation_gfg/python/MINIMUM_HEIGHT_TRIANGLE_GIVEN_BASE_AREA.py |
# Copyright (c) 2019-present, Facebook, Inc.
# 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 ) :
longest_start = - 1 ;
longest_end = 0 ;
for start in range ( n ) :
min ... | CodeGen-main | data/transcoder_evaluation_gfg/python/REMOVE_MINIMUM_ELEMENTS_EITHER_SIDE_2MIN_MAX.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# 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__':
para... | CodeGen-main | data/transcoder_evaluation_gfg/python/C_PROGRAM_FACTORIAL_NUMBER_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 ( str_ ) :
n = len ( str_ )
arr = [ 0 ] * n
concat = str_ + str_
for i in range ( n ) :
arr [... | CodeGen-main | data/transcoder_evaluation_gfg/python/LEXICOGRAPHICALLY_MINIMUM_STRING_ROTATION.py |
# Copyright (c) 2019-present, Facebook, Inc.
# 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 ( l ) :
leafNodeCount = math.pow ( 2 , l - 1 ) ;
sumLastLevel = 0 ;
sumLastLevel = ( ( leafN... | CodeGen-main | data/transcoder_evaluation_gfg/python/FIND_SUM_NODES_GIVEN_PERFECT_BINARY_TREE_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 ( st ) :
l = len ( st )
arr = [ 0 ] * l
for i in range ( 0 , l ) :
for j in range ( i , l ) :
... | CodeGen-main | data/transcoder_evaluation_gfg/python/GIVEN_LARGE_NUMBER_CHECK_SUBSEQUENCE_DIGITS_DIVISIBLE_8.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# 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 x in range ( n + 1 ) ] for y in range ( n + 1 ) ]
for i in range ( 0 , n + 1 ) :
... | CodeGen-main | data/transcoder_evaluation_gfg/python/FIND_SUM_EVEN_INDEX_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 ( str ) :
l = len ( str )
open = [ None ] * ( l + 1 )
close = [ None ] * ( l + 1 )
index = - 1
op... | CodeGen-main | data/transcoder_evaluation_gfg/python/FIND_EQUAL_POINT_STRING_BRACKETS.py |
# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# 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 ) :
lioes = list ( )
maxLen = 0
for i in range ( n ) :
lioes.append ( 1 )
i = 1
... | CodeGen-main | data/transcoder_evaluation_gfg/python/LONGEST_INCREASING_ODD_EVEN_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.
#
from queue import Queue
def f_gold ( ip , op , n ) :
Input = Queue ( )
for i in range ( n ) :
Input.put ( ip [ ... | CodeGen-main | data/transcoder_evaluation_gfg/python/STACK_PERMUTATIONS_CHECK_IF_AN_ARRAY_IS_STACK_PERMUTATION_OF_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 ( a , b ) :
m = len ( a )
n = len ( b )
lookup = [ [ 0 ] * ( n + 1 ) for i in range ( m + 1 ) ]
for i... | CodeGen-main | data/transcoder_evaluation_gfg/python/FIND_NUMBER_TIMES_STRING_OCCURS_GIVEN_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 ( m ) :
for i in range ( 0 , len ( m ) ) :
sm = 0
for j in range ( 0 , len ( m [ i ] ) ) :
... | CodeGen-main | data/transcoder_evaluation_gfg/python/MARKOV_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 = set ( )
sum = 0
for i in range ( n ) :
if arr [ i ] not in s :
s.ad... | CodeGen-main | data/transcoder_evaluation_gfg/python/FIND_SUM_NON_REPEATING_DISTINCT_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.
#
import math
def f_gold ( n ) :
return 0.0246 * ( math.pow ( 10 , n ) - 1 - ( 9 * n ) )
#TOFILL
if __name__ == '__main__'... | CodeGen-main | data/transcoder_evaluation_gfg/python/SUM_SEQUENCE_2_22_222.py |
# Copyright (c) 2019-present, Facebook, Inc.
# 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 ( 2 * ( math.sqrt ( 3 ) ) * ( side * side ) )
#TOFILL
if __name__ == '__main__'... | CodeGen-main | data/transcoder_evaluation_gfg/python/PROGRAM_FOR_SURFACE_AREA_OF_OCTAHEDRON.py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.