dhyuti-n/xlcost-variable-roles huggingface dataset:
Java program:
import java . util . * ; class GFG { static int maxN = 20 ; static int dp [ ] [ ] [ ] [ ] = new int [ maxN ] [ maxN ] [ 27 ] [ maxN ] ; public static int solve ( String s , int n , int idx , int k , char last , int count ) { if ( k < 0 ) return n + 1 ; if ( idx == n ) return 0 ; int ans = dp [ idx ] [ k ] [ last - ' a ' ] [ count ] ; if ( ans != - 1 ) return ans ; ans = n + 1 ; ans = Math . min ( ans , solve ( s , n , idx + 1 , k - 1 , last , count ) ) ; int inc = 0 ; if ( count == 1 count == 9 count == 99 ) inc = 1 ; if ( last == s . charAt ( idx ) ) { ans = Math . min ( ans , inc + solve ( s , n , idx + 1 , k , s . charAt ( idx ) , count + 1 ) ) ; } else { ans = Math . min ( ans , 1 + solve ( s , n , idx + 1 , k , s . charAt ( idx ) , 1 ) ) ; } return dp [ idx ] [ k ] [ last - ' a ' ] [ count ] = ans ; } public static int MinRunLengthEncoding ( String s , int n , int k ) { for ( int i [ ] [ ] [ ] : dp ) for ( int j [ ] [ ] : i ) for ( int p [ ] : j ) Arrays . fill ( p , - 1 ) ; return solve ( s , n , 0 , k , ( char ) 123 , 0 ) ; } public static void main ( String args [ ] ) { String S = " abbbcdcdd " ; int N = 9 , K = 2 ; System . out . println ( MinRunLengthEncoding ( S , N , K ) ) ; } }

Index/key variables: count, idx, k, maxN
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; import java . lang . * ; class GFG { static int countPaths = 0 ; static void CountUniquePaths ( int [ ] [ ] a , int i , int j , int m , int n , int ans ) { if ( i >= m j >= n ) return ; if ( i == m - 1 && j == n - 1 ) { double sr = Math . sqrt ( ans * a [ i ] [ j ] ) ; if ( ( sr - Math . floor ( sr ) ) == 0 ) countPaths ++ ; } CountUniquePaths ( a , i + 1 , j , m , n , ans * a [ i ] [ j ] ) ; CountUniquePaths ( a , i , j + 1 , m , n , ans * a [ i ] [ j ] ) ; } public static void main ( String [ ] args ) { int M = 3 , N = 2 ; int [ ] [ ] mat = { { 1 , 1 } , { 3 , 1 } , { 3 , 1 } } ; CountUniquePaths ( mat , 0 , 0 , M , N , 1 ) ; System . out . println ( countPaths ) ; } }

Index/key variables: i, j
Accumulator variables: countPaths
Class/struct names: GFG
Java program:
import java . util . * ; public class GFG { public static long mElementsWithMaxSum ( long [ ] [ ] matrix , int M , int block , long [ ] [ ] dp ) { if ( block == matrix . length ) return 0 ; if ( dp [ block ] [ M ] != - 1 ) return dp [ block ] [ M ] ; long ans = mElementsWithMaxSum ( matrix , M , block + 1 , dp ) ; for ( int i = 0 ; i < matrix [ block ] . length ; i ++ ) { for ( int j = i ; j < matrix [ block ] . length ; j ++ ) { if ( j - i + 1 <= M ) { ans = Math . max ( ans , matrix [ block ] [ j ] - ( ( i - 1 ) >= 0 ? matrix [ block ] [ i - 1 ] : 0 ) + mElementsWithMaxSum ( matrix , M - j + i - 1 , block + 1 , dp ) ) ; } } } return dp [ block ] [ M ] = ans ; } public static void preComputing ( long [ ] [ ] matrix , int N ) { for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < matrix [ i ] . length ; j ++ ) { matrix [ i ] [ j ] = ( j > 0 ? matrix [ i ] [ j - 1 ] : 0 ) + matrix [ i ] [ j ] ; } } } public static void mElementsWithMaxSumUtil ( long [ ] [ ] matrix , int M , int N ) { preComputing ( matrix , N ) ; long dp [ ] [ ] = new long [ N + 5 ] [ M + 5 ] ; for ( long i [ ] : dp ) Arrays . fill ( i , - 1 ) ; long sum = mElementsWithMaxSum ( matrix , M , 0 , dp ) ; System . out . print ( sum ) ; } public static void main ( String args [ ] ) { int N = 3 ; int M = 4 ; long [ ] [ ] matrix = { { 2 , 3 , 5 } , { - 1 , 7 } , { 8 , 10 } } ; mElementsWithMaxSumUtil ( matrix , M , N ) ; } }

