dhyuti-n/xlcost-variable-roles huggingface dataset:
Java program:
class sum_dig { static int lookup [ ] [ ] = new int [ 101 ] [ 501 ] ; static int countRec ( int n , int sum ) { if ( n == 0 ) return sum == 0 ? 1 : 0 ; if ( lookup [ n ] [ sum ] != - 1 ) return lookup [ n ] [ sum ] ; int ans = 0 ; for ( int i = 0 ; i < 10 ; i ++ ) if ( sum - i >= 0 ) ans += countRec ( n - 1 , sum - i ) ; return lookup [ n ] [ sum ] = ans ; } static int finalCount ( int n , int sum ) { for ( int i = 0 ; i <= 100 ; ++ i ) { for ( int j = 0 ; j <= 500 ; ++ j ) { lookup [ i ] [ j ] = - 1 ; } } int ans = 0 ; for ( int i = 1 ; i <= 9 ; i ++ ) if ( sum - i >= 0 ) ans += countRec ( n - 1 , sum - i ) ; return ans ; } public static void main ( String args [ ] ) { int n = 3 , sum = 5 ; System . out . println ( finalCount ( n , sum ) ) ; } }

Index/key variables: i, j, n, sum
Accumulator variables: ans, i
Iterator variables: i, j
Class/struct names: sum_dig
Java program:
public class GFG { private static void findCount ( int n , int sum ) { int start = ( int ) Math . pow ( 10 , n - 1 ) ; int end = ( int ) Math . pow ( 10 , n ) - 1 ; int count = 0 ; int i = start ; while ( i < end ) { int cur = 0 ; int temp = i ; while ( temp != 0 ) { cur += temp % 10 ; temp = temp / 10 ; } if ( cur == sum ) { count ++ ; i += 9 ; } else i ++ ; } System . out . println ( count ) ; } public static void main ( String [ ] args ) { int n = 3 ; int sum = 5 ; findCount ( n , sum ) ; } }

Accumulator variables: count, cur, i
Class/struct names: GFG
Java program:
class squares { static int getMinSquares ( int n ) { if ( n <= 3 ) return n ; int res = n ; for ( int x = 1 ; x <= n ; x ++ ) { int temp = x * x ; if ( temp > n ) break ; else res = Math . min ( res , 1 + getMinSquares ( n - temp ) ) ; } return res ; } public static void main ( String args [ ] ) { System . out . println ( getMinSquares ( 6 ) ) ; } }

Accumulator variables: x
Iterator variables: x
Class/struct names: squares
Java program:
class squares { static int getMinSquares ( int n ) { if ( n <= 3 ) return n ; int dp [ ] = new int [ n + 1 ] ; dp [ 0 ] = 0 ; dp [ 1 ] = 1 ; dp [ 2 ] = 2 ; dp [ 3 ] = 3 ; for ( int i = 4 ; i <= n ; i ++ ) { dp [ i ] = i ; for ( int x = 1 ; x <= Math . ceil ( Math . sqrt ( i ) ) ; x ++ ) { int temp = x * x ; if ( temp > i ) break ; else dp [ i ] = Math . min ( dp [ i ] , 1 + dp [ i - temp ] ) ; } } int res = dp [ n ] ; return res ; } public static void main ( String args [ ] ) { System . out . println ( getMinSquares ( 6 ) ) ; } }

Index/key variables: i, n
Accumulator variables: i, x
Iterator variables: i, x
Class/struct names: squares
Java program:
import java . util . * ; import java . awt . Point ; class GFG { public static int numSquares ( int n ) { int visited [ ] = new int [ n + 1 ] ; Queue < Point > q = new LinkedList < > ( ) ; int ans = Integer . MAX_VALUE ; q . add ( new Point ( n , 0 ) ) ; visited [ n ] = 1 ; while ( q . size ( ) != 0 ) { Point p = q . peek ( ) ; q . poll ( ) ; if ( p . x == 0 ) ans = Math . min ( ans , p . y ) ; for ( int i = 1 ; i * i <= p . x ; i ++ ) { int path = ( p . x - ( i * i ) ) ; if ( path >= 0 && ( visited [ path ] == 0 path == 0 ) ) { visited [ path ] = 1 ; q . add ( new Point ( path , p . y + 1 ) ) ; } } } return ans ; } public static void main ( String [ ] args ) { System . out . println ( numSquares ( 12 ) ) ; } }

