id stringlengths 18 123 | pair stringclasses 6
values | Code1 stringlengths 41 1.98k | Code2 stringlengths 41 1.98k | instruction stringclasses 6
values | input stringlengths 56 2k |
|---|---|---|---|---|---|
python-java-PROGRAM_CHECK_ARRAY_SORTED_NOT_ITERATIVE_RECURSIVE_1 | python-java | def arraySortedOrNot ( arr , n ) :
if ( n == 0 or n == 1 ) :
return True
for i in range ( 1 , n ) :
if ( arr [ i - 1 ] > arr [ i ] ) :
return False
return True
| static boolean arraySortedOrNot ( int arr [ ] , int n ) {
if ( n == 0 || n == 1 ) return true ;
for ( int i = 1 ;
i < n ;
i ++ ) if ( arr [ i - 1 ] > arr [ i ] ) return false ;
return true ;
}
| Translate the given code from python to java. The input Code is marked with <Code> and </Code>. | <Code>
def arraySortedOrNot ( arr , n ) :
if ( n == 0 or n == 1 ) :
return True
for i in range ( 1 , n ) :
if ( arr [ i - 1 ] > arr [ i ] ) :
return False
return True
</Code> |
python-java-CONVERT_STRING_BINARY_SEQUENCE | python-java | def strToBinary ( s ) :
bin_conv = [ ]
for c in s :
ascii_val = ord ( c )
binary_val = bin ( ascii_val )
bin_conv.append ( binary_val [ 2 : ] )
return ( ' '.join ( bin_conv ) )
| static void strToBinary ( String s ) {
int n = s . length ( ) ;
for ( int i = 0 ;
i < n ;
i ++ ) {
int val = Integer . valueOf ( s . charAt ( i ) ) ;
String bin = "" ;
while ( val > 0 ) {
if ( val % 2 == 1 ) {
bin += ' 1 ' ;
}
else bin += ' 0 ' ;
val /= 2 ;
}
... | Translate the given code from python to java. The input Code is marked with <Code> and </Code>. | <Code>
def strToBinary ( s ) :
bin_conv = [ ]
for c in s :
ascii_val = ord ( c )
binary_val = bin ( ascii_val )
bin_conv.append ( binary_val [ 2 : ] )
return ( ' '.join ( bin_conv ) )
</Code> |
python-java-GENERATE_PYTHAGORAS_TRIPLET_SINGLE_INTEGER | python-java | def evaluate ( n ) :
if ( n == 1 or n == 2 ) :
print ( "No Pythagoras" + " Triplet exists" )
elif ( n % 2 == 0 ) :
var = n * n / 4
print ( "Pythagoras Triplets" + " exist i.e." , end = "" )
print ( int ( n ) , "" , int ( var - 1 ) , "" , int ( var + 1 ) )
elif ( n % 2 != 0 ) ... | static void evaluate ( int n ) {
if ( n == 1 || n == 2 ) System . out . println ( "No Pythagoras " + "Triplet exists" ) ;
else if ( n % 2 == 0 ) {
int var = 1 * n * n / 4 ;
System . out . print ( "Pythagoras Triplets " + "exist i.e. " ) ;
System . out . print ( n + " " ) ;
System . out . print ( var... | Translate the given code from python to java. The input Code is marked with <Code> and </Code>. | <Code>
def evaluate ( n ) :
if ( n == 1 or n == 2 ) :
print ( "No Pythagoras" + " Triplet exists" )
elif ( n % 2 == 0 ) :
var = n * n / 4
print ( "Pythagoras Triplets" + " exist i.e." , end = "" )
print ( int ( n ) , "" , int ( var - 1 ) , "" , int ( var + 1 ) )
elif ( n % 2 ... |
python-java-CHECK_INTEGER_OVERFLOW_MULTIPLICATION | python-java | def isOverflow ( a , b ) :
if ( a == 0 or b == 0 ) :
return False
result = a * b
if ( result >= 9223372036854775807 or result <= - 9223372036854775808 ) :
result = 0
if ( a == ( result // b ) ) :
print ( result // b )
return False
else :
return True
| static Boolean isOverflow ( long a , long b ) {
if ( a == 0 || b == 0 ) return false ;
long result = a * b ;
if ( a == result / b ) return false ;
else return true ;
}
| Translate the given code from python to java. The input Code is marked with <Code> and </Code>. | <Code>
def isOverflow ( a , b ) :
if ( a == 0 or b == 0 ) :
return False
result = a * b
if ( result >= 9223372036854775807 or result <= - 9223372036854775808 ) :
result = 0
if ( a == ( result // b ) ) :
print ( result // b )
return False
else :
return True
</... |
python-java-FIND_EXPRESSION_DUPLICATE_PARENTHESIS_NOT | python-java | def findDuplicateparenthesis ( string ) :
Stack = [ ]
for ch in string :
if ch == ')' :
top = Stack.pop ( )
elementsInside = 0
while top != '(' :
elementsInside += 1
top = Stack.pop ( )
if elementsInside < 1 :
... | static boolean findDuplicateparenthesis ( String s ) {
Stack < Character > Stack = new Stack < > ( ) ;
char [ ] str = s . toCharArray ( ) ;
for ( char ch : str ) {
if ( ch == ' ) ' ) {
char top = Stack . peek ( ) ;
Stack . pop ( ) ;
int elementsInside = 0 ;
while ( top != ' ( ' ) {
... | Translate the given code from python to java. The input Code is marked with <Code> and </Code>. | <Code>
def findDuplicateparenthesis ( string ) :
Stack = [ ]
for ch in string :
if ch == ')' :
top = Stack.pop ( )
elementsInside = 0
while top != '(' :
elementsInside += 1
top = Stack.pop ( )
if elementsInside < 1 :
... |
python-java-COUNT_ROTATIONS_DIVISIBLE_4 | python-java | def countRotations ( n ) :
l = len ( n )
if ( l == 1 ) :
oneDigit = ( int ) ( n [ 0 ] )
if ( oneDigit % 4 == 0 ) :
return 1
return 0
count = 0
for i in range ( 0 , l - 1 ) :
twoDigit = ( int ) ( n [ i ] ) * 10 + ( int ) ( n [ i + 1 ] )
if ( twoDigit % ... | static int countRotations ( String n ) {
int len = n . length ( ) ;
if ( len == 1 ) {
int oneDigit = n . charAt ( 0 ) - ' 0 ' ;
if ( oneDigit % 4 == 0 ) return 1 ;
return 0 ;
}
int twoDigit , count = 0 ;
for ( int i = 0 ;
i < ( len - 1 ) ;
i ++ ) {
twoDigit = ( n . charAt ( i ) - ' 0 ' ) *... | Translate the given code from python to java. The input Code is marked with <Code> and </Code>. | <Code>
def countRotations ( n ) :
l = len ( n )
if ( l == 1 ) :
oneDigit = ( int ) ( n [ 0 ] )
if ( oneDigit % 4 == 0 ) :
return 1
return 0
count = 0
for i in range ( 0 , l - 1 ) :
twoDigit = ( int ) ( n [ i ] ) * 10 + ( int ) ( n [ i + 1 ] )
if ( twoD... |
python-java-FIND_DISTINCT_INTEGERS_FOR_A_TRIPLET_WITH_GIVEN_PRODUCT | python-java | def findTriplets ( x ) :
fact = [ ]
factors = set ( )
for i in range ( 2 , int ( sqrt ( x ) ) ) :
if ( x % i == 0 ) :
fact.append ( i )
if ( x / i != i ) :
fact.append ( x // i )
factors.add ( i )
factors.add ( x // i )
found = Fals... | static void findTriplets ( int x ) {
Vector < Integer > fact = new Vector < Integer > ( ) ;
HashSet < Integer > factors = new HashSet < Integer > ( ) ;
for ( int i = 2 ;
i <= Math . sqrt ( x ) ;
i ++ ) {
if ( x % i == 0 ) {
fact . add ( i ) ;
if ( x / i != i ) fact . add ( x / i ) ;
fact... | Translate the given code from python to java. The input Code is marked with <Code> and </Code>. | <Code>
def findTriplets ( x ) :
fact = [ ]
factors = set ( )
for i in range ( 2 , int ( sqrt ( x ) ) ) :
if ( x % i == 0 ) :
fact.append ( i )
if ( x / i != i ) :
fact.append ( x // i )
factors.add ( i )
factors.add ( x // i )
found... |
python-java-PRINT_WAYS_BREAK_STRING_BRACKET_FORM | python-java | def findCombinations ( string , index , out ) :
if index == len ( string ) :
print ( out )
for i in range ( index , len ( string ) , 1 ) :
findCombinations ( string , i + 1 , out + "(" + string [ index : i + 1 ] + ")" )
| static void findCombinations ( String str , int index , String out ) {
if ( index == str . length ( ) ) System . out . println ( out ) ;
for ( int i = index ;
i < str . length ( ) ;
i ++ ) findCombinations ( str , i + 1 , out + "(" + str . substring ( index , i + 1 ) + ")" ) ;
}
| Translate the given code from python to java. The input Code is marked with <Code> and </Code>. | <Code>
def findCombinations ( string , index , out ) :
if index == len ( string ) :
print ( out )
for i in range ( index , len ( string ) , 1 ) :
findCombinations ( string , i + 1 , out + "(" + string [ index : i + 1 ] + ")" )
</Code> |
python-java-EFFICIENT_SEARCH_IN_AN_ARRAY_WHERE_DIFFERENCE_BETWEEN_ADJACENT_IS_1 | python-java | def search ( arr , n , x ) :
i = 0
while ( i <= n - 1 ) :
if ( arr [ i ] == x ) :
return i
i += abs ( arr [ i ] - x )
return - 1
| static int search ( int arr [ ] , int n , int x ) {
int i = 0 ;
while ( i <= n - 1 ) {
if ( arr [ i ] == x ) return i ;
i += Math . abs ( arr [ i ] - x ) ;
}
return - 1 ;
}
| Translate the given code from python to java. The input Code is marked with <Code> and </Code>. | <Code>
def search ( arr , n , x ) :
i = 0
while ( i <= n - 1 ) :
if ( arr [ i ] == x ) :
return i
i += abs ( arr [ i ] - x )
return - 1
</Code> |
python-java-FIND_ELEMENTS_PRESENT_FIRST_ARRAY_NOT_SECOND_1 | python-java | def findMissing ( a , b , n , m ) :
s = dict ( )
for i in range ( m ) :
s [ b [ i ] ] = 1
for i in range ( n ) :
if a [ i ] not in s.keys ( ) :
print ( a [ i ] , end = " " )
| static void findMissing ( int a [ ] , int b [ ] , int n , int m ) {
HashSet < Integer > s = new HashSet < > ( ) ;
for ( int i = 0 ;
i < m ;
i ++ ) s . add ( b [ i ] ) ;
for ( int i = 0 ;
i < n ;
i ++ ) if ( ! s . contains ( a [ i ] ) ) System . out . print ( a [ i ] + " " ) ;
}
| Translate the given code from python to java. The input Code is marked with <Code> and </Code>. | <Code>
def findMissing ( a , b , n , m ) :
s = dict ( )
for i in range ( m ) :
s [ b [ i ] ] = 1
for i in range ( n ) :
if a [ i ] not in s.keys ( ) :
print ( a [ i ] , end = " " )
</Code> |
python-java-COUNT_CHARACTERS_STRING_DISTANCE_ENGLISH_ALPHABETS_1 | python-java | def countPairs ( str1 ) :
result = 0 ;
n = len ( str1 )
for i in range ( 0 , n ) :
for j in range ( 1 , MAX_CHAR + 1 ) :
if ( ( i + j ) < n ) :
if ( ( abs ( ord ( str1 [ i + j ] ) - ord ( str1 [ i ] ) ) == j ) ) :
result += 1 ;
return result
| static int countPairs ( String str ) {
int result = 0 ;
int n = str . length ( ) ;
for ( int i = 0 ;
i < n ;
i ++ ) for ( int j = 1 ;
( i + j ) < n && j <= MAX_CHAR ;
j ++ ) if ( ( Math . abs ( str . charAt ( i + j ) - str . charAt ( i ) ) == j ) ) result ++ ;
return result ;
}
| Translate the given code from python to java. The input Code is marked with <Code> and </Code>. | <Code>
def countPairs ( str1 ) :
result = 0 ;
n = len ( str1 )
for i in range ( 0 , n ) :
for j in range ( 1 , MAX_CHAR + 1 ) :
if ( ( i + j ) < n ) :
if ( ( abs ( ord ( str1 [ i + j ] ) - ord ( str1 [ i ] ) ) == j ) ) :
result += 1 ;
return result... |
python-java-FIND_MAXIMUM_SUM_POSSIBLE_EQUAL_SUM_THREE_STACKS | python-java | def maxSum ( stack1 , stack2 , stack3 , n1 , n2 , n3 ) :
sum1 , sum2 , sum3 = 0 , 0 , 0
for i in range ( n1 ) :
sum1 += stack1 [ i ]
for i in range ( n2 ) :
sum2 += stack2 [ i ]
for i in range ( n3 ) :
sum3 += stack3 [ i ]
top1 , top2 , top3 = 0 , 0 , 0
ans = 0
while ... | public static int maxSum ( int stack1 [ ] , int stack2 [ ] , int stack3 [ ] , int n1 , int n2 , int n3 ) {
int sum1 = 0 , sum2 = 0 , sum3 = 0 ;
for ( int i = 0 ;
i < n1 ;
i ++ ) sum1 += stack1 [ i ] ;
for ( int i = 0 ;
i < n2 ;
i ++ ) sum2 += stack2 [ i ] ;
for ( int i = 0 ;
i < n3 ;
i ++ ) sum3 += ... | Translate the given code from python to java. The input Code is marked with <Code> and </Code>. | <Code>
def maxSum ( stack1 , stack2 , stack3 , n1 , n2 , n3 ) :
sum1 , sum2 , sum3 = 0 , 0 , 0
for i in range ( n1 ) :
sum1 += stack1 [ i ]
for i in range ( n2 ) :
sum2 += stack2 [ i ]
for i in range ( n3 ) :
sum3 += stack3 [ i ]
top1 , top2 , top3 = 0 , 0 , 0
ans = 0
... |
python-java-MINIMUM_SUM_TWO_NUMBERS_FORMED_DIGITS_ARRAY | python-java | def solve ( arr , n ) :
arr.sort ( )
a = 0 b = 0
for i in range ( n ) :
if ( i % 2 != 0 ) :
a = a * 10 + arr [ i ]
else :
b = b * 10 + arr [ i ]
return a + b
| static int solve ( int arr [ ] , int n ) {
Arrays . sort ( arr ) ;
int a = 0 , b = 0 ;
for ( int i = 0 ;
i < n ;
i ++ ) {
if ( i % 2 != 0 ) a = a * 10 + arr [ i ] ;
else b = b * 10 + arr [ i ] ;
}
return a + b ;
}
| Translate the given code from python to java. The input Code is marked with <Code> and </Code>. | <Code>
def solve ( arr , n ) :
arr.sort ( )
a = 0 b = 0
for i in range ( n ) :
if ( i % 2 != 0 ) :
a = a * 10 + arr [ i ]
else :
b = b * 10 + arr [ i ]
return a + b
</Code> |
python-java-FIND_FIRST_NATURAL_NUMBER_WHOSE_FACTORIAL_DIVISIBLE_X | python-java | def firstFactorialDivisibleNumber ( x ) :
i = 1
fact = 1
for i in range ( 1 , x ) :
fact = fact * i
if ( fact % x == 0 ) :
break
return i
| static int firstFactorialDivisibleNumber ( int x ) {
int i = 1 ;
int fact = 1 ;
for ( i = 1 ;
i < x ;
i ++ ) {
fact = fact * i ;
if ( fact % x == 0 ) break ;
}
return i ;
}
| Translate the given code from python to java. The input Code is marked with <Code> and </Code>. | <Code>
def firstFactorialDivisibleNumber ( x ) :
i = 1
fact = 1
for i in range ( 1 , x ) :
fact = fact * i
if ( fact % x == 0 ) :
break
return i
</Code> |
python-java-COUNT_MINIMUM_STEPS_GET_GIVEN_DESIRED_ARRAY | python-java | def countMinOperations ( target , n ) :
result = 0
while ( True ) :
zero_count = 0
i = 0
while ( i < n ) :
if ( ( target [ i ] & 1 ) > 0 ) :
break
elif ( target [ i ] == 0 ) :
zero_count += 1
i += 1
if ( zero_cou... | static int countMinOperations ( int n ) {
int result = 0 ;
while ( true ) {
int zero_count = 0 ;
int i ;
for ( i = 0 ;
i < n ;
i ++ ) {
if ( arr [ i ] % 2 == 1 ) break ;
else if ( arr [ i ] == 0 ) zero_count ++ ;
}
if ( zero_count == n ) return result ;
if ( i == n ) {
... | Translate the given code from python to java. The input Code is marked with <Code> and </Code>. | <Code>
def countMinOperations ( target , n ) :
result = 0
while ( True ) :
zero_count = 0
i = 0
while ( i < n ) :
if ( ( target [ i ] & 1 ) > 0 ) :
break
elif ( target [ i ] == 0 ) :
zero_count += 1
i += 1
if ( z... |
python-java-SORT_ARRAY_CONTAIN_1_N_VALUES | python-java | def sortit ( arr , n ) :
for i in range ( n ) :
arr [ i ] = i + 1
| static void sortit ( int [ ] arr , int n ) {
for ( int i = 0 ;
i < n ;
i ++ ) {
arr [ i ] = i + 1 ;
}
}
| Translate the given code from python to java. The input Code is marked with <Code> and </Code>. | <Code>
def sortit ( arr , n ) :
for i in range ( n ) :
arr [ i ] = i + 1
</Code> |
python-java-CHANGE_BITS_CAN_MADE_ONE_FLIP | python-java | def canMakeAllSame ( str ) :
zeros = 0
ones = 0
for i in range ( 0 , len ( str ) ) :
ch = str [ i ]
if ( ch == '0' ) :
zeros = zeros + 1
else :
ones = ones + 1
return ( zeros == 1 or ones == 1 )
| static boolean canMakeAllSame ( String str ) {
int zeros = 0 , ones = 0 ;
for ( int i = 0 ;
i < str . length ( ) ;
i ++ ) {
char ch = str . charAt ( i ) ;
if ( ch == ' 0 ' ) ++ zeros ;
else ++ ones ;
}
return ( zeros == 1 || ones == 1 ) ;
}
| Translate the given code from python to java. The input Code is marked with <Code> and </Code>. | <Code>
def canMakeAllSame ( str ) :
zeros = 0
ones = 0
for i in range ( 0 , len ( str ) ) :
ch = str [ i ]
if ( ch == '0' ) :
zeros = zeros + 1
else :
ones = ones + 1
return ( zeros == 1 or ones == 1 )
</Code> |
python-java-SUM_ELEMENTS_K1TH_K2TH_SMALLEST_ELEMENTS_1 | python-java | def minheapify ( a , index ) :
small = index
l = 2 * index + 1
r = 2 * index + 2
if ( l < n and a [ l ] < a [ small ] ) :
small = l
if ( r < n and a [ r ] < a [ small ] ) :
small = r
if ( small != index ) :
( a [ small ] , a [ index ] ) = ( a [ index ] , a [ small ] )
... | static void minheapify ( int [ ] a , int index ) {
int small = index ;
int l = 2 * index + 1 ;
int r = 2 * index + 2 ;
if ( l < n && a [ l ] < a [ small ] ) small = l ;
if ( r < n && a [ r ] < a [ small ] ) small = r ;
if ( small != index ) {
int t = a [ small ] ;
a [ small ] = a [ index ] ;
a [... | Translate the given code from python to java. The input Code is marked with <Code> and </Code>. | <Code>
def minheapify ( a , index ) :
small = index
l = 2 * index + 1
r = 2 * index + 2
if ( l < n and a [ l ] < a [ small ] ) :
small = l
if ( r < n and a [ r ] < a [ small ] ) :
small = r
if ( small != index ) :
( a [ small ] , a [ index ] ) = ( a [ index ] , a [ small ... |
python-java-FIND_MINIMUM_SHIFT_LONGEST_COMMON_PREFIX | python-java | def KMP ( m , n , str2 , str1 ) :
pos = 0
Len = 0
p = [ 0 for i in range ( m + 1 ) ]
k = 0
for i in range ( 2 , n + 1 ) :
while ( k > 0 and str1 [ k ] != str1 [ i - 1 ] ) :
k = p [ k ]
if ( str1 [ k ] == str1 [ i - 1 ] ) :
k += 1
p [ i ] = k
j = 0
... | static void KMP ( int m , int n , String str2 , String str1 ) {
int pos = 0 , len = 0 ;
int [ ] p = new int [ m + 1 ] ;
int k = 0 ;
char [ ] ch1 = str1 . toCharArray ( ) ;
char [ ] ch2 = str2 . toCharArray ( ) ;
for ( int i = 2 ;
i <= n ;
i ++ ) {
while ( k > 0 && ch1 [ k ] != ch1 [ i - 1 ] ) k = p ... | Translate the given code from python to java. The input Code is marked with <Code> and </Code>. | <Code>
def KMP ( m , n , str2 , str1 ) :
pos = 0
Len = 0
p = [ 0 for i in range ( m + 1 ) ]
k = 0
for i in range ( 2 , n + 1 ) :
while ( k > 0 and str1 [ k ] != str1 [ i - 1 ] ) :
k = p [ k ]
if ( str1 [ k ] == str1 [ i - 1 ] ) :
k += 1
p [ i ] = k
... |
python-java-SWAP_MAJOR_MINOR_DIAGONALS_SQUARE_MATRIX | python-java | def swapDiagonal ( matrix ) :
for i in range ( N ) :
matrix [ i ] [ i ] , matrix [ i ] [ N - i - 1 ] = \
matrix [ i ] [ N - i - 1 ] , matrix [ i ] [ i ]
| static void swapDiagonal ( int matrix [ ] [ ] ) {
for ( int i = 0 ;
i < N ;
i ++ ) {
int temp = matrix [ i ] [ i ] ;
matrix [ i ] [ i ] = matrix [ i ] [ N - i - 1 ] ;
matrix [ i ] [ N - i - 1 ] = temp ;
}
}
| Translate the given code from python to java. The input Code is marked with <Code> and </Code>. | <Code>
def swapDiagonal ( matrix ) :
for i in range ( N ) :
matrix [ i ] [ i ] , matrix [ i ] [ N - i - 1 ] = \
matrix [ i ] [ N - i - 1 ] , matrix [ i ] [ i ]
</Code> |
python-java-REPRESENT_NUMBER_SUM_MINIMUM_POSSIBLE_PSUEDOBINARY_NUMBERS | python-java | def psuedoBinary ( n ) :
while ( n > 0 ) :
temp = n
m = 0
p = 1
while ( temp ) :
rem = temp % 10
temp = int ( temp / 10 )
if ( rem != 0 ) :
m += p
p *= 10
print ( m , end = " " )
n = n - m
| public static void psuedoBinary ( int n ) {
while ( n != 0 ) {
int temp = n , m = 0 , p = 1 ;
while ( temp != 0 ) {
int rem = temp % 10 ;
temp = temp / 10 ;
if ( rem != 0 ) m += p ;
p *= 10 ;
}
System . out . print ( m + " " ) ;
n = n - m ;
}
System . out . println ( " ... | Translate the given code from python to java. The input Code is marked with <Code> and </Code>. | <Code>
def psuedoBinary ( n ) :
while ( n > 0 ) :
temp = n
m = 0
p = 1
while ( temp ) :
rem = temp % 10
temp = int ( temp / 10 )
if ( rem != 0 ) :
m += p
p *= 10
print ( m , end = " " )
n = n - m
</Code> |
python-java-MINIMUM_NUMBER_POINTS_REMOVED_GET_REMAINING_POINTS_ONE_SIDE_AXIS | python-java | def findmin ( p , n ) :
a , b , c , d = 0 , 0 , 0 , 0
for i in range ( n ) :
if ( p [ i ] [ 0 ] <= 0 ) :
a += 1
elif ( p [ i ] [ 0 ] >= 0 ) :
b += 1
if ( p [ i ] [ 1 ] >= 0 ) :
c += 1
elif ( p [ i ] [ 1 ] <= 0 ) :
d += 1
return ... | static int findmin ( Point p [ ] , int n ) {
int a = 0 , b = 0 , c = 0 , d = 0 ;
for ( int i = 0 ;
i < n ;
i ++ ) {
if ( p [ i ] . x <= 0 ) a ++ ;
else if ( p [ i ] . x >= 0 ) b ++ ;
if ( p [ i ] . y >= 0 ) c ++ ;
else if ( p [ i ] . y <= 0 ) d ++ ;
}
return Math . min ( Math . min ( a , b )... | Translate the given code from python to java. The input Code is marked with <Code> and </Code>. | <Code>
def findmin ( p , n ) :
a , b , c , d = 0 , 0 , 0 , 0
for i in range ( n ) :
if ( p [ i ] [ 0 ] <= 0 ) :
a += 1
elif ( p [ i ] [ 0 ] >= 0 ) :
b += 1
if ( p [ i ] [ 1 ] >= 0 ) :
c += 1
elif ( p [ i ] [ 1 ] <= 0 ) :
d += 1
... |
python-java-FIND_MINIMUM_NUMBER_OF_COINS_THAT_MAKE_A_CHANGE_1 | python-java | def minCoins ( coins , m , V ) :
table = [ 0 for i in range ( V + 1 ) ]
table [ 0 ] = 0
for i in range ( 1 , V + 1 ) :
table [ i ] = sys.maxsize
for i in range ( 1 , V + 1 ) :
for j in range ( m ) :
if ( coins [ j ] <= i ) :
sub_res = table [ i - coins [ j ] ]... | static int minCoins ( int coins [ ] , int m , int V ) {
int table [ ] = new int [ V + 1 ] ;
table [ 0 ] = 0 ;
for ( int i = 1 ;
i <= V ;
i ++ ) table [ i ] = Integer . MAX_VALUE ;
for ( int i = 1 ;
i <= V ;
i ++ ) {
for ( int j = 0 ;
j < m ;
j ++ ) if ( coins [ j ] <= i ) {
int sub_res... | Translate the given code from python to java. The input Code is marked with <Code> and </Code>. | <Code>
def minCoins ( coins , m , V ) :
table = [ 0 for i in range ( V + 1 ) ]
table [ 0 ] = 0
for i in range ( 1 , V + 1 ) :
table [ i ] = sys.maxsize
for i in range ( 1 , V + 1 ) :
for j in range ( m ) :
if ( coins [ j ] <= i ) :
sub_res = table [ i - coins ... |
python-java-MAKE_LARGEST_PALINDROME_CHANGING_K_DIGITS | python-java | def maximumPalinUsingKChanges ( strr , k ) :
palin = strr
l = 0
r = len ( strr ) - 1
while ( l <= r ) :
if ( strr [ l ] != strr [ r ] ) :
palin [ l ] = palin [ r ] = max ( strr [ l ] , strr [ r ] )
k -= 1
l += 1
r -= 1
if ( k < 0 ) :
return "No... | static String maximumPalinUsingKChanges ( String str , int k ) {
char palin [ ] = str . toCharArray ( ) ;
String ans = "" ;
int l = 0 ;
int r = str . length ( ) - 1 ;
while ( l < r ) {
if ( str . charAt ( l ) != str . charAt ( r ) ) {
palin [ l ] = palin [ r ] = ( char ) Math . max ( str . charAt ( ... | Translate the given code from python to java. The input Code is marked with <Code> and </Code>. | <Code>
def maximumPalinUsingKChanges ( strr , k ) :
palin = strr
l = 0
r = len ( strr ) - 1
while ( l <= r ) :
if ( strr [ l ] != strr [ r ] ) :
palin [ l ] = palin [ r ] = max ( strr [ l ] , strr [ r ] )
k -= 1
l += 1
r -= 1
if ( k < 0 ) :
ret... |
python-java-MINIMUM_ROOMS_FOR_M_EVENTS_OF_N_BATCHES_WITH_GIVEN_SCHEDULE | python-java | def findMinRooms ( slots , n , m ) :
counts = [ 0 ] * m
for i in range ( n ) :
for j in range ( m ) :
if ( slots [ i ] [ j ] == '1' ) :
counts [ j ] += 1
return max ( counts )
| static int findMinRooms ( String slots [ ] , int n , int m ) {
int counts [ ] = new int [ m ] ;
for ( int i = 0 ;
i < m ;
i ++ ) counts [ i ] = 0 ;
for ( int i = 0 ;
i < n ;
i ++ ) for ( int j = 0 ;
j < m ;
j ++ ) if ( slots [ i ] . charAt ( j ) == ' 1 ' ) counts [ j ] ++ ;
int max = - 1 ;
for ( i... | Translate the given code from python to java. The input Code is marked with <Code> and </Code>. | <Code>
def findMinRooms ( slots , n , m ) :
counts = [ 0 ] * m
for i in range ( n ) :
for j in range ( m ) :
if ( slots [ i ] [ j ] == '1' ) :
counts [ j ] += 1
return max ( counts )
</Code> |
python-java-MAXIMUM_PATH_SUM_POSITION_JUMPS_DIVISIBILITY_CONDITION | python-java | def printMaxSum ( arr , n ) :
dp = [ 0 for i in range ( n ) ]
for i in range ( n ) :
dp [ i ] = arr [ i ]
maxi = 0
for j in range ( 1 , int ( ( i + 1 ) ** 0.5 ) + 1 ) :
if ( ( i + 1 ) % j == 0 and ( i + 1 ) != j ) :
if ( dp [ j - 1 ] > maxi ) :
... | static void printMaxSum ( int arr [ ] , int n ) {
int dp [ ] = new int [ n ] ;
Arrays . fill ( dp , 0 ) ;
for ( int i = 0 ;
i < n ;
i ++ ) {
dp [ i ] = arr [ i ] ;
int maxi = 0 ;
for ( int j = 1 ;
j <= Math . sqrt ( i + 1 ) ;
j ++ ) {
if ( ( ( i + 1 ) % j == 0 ) && ( i + 1 ) != j ) {... | Translate the given code from python to java. The input Code is marked with <Code> and </Code>. | <Code>
def printMaxSum ( arr , n ) :
dp = [ 0 for i in range ( n ) ]
for i in range ( n ) :
dp [ i ] = arr [ i ]
maxi = 0
for j in range ( 1 , int ( ( i + 1 ) ** 0.5 ) + 1 ) :
if ( ( i + 1 ) % j == 0 and ( i + 1 ) != j ) :
if ( dp [ j - 1 ] > maxi ) :
... |
python-java-MAXIMUM_SUM_ALTERNATING_SUBSEQUENCE_SUM | python-java | def maxAlternateSum ( arr , n ) :
if ( n == 1 ) :
return arr [ 0 ]
dec = [ 0 for i in range ( n + 1 ) ]
inc = [ 0 for i in range ( n + 1 ) ]
dec [ 0 ] = inc [ 0 ] = arr [ 0 ]
flag = 0
for i in range ( 1 , n ) :
for j in range ( i ) :
if ( arr [ j ] > arr [ i ] ) :
... | static int maxAlternateSum ( int arr [ ] , int n ) {
if ( n == 1 ) return arr [ 0 ] ;
int dec [ ] = new int [ n ] ;
int inc [ ] = new int [ n ] ;
dec [ 0 ] = inc [ 0 ] = arr [ 0 ] ;
int flag = 0 ;
for ( int i = 1 ;
i < n ;
i ++ ) {
for ( int j = 0 ;
j < i ;
j ++ ) {
if ( arr [ j ] > ar... | Translate the given code from python to java. The input Code is marked with <Code> and </Code>. | <Code>
def maxAlternateSum ( arr , n ) :
if ( n == 1 ) :
return arr [ 0 ]
dec = [ 0 for i in range ( n + 1 ) ]
inc = [ 0 for i in range ( n + 1 ) ]
dec [ 0 ] = inc [ 0 ] = arr [ 0 ]
flag = 0
for i in range ( 1 , n ) :
for j in range ( i ) :
if ( arr [ j ] > arr [ i ] ... |
python-java-FIND_THE_TWO_REPEATING_ELEMENTS_IN_A_GIVEN_ARRAY | python-java | def printRepeating ( arr , size ) :
print ( "Repeating elements are " , end = '' )
for i in range ( 0 , size ) :
for j in range ( i + 1 , size ) :
if arr [ i ] == arr [ j ] :
print ( arr [ i ] , end = ' ' )
| void printRepeating ( int arr [ ] , int size ) {
int i , j ;
System . out . println ( "Repeated Elements are :" ) ;
for ( i = 0 ;
i < size ;
i ++ ) {
for ( j = i + 1 ;
j < size ;
j ++ ) {
if ( arr [ i ] == arr [ j ] ) System . out . print ( arr [ i ] + " " ) ;
}
}
}
| Translate the given code from python to java. The input Code is marked with <Code> and </Code>. | <Code>
def printRepeating ( arr , size ) :
print ( "Repeating elements are " , end = '' )
for i in range ( 0 , size ) :
for j in range ( i + 1 , size ) :
if arr [ i ] == arr [ j ] :
print ( arr [ i ] , end = ' ' )
</Code> |
python-java-MINIMUM_PRODUCT_K_INTEGERS_ARRAY_POSITIVE_INTEGERS | python-java | def minProduct ( arr , n , k ) :
heapq.heapify ( arr )
count = 0
ans = 1
while ( arr ) and count < k :
x = heapq.heappop ( arr )
ans = ans * x
count = count + 1
return ans
| public static int minProduct ( int [ ] arr , int n , int k ) {
PriorityQueue < Integer > pq = new PriorityQueue < > ( ) ;
for ( int i = 0 ;
i < n ;
i ++ ) pq . add ( arr [ i ] ) ;
int count = 0 , ans = 1 ;
while ( pq . isEmpty ( ) == false && count < k ) {
ans = ans * pq . element ( ) ;
pq . remove ... | Translate the given code from python to java. The input Code is marked with <Code> and </Code>. | <Code>
def minProduct ( arr , n , k ) :
heapq.heapify ( arr )
count = 0
ans = 1
while ( arr ) and count < k :
x = heapq.heappop ( arr )
ans = ans * x
count = count + 1
return ans
</Code> |
python-java-C_PROGRAM_FIND_LARGEST_ELEMENT_ARRAY_1 | python-java | def largest ( arr , n ) :
return max ( arr )
| static int largest ( int [ ] arr , int n ) {
Arrays . sort ( arr ) ;
return arr [ n - 1 ] ;
}
| Translate the given code from python to java. The input Code is marked with <Code> and </Code>. | <Code>
def largest ( arr , n ) :
return max ( arr )
</Code> |
python-java-PROGRAM_TO_EFFICIENTLY_CALCULATE_EX | python-java | def exponential ( n , x ) :
sum = 1.0
for i in range ( n , 0 , - 1 ) :
sum = 1 + x * sum / i
print ( "e^x =" , sum )
| static float exponential ( int n , float x ) {
float sum = 1 ;
for ( int i = n - 1 ;
i > 0 ;
-- i ) sum = 1 + x * sum / i ;
return sum ;
}
| Translate the given code from python to java. The input Code is marked with <Code> and </Code>. | <Code>
def exponential ( n , x ) :
sum = 1.0
for i in range ( n , 0 , - 1 ) :
sum = 1 + x * sum / i
print ( "e^x =" , sum )
</Code> |
python-java-FIRST_ELEMENT_OCCURRING_K_TIMES_ARRAY | python-java | def firstElement ( arr , n , k ) :
count_map = { }
for i in range ( 0 , n ) :
if ( arr [ i ] in count_map.keys ( ) ) :
count_map [ arr [ i ] ] += 1
else :
count_map [ arr [ i ] ] = 1
i += 1
for i in range ( 0 , n ) :
if ( count_map [ arr [ i ] ] == k )... | static int firstElement ( int arr [ ] , int n , int k ) {
HashMap < Integer , Integer > count_map = new HashMap < > ( ) ;
for ( int i = 0 ;
i < n ;
i ++ ) {
int a = 0 ;
if ( count_map . get ( arr [ i ] ) != null ) {
a = count_map . get ( arr [ i ] ) ;
}
count_map . put ( arr [ i ] , a + 1 ... | Translate the given code from python to java. The input Code is marked with <Code> and </Code>. | <Code>
def firstElement ( arr , n , k ) :
count_map = { }
for i in range ( 0 , n ) :
if ( arr [ i ] in count_map.keys ( ) ) :
count_map [ arr [ i ] ] += 1
else :
count_map [ arr [ i ] ] = 1
i += 1
for i in range ( 0 , n ) :
if ( count_map [ arr [ i ] ]... |
python-java-DYNAMIC_PROGRAMMING_SET_36_CUT_A_ROPE_TO_MAXIMIZE_PRODUCT_1 | python-java | def maxProd ( n ) :
if ( n == 2 or n == 3 ) :
return ( n - 1 )
res = 1
while ( n > 4 ) :
n -= 3
res *= 3
return ( n * res )
| static int maxProd ( int n ) {
if ( n == 2 || n == 3 ) return ( n - 1 ) ;
int res = 1 ;
while ( n > 4 ) {
n -= 3 ;
res *= 3 ;
}
return ( n * res ) ;
}
| Translate the given code from python to java. The input Code is marked with <Code> and </Code>. | <Code>
def maxProd ( n ) :
if ( n == 2 or n == 3 ) :
return ( n - 1 )
res = 1
while ( n > 4 ) :
n -= 3
res *= 3
return ( n * res )
</Code> |
python-java-MAXIMUM_SUM_2_X_N_GRID_NO_TWO_ELEMENTS_ADJACENT | python-java | def maxSum ( grid , n ) :
incl = max ( grid [ 0 ] [ 0 ] , grid [ 1 ] [ 0 ] )
excl = 0
for i in range ( 1 , n ) :
excl_new = max ( excl , incl )
incl = excl + max ( grid [ 0 ] [ i ] , grid [ 1 ] [ i ] )
excl = excl_new
return max ( excl , incl )
| public static int maxSum ( int grid [ ] [ ] , int n ) {
int incl = Math . max ( grid [ 0 ] [ 0 ] , grid [ 1 ] [ 0 ] ) ;
int excl = 0 , excl_new ;
for ( int i = 1 ;
i < n ;
i ++ ) {
excl_new = Math . max ( excl , incl ) ;
incl = excl + Math . max ( grid [ 0 ] [ i ] , grid [ 1 ] [ i ] ) ;
excl = exc... | Translate the given code from python to java. The input Code is marked with <Code> and </Code>. | <Code>
def maxSum ( grid , n ) :
incl = max ( grid [ 0 ] [ 0 ] , grid [ 1 ] [ 0 ] )
excl = 0
for i in range ( 1 , n ) :
excl_new = max ( excl , incl )
incl = excl + max ( grid [ 0 ] [ i ] , grid [ 1 ] [ i ] )
excl = excl_new
return max ( excl , incl )
</Code> |
python-java-FIND_ROTATION_COUNT_ROTATED_SORTED_ARRAY_1 | python-java | def countRotations ( arr , low , high ) :
if ( high < low ) :
return 0
if ( high == low ) :
return low
mid = low + ( high - low ) / 2
mid = int ( mid )
if ( mid < high and arr [ mid + 1 ] < arr [ mid ] ) :
return ( mid + 1 )
if ( mid > low and arr [ mid ] < arr [ mid - 1 ... | static int countRotations ( int arr [ ] , int low , int high ) {
if ( high < low ) return 0 ;
if ( high == low ) return low ;
int mid = low + ( high - low ) / 2 ;
if ( mid < high && arr [ mid + 1 ] < arr [ mid ] ) return ( mid + 1 ) ;
if ( mid > low && arr [ mid ] < arr [ mid - 1 ] ) return mid ;
if ( arr [... | Translate the given code from python to java. The input Code is marked with <Code> and </Code>. | <Code>
def countRotations ( arr , low , high ) :
if ( high < low ) :
return 0
if ( high == low ) :
return low
mid = low + ( high - low ) / 2
mid = int ( mid )
if ( mid < high and arr [ mid + 1 ] < arr [ mid ] ) :
return ( mid + 1 )
if ( mid > low and arr [ mid ] < arr [ m... |
python-java-SUM_MATRIX_ELEMENT_ELEMENT_INTEGER_DIVISION_ROW_COLUMN_1 | python-java | def findSum ( n ) :
ans = 0 temp = 0
for i in range ( 1 , n + 1 ) :
if temp < n :
temp = i - 1
num = 1
while temp < n :
if temp + i <= n :
ans += i * num
else :
ans += ( n - temp ) * num
... | static int findSum ( int n ) {
int ans = 0 , temp = 0 , num ;
for ( int i = 1 ;
i <= n && temp < n ;
i ++ ) {
temp = i - 1 ;
num = 1 ;
while ( temp < n ) {
if ( temp + i <= n ) ans += ( i * num ) ;
else ans += ( ( n - temp ) * num ) ;
temp += i ;
num ++ ;
}
}
return a... | Translate the given code from python to java. The input Code is marked with <Code> and </Code>. | <Code>
def findSum ( n ) :
ans = 0 temp = 0
for i in range ( 1 , n + 1 ) :
if temp < n :
temp = i - 1
num = 1
while temp < n :
if temp + i <= n :
ans += i * num
else :
ans += ( n - temp ) * num
... |
python-java-CHECK_HALF_STRING_CHARACTER_FREQUENCY_CHARACTER | python-java | def checkCorrectOrNot ( s ) :
global MAX_CHAR
count1 = [ 0 ] * MAX_CHAR
count2 = [ 0 ] * MAX_CHAR
n = len ( s )
if n == 1 :
return true
i = 0 j = n - 1
while ( i < j ) :
count1 [ ord ( s [ i ] ) - ord ( 'a' ) ] += 1
count2 [ ord ( s [ j ] ) - ord ( 'a' ) ] += 1
... | static boolean checkCorrectOrNot ( String s ) {
int [ ] count1 = new int [ MAX_CHAR ] ;
int [ ] count2 = new int [ MAX_CHAR ] ;
int n = s . length ( ) ;
if ( n == 1 ) return true ;
for ( int i = 0 , j = n - 1 ;
i < j ;
i ++ , j -- ) {
count1 [ s . charAt ( i ) - ' a ' ] ++ ;
count2 [ s . charAt ( ... | Translate the given code from python to java. The input Code is marked with <Code> and </Code>. | <Code>
def checkCorrectOrNot ( s ) :
global MAX_CHAR
count1 = [ 0 ] * MAX_CHAR
count2 = [ 0 ] * MAX_CHAR
n = len ( s )
if n == 1 :
return true
i = 0 j = n - 1
while ( i < j ) :
count1 [ ord ( s [ i ] ) - ord ( 'a' ) ] += 1
count2 [ ord ( s [ j ] ) - ord ( 'a' ) ] += 1... |
python-java-SUM_FACTORS_NUMBER | python-java | def divSum ( n ) :
result = 0
for i in range ( 2 , ( int ) ( math.sqrt ( n ) ) + 1 ) :
if ( n % i == 0 ) :
if ( i == ( n / i ) ) :
result = result + i
else :
result = result + ( i + n // i )
return ( result + n + 1 )
| static int divSum ( int n ) {
int result = 0 ;
for ( int i = 2 ;
i <= Math . sqrt ( n ) ;
i ++ ) {
if ( n % i == 0 ) {
if ( i == ( n / i ) ) result += i ;
else result += ( i + n / i ) ;
}
}
return ( result + n + 1 ) ;
}
| Translate the given code from python to java. The input Code is marked with <Code> and </Code>. | <Code>
def divSum ( n ) :
result = 0
for i in range ( 2 , ( int ) ( math.sqrt ( n ) ) + 1 ) :
if ( n % i == 0 ) :
if ( i == ( n / i ) ) :
result = result + i
else :
result = result + ( i + n // i )
return ( result + n + 1 )
</Code> |
python-java-ROTATE_MATRIX_180_DEGREE | python-java | def rotateMatrix ( mat ) :
i = N - 1
while ( i >= 0 ) :
j = N - 1
while ( j >= 0 ) :
print ( mat [ i ] [ j ] , end = " " )
j = j - 1
print ( )
i = i - 1
| static void rotateMatrix ( int mat [ ] [ ] ) {
for ( int i = N - 1 ;
i >= 0 ;
i -- ) {
for ( int j = N - 1 ;
j >= 0 ;
j -- ) System . out . print ( mat [ i ] [ j ] + " " ) ;
System . out . println ( ) ;
}
}
| Translate the given code from python to java. The input Code is marked with <Code> and </Code>. | <Code>
def rotateMatrix ( mat ) :
i = N - 1
while ( i >= 0 ) :
j = N - 1
while ( j >= 0 ) :
print ( mat [ i ] [ j ] , end = " " )
j = j - 1
print ( )
i = i - 1
</Code> |
python-java-PRINT_MATRIX_SPIRAL_FORM_STARTING_POINT | python-java | def printSpiral ( mat , r , c ) :
a = 0
b = 2
low_row = 0 if ( 0 > a ) else a
low_column = 0 if ( 0 > b ) else b - 1
high_row = r - 1 if ( ( a + 1 ) >= r ) else a + 1
high_column = c - 1 if ( ( b + 1 ) >= c ) else b + 1
while ( ( low_row > 0 - r and low_column > 0 - c ) ) :
i = low_c... | static void printSpiral ( int [ ] [ ] mat , int r , int c ) {
int i , a = 0 , b = 2 ;
int low_row = ( 0 > a ) ? 0 : a ;
int low_column = ( 0 > b ) ? 0 : b - 1 ;
int high_row = ( ( a + 1 ) >= r ) ? r - 1 : a + 1 ;
int high_column = ( ( b + 1 ) >= c ) ? c - 1 : b + 1 ;
while ( ( low_row > 0 - r && low_column ... | Translate the given code from python to java. The input Code is marked with <Code> and </Code>. | <Code>
def printSpiral ( mat , r , c ) :
a = 0
b = 2
low_row = 0 if ( 0 > a ) else a
low_column = 0 if ( 0 > b ) else b - 1
high_row = r - 1 if ( ( a + 1 ) >= r ) else a + 1
high_column = c - 1 if ( ( b + 1 ) >= c ) else b + 1
while ( ( low_row > 0 - r and low_column > 0 - c ) ) :
i ... |
python-java-COUNT_EVEN_LENGTH_BINARY_SEQUENCES_WITH_SAME_SUM_OF_FIRST_AND_SECOND_HALF_BITS_1 | python-java | def countSeq ( n ) :
nCr = 1
res = 1
for r in range ( 1 , n + 1 ) :
nCr = ( nCr * ( n + 1 - r ) ) / r ;
res += nCr * nCr ;
return res ;
| static int countSeq ( int n ) {
int nCr = 1 , res = 1 ;
for ( int r = 1 ;
r <= n ;
r ++ ) {
nCr = ( nCr * ( n + 1 - r ) ) / r ;
res += nCr * nCr ;
}
return res ;
}
| Translate the given code from python to java. The input Code is marked with <Code> and </Code>. | <Code>
def countSeq ( n ) :
nCr = 1
res = 1
for r in range ( 1 , n + 1 ) :
nCr = ( nCr * ( n + 1 - r ) ) / r ;
res += nCr * nCr ;
return res ;
</Code> |
python-java-PROGRAM_CALCULATE_AREA_OCTAGON | python-java | def areaOctagon ( side ) :
return ( 2 * ( 1 + ( math.sqrt ( 2 ) ) ) * side * side )
| static double areaOctagon ( double side ) {
return ( float ) ( 2 * ( 1 + Math . sqrt ( 2 ) ) * side * side ) ;
}
| Translate the given code from python to java. The input Code is marked with <Code> and </Code>. | <Code>
def areaOctagon ( side ) :
return ( 2 * ( 1 + ( math.sqrt ( 2 ) ) ) * side * side )
</Code> |
python-java-MAXIMUM_CONSECUTIVE_NUMBERS_PRESENT_ARRAY | python-java | def findLongestConseqSubseq ( arr , n ) :
S = set ( )
for i in range ( n ) :
S.add ( arr [ i ] )
ans = 0
for i in range ( n ) :
if S.__contains__ ( arr [ i ] ) :
j = arr [ i ]
while ( S.__contains__ ( j ) ) :
j += 1
ans = max ( ans , j ... | static int findLongestConseqSubseq ( int arr [ ] , int n ) {
HashSet < Integer > S = new HashSet < Integer > ( ) ;
for ( int i = 0 ;
i < n ;
i ++ ) S . add ( arr [ i ] ) ;
int ans = 0 ;
for ( int i = 0 ;
i < n ;
i ++ ) {
if ( S . contains ( arr [ i ] ) ) {
int j = arr [ i ] ;
while ( S .... | Translate the given code from python to java. The input Code is marked with <Code> and </Code>. | <Code>
def findLongestConseqSubseq ( arr , n ) :
S = set ( )
for i in range ( n ) :
S.add ( arr [ i ] )
ans = 0
for i in range ( n ) :
if S.__contains__ ( arr [ i ] ) :
j = arr [ i ]
while ( S.__contains__ ( j ) ) :
j += 1
ans = max ( a... |
python-java-SHORTEST_POSSIBLE_COMBINATION_TWO_STRINGS | python-java | def printSuperSeq ( a , b ) :
m = len ( a )
n = len ( b )
dp = [ [ 0 ] * ( n + 1 ) for i in range ( m + 1 ) ]
for i in range ( 0 , m + 1 ) :
for j in range ( 0 , n + 1 ) :
if not i :
dp [ i ] [ j ] = j
elif not j :
dp [ i ] [ j ] = i
... | static void printSuperSeq ( String a , String b ) {
int m = a . length ( ) , n = b . length ( ) ;
int [ ] [ ] dp = new int [ m + 1 ] [ n + 1 ] ;
for ( int i = 0 ;
i <= m ;
i ++ ) {
for ( int j = 0 ;
j <= n ;
j ++ ) {
if ( i == 0 ) dp [ i ] [ j ] = j ;
else if ( j == 0 ) dp [ i ] [ j ] ... | Translate the given code from python to java. The input Code is marked with <Code> and </Code>. | <Code>
def printSuperSeq ( a , b ) :
m = len ( a )
n = len ( b )
dp = [ [ 0 ] * ( n + 1 ) for i in range ( m + 1 ) ]
for i in range ( 0 , m + 1 ) :
for j in range ( 0 , n + 1 ) :
if not i :
dp [ i ] [ j ] = j
elif not j :
dp [ i ] [ j ] = i... |
python-java-COUNT_POSSIBLE_PATHS_TOP_LEFT_BOTTOM_RIGHT_NXM_MATRIX_2 | python-java | def numberOfPaths ( p , q ) :
dp = [ 1 for i in range ( q ) ]
for i in range ( p - 1 ) :
for j in range ( 1 , q ) :
dp [ j ] += dp [ j - 1 ]
return dp [ q - 1 ]
| static int numberOfPaths ( int m , int n ) {
int [ ] dp = new int [ n ] ;
dp [ 0 ] = 1 ;
for ( int i = 0 ;
i < m ;
i ++ ) {
for ( int j = 1 ;
j < n ;
j ++ ) {
dp [ j ] += dp [ j - 1 ] ;
}
}
return dp [ n - 1 ] ;
}
| Translate the given code from python to java. The input Code is marked with <Code> and </Code>. | <Code>
def numberOfPaths ( p , q ) :
dp = [ 1 for i in range ( q ) ]
for i in range ( p - 1 ) :
for j in range ( 1 , q ) :
dp [ j ] += dp [ j - 1 ]
return dp [ q - 1 ]
</Code> |
python-java-FIND_WHETHER_A_GIVEN_NUMBER_IS_A_POWER_OF_4_OR_NOT_1 | python-java | def isPowerOfFour ( n ) :
count = 0
if ( n and ( not ( n & ( n - 1 ) ) ) ) :
while ( n > 1 ) :
n >>= 1
count += 1
if ( count % 2 == 0 ) :
return True
else :
return False
| static int isPowerOfFour ( int n ) {
int count = 0 ;
int x = n & ( n - 1 ) ;
if ( n > 0 && x == 0 ) {
while ( n > 1 ) {
n >>= 1 ;
count += 1 ;
}
return ( count % 2 == 0 ) ? 1 : 0 ;
}
return 0 ;
}
| Translate the given code from python to java. The input Code is marked with <Code> and </Code>. | <Code>
def isPowerOfFour ( n ) :
count = 0
if ( n and ( not ( n & ( n - 1 ) ) ) ) :
while ( n > 1 ) :
n >>= 1
count += 1
if ( count % 2 == 0 ) :
return True
else :
return False
</Code> |
python-java-FIND_SUM_ODD_FACTORS_NUMBER | python-java | def sumofoddFactors ( n ) :
res = 1
while n % 2 == 0 :
n = n // 2
for i in range ( 3 , int ( math.sqrt ( n ) + 1 ) ) :
count = 0
curr_sum = 1
curr_term = 1
while n % i == 0 :
count += 1
n = n // i
curr_term *= i
curr_sum... | static int sumofoddFactors ( int n ) {
int res = 1 ;
while ( n % 2 == 0 ) n = n / 2 ;
for ( int i = 3 ;
i <= Math . sqrt ( n ) ;
i ++ ) {
int count = 0 , curr_sum = 1 ;
int curr_term = 1 ;
while ( n % i == 0 ) {
count ++ ;
n = n / i ;
curr_term *= i ;
curr_sum += curr_term ... | Translate the given code from python to java. The input Code is marked with <Code> and </Code>. | <Code>
def sumofoddFactors ( n ) :
res = 1
while n % 2 == 0 :
n = n // 2
for i in range ( 3 , int ( math.sqrt ( n ) + 1 ) ) :
count = 0
curr_sum = 1
curr_term = 1
while n % i == 0 :
count += 1
n = n // i
curr_term *= i
c... |
python-java-FIND_THE_ELEMENT_BEFORE_WHICH_ALL_THE_ELEMENTS_ARE_SMALLER_THAN_IT_AND_AFTER_WHICH_ALL_ARE_GREATER_THAN_IT | python-java | def findElement ( arr , n ) :
leftMax = [ None ] * n
leftMax [ 0 ] = float ( '-inf' )
for i in range ( 1 , n ) :
leftMax [ i ] = max ( leftMax [ i - 1 ] , arr [ i - 1 ] )
rightMin = float ( 'inf' )
for i in range ( n - 1 , - 1 , - 1 ) :
if leftMax [ i ] < arr [ i ] and rightMin > arr... | static int findElement ( int [ ] arr , int n ) {
int [ ] leftMax = new int [ n ] ;
leftMax [ 0 ] = Integer . MIN_VALUE ;
for ( int i = 1 ;
i < n ;
i ++ ) leftMax [ i ] = Math . max ( leftMax [ i - 1 ] , arr [ i - 1 ] ) ;
int rightMin = Integer . MAX_VALUE ;
for ( int i = n - 1 ;
i >= 0 ;
i -- ) {
... | Translate the given code from python to java. The input Code is marked with <Code> and </Code>. | <Code>
def findElement ( arr , n ) :
leftMax = [ None ] * n
leftMax [ 0 ] = float ( '-inf' )
for i in range ( 1 , n ) :
leftMax [ i ] = max ( leftMax [ i - 1 ] , arr [ i - 1 ] )
rightMin = float ( 'inf' )
for i in range ( n - 1 , - 1 , - 1 ) :
if leftMax [ i ] < arr [ i ] and rightMi... |
python-java-SEARCH_AN_ELEMENT_IN_A_SORTED_AND_PIVOTED_ARRAY | python-java | def search ( arr , l , h , key ) :
if l > h :
return - 1
mid = ( l + h ) // 2
if arr [ mid ] == key :
return mid
if arr [ l ] <= arr [ mid ] :
if key >= arr [ l ] and key <= arr [ mid ] :
return search ( arr , l , mid - 1 , key )
return search ( arr , mid + 1 ... | static int search ( int arr [ ] , int l , int h , int key ) {
if ( l > h ) return - 1 ;
int mid = ( l + h ) / 2 ;
if ( arr [ mid ] == key ) return mid ;
if ( arr [ l ] <= arr [ mid ] ) {
if ( key >= arr [ l ] && key <= arr [ mid ] ) return search ( arr , l , mid - 1 , key ) ;
return search ( arr , mid +... | Translate the given code from python to java. The input Code is marked with <Code> and </Code>. | <Code>
def search ( arr , l , h , key ) :
if l > h :
return - 1
mid = ( l + h ) // 2
if arr [ mid ] == key :
return mid
if arr [ l ] <= arr [ mid ] :
if key >= arr [ l ] and key <= arr [ mid ] :
return search ( arr , l , mid - 1 , key )
return search ( arr , m... |
python-java-EXPONENTIAL_SQUARING_FAST_MODULO_MULTIPLICATION | python-java | def exponentiation ( bas , exp ) :
if ( exp == 0 ) :
return 1
if ( exp == 1 ) :
return bas % N
t = exponentiation ( bas , int ( exp / 2 ) )
t = ( t * t ) % N
if ( exp % 2 == 0 ) :
return t
else :
return ( ( bas % N ) * t ) % N
| static long exponentiation ( long base , long exp ) {
if ( exp == 0 ) return 1 ;
if ( exp == 1 ) return base % N ;
long t = exponentiation ( base , exp / 2 ) ;
t = ( t * t ) % N ;
if ( exp % 2 == 0 ) return t ;
else return ( ( base % N ) * t ) % N ;
}
| Translate the given code from python to java. The input Code is marked with <Code> and </Code>. | <Code>
def exponentiation ( bas , exp ) :
if ( exp == 0 ) :
return 1
if ( exp == 1 ) :
return bas % N
t = exponentiation ( bas , int ( exp / 2 ) )
t = ( t * t ) % N
if ( exp % 2 == 0 ) :
return t
else :
return ( ( bas % N ) * t ) % N
</Code> |
python-java-DIVISIBILITY_CHECK | python-java | def divisibilityCheck ( arr , n ) :
s = dict ( )
max_ele = - 10 ** 9
for i in range ( n ) :
s [ arr [ i ] ] = 1
max_ele = max ( max_ele , arr [ i ] )
res = dict ( )
for i in range ( n ) :
if ( arr [ i ] != 0 ) :
for j in range ( arr [ i ] * 2 , max_ele + 1 , arr [... | static void divisibilityCheck ( List < Integer > arr , int n ) {
List < Integer > s = new ArrayList < Integer > ( ) ;
int max_ele = Integer . MIN_VALUE ;
for ( int i = 0 ;
i < n ;
i ++ ) {
s . add ( arr . get ( i ) ) ;
max_ele = Math . max ( max_ele , arr . get ( i ) ) ;
}
LinkedHashSet < Integer ... | Translate the given code from python to java. The input Code is marked with <Code> and </Code>. | <Code>
def divisibilityCheck ( arr , n ) :
s = dict ( )
max_ele = - 10 ** 9
for i in range ( n ) :
s [ arr [ i ] ] = 1
max_ele = max ( max_ele , arr [ i ] )
res = dict ( )
for i in range ( n ) :
if ( arr [ i ] != 0 ) :
for j in range ( arr [ i ] * 2 , max_ele + 1 ... |
python-java-FIND_THE_TWO_REPEATING_ELEMENTS_IN_A_GIVEN_ARRAY_3 | python-java | def printRepeating ( arr , size ) :
print ( " The repeating elements are" , end = " " )
for i in range ( 0 , size ) :
if ( arr [ abs ( arr [ i ] ) ] > 0 ) :
arr [ abs ( arr [ i ] ) ] = ( - 1 ) * arr [ abs ( arr [ i ] ) ]
else :
print ( abs ( arr [ i ] ) , end = " " )
| void printRepeating ( int arr [ ] , int size ) {
int i ;
System . out . println ( "The repeating elements are : " ) ;
for ( i = 0 ;
i < size ;
i ++ ) {
if ( arr [ Math . abs ( arr [ i ] ) ] > 0 ) arr [ Math . abs ( arr [ i ] ) ] = - arr [ Math . abs ( arr [ i ] ) ] ;
else System . out . print ( Math .... | Translate the given code from python to java. The input Code is marked with <Code> and </Code>. | <Code>
def printRepeating ( arr , size ) :
print ( " The repeating elements are" , end = " " )
for i in range ( 0 , size ) :
if ( arr [ abs ( arr [ i ] ) ] > 0 ) :
arr [ abs ( arr [ i ] ) ] = ( - 1 ) * arr [ abs ( arr [ i ] ) ]
else :
print ( abs ( arr [ i ] ) , end = " "... |
python-java-DYNAMIC_PROGRAMMING_SET_17_PALINDROME_PARTITIONING | python-java | def minPalPartion ( str ) :
n = len ( str )
C = [ [ 0 for i in range ( n ) ] for i in range ( n ) ]
P = [ [ False for i in range ( n ) ] for i in range ( n ) ]
j = 0
k = 0
L = 0
for i in range ( n ) :
P [ i ] [ i ] = True
C [ i ] [ i ] = 0
for L in range ( 2 , n + 1 ) :
... | static int minPalPartion ( String str ) {
int n = str . length ( ) ;
int [ ] [ ] C = new int [ n ] [ n ] ;
boolean [ ] [ ] P = new boolean [ n ] [ n ] ;
int i , j , k , L ;
for ( i = 0 ;
i < n ;
i ++ ) {
P [ i ] [ i ] = true ;
C [ i ] [ i ] = 0 ;
}
for ( L = 2 ;
L <= n ;
L ++ ) {
for (... | Translate the given code from python to java. The input Code is marked with <Code> and </Code>. | <Code>
def minPalPartion ( str ) :
n = len ( str )
C = [ [ 0 for i in range ( n ) ] for i in range ( n ) ]
P = [ [ False for i in range ( n ) ] for i in range ( n ) ]
j = 0
k = 0
L = 0
for i in range ( n ) :
P [ i ] [ i ] = True
C [ i ] [ i ] = 0
for L in range ( 2 , n + ... |
python-java-HEIGHT_COMPLETE_BINARY_TREE_HEAP_N_NODES | python-java | def height ( N ) :
return math.ceil ( math.log2 ( N + 1 ) ) - 1
| static int height ( int N ) {
return ( int ) Math . ceil ( Math . log ( N + 1 ) / Math . log ( 2 ) ) - 1 ;
}
| Translate the given code from python to java. The input Code is marked with <Code> and </Code>. | <Code>
def height ( N ) :
return math.ceil ( math.log2 ( N + 1 ) ) - 1
</Code> |
python-java-DISTRIBUTING_ITEMS_PERSON_CANNOT_TAKE_TWO_ITEMS_TYPE_1 | python-java | def checkCount ( arr , n , k ) :
mp = defaultdict ( lambda : 0 )
for i in range ( n ) :
mp [ arr [ i ] ] += 1
for key , values in mp.items ( ) :
if values > 2 * k :
return False
return True
| static boolean checkCount ( int arr [ ] , int n , int k ) {
HashMap < Integer , Integer > hash = new HashMap < > ( ) ;
for ( int i = 0 ;
i < n ;
i ++ ) {
if ( ! hash . containsKey ( arr [ i ] ) ) hash . put ( arr [ i ] , 0 ) ;
hash . put ( arr [ i ] , hash . get ( arr [ i ] ) + 1 ) ;
}
for ( Map . E... | Translate the given code from python to java. The input Code is marked with <Code> and </Code>. | <Code>
def checkCount ( arr , n , k ) :
mp = defaultdict ( lambda : 0 )
for i in range ( n ) :
mp [ arr [ i ] ] += 1
for key , values in mp.items ( ) :
if values > 2 * k :
return False
return True
</Code> |
python-java-REMOVE_CONSECUTIVE_DUPLICATES_STRING | python-java | def removeDuplicates ( S ) :
n = len ( S )
if ( n < 2 ) :
return
j = 0
for i in range ( n ) :
if ( S [ j ] != S [ i ] ) :
j += 1
S [ j ] = S [ i ]
j += 1
S = S [ : j ]
return S
| static void removeDuplicates ( char [ ] S ) {
int n = S . length ;
if ( n < 2 ) {
return ;
}
int j = 0 ;
for ( int i = 1 ;
i < n ;
i ++ ) {
if ( S [ j ] != S [ i ] ) {
j ++ ;
S [ j ] = S [ i ] ;
}
}
System . out . println ( Arrays . copyOfRange ( S , 0 , j + 1 ) ) ;
}
| Translate the given code from python to java. The input Code is marked with <Code> and </Code>. | <Code>
def removeDuplicates ( S ) :
n = len ( S )
if ( n < 2 ) :
return
j = 0
for i in range ( n ) :
if ( S [ j ] != S [ i ] ) :
j += 1
S [ j ] = S [ i ]
j += 1
S = S [ : j ]
return S
</Code> |
python-java-THIRD_LARGEST_ELEMENT_ARRAY_DISTINCT_ELEMENTS_1 | python-java | def thirdLargest ( arr , arr_size ) :
if ( arr_size < 3 ) :
print ( " Invalid Input " )
return
first = arr [ 0 ]
second = - sys.maxsize
third = - sys.maxsize
for i in range ( 1 , arr_size ) :
if ( arr [ i ] > first ) :
third = second
second = first
... | static void thirdLargest ( int arr [ ] , int arr_size ) {
if ( arr_size < 3 ) {
System . out . printf ( " Invalid Input " ) ;
return ;
}
int first = arr [ 0 ] , second = Integer . MIN_VALUE , third = Integer . MIN_VALUE ;
for ( int i = 1 ;
i < arr_size ;
i ++ ) {
if ( arr [ i ] > first ) {
... | Translate the given code from python to java. The input Code is marked with <Code> and </Code>. | <Code>
def thirdLargest ( arr , arr_size ) :
if ( arr_size < 3 ) :
print ( " Invalid Input " )
return
first = arr [ 0 ]
second = - sys.maxsize
third = - sys.maxsize
for i in range ( 1 , arr_size ) :
if ( arr [ i ] > first ) :
third = second
second = fi... |
python-java-LONGEST_INCREASING_ODD_EVEN_SUBSEQUENCE | python-java | def longOddEvenIncSeq ( arr , n ) :
lioes = list ( )
maxLen = 0
for i in range ( n ) :
lioes.append ( 1 )
i = 1
for i in range ( n ) :
for j in range ( i ) :
if ( arr [ i ] > arr [ j ] and ( arr [ i ] + arr [ j ] ) % 2 != 0 and lioes [ i ] < lioes [ j ] + 1 ) :
... | public static int longOddEvenIncSeq ( int arr [ ] , int n ) {
int [ ] lioes = new int [ n ] ;
int maxLen = 0 ;
for ( int i = 0 ;
i < n ;
i ++ ) lioes [ i ] = 1 ;
for ( int i = 1 ;
i < n ;
i ++ ) for ( int j = 0 ;
j < i ;
j ++ ) if ( arr [ i ] > arr [ j ] && ( arr [ i ] + arr [ j ] ) % 2 != 0 && lioe... | Translate the given code from python to java. The input Code is marked with <Code> and </Code>. | <Code>
def longOddEvenIncSeq ( arr , n ) :
lioes = list ( )
maxLen = 0
for i in range ( n ) :
lioes.append ( 1 )
i = 1
for i in range ( n ) :
for j in range ( i ) :
if ( arr [ i ] > arr [ j ] and ( arr [ i ] + arr [ j ] ) % 2 != 0 and lioes [ i ] < lioes [ j ] + 1 ) :
... |
python-java-ADD_1_TO_A_GIVEN_NUMBER_1 | python-java | def addOne ( x ) :
return ( - ( ~ x ) )
| static int addOne ( int x ) {
return ( - ( ~ x ) ) ;
}
| Translate the given code from python to java. The input Code is marked with <Code> and </Code>. | <Code>
def addOne ( x ) :
return ( - ( ~ x ) )
</Code> |
python-java-NUMBER_DECIMAL_NUMBERS_LENGTH_K_STRICT_MONOTONE | python-java | def getNumStrictMonotone ( ln ) :
DP = [ [ 0 ] * DP_s for _ in range ( ln ) ]
for i in range ( DP_s ) :
DP [ 0 ] [ i ] = i + 1
for i in range ( 1 , ln ) :
for j in range ( 1 , DP_s ) :
DP [ i ] [ j ] = DP [ i - 1 ] [ j - 1 ] + DP [ i ] [ j - 1 ]
return DP [ ln - 1 ] [ DP_s - ... | static int getNumStrictMonotone ( int len ) {
int [ ] [ ] DP = new int [ len ] [ DP_s ] ;
for ( int i = 0 ;
i < DP_s ;
++ i ) DP [ 0 ] [ i ] = i + 1 ;
for ( int i = 1 ;
i < len ;
++ i ) for ( int j = 1 ;
j < DP_s ;
++ j ) DP [ i ] [ j ] = DP [ i - 1 ] [ j - 1 ] + DP [ i ] [ j - 1 ] ;
return DP [ len... | Translate the given code from python to java. The input Code is marked with <Code> and </Code>. | <Code>
def getNumStrictMonotone ( ln ) :
DP = [ [ 0 ] * DP_s for _ in range ( ln ) ]
for i in range ( DP_s ) :
DP [ 0 ] [ i ] = i + 1
for i in range ( 1 , ln ) :
for j in range ( 1 , DP_s ) :
DP [ i ] [ j ] = DP [ i - 1 ] [ j - 1 ] + DP [ i ] [ j - 1 ]
return DP [ ln - 1 ] [ ... |
python-java-SEARCH_ALMOST_SORTED_ARRAY | python-java | def binarySearch ( arr , l , r , x ) :
if ( r >= l ) :
mid = int ( l + ( r - l ) / 2 )
if ( arr [ mid ] == x ) : return mid
if ( mid > l and arr [ mid - 1 ] == x ) :
return ( mid - 1 )
if ( mid < r and arr [ mid + 1 ] == x ) :
return ( mid + 1 )
if ( a... | int binarySearch ( int arr [ ] , int l , int r , int x ) {
if ( r >= l ) {
int mid = l + ( r - l ) / 2 ;
if ( arr [ mid ] == x ) return mid ;
if ( mid > l && arr [ mid - 1 ] == x ) return ( mid - 1 ) ;
if ( mid < r && arr [ mid + 1 ] == x ) return ( mid + 1 ) ;
if ( arr [ mid ] > x ) return binary... | Translate the given code from python to java. The input Code is marked with <Code> and </Code>. | <Code>
def binarySearch ( arr , l , r , x ) :
if ( r >= l ) :
mid = int ( l + ( r - l ) / 2 )
if ( arr [ mid ] == x ) : return mid
if ( mid > l and arr [ mid - 1 ] == x ) :
return ( mid - 1 )
if ( mid < r and arr [ mid + 1 ] == x ) :
return ( mid + 1 )
... |
python-java-BRESENHAMS_LINE_GENERATION_ALGORITHM | python-java | def bresenham ( x1 , y1 , x2 , y2 ) :
m_new = 2 * ( y2 - y1 )
slope_error_new = m_new - ( x2 - x1 )
y = y1
for x in range ( x1 , x2 + 1 ) :
print ( "(" , x , "," , y , ")\n" )
slope_error_new = slope_error_new + m_new
if ( slope_error_new >= 0 ) :
y = y + 1
... | static void bresenham ( int x1 , int y1 , int x2 , int y2 ) {
int m_new = 2 * ( y2 - y1 ) ;
int slope_error_new = m_new - ( x2 - x1 ) ;
for ( int x = x1 , y = y1 ;
x <= x2 ;
x ++ ) {
System . out . print ( "(" + x + "," + y + ")\n" ) ;
slope_error_new += m_new ;
if ( slope_error_new >= 0 ) {
... | Translate the given code from python to java. The input Code is marked with <Code> and </Code>. | <Code>
def bresenham ( x1 , y1 , x2 , y2 ) :
m_new = 2 * ( y2 - y1 )
slope_error_new = m_new - ( x2 - x1 )
y = y1
for x in range ( x1 , x2 + 1 ) :
print ( "(" , x , "," , y , ")\n" )
slope_error_new = slope_error_new + m_new
if ( slope_error_new >= 0 ) :
y = y + 1
... |
python-java-HIGHWAY_BILLBOARD_PROBLEM | python-java | def maxRevenue ( m , x , revenue , n , t ) :
maxRev = [ 0 ] * ( m + 1 )
nxtbb = 0
for i in range ( 1 , m + 1 ) :
if ( nxtbb < n ) :
if ( x [ nxtbb ] != i ) :
maxRev [ i ] = maxRev [ i - 1 ]
else :
if ( i <= t ) :
maxRev [ i ... | static int maxRevenue ( int m , int [ ] x , int [ ] revenue , int n , int t ) {
int [ ] maxRev = new int [ m + 1 ] ;
for ( int i = 0 ;
i < m + 1 ;
i ++ ) maxRev [ i ] = 0 ;
int nxtbb = 0 ;
for ( int i = 1 ;
i <= m ;
i ++ ) {
if ( nxtbb < n ) {
if ( x [ nxtbb ] != i ) maxRev [ i ] = maxRev [ i ... | Translate the given code from python to java. The input Code is marked with <Code> and </Code>. | <Code>
def maxRevenue ( m , x , revenue , n , t ) :
maxRev = [ 0 ] * ( m + 1 )
nxtbb = 0
for i in range ( 1 , m + 1 ) :
if ( nxtbb < n ) :
if ( x [ nxtbb ] != i ) :
maxRev [ i ] = maxRev [ i - 1 ]
else :
if ( i <= t ) :
maxR... |
python-java-PROGRAM_FIND_LINE_PASSING_2_POINTS | python-java | def lineFromPoints ( P , Q ) :
a = Q [ 1 ] - P [ 1 ]
b = P [ 0 ] - Q [ 0 ]
c = a * ( P [ 0 ] ) + b * ( P [ 1 ] )
if ( b < 0 ) :
print ( "The line passing through points P and Q is:" , a , "x " , b , "y = " , c , "\n" )
else :
print ( "The line passing through points P and Q is: " , a... | static void lineFromPoints ( Pair P , Pair Q ) {
int a = Q . second - P . second ;
int b = P . first - Q . first ;
int c = a * ( P . first ) + b * ( P . second ) ;
if ( b < 0 ) {
System . out . println ( "The line passing through points P and Q is: " + a + "x " + b + "y = " + c ) ;
}
else {
System .... | Translate the given code from python to java. The input Code is marked with <Code> and </Code>. | <Code>
def lineFromPoints ( P , Q ) :
a = Q [ 1 ] - P [ 1 ]
b = P [ 0 ] - Q [ 0 ]
c = a * ( P [ 0 ] ) + b * ( P [ 1 ] )
if ( b < 0 ) :
print ( "The line passing through points P and Q is:" , a , "x " , b , "y = " , c , "\n" )
else :
print ( "The line passing through points P and Q is... |
python-java-CHINESE_REMAINDER_THEOREM_SET_1_INTRODUCTION | python-java | def findMinX ( num , rem , k ) :
x = 1
while ( True ) :
j = 0
while ( j < k ) :
if ( x % num [ j ] != rem [ j ] ) :
break
j += 1
if ( j == k ) :
return x
x += 1
| static int findMinX ( int num [ ] , int rem [ ] , int k ) {
int x = 1 ;
while ( true ) {
int j ;
for ( j = 0 ;
j < k ;
j ++ ) if ( x % num [ j ] != rem [ j ] ) break ;
if ( j == k ) return x ;
x ++ ;
}
}
| Translate the given code from python to java. The input Code is marked with <Code> and </Code>. | <Code>
def findMinX ( num , rem , k ) :
x = 1
while ( True ) :
j = 0
while ( j < k ) :
if ( x % num [ j ] != rem [ j ] ) :
break
j += 1
if ( j == k ) :
return x
x += 1
</Code> |
python-java-FIND_A_TRIPLET_THAT_SUM_TO_A_GIVEN_VALUE | python-java | def find3Numbers ( A , arr_size , sum ) :
for i in range ( 0 , arr_size - 2 ) :
for j in range ( i + 1 , arr_size - 1 ) :
for k in range ( j + 1 , arr_size ) :
if A [ i ] + A [ j ] + A [ k ] == sum :
print ( "Triplet is" , A [ i ] , ", " , A [ j ] , ", " , A [... | boolean find3Numbers ( int A [ ] , int arr_size , int sum ) {
int l , r ;
for ( int i = 0 ;
i < arr_size - 2 ;
i ++ ) {
for ( int j = i + 1 ;
j < arr_size - 1 ;
j ++ ) {
for ( int k = j + 1 ;
k < arr_size ;
k ++ ) {
if ( A [ i ] + A [ j ] + A [ k ] == sum ) {
Syst... | Translate the given code from python to java. The input Code is marked with <Code> and </Code>. | <Code>
def find3Numbers ( A , arr_size , sum ) :
for i in range ( 0 , arr_size - 2 ) :
for j in range ( i + 1 , arr_size - 1 ) :
for k in range ( j + 1 , arr_size ) :
if A [ i ] + A [ j ] + A [ k ] == sum :
print ( "Triplet is" , A [ i ] , ", " , A [ j ] , ", ... |
python-java-K_MAXIMUM_SUM_COMBINATIONS_TWO_ARRAYS | python-java | def KMaxCombinations ( A , B , N , K ) :
pq = PriorityQueue ( )
for i in range ( 0 , N ) :
for j in range ( 0 , N ) :
a = A [ i ] + B [ j ]
pq.put ( ( - a , a ) )
count = 0
while ( count < K ) :
print ( pq.get ( ) [ 1 ] )
count = count + 1
| static void KMaxCombinations ( int A [ ] , int B [ ] , int N , int K ) {
PriorityQueue < Integer > pq = new PriorityQueue < Integer > ( Collections . reverseOrder ( ) ) ;
for ( int i = 0 ;
i < N ;
i ++ ) for ( int j = 0 ;
j < N ;
j ++ ) pq . add ( A [ i ] + B [ j ] ) ;
int count = 0 ;
while ( count < K ... | Translate the given code from python to java. The input Code is marked with <Code> and </Code>. | <Code>
def KMaxCombinations ( A , B , N , K ) :
pq = PriorityQueue ( )
for i in range ( 0 , N ) :
for j in range ( 0 , N ) :
a = A [ i ] + B [ j ]
pq.put ( ( - a , a ) )
count = 0
while ( count < K ) :
print ( pq.get ( ) [ 1 ] )
count = count + 1
</Code> |
python-java-TRIANGULAR_MATCHSTICK_NUMBER | python-java | def numberOfSticks ( x ) :
return ( 3 * x * ( x + 1 ) ) / 2
| public static int numberOfSticks ( int x ) {
return ( 3 * x * ( x + 1 ) ) / 2 ;
}
| Translate the given code from python to java. The input Code is marked with <Code> and </Code>. | <Code>
def numberOfSticks ( x ) :
return ( 3 * x * ( x + 1 ) ) / 2
</Code> |
python-java-COUNT_SUBSTRINGS_WITH_SAME_FIRST_AND_LAST_CHARACTERS_1 | python-java | def countSubstringWithEqualEnds ( s ) :
result = 0
n = len ( s )
count = [ 0 ] * MAX_CHAR
for i in range ( n ) :
count [ ord ( s [ i ] ) - ord ( 'a' ) ] += 1
for i in range ( MAX_CHAR ) :
result += ( count [ i ] * ( count [ i ] + 1 ) / 2 )
return result
| static int countSubstringWithEqualEnds ( String s ) {
int result = 0 ;
int n = s . length ( ) ;
int [ ] count = new int [ MAX_CHAR ] ;
for ( int i = 0 ;
i < n ;
i ++ ) count [ s . charAt ( i ) - ' a ' ] ++ ;
for ( int i = 0 ;
i < MAX_CHAR ;
i ++ ) result += ( count [ i ] * ( count [ i ] + 1 ) / 2 ) ;
... | Translate the given code from python to java. The input Code is marked with <Code> and </Code>. | <Code>
def countSubstringWithEqualEnds ( s ) :
result = 0
n = len ( s )
count = [ 0 ] * MAX_CHAR
for i in range ( n ) :
count [ ord ( s [ i ] ) - ord ( 'a' ) ] += 1
for i in range ( MAX_CHAR ) :
result += ( count [ i ] * ( count [ i ] + 1 ) / 2 )
return result
</Code> |
python-java-DIVISIBILITY_BY_7 | python-java | def isDivisibleBy7 ( num ) :
if num < 0 :
return isDivisibleBy7 ( - num )
if ( num == 0 or num == 7 ) :
return True
if ( num < 10 ) :
return False
return isDivisibleBy7 ( num // 10 - 2 * ( num - num // 10 * 10 ) )
| static boolean isDivisibleBy7 ( int num ) {
if ( num < 0 ) return isDivisibleBy7 ( - num ) ;
if ( num == 0 || num == 7 ) return true ;
if ( num < 10 ) return false ;
return isDivisibleBy7 ( num / 10 - 2 * ( num - num / 10 * 10 ) ) ;
}
| Translate the given code from python to java. The input Code is marked with <Code> and </Code>. | <Code>
def isDivisibleBy7 ( num ) :
if num < 0 :
return isDivisibleBy7 ( - num )
if ( num == 0 or num == 7 ) :
return True
if ( num < 10 ) :
return False
return isDivisibleBy7 ( num // 10 - 2 * ( num - num // 10 * 10 ) )
</Code> |
python-java-FIND_ONE_MULTIPLE_REPEATING_ELEMENTS_READ_ARRAY | python-java | def findRepeatingNumber ( arr , n ) :
sq = sqrt ( n )
range__ = int ( ( n / sq ) + 1 )
count = [ 0 for i in range ( range__ ) ]
for i in range ( 0 , n + 1 , 1 ) :
count [ int ( ( arr [ i ] - 1 ) / sq ) ] += 1
selected_block = range__ - 1
for i in range ( 0 , range__ - 1 , 1 ) :
i... | static int findRepeatingNumber ( int [ ] arr , int n ) {
int sq = ( int ) Math . sqrt ( n ) ;
int range = ( n / sq ) + 1 ;
int [ ] count = new int [ range ] ;
for ( int i = 0 ;
i <= n ;
i ++ ) {
count [ ( arr [ i ] - 1 ) / sq ] ++ ;
}
int selected_block = range - 1 ;
for ( int i = 0 ;
i < range ... | Translate the given code from python to java. The input Code is marked with <Code> and </Code>. | <Code>
def findRepeatingNumber ( arr , n ) :
sq = sqrt ( n )
range__ = int ( ( n / sq ) + 1 )
count = [ 0 for i in range ( range__ ) ]
for i in range ( 0 , n + 1 , 1 ) :
count [ int ( ( arr [ i ] - 1 ) / sq ) ] += 1
selected_block = range__ - 1
for i in range ( 0 , range__ - 1 , 1 ) :
... |
python-java-FIND_N_TH_ELEMENT_FROM_STERNS_DIATOMIC_SERIES | python-java | def findSDSFunc ( n ) :
DP = [ 0 ] * ( n + 1 )
DP [ 0 ] = 0
DP [ 1 ] = 1
for i in range ( 2 , n + 1 ) :
if ( int ( i % 2 ) == 0 ) :
DP [ i ] = DP [ int ( i / 2 ) ]
else :
DP [ i ] = ( DP [ int ( ( i - 1 ) / 2 ) ] + DP [ int ( ( i + 1 ) / 2 ) ] )
return DP [ n ... | static int findSDSFunc ( int n ) {
int DP [ ] = new int [ n + 1 ] ;
DP [ 0 ] = 0 ;
DP [ 1 ] = 1 ;
for ( int i = 2 ;
i <= n ;
i ++ ) {
if ( i % 2 == 0 ) DP [ i ] = DP [ i / 2 ] ;
else DP [ i ] = DP [ ( i - 1 ) / 2 ] + DP [ ( i + 1 ) / 2 ] ;
}
return DP [ n ] ;
}
| Translate the given code from python to java. The input Code is marked with <Code> and </Code>. | <Code>
def findSDSFunc ( n ) :
DP = [ 0 ] * ( n + 1 )
DP [ 0 ] = 0
DP [ 1 ] = 1
for i in range ( 2 , n + 1 ) :
if ( int ( i % 2 ) == 0 ) :
DP [ i ] = DP [ int ( i / 2 ) ]
else :
DP [ i ] = ( DP [ int ( ( i - 1 ) / 2 ) ] + DP [ int ( ( i + 1 ) / 2 ) ] )
return ... |
python-java-RECURSIVE_C_PROGRAM_LINEARLY_SEARCH_ELEMENT_GIVEN_ARRAY | python-java | def recSearch ( arr , l , r , x ) :
if r < l :
return - 1
if arr [ l ] == x :
return l
if arr [ r ] == x :
return r
return recSearch ( arr , l + 1 , r - 1 , x )
| static int recSearch ( int arr [ ] , int l , int r , int x ) {
if ( r < l ) return - 1 ;
if ( arr [ l ] == x ) return l ;
if ( arr [ r ] == x ) return r ;
return recSearch ( arr , l + 1 , r - 1 , x ) ;
}
| Translate the given code from python to java. The input Code is marked with <Code> and </Code>. | <Code>
def recSearch ( arr , l , r , x ) :
if r < l :
return - 1
if arr [ l ] == x :
return l
if arr [ r ] == x :
return r
return recSearch ( arr , l + 1 , r - 1 , x )
</Code> |
python-java-CHECK_LARGE_NUMBER_DIVISIBLE_4_NOT | python-java | def check ( st ) :
n = len ( st )
if ( n == 0 ) :
return False
if ( n == 1 ) :
return ( ( st [ 0 ] - '0' ) % 4 == 0 )
last = ( int ) ( st [ n - 1 ] )
second_last = ( int ) ( st [ n - 2 ] )
return ( ( second_last * 10 + last ) % 4 == 0 )
| static boolean check ( String str ) {
int n = str . length ( ) ;
if ( n == 0 ) return false ;
if ( n == 1 ) return ( ( str . charAt ( 0 ) - ' 0 ' ) % 4 == 0 ) ;
int last = str . charAt ( n - 1 ) - ' 0 ' ;
int second_last = str . charAt ( n - 2 ) - ' 0 ' ;
return ( ( second_last * 10 + last ) % 4 == 0 ) ;
}
| Translate the given code from python to java. The input Code is marked with <Code> and </Code>. | <Code>
def check ( st ) :
n = len ( st )
if ( n == 0 ) :
return False
if ( n == 1 ) :
return ( ( st [ 0 ] - '0' ) % 4 == 0 )
last = ( int ) ( st [ n - 1 ] )
second_last = ( int ) ( st [ n - 2 ] )
return ( ( second_last * 10 + last ) % 4 == 0 )
</Code> |
python-java-LOWER_CASE_UPPER_CASE_INTERESTING_FACT | python-java | def to_upper ( string ) :
for i in range ( len ( string ) ) :
if ( 'a' <= string [ i ] <= 'z' ) :
string = ( string [ 0 : i ] + chr ( ord ( string [ i ] ) - ord ( 'a' ) + ord ( 'A' ) ) + string [ i + 1 : ] )
return string
| static String to_upper ( char [ ] in ) {
for ( int i = 0 ;
i < in . length ;
i ++ ) {
if ( ' a ' <= in [ i ] & in [ i ] <= ' z ' ) {
in [ i ] = ( char ) ( in [ i ] - ' a ' + ' A ' ) ;
}
}
return String . valueOf ( in ) ;
}
| Translate the given code from python to java. The input Code is marked with <Code> and </Code>. | <Code>
def to_upper ( string ) :
for i in range ( len ( string ) ) :
if ( 'a' <= string [ i ] <= 'z' ) :
string = ( string [ 0 : i ] + chr ( ord ( string [ i ] ) - ord ( 'a' ) + ord ( 'A' ) ) + string [ i + 1 : ] )
return string
</Code> |
python-java-REMOVE_MINIMUM_NUMBER_CHARACTERS_TWO_STRINGS_BECOME_ANAGRAM | python-java | def remAnagram ( str1 , str2 ) :
count1 = [ 0 ] * CHARS
count2 = [ 0 ] * CHARS
i = 0
while i < len ( str1 ) :
count1 [ ord ( str1 [ i ] ) - ord ( 'a' ) ] += 1
i += 1
i = 0
while i < len ( str2 ) :
count2 [ ord ( str2 [ i ] ) - ord ( 'a' ) ] += 1
i += 1
result ... | static int remAnagram ( String str1 , String str2 ) {
int count1 [ ] = new int [ 26 ] ;
int count2 [ ] = new int [ 26 ] ;
for ( int i = 0 ;
i < str1 . length ( ) ;
i ++ ) count1 [ str1 . charAt ( i ) - ' a ' ] ++ ;
for ( int i = 0 ;
i < str2 . length ( ) ;
i ++ ) count2 [ str2 . charAt ( i ) - ' a ' ] +... | Translate the given code from python to java. The input Code is marked with <Code> and </Code>. | <Code>
def remAnagram ( str1 , str2 ) :
count1 = [ 0 ] * CHARS
count2 = [ 0 ] * CHARS
i = 0
while i < len ( str1 ) :
count1 [ ord ( str1 [ i ] ) - ord ( 'a' ) ] += 1
i += 1
i = 0
while i < len ( str2 ) :
count2 [ ord ( str2 [ i ] ) - ord ( 'a' ) ] += 1
i += 1
... |
python-java-SORT_ARRAY_WAVE_FORM_2_1 | python-java | def sortInWave ( arr , n ) :
for i in range ( 0 , n , 2 ) :
if ( i > 0 and arr [ i ] < arr [ i - 1 ] ) :
arr [ i ] , arr [ i - 1 ] = arr [ i - 1 ] , arr [ i ]
if ( i < n - 1 and arr [ i ] < arr [ i + 1 ] ) :
arr [ i ] , arr [ i + 1 ] = arr [ i + 1 ] , arr [ i ]
| void sortInWave ( int arr [ ] , int n ) {
for ( int i = 0 ;
i < n ;
i += 2 ) {
if ( i > 0 && arr [ i - 1 ] > arr [ i ] ) swap ( arr , i - 1 , i ) ;
if ( i < n - 1 && arr [ i ] < arr [ i + 1 ] ) swap ( arr , i , i + 1 ) ;
}
}
| Translate the given code from python to java. The input Code is marked with <Code> and </Code>. | <Code>
def sortInWave ( arr , n ) :
for i in range ( 0 , n , 2 ) :
if ( i > 0 and arr [ i ] < arr [ i - 1 ] ) :
arr [ i ] , arr [ i - 1 ] = arr [ i - 1 ] , arr [ i ]
if ( i < n - 1 and arr [ i ] < arr [ i + 1 ] ) :
arr [ i ] , arr [ i + 1 ] = arr [ i + 1 ] , arr [ i ]
</Code... |
python-java-FORM_MINIMUM_NUMBER_FROM_GIVEN_SEQUENCE_1 | python-java | def getMinNumberForPattern ( seq ) :
n = len ( seq )
if ( n >= 9 ) :
return "-1"
result = [ None ] * ( n + 1 )
count = 1
for i in range ( n + 1 ) :
if ( i == n or seq [ i ] == 'I' ) :
for j in range ( i - 1 , - 2 , - 1 ) :
result [ j + 1 ] = int ( '0' + st... | static String getMinNumberForPattern ( String seq ) {
int n = seq . length ( ) ;
if ( n >= 9 ) return "-1" ;
char result [ ] = new char [ n + 1 ] ;
int count = 1 ;
for ( int i = 0 ;
i <= n ;
i ++ ) {
if ( i == n || seq . charAt ( i ) == ' I ' ) {
for ( int j = i - 1 ;
j >= - 1 ;
j --... | Translate the given code from python to java. The input Code is marked with <Code> and </Code>. | <Code>
def getMinNumberForPattern ( seq ) :
n = len ( seq )
if ( n >= 9 ) :
return "-1"
result = [ None ] * ( n + 1 )
count = 1
for i in range ( n + 1 ) :
if ( i == n or seq [ i ] == 'I' ) :
for j in range ( i - 1 , - 2 , - 1 ) :
result [ j + 1 ] = int ( '... |
python-java-CHECK_IF_STRING_REMAINS_PALINDROME_AFTER_REMOVING_GIVEN_NUMBER_OF_CHARACTERS | python-java | def isPossible ( str , n ) :
l = len ( str )
if ( l >= n ) :
return True
return False
| static boolean isPossible ( String str , int n ) {
int len = str . length ( ) ;
if ( len >= n ) return true ;
return false ;
}
| Translate the given code from python to java. The input Code is marked with <Code> and </Code>. | <Code>
def isPossible ( str , n ) :
l = len ( str )
if ( l >= n ) :
return True
return False
</Code> |
python-java-FIND_CENTER_CIRCLE_USING_ENDPOINTS_DIAMETER | python-java | def center ( x1 , x2 , y1 , y2 ) :
print ( int ( ( x1 + x2 ) / 2 ) , end = "" )
print ( "," , int ( ( y1 + y2 ) / 2 ) )
| static void center ( int x1 , int x2 , int y1 , int y2 ) {
System . out . print ( ( float ) ( x1 + x2 ) / 2 + ", " + ( float ) ( y1 + y2 ) / 2 ) ;
}
| Translate the given code from python to java. The input Code is marked with <Code> and </Code>. | <Code>
def center ( x1 , x2 , y1 , y2 ) :
print ( int ( ( x1 + x2 ) / 2 ) , end = "" )
print ( "," , int ( ( y1 + y2 ) / 2 ) )
</Code> |
python-java-GREEDY_ALGORITHM_TO_FIND_MINIMUM_NUMBER_OF_COINS | python-java | def findMin ( V ) :
deno = [ 1 , 2 , 5 , 10 , 20 , 50 , 100 , 500 , 1000 ]
n = len ( deno )
ans = [ ]
i = n - 1
while ( i >= 0 ) :
while ( V >= deno [ i ] ) :
V -= deno [ i ]
ans.append ( deno [ i ] )
i -= 1
for i in range ( len ( ans ) ) :
print (... | static void findMin ( int V ) {
Vector < Integer > ans = new Vector < > ( ) ;
for ( int i = n - 1 ;
i >= 0 ;
i -- ) {
while ( V >= deno [ i ] ) {
V -= deno [ i ] ;
ans . add ( deno [ i ] ) ;
}
}
for ( int i = 0 ;
i < ans . size ( ) ;
i ++ ) {
System . out . print ( " " + ans . el... | Translate the given code from python to java. The input Code is marked with <Code> and </Code>. | <Code>
def findMin ( V ) :
deno = [ 1 , 2 , 5 , 10 , 20 , 50 , 100 , 500 , 1000 ]
n = len ( deno )
ans = [ ]
i = n - 1
while ( i >= 0 ) :
while ( V >= deno [ i ] ) :
V -= deno [ i ]
ans.append ( deno [ i ] )
i -= 1
for i in range ( len ( ans ) ) :
... |
python-java-HOW_TO_AVOID_OVERFLOW_IN_MODULAR_MULTIPLICATION | python-java | def mulmod ( a , b , mod ) :
res = 0
a = a % mod
while ( b > 0 ) :
if ( b % 2 == 1 ) :
res = ( res + a ) % mod
a = ( a * 2 ) % mod
b //= 2
return res % mod
| static long mulmod ( long a , long b , long mod ) {
long res = 0 ;
a = a % mod ;
while ( b > 0 ) {
if ( b % 2 == 1 ) {
res = ( res + a ) % mod ;
}
a = ( a * 2 ) % mod ;
b /= 2 ;
}
return res % mod ;
}
| Translate the given code from python to java. The input Code is marked with <Code> and </Code>. | <Code>
def mulmod ( a , b , mod ) :
res = 0
a = a % mod
while ( b > 0 ) :
if ( b % 2 == 1 ) :
res = ( res + a ) % mod
a = ( a * 2 ) % mod
b //= 2
return res % mod
</Code> |
python-java-FIND_NTH_TERM_DRAGON_CURVE_SEQUENCE | python-java | def Dragon_Curve_Sequence ( n ) :
s = "1"
for i in range ( 2 , n + 1 ) :
temp = "1"
prev = '1'
zero = '0'
one = '1'
for j in range ( len ( s ) ) :
temp += s [ j ]
if ( prev == '0' ) :
temp += one
prev = one
... | static String Dragon_Curve_Sequence ( int n ) {
String s = "1" ;
for ( int i = 2 ;
i <= n ;
i ++ ) {
String temp = "1" ;
char prev = ' 1 ' , zero = ' 0 ' , one = ' 1 ' ;
for ( int j = 0 ;
j < s . length ( ) ;
j ++ ) {
temp += s . charAt ( j ) ;
if ( prev == ' 0 ' ) {
temp... | Translate the given code from python to java. The input Code is marked with <Code> and </Code>. | <Code>
def Dragon_Curve_Sequence ( n ) :
s = "1"
for i in range ( 2 , n + 1 ) :
temp = "1"
prev = '1'
zero = '0'
one = '1'
for j in range ( len ( s ) ) :
temp += s [ j ]
if ( prev == '0' ) :
temp += one
prev = one
... |
python-java-MINIMUM_POSITIVE_POINTS_TO_REACH_DESTINATION | python-java | def minInitialPoints ( points ) :
dp = [ [ 0 for x in range ( C + 1 ) ] for y in range ( R + 1 ) ]
m , n = R , C
if points [ m - 1 ] [ n - 1 ] > 0 :
dp [ m - 1 ] [ n - 1 ] = 1
else :
dp [ m - 1 ] [ n - 1 ] = abs ( points [ m - 1 ] [ n - 1 ] ) + 1
for i in range ( m - 2 , - 1 , - 1 ) ... | static int minInitialPoints ( int points [ ] [ ] , int R , int C ) {
int dp [ ] [ ] = new int [ R ] [ C ] ;
int m = R , n = C ;
dp [ m - 1 ] [ n - 1 ] = points [ m - 1 ] [ n - 1 ] > 0 ? 1 : Math . abs ( points [ m - 1 ] [ n - 1 ] ) + 1 ;
for ( int i = m - 2 ;
i >= 0 ;
i -- ) dp [ i ] [ n - 1 ] = Math . max ... | Translate the given code from python to java. The input Code is marked with <Code> and </Code>. | <Code>
def minInitialPoints ( points ) :
dp = [ [ 0 for x in range ( C + 1 ) ] for y in range ( R + 1 ) ]
m , n = R , C
if points [ m - 1 ] [ n - 1 ] > 0 :
dp [ m - 1 ] [ n - 1 ] = 1
else :
dp [ m - 1 ] [ n - 1 ] = abs ( points [ m - 1 ] [ n - 1 ] ) + 1
for i in range ( m - 2 , - 1 ,... |
python-java-FIND_REPETITIVE_ELEMENT_1_N_1 | python-java | def findRepeating ( arr , n ) :
return sum ( arr ) - ( ( ( n - 1 ) * n ) // 2 )
| static int findRepeating ( int [ ] arr , int n ) {
int sum = 0 ;
for ( int i = 0 ;
i < n ;
i ++ ) sum += arr [ i ] ;
return sum - ( ( ( n - 1 ) * n ) / 2 ) ;
}
| Translate the given code from python to java. The input Code is marked with <Code> and </Code>. | <Code>
def findRepeating ( arr , n ) :
return sum ( arr ) - ( ( ( n - 1 ) * n ) // 2 )
</Code> |
python-java-C_PROGRAM_FIND_SECOND_FREQUENT_CHARACTER | python-java | def getSecondMostFreq ( str ) :
NO_OF_CHARS = 256
count = [ 0 ] * NO_OF_CHARS
for i in range ( len ( str ) ) :
count [ ord ( str [ i ] ) ] += 1
first , second = 0 , 0
for i in range ( NO_OF_CHARS ) :
if count [ i ] > count [ first ] :
second = first
first = i
... | static char getSecondMostFreq ( String str ) {
int [ ] count = new int [ NO_OF_CHARS ] ;
int i ;
for ( i = 0 ;
i < str . length ( ) ;
i ++ ) ( count [ str . charAt ( i ) ] ) ++ ;
int first = 0 , second = 0 ;
for ( i = 0 ;
i < NO_OF_CHARS ;
i ++ ) {
if ( count [ i ] > count [ first ] ) {
seco... | Translate the given code from python to java. The input Code is marked with <Code> and </Code>. | <Code>
def getSecondMostFreq ( str ) :
NO_OF_CHARS = 256
count = [ 0 ] * NO_OF_CHARS
for i in range ( len ( str ) ) :
count [ ord ( str [ i ] ) ] += 1
first , second = 0 , 0
for i in range ( NO_OF_CHARS ) :
if count [ i ] > count [ first ] :
second = first
fir... |
python-java-SUM_TWO_LARGE_NUMBERS | python-java | def findSum ( str1 , str2 ) :
if ( len ( str1 ) > len ( str2 ) ) :
t = str1
str1 = str2
str2 = t
str = ""
n1 = len ( str1 )
n2 = len ( str2 )
str1 = str1 [ : : - 1 ]
str2 = str2 [ : : - 1 ]
carry = 0
for i in range ( n1 ) :
sum = ( ( ord ( str1 [ i ] ) - 4... | static String findSum ( String str1 , String str2 ) {
if ( str1 . length ( ) > str2 . length ( ) ) {
String t = str1 ;
str1 = str2 ;
str2 = t ;
}
String str = "" ;
int n1 = str1 . length ( ) , n2 = str2 . length ( ) ;
str1 = new StringBuilder ( str1 ) . reverse ( ) . toString ( ) ;
str2 = new St... | Translate the given code from python to java. The input Code is marked with <Code> and </Code>. | <Code>
def findSum ( str1 , str2 ) :
if ( len ( str1 ) > len ( str2 ) ) :
t = str1
str1 = str2
str2 = t
str = ""
n1 = len ( str1 )
n2 = len ( str2 )
str1 = str1 [ : : - 1 ]
str2 = str2 [ : : - 1 ]
carry = 0
for i in range ( n1 ) :
sum = ( ( ord ( str1 [ i ... |
python-java-NEXT_GREATER_ELEMENT | python-java | def printNGE ( arr ) :
for i in range ( 0 , len ( arr ) , 1 ) :
next = - 1
for j in range ( i + 1 , len ( arr ) , 1 ) :
if arr [ i ] < arr [ j ] :
next = arr [ j ]
break
print ( str ( arr [ i ] ) + " -- " + str ( next ) )
| static void printNGE ( int arr [ ] , int n ) {
int next , i , j ;
for ( i = 0 ;
i < n ;
i ++ ) {
next = - 1 ;
for ( j = i + 1 ;
j < n ;
j ++ ) {
if ( arr [ i ] < arr [ j ] ) {
next = arr [ j ] ;
break ;
}
}
System . out . println ( arr [ i ] + " -- " + next ) ... | Translate the given code from python to java. The input Code is marked with <Code> and </Code>. | <Code>
def printNGE ( arr ) :
for i in range ( 0 , len ( arr ) , 1 ) :
next = - 1
for j in range ( i + 1 , len ( arr ) , 1 ) :
if arr [ i ] < arr [ j ] :
next = arr [ j ]
break
print ( str ( arr [ i ] ) + " -- " + str ( next ) )
</Code> |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.