Index/key variables: M, block, i, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int lastRemaining ( int n , HashMap < Integer , Integer > dp ) { if ( dp . containsKey ( n ) ) return dp . get ( n ) ; if ( n == 1 ) return 1 ; else dp . put ( n , 2 * ( 1 + n / 2 - lastRemaining ( n / 2 , dp ) ) ) ; return dp . get ( n ) ; } public static void main ( String [ ] args ) { int N = 5 ; HashMap < Integer , Integer > dp = new HashMap < Integer , Integer > ( ) ; System . out . print ( lastRemaining ( N , dp ) ) ; } }

Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int [ ] [ ] dp = new int [ 1005 ] [ 1005 ] ; static int maximumSumUtil ( int a [ ] , int index , int count , int n ) { if ( index > n count > n + 1 ) { return 0 ; } if ( dp [ index ] [ count ] != - 1 ) return dp [ index ] [ count ] ; int ans1 = maximumSumUtil ( a , index + 1 , count + 1 , n ) + a [ index ] * count ; int ans2 = maximumSumUtil ( a , index + 1 , count , n ) ; return ( dp [ index ] [ count ] = Math . max ( ans1 , ans2 ) ) ; } static void maximumSum ( int arr [ ] , int N ) { for ( int i = 0 ; i < 1005 ; i ++ ) { for ( int j = 0 ; j < 1005 ; j ++ ) { dp [ i ] [ j ] = - 1 ; } } System . out . print ( maximumSumUtil ( arr , 0 , 1 , N - 1 ) ) ; } public static void main ( String [ ] args ) { int arr [ ] = { - 1 , 2 , - 10 , 4 , - 20 } ; int N = arr . length ; maximumSum ( arr , N ) ; } }

Index/key variables: count, i, index, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class GFG { static void rearrange ( int [ ] arr , int n , int x ) { TreeMap < Integer , ArrayList < Integer > > m = new TreeMap < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { int diff = Math . abs ( x - arr [ i ] ) ; if ( m . containsKey ( diff ) ) { ArrayList < Integer > al = m . get ( diff ) ; al . add ( arr [ i ] ) ; m . put ( diff , al ) ; } else { ArrayList < Integer > al = new ArrayList < > ( ) ; al . add ( arr [ i ] ) ; m . put ( diff , al ) ; } } int index = 0 ; for ( Map . Entry entry : m . entrySet ( ) ) { ArrayList < Integer > al = m . get ( entry . getKey ( ) ) ; for ( int i = 0 ; i < al . size ( ) ; i ++ ) arr [ index ++ ] = al . get ( i ) ; } } static void printArray ( int [ ] arr , int n ) { for ( int i = 0 ; i < n ; i ++ ) System . out . print ( arr [ i ] + " ▁ " ) ; } public static void main ( String args [ ] ) { int [ ] arr = { 10 , 5 , 3 , 9 , 2 } ; int n = arr . length ; int x = 7 ; rearrange ( arr , n , x ) ; printArray ( arr , n ) ; } }