Index/key variables: n, path
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
class coin { static int minCoins ( int coins [ ] , int m , int V ) { if ( V == 0 ) return 0 ; int res = Integer . MAX_VALUE ; for ( int i = 0 ; i < m ; i ++ ) { if ( coins [ i ] <= V ) { int sub_res = minCoins ( coins , m , V - coins [ i ] ) ; if ( sub_res != Integer . MAX_VALUE && sub_res + 1 < res ) res = sub_res + 1 ; } } return res ; } public static void main ( String args [ ] ) { int coins [ ] = { 9 , 6 , 5 , 1 } ; int m = coins . length ; int V = 11 ; System . out . println ( " Minimum ▁ coins ▁ required ▁ is ▁ " + minCoins ( coins , m , V ) ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: coin
Java program:
import java . io . * ; class GFG { 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 = table [ i - coins [ j ] ] ; if ( sub_res != Integer . MAX_VALUE && sub_res + 1 < table [ i ] ) table [ i ] = sub_res + 1 ; } } if ( table [ V ] == Integer . MAX_VALUE ) return - 1 ; return table [ V ] ; } public static void main ( String [ ] args ) { int coins [ ] = { 9 , 6 , 5 , 1 } ; int m = coins . length ; int V = 11 ; System . out . println ( " Minimum ▁ coins ▁ required ▁ is ▁ " + minCoins ( coins , m , V ) ) ; } }

Index/key variables: V, i, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
class GFG { static int superSeq ( String X , String Y , int m , int n ) { if ( m == 0 ) return n ; if ( n == 0 ) return m ; if ( X . charAt ( m - 1 ) == Y . charAt ( n - 1 ) ) return 1 + superSeq ( X , Y , m - 1 , n - 1 ) ; return 1 + Math . min ( superSeq ( X , Y , m - 1 , n ) , superSeq ( X , Y , m , n - 1 ) ) ; } public static void main ( String args [ ] ) { String X = " AGGTAB " ; String Y = " GXTXAYB " ; System . out . println ( " Length ▁ of ▁ the ▁ shortest " + " supersequence ▁ is : ▁ " + superSeq ( X , Y , X . length ( ) , Y . length ( ) ) ) ; } }

Class/struct names: GFG
Java program:
class GFG { static int superSeq ( String X , String Y , int m , int n ) { 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 ] = i ; else if ( X . charAt ( i - 1 ) == Y . charAt ( j - 1 ) ) dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ] ; else dp [ i ] [ j ] = 1 + Math . min ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] ) ; } } return dp [ m ] [ n ] ; } public static void main ( String args [ ] ) { String X = " AGGTAB " ; String Y = " GXTXAYB " ; System . out . println ( " Length ▁ of ▁ the ▁ shortest ▁ supersequence ▁ is ▁ " + superSeq ( X , Y , X . length ( ) , Y . length ( ) ) ) ; } }

Index/key variables: i, j, m, n
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static int sumOfDigitsFrom1ToN ( int n ) { int result = 0 ; for ( int x = 1 ; x <= n ; x ++ ) result += sumOfDigits ( x ) ; return result ; } static int sumOfDigits ( int x ) { int sum = 0 ; while ( x != 0 ) { sum += x % 10 ; x = x / 10 ; } return sum ; } public static void main ( String args [ ] ) { int n = 328 ; System . out . println ( " Sum ▁ of ▁ digits ▁ in ▁ numbers " + " ▁ from ▁ 1 ▁ to ▁ " + n + " ▁ is ▁ " + sumOfDigitsFrom1ToN ( n ) ) ; } }