Index/key variables: i
Accumulator variables: i, index
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; import java . util . Collections ; import java . util . Vector ; Vector < Integer > v = new Vector < Integer > ( n ) ; class GFG { static Vector < Integer > find_sequence ( int n ) { Vector < Integer > temp = new Vector < Integer > ( ) ; temp . add ( 1 ) ; temp . add ( - 1 ) ; if ( n == 1 ) return temp ; Vector < Integer > arr = find_sequence ( n - 1 ) ; Vector < Integer > ans = new Vector < Integer > ( n ) ; ans . add ( arr . get ( 0 ) + 1 ) ; ans . add ( n - 1 ) ; if ( n % 2 == 0 ) { Vector < Integer > div_by_2 = find_sequence ( n / 2 ) ; if ( div_by_2 . get ( 0 ) < ans . get ( 0 ) ) { ans . clear ( ) ; ans . add ( div_by_2 . get ( 0 ) + 1 ) ; ans . add ( n / 2 ) ; } } if ( n % 3 == 0 ) { Vector < Integer > div_by_3 = find_sequence ( n / 3 ) ; if ( div_by_3 . get ( 0 ) < ans . get ( 0 ) ) { ans . clear ( ) ; ans . add ( div_by_3 . get ( 0 ) + 1 ) ; ans . add ( n / 3 ) ; } } return ans ; } static Vector < Integer > find_solution ( int n ) { Vector < Integer > a = find_sequence ( n ) ; System . out . println ( a . get ( 0 ) ) ; Vector < Integer > sequence = new Vector < Integer > ( ) ; sequence . add ( n ) ; while ( a . get ( 1 ) != - 1 ) { sequence . add ( a . get ( 1 ) ) ; Vector < Integer > arr = find_sequence ( a . get ( 1 ) ) ; a . set ( 1 , arr . get ( 1 ) ) ; } Collections . reverse ( sequence ) ; return sequence ; } public static void main ( String args [ ] ) { int n = 5 ; Vector < Integer > res = find_solution ( n ) ; for ( int i = 0 ; i < res . size ( ) ; i ++ ) { System . out . print ( res . get ( i ) + " ▁ " ) ; } } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class GFG { static int n , t ; public static int FindNoOfFullVessels ( int n , int t ) { double Matrix [ ] [ ] = new double [ n ] [ n ] ; Matrix [ 0 ] [ 0 ] = t * 1.0 ; int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j <= i ; j ++ ) { double exceededwater = Matrix [ i ] [ j ] - 1.0 ; if ( exceededwater < 0 ) continue ; ans ++ ; if ( i + 1 < n ) Matrix [ i + 1 ] [ j ] += exceededwater / 2 ; if ( i + 1 < n && j + 1 < n ) Matrix [ i + 1 ] [ j + 1 ] += exceededwater / 2 ; } } return ans ; } public static void main ( String [ ] args ) { int N = 3 ; int T = 4 ; System . out . println ( FindNoOfFullVessels ( N , T ) ) ; } }

Index/key variables: i, j, n
Accumulator variables: ans, i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class SortWave { void swap ( int arr [ ] , int a , int b ) { int temp = arr [ a ] ; arr [ a ] = arr [ b ] ; arr [ b ] = temp ; } void sortInWave ( int arr [ ] , int n ) { Arrays . sort ( arr ) ; for ( int i = 0 ; i < n - 1 ; i += 2 ) swap ( arr , i , i + 1 ) ; } public static void main ( String args [ ] ) { SortWave ob = new SortWave ( ) ; int arr [ ] = { 10 , 90 , 49 , 2 , 1 , 5 , 23 } ; int n = arr . length ; ob . sortInWave ( arr , n ) ; for ( int i : arr ) System . out . print ( i + " ▁ " ) ; } }

Index/key variables: a, b
Accumulator variables: i
Iterator variables: i
Class/struct names: SortWave
Java program:
import java . util . * ; class GFG { static int findMaxTimes ( String S ) { int [ ] arr = new int [ 26 ] ; int [ ] [ ] dp = new int [ 26 ] [ 26 ] ; for ( int i = 0 ; i < S . length ( ) ; i ++ ) { int now = S . charAt ( i ) - ' a ' ; for ( int j = 0 ; j < 26 ; j ++ ) { dp [ j ] [ now ] += arr [ j ] ; } arr [ now ] ++ ; } int ans = 0 ; for ( int i = 0 ; i < 26 ; i ++ ) ans = Math . max ( ans , arr [ i ] ) ; for ( int i = 0 ; i < 26 ; i ++ ) { for ( int j = 0 ; j < 26 ; j ++ ) { ans = Math . max ( ans , dp [ i ] [ j ] ) ; } } return ans ; } public static void main ( String [ ] args ) { String S = " ddee " ; System . out . print ( findMaxTimes ( S ) ) ; } }

Index/key variables: i, j, now
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
class SortWave { void swap ( int arr [ ] , int a , int b ) { int temp = arr [ a ] ; arr [ a ] = arr [ b ] ; arr [ b ] = temp ; } 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 ) ; } } public static void main ( String args [ ] ) { SortWave ob = new SortWave ( ) ; int arr [ ] = { 10 , 90 , 49 , 2 , 1 , 5 , 23 } ; int n = arr . length ; ob . sortInWave ( arr , n ) ; for ( int i : arr ) System . out . print ( i + " ▁ " ) ; } }

Index/key variables: a, b, i
Accumulator variables: i
Iterator variables: i
Class/struct names: SortWave
Java program:
class Node { int data ; Node left ; Node right ; public Node ( int data ) { this . data = data ; left = null ; right = null ; } } public void print ( Node root ) { if ( root == null ) return ; print ( root . left ) ; System . out . print ( root . data + " ▁ " ) ; print ( root . right ) ; } } class BinaryTree { Node root ; public Node prune ( Node root , int sum ) { if ( root == null ) return null ; root . left = prune ( root . left , sum - root . data ) ; root . right = prune ( root . right , sum - root . data ) ; if ( isLeaf ( root ) ) { if ( sum > root . data ) root = null ; } return root ; } public boolean isLeaf ( Node root ) { if ( root == null ) return false ; if ( root . left == null && root . right == null ) return true ; return false ; } public class GFG { public static void main ( String args [ ] ) { BinaryTree tree = new BinaryTree ( ) ; tree . root = new Node ( 1 ) ; tree . root . left = new Node ( 2 ) ; tree . root . right = new Node ( 3 ) ; tree . root . left . left = new Node ( 4 ) ; tree . root . left . right = new Node ( 5 ) ; tree . root . right . left = new Node ( 6 ) ; tree . root . right . right = new Node ( 7 ) ; tree . root . left . left . left = new Node ( 8 ) ; tree . root . left . left . right = new Node ( 9 ) ; tree . root . left . right . left = new Node ( 12 ) ; tree . root . right . right . left = new Node ( 10 ) ; tree . root . right . right . left . right = new Node ( 11 ) ; tree . root . left . left . right . left = new Node ( 13 ) ; tree . root . left . left . right . right = new Node ( 14 ) ; tree . root . left . left . right . right . left = new Node ( 15 ) ; System . out . println ( " Tree ▁ before ▁ truncation " ) ; tree . print ( tree . root ) ; tree . prune ( tree . root , 45 ) ; System . out . println ( " Tree after truncation "); tree . print ( tree . root ) ; } }

Class/struct names: BinaryTree, GFG, Node
Java program:
import java . util . * ; class GFG { static int count_unique_sum ( int n ) { int i ; int ar [ ] = new int [ n + 1 ] ; int fsum [ ] = new int [ n + 1 ] ; int rsum [ ] = new int [ n + 1 ] ; int ans = 1 ; Arrays . fill ( fsum , 0 ) ; Arrays . fill ( rsum , 0 ) ; for ( i = 0 ; i <= n ; i ++ ) { ar [ i ] = i ; } fsum [ 0 ] = ar [ 0 ] ; rsum [ n ] = ar [ n ] ; for ( i = 1 ; i <= n ; i ++ ) { fsum [ i ] = ar [ i ] + fsum [ i - 1 ] ; } for ( i = n - 1 ; i >= 0 ; i -- ) { rsum [ i ] = ar [ i ] + rsum [ i + 1 ] ; } for ( int k = 2 ; k <= n ; k ++ ) { ans += 1 + rsum [ n + 1 - k ] - fsum [ k - 1 ] ; } return ans ; } public static void main ( String [ ] args ) { int N = 4 ; System . out . print ( count_unique_sum ( N ) ) ; } }

Index/key variables: i, n
Accumulator variables: ans, i, k
Iterator variables: i, k
Class/struct names: GFG
Java program:
class MergeArrays { void moveToEnd ( int mPlusN [ ] , int size ) { int i , j = size - 1 ; for ( i = size - 1 ; i >= 0 ; i -- ) { if ( mPlusN [ i ] != - 1 ) { mPlusN [ j ] = mPlusN [ i ] ; j -- ; } } } void merge ( int mPlusN [ ] , int N [ ] , int m , int n ) { int i = n ; int j = 0 ; int k = 0 ; while ( k < ( m + n ) ) { if ( ( i < ( m + n ) && mPlusN [ i ] <= N [ j ] ) || ( j == n ) ) { mPlusN [ k ] = mPlusN [ i ] ; k ++ ; i ++ ; } else { mPlusN [ k ] = N [ j ] ; k ++ ; j ++ ; } } } void printArray ( int arr [ ] , int size ) { int i ; for ( i = 0 ; i < size ; i ++ ) System . out . print ( arr [ i ] + " ▁ " ) ; System . out . println ( " " ) ; } public static void main ( String [ ] args ) { MergeArrays mergearray = new MergeArrays ( ) ; int mPlusN [ ] = { 2 , 8 , - 1 , - 1 , - 1 , 13 , - 1 , 15 , 20 } ; int N [ ] = { 5 , 7 , 9 , 25 } ; int n = N . length ; int m = mPlusN . length - n ; mergearray . moveToEnd ( mPlusN , m + n ) ; mergearray . merge ( mPlusN , N , m , n ) ; mergearray . printArray ( mPlusN , m + n ) ; } }

Index/key variables: i, j, k
Accumulator variables: i, j, k
Iterator variables: i
Class/struct names: MergeArrays
Java program:
import java . util . * ; class GFG { public static long getCount ( int n , int k ) { if ( n == 1 ) return 10 ; long dp [ ] = new long [ 11 ] ; long next [ ] = new long [ 11 ] ; for ( int i = 1 ; i <= 9 ; i ++ ) dp [ i ] = 1 ; for ( int i = 2 ; i <= n ; i ++ ) { for ( int j = 0 ; j <= 9 ; j ++ ) { int l = Math . max ( 0 , j - k ) ; int r = Math . min ( 9 , j + k ) ; next [ l ] += dp [ j ] ; next [ r + 1 ] -= dp [ j ] ; } for ( int j = 1 ; j <= 9 ; j ++ ) next [ j ] += next [ j - 1 ] ; for ( int j = 0 ; j < 10 ; j ++ ) { dp [ j ] = next [ j ] ; next [ j ] = 0 ; } } long count = 0 ; for ( int i = 0 ; i <= 9 ; i ++ ) count += dp [ i ] ; return count ; } public static void main ( String [ ] args ) { int n = 2 , k = 1 ; System . out . println ( getCount ( n , k ) ) ; } }

Index/key variables: i, j, l
Accumulator variables: count, i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . Arrays ; class GFG { static boolean sortedAfterSwap ( int A [ ] , boolean B [ ] , int n ) { int i , j ; for ( i = 0 ; i < n - 1 ; i ++ ) { if ( B [ i ] ) { j = i ; while ( B [ j ] ) { j ++ ; } Arrays . sort ( A , i , 1 + j ) ; i = j ; } } for ( i = 0 ; i < n ; i ++ ) { if ( A [ i ] != i + 1 ) { return false ; } } return true ; } public static void main ( String [ ] args ) { int A [ ] = { 1 , 2 , 5 , 3 , 4 , 6 } ; boolean B [ ] = { false , true , true , true , false } ; int n = A . length ; if ( sortedAfterSwap ( A , B , n ) ) { System . out . println ( " A ▁ can ▁ be ▁ sorted " ) ; } else { System . out . println ( " A ▁ can ▁ not ▁ be ▁ sorted " ) ; } } }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . ArrayList ; import java . util . Collections ; class GFG { static class Edge { int src , dest , weight ; } static class Graph { int V , E ; Edge [ ] edge ; } static Graph createGraph ( int V , int E ) { Graph graph = new Graph ( ) ; graph . V = V ; graph . E = E ; graph . edge = new Edge [ graph . E ] ; for ( int i = 0 ; i < graph . E ; i ++ ) { graph . edge [ i ] = new Edge ( ) ; } return graph ; } static void NegCycleBellmanFord ( Graph graph , int src ) { int V = graph . V ; int E = graph . E ; int [ ] dist = new int [ V ] ; int [ ] parent = new int [ V ] ; for ( int i = 0 ; i < V ; i ++ ) { dist [ i ] = 1000000 ; parent [ i ] = - 1 ; } dist [ src ] = 0 ; for ( int i = 1 ; i <= V - 1 ; i ++ ) { for ( int j = 0 ; j < E ; j ++ ) { int u = graph . edge [ j ] . src ; int v = graph . edge [ j ] . dest ; int weight = graph . edge [ j ] . weight ; if ( dist [ u ] != 1000000 && dist [ u ] + weight < dist [ v ] ) { dist [ v ] = dist [ u ] + weight ; parent [ v ] = u ; } } } int C = - 1 ; for ( int i = 0 ; i < E ; i ++ ) { int u = graph . edge [ i ] . src ; int v = graph . edge [ i ] . dest ; int weight = graph . edge [ i ] . weight ; if ( dist [ u ] != 1000000 && dist [ u ] + weight < dist [ v ] ) { C = v ; break ; } } if ( C != - 1 ) { for ( int i = 0 ; i < V ; i ++ ) C = parent [ C ] ; ArrayList < Integer > cycle = new ArrayList < > ( ) ; for ( int v = C ; ; v = parent [ v ] ) { cycle . add ( v ) ; if ( v == C && cycle . size ( ) > 1 ) break ; } Collections . reverse ( cycle ) ; for ( int v : cycle ) System . out . print ( v + " ▁ " ) ; System . out . println ( ) ; } else System . out . println ( - 1 ) ; } public static void main ( String [ ] args ) { int V = 5 ; int E = 5 ; Graph graph = createGraph ( V , E ) ; graph . edge [ 0 ] . src = 0 ; graph . edge [ 0 ] . dest = 1 ; graph . edge [ 0 ] . weight = 1 ; graph . edge [ 1 ] . src = 1 ; graph . edge [ 1 ] . dest = 2 ; graph . edge [ 1 ] . weight = 2 ; graph . edge [ 2 ] . src = 2 ; graph . edge [ 2 ] . dest = 3 ; graph . edge [ 2 ] . weight = 3 ; graph . edge [ 3 ] . src = 3 ; graph . edge [ 3 ] . dest = 4 ; graph . edge [ 3 ] . weight = - 3 ; graph . edge [ 4 ] . src = 4 ; graph . edge [ 4 ] . dest = 1 ; graph . edge [ 4 ] . weight = - 3 ; NegCycleBellmanFord ( graph , 0 ) ; } }

Index/key variables: C, V, i, j, src, u, v
Accumulator variables: i, j
Iterator variables: i, j, v
Class/struct names: Edge, GFG, Graph
Java program:
class GFG { static int sortedAfterSwap ( int [ ] A , int [ ] B , int n ) { int t = 0 ; for ( int i = 0 ; i < n - 1 ; i ++ ) { if ( B [ i ] != 0 ) { if ( A [ i ] != i + 1 ) t = A [ i ] ; A [ i ] = A [ i + 1 ] ; A [ i + 1 ] = t ; } } for ( int i = 0 ; i < n ; i ++ ) { if ( A [ i ] != i + 1 ) return 0 ; } return 1 ; } public static void main ( String [ ] args ) { int [ ] A = { 1 , 2 , 5 , 3 , 4 , 6 } ; int [ ] B = { 0 , 1 , 1 , 1 , 0 } ; int n = A . length ; if ( sortedAfterSwap ( A , B , n ) == 0 ) System . out . println ( " A ▁ can ▁ be ▁ sorted " ) ; else System . out . println ( " A ▁ can ▁ not ▁ be ▁ sorted " ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
class segregation { static void segregate0and1 ( int arr [ ] , int n ) { int type0 = 0 ; int type1 = n - 1 ; while ( type0 < type1 ) { if ( arr [ type0 ] == 1 ) { arr [ type0 ] = arr [ type0 ] + arr [ type1 ] ; arr [ type1 ] = arr [ type0 ] - arr [ type1 ] ; arr [ type0 ] = arr [ type0 ] - arr [ type1 ] ; type1 -- ; } else { type0 ++ ; } } } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 1 , 1 , 0 , 1 , 0 , 0 , 1 , 1 , 1 , 1 , 1 , 0 , 0 } ; segregate0and1 ( arr , arr . length ) ; for ( int a : arr ) System . out . print ( a + " ▁ " ) ; } }

Index/key variables: type0, type1
Accumulator variables: type0, type1
Iterator variables: a
Class/struct names: segregation
Java program:
import java . util . * ; class GFG { static int printpentaRec ( int n ) { if ( n == 0 n == 1 n == 2 n == 3 n == 4 ) return 0 ; else if ( n == 5 ) return 1 ; else return ( printpentaRec ( n - 1 ) + printpentaRec ( n - 2 ) + printpentaRec ( n - 3 ) + printpentaRec ( n - 4 ) + printpentaRec ( n - 5 ) ) ; } static void printPenta ( int n ) { System . out . print ( printpentaRec ( n ) + "NEW_LINE"); } public static void main ( String [ ] args ) { int n = 10 ; printPenta ( n ) ; } }

Class/struct names: GFG
Java program:
class Test { static int arr [ ] = new int [ ] { 1 , 20 , 6 , 4 , 5 } ; static int getInvCount ( int n ) { int inv_count = 0 ; for ( int i = 0 ; i < n - 1 ; i ++ ) for ( int j = i + 1 ; j < n ; j ++ ) if ( arr [ i ] > arr [ j ] ) inv_count ++ ; return inv_count ; } public static void main ( String [ ] args ) { System . out . println ( " Number ▁ of ▁ inversions ▁ are ▁ " + getInvCount ( arr . length ) ) ; } }

Index/key variables: i, j
Accumulator variables: i, inv_count, j
Iterator variables: i, j
Class/struct names: Test
Java program:
import java . util . * ; class GFG { static class Query { int L , R ; public Query ( int l , int r ) { super ( ) ; L = l ; R = r ; } } ; static int findResultUtil ( int arr [ ] , int L , int R ) { int result = 0 ; boolean flag = false ; for ( int i = L ; i <= R ; i ++ ) { if ( flag == false ) { result = result + arr [ i ] ; flag = true ; } else { result = result - arr [ i ] ; flag = false ; } } return result ; } static void findResult ( int arr [ ] , int n , Query q [ ] , int m ) { for ( int i = 0 ; i < m ; i ++ ) { System . out . print ( findResultUtil ( arr , q [ i ] . L , q [ i ] . R ) + " ▁ " ) ; } } public static void main ( String [ ] args ) { int arr [ ] = { 10 , 13 , 15 , 2 , 45 , 31 , 22 , 3 , 27 } ; int n = arr . length ; Query q [ ] = { new Query ( 2 , 5 ) , new Query ( 6 , 8 ) , new Query ( 1 , 7 ) , new Query ( 4 , 8 ) , new Query ( 0 , 5 ) } ; int m = q . length ; findResult ( arr , n , q , m ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Boolean variables: flag
Class/struct names: GFG, Query
Java program:
import java . util . * ; import java . lang . * ; class Main { static void minAbsSumPair ( int arr [ ] , int arr_size ) { int inv_count = 0 ; int l , r , min_sum , sum , min_l , min_r ; if ( arr_size < 2 ) { System . out . println ( " Invalid ▁ Input " ) ; return ; } min_l = 0 ; min_r = 1 ; min_sum = arr [ 0 ] + arr [ 1 ] ; for ( l = 0 ; l < arr_size - 1 ; l ++ ) { for ( r = l + 1 ; r < arr_size ; r ++ ) { sum = arr [ l ] + arr [ r ] ; if ( Math . abs ( min_sum ) > Math . abs ( sum ) ) { min_sum = sum ; min_l = l ; min_r = r ; } } } System . out . println ( " ▁ The ▁ two ▁ elements ▁ whose ▁ " + " sum ▁ is ▁ minimum ▁ are ▁ " + arr [ min_l ] + " ▁ and ▁ " + arr [ min_r ] ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 60 , - 10 , 70 , - 80 , 85 } ; minAbsSumPair ( arr , 6 ) ; } }

Index/key variables: l, min_l, min_r, r
Accumulator variables: l, r
Iterator variables: l, r
Class/struct names: Main
Java program:
import java . util . * ; class GFG { static int maximumSum ( int S , int M , int N , int [ ] [ ] stacks ) { int [ ] [ ] dp = new int [ S + 1 ] [ N + 1 ] ; for ( int i = 0 ; i < S ; i ++ ) { for ( int j = 0 ; j <= N ; j ++ ) { for ( int k = 0 ; k <= Math . min ( j , M ) ; k ++ ) { dp [ i + 1 ] [ j ] = Math . max ( dp [ i + 1 ] [ j ] , stacks [ i ] [ k ] + dp [ i ] [ j - k ] ) ; } } } int result = Integer . MIN_VALUE ; for ( int i = 0 ; i <= N ; i ++ ) { result = Math . max ( result , dp [ S ] [ i ] ) ; } return result ; } public static void main ( String [ ] args ) { int S = 2 ; int M = 4 ; int [ ] [ ] stacks = { { 2 , 6 , 4 , 5 } , { 1 , 6 , 15 , 10 } } ; int N = 3 ; System . out . print ( maximumSum ( S , M , N , stacks ) ) ; } }

Index/key variables: S, i, j, k
Accumulator variables: i, j, k
Iterator variables: i, j, k
Class/struct names: GFG