Accumulator variables: result, sum, x
Iterator variables: x
Class/struct names: GFG
Java program:
import java . io . * ; import java . math . * ; class GFG { static int sumOfDigitsFrom1ToN ( int n ) { if ( n < 10 ) return ( n * ( n + 1 ) / 2 ) ; int d = ( int ) ( Math . log10 ( n ) ) ; int a [ ] = new int [ d + 1 ] ; a [ 0 ] = 0 ; a [ 1 ] = 45 ; for ( int i = 2 ; i <= d ; i ++ ) a [ i ] = a [ i - 1 ] * 10 + 45 * ( int ) ( Math . ceil ( Math . pow ( 10 , i - 1 ) ) ) ; int p = ( int ) ( Math . ceil ( Math . pow ( 10 , d ) ) ) ; int msd = n / p ; return ( msd * a [ d ] + ( msd * ( msd - 1 ) / 2 ) * p + msd * ( 1 + n % p ) + sumOfDigitsFrom1ToN ( n % p ) ) ; } public static void main ( String args [ ] ) { int n = 328 ; System . out . println ( " Sum ▁ of ▁ digits ▁ in ▁ numbers ▁ " + " from ▁ 1 ▁ to ▁ " + n + " ▁ is ▁ " + sumOfDigitsFrom1ToN ( n ) ) ; } }

Index/key variables: d, i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; import java . math . * ; class GFG { static int sumOfDigitsFrom1ToNUtil ( int n , int a [ ] ) { if ( n < 10 ) return ( n * ( n + 1 ) / 2 ) ; int d = ( int ) ( Math . log10 ( n ) ) ; int p = ( int ) ( Math . ceil ( Math . pow ( 10 , d ) ) ) ; int msd = n / p ; return ( msd * a [ d ] + ( msd * ( msd - 1 ) / 2 ) * p + msd * ( 1 + n % p ) + sumOfDigitsFrom1ToNUtil ( n % p , a ) ) ; } static int sumOfDigitsFrom1ToN ( int n ) { int d = ( int ) ( Math . log10 ( n ) ) ; int a [ ] = new int [ d + 1 ] ; a [ 0 ] = 0 ; a [ 1 ] = 45 ; for ( int i = 2 ; i <= d ; i ++ ) a [ i ] = a [ i - 1 ] * 10 + 45 * ( int ) ( Math . ceil ( Math . pow ( 10 , i - 1 ) ) ) ; return sumOfDigitsFrom1ToNUtil ( n , a ) ; } public static void main ( String args [ ] ) { int n = 328 ; System . out . println ( " Sum ▁ of ▁ digits ▁ in ▁ numbers ▁ " + " from ▁ 1 ▁ to ▁ " + n + " ▁ is ▁ " + sumOfDigitsFrom1ToN ( n ) ) ; } }

Index/key variables: d, i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
class Building { static int countWays ( int N ) { if ( N == 1 ) return 4 ; int countB = 1 , countS = 1 , prev_countB , prev_countS ; for ( int i = 2 ; i <= N ; i ++ ) { prev_countB = countB ; prev_countS = countS ; countS = prev_countB + prev_countS ; countB = prev_countS ; } int result = countS + countB ; return ( result * result ) ; } public static void main ( String args [ ] ) { int N = 3 ; System . out . println ( " Count ▁ of ▁ ways ▁ for ▁ " + N + " ▁ sections ▁ is ▁ " + countWays ( N ) ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: Building
Java program:
class GFG { static int min ( int x , int y ) { return ( x < y ) ? x : y ; } static class node { int data ; int vc ; node left , right ; } ; static int vCover ( node root ) { if ( root == null ) return 0 ; if ( root . left == null && root . right == null ) return 0 ; if ( root . vc != 0 ) return root . vc ; int size_incl = 1 + vCover ( root . left ) + vCover ( root . right ) ; int size_excl = 0 ; if ( root . left != null ) size_excl += 1 + vCover ( root . left . left ) + vCover ( root . left . right ) ; if ( root . right != null ) size_excl += 1 + vCover ( root . right . left ) + vCover ( root . right . right ) ; root . vc = Math . min ( size_incl , size_excl ) ; return root . vc ; } static node newNode ( int data ) { node temp = new node ( ) ; temp . data = data ; temp . left = temp . right = null ; temp . vc = 0 ; return temp ; } public static void main ( String [ ] args ) { node root = newNode ( 20 ) ; root . left = newNode ( 8 ) ; root . left . left = newNode ( 4 ) ; root . left . right = newNode ( 12 ) ; root . left . right . left = newNode ( 10 ) ; root . left . right . right = newNode ( 14 ) ; root . right = newNode ( 22 ) ; root . right . right = newNode ( 25 ) ; System . out . printf ( " Size ▁ of ▁ the ▁ smallest ▁ vertex " + " cover ▁ is ▁ % d ▁ " , vCover ( root ) ) ; } }

Accumulator variables: size_excl
Class/struct names: GFG, node
Java program:
import java . util . Arrays ; class GFG { static int count ( int n ) { int table [ ] = new int [ n + 1 ] , i ; Arrays . fill ( table , 0 ) ; table [ 0 ] = 1 ; for ( i = 3 ; i <= n ; i ++ ) table [ i ] += table [ i - 3 ] ; for ( i = 5 ; i <= n ; i ++ ) table [ i ] += table [ i - 5 ] ; for ( i = 10 ; i <= n ; i ++ ) table [ i ] += table [ i - 10 ] ; return table [ n ] ; } public static void main ( String [ ] args ) { int n = 20 ; System . out . println ( " Count ▁ for ▁ " + n + " ▁ is ▁ " + count ( n ) ) ; n = 13 ; System . out . println ( " Count ▁ for ▁ " + n + " ▁ is ▁ " + count ( n ) ) ; } }

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
public class NaiveSearch { public static void search ( String txt , String pat ) { int M = pat . length ( ) ; int N = txt . length ( ) ; for ( int i = 0 ; i <= N - M ; i ++ ) { int j ; for ( j = 0 ; j < M ; j ++ ) if ( txt . charAt ( i + j ) != pat . charAt ( j ) ) break ; if ( j == M ) System . out . println ( " Pattern ▁ found ▁ at ▁ index ▁ " + i ) ; } } public static void main ( String [ ] args ) { String txt = " AABAACAADAABAAABAA " ; String pat = " AABA " ; search ( txt , pat ) ; } }

Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: NaiveSearch
Java program:
public class Main { public final static int d = 256 ; static void search ( String pat , String txt , int q ) { int M = pat . length ( ) ; int N = txt . length ( ) ; int i , j ; int p = 0 ; int t = 0 ; int h = 1 ; for ( i = 0 ; i < M - 1 ; i ++ ) h = ( h * d ) % q ; for ( i = 0 ; i < M ; i ++ ) { p = ( d * p + pat . charAt ( i ) ) % q ; t = ( d * t + txt . charAt ( i ) ) % q ; } for ( i = 0 ; i <= N - M ; i ++ ) { if ( p == t ) { for ( j = 0 ; j < M ; j ++ ) { if ( txt . charAt ( i + j ) != pat . charAt ( j ) ) break ; } if ( j == M ) System . out . println ( " Pattern ▁ found ▁ at ▁ index ▁ " + i ) ; } if ( i < N - M ) { t = ( d * ( t - txt . charAt ( i ) * h ) + txt . charAt ( i + M ) ) % q ; if ( t < 0 ) t = ( t + q ) ; } } } public static void main ( String [ ] args ) { String txt = " GEEKS ▁ FOR ▁ GEEKS " ; String pat = " GEEK " ; int q = 101 ; search ( pat , txt , q ) ; } }

Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: Main
Java program:
class AWQ { static int NO_OF_CHARS = 256 ; static int max ( int a , int b ) { return ( a > b ) ? a : b ; } static void badCharHeuristic ( char [ ] str , int size , int badchar [ ] ) { for ( int i = 0 ; i < NO_OF_CHARS ; i ++ ) badchar [ i ] = - 1 ; for ( i = 0 ; i < size ; i ++ ) badchar [ ( int ) str [ i ] ] = i ; } static void search ( char txt [ ] , char pat [ ] ) { int m = pat . length ; int n = txt . length ; int badchar [ ] = new int [ NO_OF_CHARS ] ; badCharHeuristic ( pat , m , badchar ) ; int s = 0 ; while ( s <= ( n - m ) ) { int j = m - 1 ; while ( j >= 0 && pat [ j ] == txt [ s + j ] ) j -- ; if ( j < 0 ) { System . out . println ( " Patterns ▁ occur ▁ at ▁ shift ▁ = ▁ " + s ) ; s += ( s + m < n ) ? m - badchar [ txt [ s + m ] ] : 1 ; } else s += max ( 1 , j - badchar [ txt [ s + j ] ] ) ; } } public static void main ( String [ ] args ) { char txt [ ] = " ABAAABCD " . toCharArray ( ) ; char pat [ ] = " ABC " . toCharArray ( ) ; search ( txt , pat ) ; } }

Index/key variables: NO_OF_CHARS, i, j
Accumulator variables: i, j, s
Iterator variables: i
Class/struct names: AWQ
Java program:
public class GFG { static final int MAX = 256 ; static boolean compare ( char arr1 [ ] , char arr2 [ ] ) { for ( int i = 0 ; i < MAX ; i ++ ) if ( arr1 [ i ] != arr2 [ i ] ) return false ; return true ; } static void search ( String pat , String txt ) { int M = pat . length ( ) ; int N = txt . length ( ) ; char [ ] countP = new char [ MAX ] ; char [ ] countTW = new char [ MAX ] ; for ( int i = 0 ; i < M ; i ++ ) { ( countP [ pat . charAt ( i ) ] ) ++ ; ( countTW [ txt . charAt ( i ) ] ) ++ ; } for ( int i = M ; i < N ; i ++ ) { if ( compare ( countP , countTW ) ) System . out . println ( " Found ▁ at ▁ Index ▁ " + ( i - M ) ) ; ( countTW [ txt . charAt ( i ) ] ) ++ ; countTW [ txt . charAt ( i - M ) ] -- ; } if ( compare ( countP , countTW ) ) System . out . println ( " Found ▁ at ▁ Index ▁ " + ( N - M ) ) ; } public static void main ( String args [ ] ) { String txt = " BACDGABCDA " ; String pat = " ABCD " ; search ( pat , txt ) ; } }

Index/key variables: MAX, i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void findLongestPalindromicString ( String text ) { int N = text . length ( ) ; if ( N == 0 ) return ; N = 2 * N + 1 ; int [ ] L = new int [ N + 1 ] ; L [ 0 ] = 0 ; L [ 1 ] = 1 ; int C = 1 ; int R = 2 ; int i = 0 ; int iMirror ; int maxLPSLength = 0 ; int maxLPSCenterPosition = 0 ; int start = - 1 ; int end = - 1 ; int diff = - 1 ; for ( i = 2 ; i < N ; i ++ ) { iMirror = 2 * C - i ; L [ i ] = 0 ; diff = R - i ; if ( diff > 0 ) L [ i ] = Math . min ( L [ iMirror ] , diff ) ; while ( ( ( i + L [ i ] ) + 1 < N && ( i - L [ i ] ) > 0 ) && ( ( ( i + L [ i ] + 1 ) % 2 == 0 ) || ( text . charAt ( ( i + L [ i ] + 1 ) / 2 ) == text . charAt ( ( i - L [ i ] - 1 ) / 2 ) ) ) ) { L [ i ] ++ ; } if ( L [ i ] > maxLPSLength ) { maxLPSLength = L [ i ] ; maxLPSCenterPosition = i ; } if ( i + L [ i ] > R ) { C = i ; R = i + L [ i ] ; } } start = ( maxLPSCenterPosition - maxLPSLength ) / 2 ; end = start + maxLPSLength - 1 ; System . out . printf ( " LPS ▁ of ▁ string ▁ is ▁ % s ▁ : ▁ " , text ) ; for ( i = start ; i <= end ; i ++ ) System . out . print ( text . charAt ( i ) ) ; System . out . println ( ) ; } public static void main ( String [ ] args ) { String text = " babcbabcbaccba " ; findLongestPalindromicString ( text ) ; text = " abaaba " ; findLongestPalindromicString ( text ) ; text = " abababa " ; findLongestPalindromicString ( text ) ; text = " abcbabcbabcba " ; findLongestPalindromicString ( text ) ; text = " forgeeksskeegfor " ; findLongestPalindromicString ( text ) ; text = " caba " ; findLongestPalindromicString ( text ) ; text = " abacdfgdcaba " ; findLongestPalindromicString ( text ) ; text = " abacdfgdcabba " ; findLongestPalindromicString ( text ) ; text = " abacdedcaba " ; findLongestPalindromicString ( text ) ; } }

Index/key variables: i, iMirror
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; class Permutation { static void printPatternUtil ( String str , char buf [ ] , int i , int j , int n ) { if ( i == n ) { buf [ j ] = ' \0' ; System . out . println ( buf ) ; return ; } buf [ j ] = str . charAt ( i ) ; printPatternUtil ( str , buf , i + 1 , j + 1 , n ) ; buf [ j ] = ' ▁ ' ; buf [ j + 1 ] = str . charAt ( i ) ; printPatternUtil ( str , buf , i + 1 , j + 2 , n ) ; } static void printPattern ( String str ) { int len = str . length ( ) ; char [ ] buf = new char [ 2 * len ] ; buf [ 0 ] = str . charAt ( 0 ) ; printPatternUtil ( str , buf , 1 , 1 , len ) ; } public static void main ( String [ ] args ) { String str = " ABCD " ; printPattern ( str ) ; } }

Index/key variables: j
Class/struct names: Permutation
Java program:
class Main { static int getMedian ( int ar1 [ ] , int ar2 [ ] , int n ) { int i = 0 ; int j = 0 ; int count ; int m1 = - 1 , m2 = - 1 ; for ( count = 0 ; count <= n ; count ++ ) { if ( i == n ) { m1 = m2 ; m2 = ar2 [ 0 ] ; break ; } else if ( j == n ) { m1 = m2 ; m2 = ar1 [ 0 ] ; break ; } if ( ar1 [ i ] <= ar2 [ j ] ) { m1 = m2 ; m2 = ar1 [ i ] ; i ++ ; } else { m1 = m2 ; m2 = ar2 [ j ] ; j ++ ; } } return ( m1 + m2 ) / 2 ; } public static void main ( String [ ] args ) { int ar1 [ ] = { 1 , 12 , 15 , 26 , 38 } ; int ar2 [ ] = { 2 , 13 , 17 , 30 , 45 } ; int n1 = ar1 . length ; int n2 = ar2 . length ; if ( n1 == n2 ) System . out . println ( " Median ▁ is ▁ " + getMedian ( ar1 , ar2 , n1 ) ) ; else System . out . println ( " arrays ▁ are ▁ of ▁ unequal ▁ size " ) ; } }

Index/key variables: i, j
Accumulator variables: count, i, j
Iterator variables: count
Class/struct names: Main
Java program:
import java . util . * ; class GfG { static int getMedian ( int [ ] a , int [ ] b , int startA , int startB , int endA , int endB ) { if ( endA - startA == 1 ) { return ( Math . max ( a [ startA ] , b [ startB ] ) + Math . min ( a [ endA ] , b [ endB ] ) ) / 2 ; } int m1 = median ( a , startA , endA ) ; int m2 = median ( b , startB , endB ) ; if ( m1 == m2 ) { return m1 ; } else if ( m1 < m2 ) { return getMedian ( a , b , ( endA + startA + 1 ) / 2 , startB , endA , ( endB + startB + 1 ) / 2 ) ; } else { return getMedian ( a , b , startA , ( endB + startB + 1 ) / 2 , ( endA + startA + 1 ) / 2 , endB ) ; } } static int median ( int [ ] arr , int start , int end ) { int n = end - start + 1 ; if ( n % 2 == 0 ) { return ( arr [ start + ( n / 2 ) ] + arr [ start + ( n / 2 - 1 ) ] ) / 2 ; } else { return arr [ start + n / 2 ] ; } } public static void main ( String [ ] args ) { int ar1 [ ] = { 1 , 2 , 3 , 6 } ; int ar2 [ ] = { 4 , 6 , 8 , 10 } ; int n1 = ar1 . length ; int n2 = ar2 . length ; if ( n1 != n2 ) { System . out . println ( " Doesn ' t ▁ work ▁ for ▁ arrays ▁ " + " of ▁ unequal ▁ size " ) ; } else if ( n1 == 0 ) { System . out . println ( " Arrays ▁ are ▁ empty . " ) ; } else if ( n1 == 1 ) { System . out . println ( ( ar1 [ 0 ] + ar2 [ 0 ] ) / 2 ) ; } else { System . out . println ( " Median ▁ is ▁ " + getMedian ( ar1 , ar2 , 0 , 0 , ar1 . length - 1 , ar2 . length - 1 ) ) ; } } }

Index/key variables: endA, endB, startA, startB
Class/struct names: GfG
Java program:
import java . io . * ; import java . util . * ; class GFG { public static int getMedian ( int ar1 [ ] , int ar2 [ ] , int n ) { int j = 0 ; int i = n - 1 ; while ( ar1 [ i ] > ar2 [ j ] && j < n && i > - 1 ) { int temp = ar1 [ i ] ; ar1 [ i ] = ar2 [ j ] ; ar2 [ j ] = temp ; i -- ; j ++ ; } Arrays . sort ( ar1 ) ; Arrays . sort ( ar2 ) ; return ( ar1 [ n - 1 ] + ar2 [ 0 ] ) / 2 ; } public static void main ( String [ ] args ) { int ar1 [ ] = { 1 , 12 , 15 , 26 , 38 } ; int ar2 [ ] = { 2 , 13 , 17 , 30 , 45 } ; int n1 = 5 ; int n2 = 5 ; if ( n1 == n2 ) System . out . println ( " Median ▁ is ▁ " + getMedian ( ar1 , ar2 , n1 ) ) ; else System . out . println ( " Doesn ' t ▁ work ▁ for ▁ arrays ▁ of ▁ unequal ▁ size " ) ; } }

Index/key variables: i, j
Accumulator variables: i, j
Class/struct names: GFG
Java program:
class GFG { static class Point { int x ; int y ; public Point ( int x , int y ) { this . x = x ; this . y = y ; } } ; static boolean onSegment ( Point p , Point q , Point r ) { if ( q . x <= Math . max ( p . x , r . x ) && q . x >= Math . min ( p . x , r . x ) && q . y <= Math . max ( p . y , r . y ) && q . y >= Math . min ( p . y , r . y ) ) return true ; return false ; } static int orientation ( Point p , Point q , Point r ) { int val = ( q . y - p . y ) * ( r . x - q . x ) - ( q . x - p . x ) * ( r . y - q . y ) ; if ( val == 0 ) return 0 ; return ( val > 0 ) ? 1 : 2 ; } static boolean doIntersect ( Point p1 , Point q1 , Point p2 , Point q2 ) { int o1 = orientation ( p1 , q1 , p2 ) ; int o2 = orientation ( p1 , q1 , q2 ) ; int o3 = orientation ( p2 , q2 , p1 ) ; int o4 = orientation ( p2 , q2 , q1 ) ; if ( o1 != o2 && o3 != o4 ) return true ; if ( o1 == 0 && onSegment ( p1 , p2 , q1 ) ) return true ; if ( o2 == 0 && onSegment ( p1 , q2 , q1 ) ) return true ; if ( o3 == 0 && onSegment ( p2 , p1 , q2 ) ) return true ; if ( o4 == 0 && onSegment ( p2 , q1 , q2 ) ) return true ; return false ; } public static void main ( String [ ] args ) { Point p1 = new Point ( 1 , 1 ) ; Point q1 = new Point ( 10 , 1 ) ; Point p2 = new Point ( 1 , 2 ) ; Point q2 = new Point ( 10 , 2 ) ; if ( doIntersect ( p1 , q1 , p2 , q2 ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; p1 = new Point ( 10 , 1 ) ; q1 = new Point ( 0 , 10 ) ; p2 = new Point ( 0 , 0 ) ; q2 = new Point ( 10 , 10 ) ; if ( doIntersect ( p1 , q1 , p2 , q2 ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; p1 = new Point ( - 5 , - 5 ) ; q1 = new Point ( 0 , 0 ) ; p2 = new Point ( 1 , 1 ) ; q2 = new Point ( 10 , 10 ) ; ; if ( doIntersect ( p1 , q1 , p2 , q2 ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }

Class/struct names: GFG, Point
Java program:
import java . util . * ; class GFG { static double area ( int x1 , int y1 , int x2 , int y2 , int x3 , int y3 ) { return Math . abs ( ( x1 * ( y2 - y3 ) + x2 * ( y3 - y1 ) + x3 * ( y1 - y2 ) ) / 2.0 ) ; } static boolean isInside ( int x1 , int y1 , int x2 , int y2 , int x3 , int y3 , int x , int y ) { double A = area ( x1 , y1 , x2 , y2 , x3 , y3 ) ; double A1 = area ( x , y , x2 , y2 , x3 , y3 ) ; double A2 = area ( x1 , y1 , x , y , x3 , y3 ) ; double A3 = area ( x1 , y1 , x2 , y2 , x , y ) ; return ( A == A1 + A2 + A3 ) ; } public static void main ( String [ ] args ) { if ( isInside ( 0 , 0 , 20 , 0 , 10 , 30 , 10 , 15 ) ) System . out . println ( " Inside " ) ; else System . out . println ( " Not ▁ Inside " ) ; } }

Class/struct names: GFG