dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
let MAX = 100 ; function isUnique ( mat , i , j , n , m ) { let sumrow = 0 ; for ( let k = 0 ; k < m ; k ++ ) { sumrow += mat [ i ] [ k ] ; if ( sumrow > 1 ) return false ; } let sumcol = 0 ; for ( let k = 0 ; k < n ; k ++ ) { sumcol += mat [ k ] [ j ] ; if ( sumcol > 1 ) return false ; } return true ; } function countUnique ( mat , n , m ) { let uniquecount = 0 ; for ( let i = 0 ; i < n ; i ++ ) for ( let j = 0 ; j < m ; j ++ ) if ( mat [ i ] [ j ] != 0 && isUnique ( mat , i , j , n , m ) ) uniquecount ++ ; return uniquecount ; } let mat = [ [ 0 , 1 , 0 , 0 ] , [ 0 , 0 , 1 , 0 ] , [ 1 , 0 , 0 , 1 ] ] ; document . write ( countUnique ( mat , 3 , 4 ) ) ;

Index/key variables: i, j, k
Accumulator variables: i, j, k, sumcol, sumrow, uniquecount
Iterator variables: i, j, k
Javascript program:
let MAX = 100 ; function countUnique ( mat , n , m ) { let rowsum = new Array ( n ) ; rowsum . fill ( 0 ) ; let colsum = new Array ( m ) ; colsum . fill ( 0 ) ; for ( let i = 0 ; i < n ; i ++ ) for ( let j = 0 ; j < m ; j ++ ) if ( mat [ i ] [ j ] != 0 ) { rowsum [ i ] ++ ; colsum [ j ] ++ ; } let uniquecount = 0 ; for ( let i = 0 ; i < n ; i ++ ) for ( let j = 0 ; j < m ; j ++ ) if ( mat [ i ] [ j ] != 0 && rowsum [ i ] == 1 && colsum [ j ] == 1 ) uniquecount ++ ; return uniquecount ; } let mat = [ [ 0 , 1 , 0 , 0 ] , [ 0 , 0 , 1 , 0 ] , [ 1 , 0 , 0 , 1 ] ] ; document . write ( countUnique ( mat , 3 , 4 ) ) ;

Index/key variables: i, j
Accumulator variables: i, j, uniquecount
Iterator variables: i, j
Javascript program:
let MAX = 100 ; function countCommon ( mat , n ) { let res = 0 ; for ( let i = 0 ; i < n ; i ++ ) if ( mat [ i ] [ i ] == mat [ i ] [ n - i - 1 ] ) res ++ ; return res ; } let mat = [ [ 1 , 2 , 3 ] , [ 4 , 5 , 6 ] , [ 7 , 8 , 9 ] ] ; document . write ( countCommon ( mat , 3 ) ) ;

Index/key variables: i
Accumulator variables: i, res
Iterator variables: i
Javascript program:
function areSumSame ( a , n , m ) { let sum1 = 0 , sum2 = 0 ; for ( let i = 0 ; i < n ; i ++ ) { sum1 = 0 ; sum2 = 0 ; for ( let j = 0 ; j < m ; j ++ ) { sum1 += a [ i ] [ j ] ; sum2 += a [ j ] [ i ] ; } if ( sum1 == sum2 ) return true ; } return false ; } let n = 4 ; let m = 4 ; let M = [ [ 1 , 2 , 3 , 4 ] , [ 9 , 5 , 3 , 1 ] , [ 0 , 3 , 5 , 6 ] , [ 0 , 4 , 5 , 6 ] ] ; if ( areSumSame ( M , n , m ) == true ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i, j
Accumulator variables: i, j, sum1, sum2
Iterator variables: i, j
Javascript program:
class NodeTemp { constructor ( data ) { this . data = data ; this . next = this . child = null ; } } function addSibling ( node , data ) { if ( node == null ) return null ; while ( node . next != null ) node = node . next ; return ( node . next = new NodeTemp ( data ) ) ; } function addChild ( node , data ) { if ( node == null ) return null ; if ( node . child != null ) return ( addSibling ( node . child , data ) ) ; else return ( node . child = new NodeTemp ( data ) ) ; } function traverseTree ( root ) { if ( root == null ) return ; while ( root != null ) { document . write ( root . data + " " ) ; if ( root . child != null ) traverseTree ( root . child ) ; root = root . next ; } } let root = new NodeTemp ( 10 ) ; let n1 = addChild ( root , 2 ) ; let n2 = addChild ( root , 3 ) ; let n3 = addChild ( root , 4 ) ; let n4 = addChild ( n3 , 6 ) ; let n5 = addChild ( root , 5 ) ; let n6 = addChild ( n5 , 7 ) ; let n7 = addChild ( n5 , 8 ) ; let n8 = addChild ( n5 , 9 ) ; traverseTree ( root ) ;

Class/struct names: NodeTemp
Javascript program:
var N = 4 function findMax ( arr ) { var row = 0 , i , j ; for ( i = 0 , j = N - 1 ; i < N ; i ++ ) { while ( arr [ i ] [ j ] == 1 && j >= 0 ) { row = i ; j -- ; } } document . write ( " " + ( row + 1 ) ) ; document . write ( " " + ( N - 1 - j ) ) ; } var arr = [ [ 0 , 0 , 0 , 1 ] , [ 0 , 0 , 0 , 1 ] , [ 0 , 0 , 0 , 0 ] , [ 0 , 1 , 1 , 1 ] ] ; findMax ( arr ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i
Javascript program:
class Cell { constructor ( x , y ) { this . x = x ; this . y = y ; } } function isAllCellTraversed ( grid ) { let visited = new Array ( grid . length ) ; for ( let i = 0 ; i < visited . length ; i ++ ) { visited [ i ] = new Array ( grid [ 0 ] . length ) ; } let total = grid . length * grid [ 0 ] . length ; let startx = grid [ 0 ] [ 0 ] . x ; let starty = grid [ 0 ] [ 0 ] . y ; for ( let i = 0 ; i < total - 2 ; i ++ ) { if ( grid [ startx ] [ starty ] == null ) return false ; if ( visited [ startx ] [ starty ] == true ) return false ; visited [ startx ] [ starty ] = true ; let x = grid [ startx ] [ starty ] . x ; let y = grid [ startx ] [ starty ] . y ; startx = x ; starty = y ; } if ( grid [ startx ] [ starty ] == null ) return true ; return false ; } let cell = new Array ( 3 ) ; for ( let i = 0 ; i < 3 ; i ++ ) { cell [ i ] = new Array ( 2 ) ; } cell [ 0 ] [ 0 ] = new Cell ( 0 , 1 ) ; cell [ 0 ] [ 1 ] = new Cell ( 2 , 0 ) ; cell [ 1 ] [ 0 ] = null ; cell [ 1 ] [ 1 ] = new Cell ( 1 , 0 ) ; cell [ 2 ] [ 0 ] = new Cell ( 2 , 1 ) ; cell [ 2 ] [ 1 ] = new Cell ( 1 , 1 ) ; document . write ( isAllCellTraversed ( cell ) ) ;

Index/key variables: i, startx, starty
Accumulator variables: i
Iterator variables: i
Class/struct names: Cell
Javascript program:
function isPalin ( str ) { let len = str . length / 2 ; for ( let i = 0 ; i < len ; i ++ ) { if ( str [ i ] != str [ str . length - i - 1 ] ) return false ; } return true ; } function palindromicPath ( str , a , i , j , m , n ) { if ( j < m - 1 i < n - 1 ) { if ( i < n - 1 ) palindromicPath ( str + a [ i ] [ j ] , a , i + 1 , j , m , n ) ; if ( j < m - 1 ) palindromicPath ( str + a [ i ] [ j ] , a , i , j + 1 , m , n ) ; } else { str = str + a [ n - 1 ] [ m - 1 ] ; if ( isPalin ( str ) ) document . write ( str + " " ) ; } } let arr = [ [ ' ' , ' ' , ' ' , ' ' ] , [ ' ' , ' ' , ' ' , ' ' ] , [ ' ' , ' ' , ' ' , ' ' ] ] let str = " " palindromicPath ( str , arr , 0 , 0 , 4 , 3 )

Index/key variables: i, j
Accumulator variables: i
Iterator variables: i
Javascript program:
let n = 4 ; let m = 4 ; function findPossibleMoves ( mat , p , q ) { let X = [ 2 , 1 , - 1 , - 2 , - 2 , - 1 , 1 , 2 ] ; let Y = [ 1 , 2 , 2 , 1 , - 1 , - 2 , - 2 , - 1 ] ; let count = 0 ; for ( let i = 0 ; i < 8 ; i ++ ) { let x = p + X [ i ] ; let y = q + Y [ i ] ; if ( x >= 0 && y >= 0 && x < n && y < m && mat [ x ] [ y ] == 0 ) count ++ ; } return count ; } let mat = [ [ 1 , 0 , 1 , 0 ] , [ 0 , 1 , 1 , 1 ] , [ 1 , 1 , 0 , 1 ] , [ 0 , 1 , 1 , 1 ] ] ; let p = 2 , q = 2 ; document . write ( findPossibleMoves ( mat , p , q ) ) ;

Index/key variables: i, x, y
Accumulator variables: count, i
Iterator variables: i
Javascript program:
const MAX = 100 ; void printDiagonalSums ( mat , n ) { let principal = 0 , secondary = 0 ; for ( let i = 0 ; i < n ; i ++ ) { for ( let j = 0 ; j < n ; j ++ ) { if ( i == j ) principal += mat [ i ] [ j ] ; if ( ( i + j ) == ( n - 1 ) ) secondary += mat [ i ] [ j ] ; } } document . write ( " " + principal + " " ) ; document . write ( " " + secondary + " " ) ; } let a = [ [ 1 , 2 , 3 , 4 ] , [ 5 , 6 , 7 , 8 ] , [ 1 , 2 , 3 , 4 ] , [ 5 , 6 , 7 , 8 ] ] ; printDiagonalSums ( a , 4 ) ;

Index/key variables: i, j
Accumulator variables: i, j, principal, secondary
Iterator variables: i, j
Javascript program:
function printDiagonalSums ( mat , n ) { let principal = 0 , secondary = 0 ; for ( let i = 0 ; i < n ; i ++ ) { principal += mat [ i ] [ i ] ; secondary += mat [ i ] [ n - i - 1 ] ; } document . write ( " " + principal + " " ) ; document . write ( " " + secondary ) ; } let a = [ [ 1 , 2 , 3 , 4 ] , [ 5 , 6 , 7 , 8 ] , [ 1 , 2 , 3 , 4 ] , [ 5 , 6 , 7 , 8 ] ] ; printDiagonalSums ( a , 4 ) ;

Index/key variables: i
Accumulator variables: i, principal, secondary
Iterator variables: i
Javascript program:
class Node { constructor ( data ) { this . data = data ; this . next = this . child = null ; } } function addSibling ( n , data ) { if ( n == null ) return null ; while ( n . next != null ) n = n . next ; return ( n . next = new Node ( data ) ) ; } function addChild ( n , data ) { if ( n == null ) return null ; if ( n . child != null ) return addSibling ( n . child , data ) ; else return ( n . child = new Node ( data ) ) ; } function traverseTree ( root ) { if ( root == null ) return ; document . write ( root . data + " " ) ; if ( root . child == null ) return ; let q = [ ] ; let curr = root . child ; q . push ( curr ) ; while ( q . length != 0 ) { curr = q [ 0 ] ; q . shift ( ) ; while ( curr != null ) { document . write ( curr . data + " " ) ; if ( curr . child != null ) { q . push ( curr . child ) ; } curr = curr . next ; } } } let root = new Node ( 10 ) ; let n1 = addChild ( root , 2 ) ; let n2 = addChild ( root , 3 ) ; let n3 = addChild ( root , 4 ) ; let n4 = addChild ( n3 , 6 ) ; let n5 = addChild ( root , 5 ) ; let n6 = addChild ( n5 , 7 ) ; let n7 = addChild ( n5 , 8 ) ; let n8 = addChild ( n5 , 9 ) ; traverseTree ( root ) ;

Class/struct names: Node
Javascript program:
function getBoundarySum ( a , m , n ) { let sum = 0 ; for ( let i = 0 ; i < m ; i ++ ) { for ( let j = 0 ; j < n ; j ++ ) { if ( i == 0 ) sum += a [ i ] [ j ] ; else if ( i == m - 1 ) sum += a [ i ] [ j ] ; else if ( j == 0 ) sum += a [ i ] [ j ] ; else if ( j == n - 1 ) sum += a [ i ] [ j ] ; } } return sum ; } let a = [ [ 1 , 2 , 3 , 4 ] , [ 5 , 6 , 7 , 8 ] , [ 1 , 2 , 3 , 4 ] , [ 5 , 6 , 7 , 8 ] ] ; let sum = getBoundarySum ( a , 4 , 4 ) ; document . write ( " " + " " + sum ) ;

Index/key variables: i, j
Accumulator variables: i, j, sum
Iterator variables: i, j
Javascript program:
const MAX = 100 ; function printSpiral ( mat , r , c ) { let i , a = 0 , b = 2 ; let low_row = ( 0 > a ) ? 0 : a ; let low_column = ( 0 > b ) ? 0 : b - 1 ; let high_row = ( ( a + 1 ) >= r ) ? r - 1 : a + 1 ; let high_column = ( ( b + 1 ) >= c ) ? c - 1 : b + 1 ; while ( ( low_row > 0 - r && low_column > 0 - c ) ) { for ( i = low_column + 1 ; i <= high_column && i < c && low_row >= 0 ; ++ i ) document . write ( mat [ low_row ] [ i ] + " " ) ; low_row -= 1 ; for ( i = low_row + 2 ; i <= high_row && i < r && high_column < c ; ++ i ) document . write ( mat [ i ] [ high_column ] + " " ) ; high_column += 1 ; for ( i = high_column - 2 ; i >= low_column && i >= 0 && high_row < r ; -- i ) document . write ( mat [ high_row ] [ i ] + " " ) ; high_row += 1 ; for ( i = high_row - 2 ; i > low_row && i >= 0 && low_column >= 0 ; -- i ) document . write ( mat [ i ] [ low_column ] + " " ) ; low_column -= 1 ; } document . write ( " " ) ; } let mat = [ [ 1 , 2 , 3 ] , [ 4 , 5 , 6 ] , [ 7 , 8 , 9 ] ] ; let r = 3 , c = 3 ; printSpiral ( mat , r , c ) ;

Index/key variables: high_column, high_row, i, low_column, low_row
Accumulator variables: high_column, high_row, low_column, low_row
Iterator variables: i
Javascript program:
let N = 3 ; function interchangeDiagonals ( array ) { for ( let i = 0 ; i < N ; ++ i ) if ( i != parseInt ( N / 2 ) ) { let temp = array [ i ] [ i ] ; array [ i ] [ i ] = array [ i ] [ N - i - 1 ] ; array [ i ] [ N - i - 1 ] = temp ; } for ( let i = 0 ; i < N ; ++ i ) { for ( let j = 0 ; j < N ; ++ j ) document . write ( " " + array [ i ] [ j ] ) ; document . write ( " " ) ; } } let array = [ [ 4 , 5 , 6 ] , [ 1 , 2 , 3 ] , [ 7 , 8 , 9 ] ] ; interchangeDiagonals ( array ) ;

Index/key variables: i, j
Iterator variables: i, j
Javascript program:
function difference ( arr , n ) { let d1 = 0 , d2 = 0 ; for ( let i = 0 ; i < n ; i ++ ) { for ( let j = 0 ; j < n ; j ++ ) { if ( i == j ) d1 += arr [ i ] [ j ] ; if ( i == n - j - 1 ) d2 += arr [ i ] [ j ] ; } } return Math . abs ( d1 - d2 ) ; } let n = 3 ; let arr = [ [ 11 , 2 , 4 ] , [ 4 , 5 , 6 ] , [ 10 , 8 , - 12 ] ] ; document . write ( difference ( arr , n ) ) ;

Index/key variables: i, j
Accumulator variables: d1, d2, i, j
Iterator variables: i, j
Javascript program:
function difference ( arr , n ) { let d1 = 0 , d2 = 0 ; for ( let i = 0 ; i < n ; i ++ ) { d1 += arr [ i ] [ i ] ; d2 += arr [ i ] [ n - i - 1 ] ; } return Math . abs ( d1 - d2 ) ; } let n = 3 ; let arr = [ [ 11 , 2 , 4 ] , [ 4 , 5 , 6 ] , [ 10 , 8 , - 12 ] ] ; document . write ( difference ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: d1, d2, i
Iterator variables: i
Javascript program:
const MAX = 100 ; function spiralFill ( m , n , a ) { let val = 1 ; let k = 0 , l = 0 ; while ( k < m && l < n ) { for ( let i = l ; i < n ; ++ i ) a [ k ] [ i ] = val ++ ; k ++ ; for ( let i = k ; i < m ; ++ i ) a [ i ] [ n - 1 ] = val ++ ; n -- ; if ( k < m ) { for ( let i = n - 1 ; i >= l ; -- i ) a [ m - 1 ] [ i ] = val ++ ; m -- ; } if ( l < n ) { for ( let i = m - 1 ; i >= k ; -- i ) a [ i ] [ l ] = val ++ ; l ++ ; } } } let m = 4 , n = 4 ; let a = Array . from ( Array ( MAX ) , ( ) => new Array ( MAX ) ) ; spiralFill ( m , n , a ) ; for ( let i = 0 ; i < m ; i ++ ) { for ( let j = 0 ; j < n ; j ++ ) document . write ( a [ i ] [ j ] + " " ) ; document . write ( " " ) ; }

Index/key variables: i, j, k, l
Accumulator variables: i, j, k, l, m, n, val
Iterator variables: i, j
Javascript program:
let MAX = 100 ; function maxMin ( arr , n ) { let min = + 2147483647 ; let max = - 2147483648 ; for ( let i = 0 ; i < n ; i ++ ) { for ( let j = 0 ; j <= n / 2 ; j ++ ) { if ( arr [ i ] [ j ] > arr [ i ] [ n - j - 1 ] ) { if ( min > arr [ i ] [ n - j - 1 ] ) min = arr [ i ] [ n - j - 1 ] ; if ( max < arr [ i ] [ j ] ) max = arr [ i ] [ j ] ; } else { if ( min > arr [ i ] [ j ] ) min = arr [ i ] [ j ] ; if ( max < arr [ i ] [ n - j - 1 ] ) max = arr [ i ] [ n - j - 1 ] ; } } } document . write ( " " + max + " " + min ) ; } let arr = [ [ 5 , 9 , 11 ] , [ 25 , 0 , 14 ] , [ 21 , 6 , 4 ] ] ; maxMin ( arr , 3 ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function antiSpiralTraversal ( m , n , a ) { let i , k = 0 , l = 0 ; let stk = [ ] ; while ( k <= m && l <= n ) { for ( i = l ; i <= n ; ++ i ) stk . push ( a [ k ] [ i ] ) ; k ++ ; for ( i = k ; i <= m ; ++ i ) stk . push ( a [ i ] [ n ] ) ; n -- ; if ( k <= m ) { for ( i = n ; i >= l ; -- i ) stk . push ( a [ m ] [ i ] ) ; m -- ; } if ( l <= n ) { for ( i = m ; i >= k ; -- i ) stk . push ( a [ i ] [ l ] ) ; l ++ ; } } while ( stk . length != 0 ) { document . write ( stk [ stk . length - 1 ] + " " ) ; stk . pop ( ) ; } } let mat = [ [ 1 , 2 , 3 , 4 , 5 ] , [ 6 , 7 , 8 , 9 , 10 ] , [ 11 , 12 , 13 , 14 , 15 ] , [ 16 , 17 , 18 , 19 , 20 ] ] ; antiSpiralTraversal ( mat . length - 1 , mat [ 0 ] . length - 1 , mat ) ;

Index/key variables: i, k, l, m, n
Accumulator variables: k, l, m, n
Iterator variables: i
Javascript program:
let N = 5 ; let M = 5 ; function minOperation ( arr ) { let ans = 0 ; for ( let i = N - 1 ; i >= 0 ; i -- ) { for ( let j = M - 1 ; j >= 0 ; j -- ) { if ( arr [ i ] [ j ] == false ) { ans ++ ; for ( let k = 0 ; k <= i ; k ++ ) { for ( let h = 0 ; h <= j ; h ++ ) { if ( arr [ k ] [ h ] == true ) { arr [ k ] [ h ] = false ; } else { arr [ k ] [ h ] = true ; } } } } } } return ans ; } let mat = [ [ 0 , 0 , 1 , 1 , 1 ] , [ 0 , 0 , 0 , 1 , 1 ] , [ 0 , 0 , 0 , 1 , 1 ] , [ 1 , 1 , 1 , 1 , 1 ] , [ 1 , 1 , 1 , 1 , 1 ] ] document . write ( minOperation ( mat ) )

Index/key variables: h, i, j, k
Accumulator variables: ans, h, i, j, k
Iterator variables: h, i, j, k
Javascript program:
function findSum ( n ) { let ans = 0 , temp = 0 , num ; for ( let 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 ans ; } let N = 2 ; document . write ( findSum ( N ) ) ;

Accumulator variables: ans, i, num, temp
Iterator variables: i
Javascript program:
function printCoils ( n ) { let m = 8 * n * n ; let coil1 = new Array ( m ) ; coil1 . fill ( 0 ) ; coil1 [ 0 ] = 8 * n * n + 2 * n ; let curr = coil1 [ 0 ] ; let nflg = 1 , step = 2 ; let index = 1 ; while ( index < m ) { for ( let i = 0 ; i < step ; i ++ ) { curr = coil1 [ index ++ ] = ( curr - 4 * n * nflg ) ; if ( index >= m ) break ; } if ( index >= m ) break ; for ( let i = 0 ; i < step ; i ++ ) { curr = coil1 [ index ++ ] = curr + nflg ; if ( index >= m ) break ; } nflg = nflg * ( - 1 ) ; step += 2 ; } let coil2 = new Array ( m ) ; coil2 . fill ( 0 ) ; for ( let i = 0 ; i < 8 * n * n ; i ++ ) coil2 [ i ] = 16 * n * n + 1 - coil1 [ i ] ; document . write ( " " ) ; for ( let i = 0 ; i < 8 * n * n ; i ++ ) document . write ( coil1 [ i ] + " " ) ; document . write ( " " + " " ) ; for ( let i = 0 ; i < 8 * n * n ; i ++ ) document . write ( coil2 [ i ] + " " ) ; } let n = 1 ; printCoils ( n ) ;

Index/key variables: i
Accumulator variables: i, index, step
Iterator variables: i
Javascript program:
function findSum ( n ) { let arr = new Array ( n ) ; for ( let i = 0 ; i < n ; i ++ ) { arr [ i ] = new Array ( n ) ; for ( let j = 0 ; j < n ; j ++ ) { arr [ i ] [ j ] = 0 ; } } for ( let i = 0 ; i < n ; i ++ ) for ( let j = 0 ; j < n ; j ++ ) arr [ i ] [ j ] = Math . abs ( i - j ) ; let sum = 0 ; for ( let i = 0 ; i < n ; i ++ ) for ( let j = 0 ; j < n ; j ++ ) sum += arr [ i ] [ j ] ; return sum ; } let n = 3 ; document . write ( findSum ( n ) ) ;

Index/key variables: i, j
Accumulator variables: i, j, sum
Iterator variables: i, j
Javascript program:
function findSum ( n ) { let sum = 0 ; for ( let i = 0 ; i < n ; i ++ ) sum += i * ( n - i ) ; return 2 * sum ; } let n = 3 ; document . write ( findSum ( n ) ) ;

Accumulator variables: i, sum
Iterator variables: i
Javascript program:
function findSum ( n ) { n -- ; let sum = 0 ; sum += ( n * ( n + 1 ) ) / 2 ; sum += ( n * ( n + 1 ) * ( 2 * n + 1 ) ) / 6 ; return sum ; } let n = 3 ; document . write ( findSum ( n ) ) ;

Accumulator variables: n, sum
Javascript program:
let R = 3 ; let C = 5 ; function numofneighbour ( mat , i , j ) { let count = 0 ; if ( i > 0 && mat [ i - 1 ] [ j ] == 1 ) count ++ ; if ( j > 0 && mat [ i ] [ j - 1 ] == 1 ) count ++ ; if ( i < R - 1 && mat [ i + 1 ] [ j ] == 1 ) count ++ ; if ( j < C - 1 && mat [ i ] [ j + 1 ] == 1 ) count ++ ; return count ; } function findperimeter ( mat ) { let perimeter = 0 ; for ( let i = 0 ; i < R ; i ++ ) for ( let j = 0 ; j < C ; j ++ ) if ( mat [ i ] [ j ] == 1 ) perimeter += ( 4 - numofneighbour ( mat , i , j ) ) ; return perimeter ; } let mat = [ [ 0 , 1 , 0 , 0 , 0 ] , [ 1 , 1 , 1 , 0 , 0 ] , [ 1 , 0 , 0 , 0 , 0 ] ] ; document . write ( findperimeter ( mat ) ) ;

Index/key variables: i, j
Accumulator variables: count, i, j, perimeter
Iterator variables: i, j
Javascript program:
function printMatrixDiagonal ( arr , len ) { let i = 0 , j = 0 ; let isUp = true ; for ( let k = 0 ; k < len * len ; ) { if ( isUp ) { for ( ; i >= 0 && j < len ; i -- , j ++ ) { document . write ( arr [ i ] [ j ] + ' ' ) ; k ++ ; } if ( i < 0 && j < len ) i = 0 ; if ( j === len ) i = i + 2 , j -- ; } else { for ( ; j >= 0 && i < len ; i ++ , j -- ) { document . write ( arr [ i ] [ j ] + ' ' ) ; k ++ ; } if ( j < 0 && i < len ) j = 0 ; if ( i === len ) j = j + 2 , i -- ; } isUp = ! isUp } } let arr = [ [ 1 , 2 , 3 ] , [ 4 , 5 , 6 ] , [ 7 , 8 , 9 ] ] ; let arrLength = arr . length ; printMatrixDiagonal ( arr , arrLength ) ;

Index/key variables: i, j
Accumulator variables: i, j, k
Iterator variables: k
Boolean variables: isUp
Javascript program:
function MatrixDiag ( arr ) { let arr = [ [ 1 , 2 , 3 , 4 ] , [ 5 , 6 , 7 , 8 ] , [ 9 , 10 , 11 , 12 ] , [ 13 , 14 , 15 , 16 ] ] ; let n = arr . length , mode = 0 , it = 0 , lower = 0 ; for ( let t = 0 ; t < ( 2 * n - 1 ) ; t ++ ) { let t1 = t ; if ( t1 >= n ) { mode ++ ; t1 = n - 1 ; it -- ; lower ++ ; } else { lower = 0 ; it ++ ; } for ( let i = t1 ; i >= lower ; i -- ) { if ( ( t1 + mode ) % 2 === 0 ) { console . log ( arr [ i ] [ t1 + lower - i ] ) } else { console . log ( arr [ t1 + lower - i ] [ i ] ) } } } } MatrixDiag ( arr )

Index/key variables: i
Accumulator variables: i, it, lower, mode, t
Iterator variables: i, t
Javascript program:
function maxRowDiff ( mat , m , n ) { let rowSum = new Array ( m ) ; for ( let i = 0 ; i < m ; i ++ ) { let sum = 0 ; for ( let j = 0 ; j < n ; j ++ ) sum += mat [ i ] [ j ] ; rowSum [ i ] = sum ; } let max_diff = rowSum [ 1 ] - rowSum [ 0 ] ; let min_element = rowSum [ 0 ] ; for ( let i = 1 ; i < m ; i ++ ) { if ( rowSum [ i ] - min_element > max_diff ) max_diff = rowSum [ i ] - min_element ; if ( rowSum [ i ] < min_element ) min_element = rowSum [ i ] ; } return max_diff ; } let m = 5 , n = 4 ; let mat = [ [ - 1 , 2 , 3 , 4 ] , [ 5 , 3 , - 2 , 1 ] , [ 6 , 7 , 2 , - 3 ] , [ 2 , 9 , 1 , 4 ] , [ 2 , 1 , - 2 , 0 ] ] ; document . write ( maxRowDiff ( mat , m , n ) ) ;

Index/key variables: i, j
Accumulator variables: i, j, sum
Iterator variables: i, j
Javascript program:
let R = 4 ; let C = 4 ; function getTotalCoverageOfMatrix ( mat ) { let res = 0 ; for ( let i = 0 ; i < R ; i ++ ) { let isOne = false ; for ( let j = 0 ; j < C ; j ++ ) { if ( mat [ i ] [ j ] == 1 ) isOne = true ; else if ( isOne ) res ++ ; } isOne = false ; for ( let j = C - 1 ; j >= 0 ; j -- ) { if ( mat [ i ] [ j ] == 1 ) isOne = true ; else if ( isOne ) res ++ ; } } for ( let j = 0 ; j < C ; j ++ ) { let isOne = false ; for ( let i = 0 ; i < R ; i ++ ) { if ( mat [ i ] [ j ] == 1 ) isOne = true ; else if ( isOne ) res ++ ; } isOne = false ; for ( let i = R - 1 ; i >= 0 ; i -- ) { if ( mat [ i ] [ j ] == 1 ) isOne = true ; else if ( isOne ) res ++ ; } } return res ; } let mat = [ [ 0 , 0 , 0 , 0 ] , [ 1 , 0 , 0 , 1 ] , [ 0 , 1 , 1 , 0 ] , [ 0 , 1 , 0 , 0 ] ] ; document . write ( getTotalCoverageOfMatrix ( mat ) ) ;

Index/key variables: i, j
Accumulator variables: i, j, res
Iterator variables: i, j
Boolean variables: isOne
Javascript program:
let MAX = 100 ; function sortedCount ( mat , r , c ) { let result = 0 ; for ( let i = 0 ; i < r ; i ++ ) { let j ; for ( j = 0 ; j < c - 1 ; j ++ ) if ( mat [ i ] [ j + 1 ] <= mat [ i ] [ j ] ) break ; if ( j == c - 1 ) result ++ ; } for ( let i = 0 ; i < r ; i ++ ) { let j ; for ( j = c - 1 ; j > 0 ; j -- ) if ( mat [ i ] [ j - 1 ] <= mat [ i ] [ j ] ) break ; if ( c > 1 && j == 0 ) result ++ ; } return result ; } let m = 4 , n = 5 ; let mat = [ [ 1 , 2 , 3 , 4 , 5 ] , [ 4 , 3 , 1 , 2 , 6 ] , [ 8 , 7 , 6 , 5 , 4 ] , [ 5 , 7 , 8 , 9 , 10 ] ] document . write ( sortedCount ( mat , m , n ) )

Index/key variables: i, j
Accumulator variables: i, j, result
Iterator variables: i, j
Javascript program:
const MAX = 1000 ; function maxXOR ( mat , N ) { let r_xor , c_xor ; let max_xor = 0 ; for ( let i = 0 ; i < N ; i ++ ) { r_xor = 0 , c_xor = 0 ; for ( let j = 0 ; j < N ; j ++ ) { r_xor = r_xor ^ mat [ i ] [ j ] ; c_xor = c_xor ^ mat [ j ] [ i ] ; } if ( max_xor < Math . max ( r_xor , c_xor ) ) max_xor = Math . max ( r_xor , c_xor ) ; } return max_xor ; } let N = 3 ; let mat = [ [ 1 , 5 , 4 ] , [ 3 , 7 , 2 ] , [ 5 , 9 , 10 ] ] ; document . write ( " " + maxXOR ( mat , N ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
let R = 3 ; let C = 6 ; function spiralPrint ( m , n , a , c ) { let i , k = 0 , l = 0 ; let count = 0 ; while ( k < m && l < n ) { for ( i = l ; i < n ; ++ i ) { count ++ ; if ( count == c ) document . write ( a [ k ] [ i ] + " " ) ; } k ++ ; for ( i = k ; i < m ; ++ i ) { count ++ ; if ( count == c ) document . write ( a [ i ] [ n - 1 ] + " " ) ; } n -- ; if ( k < m ) { for ( i = n - 1 ; i >= l ; -- i ) { count ++ ; if ( count == c ) document . write ( a [ m - 1 ] [ i ] + " " ) ; } m -- ; } if ( l < n ) { for ( i = m - 1 ; i >= k ; -- i ) { count ++ ; if ( count == c ) document . write ( a [ i ] [ l ] + " " ) ; } l ++ ; } } } let a = [ [ 1 , 2 , 3 , 4 , 5 , 6 ] , [ 7 , 8 , 9 , 10 , 11 , 12 ] , [ 13 , 14 , 15 , 16 , 17 , 18 ] ] , k = 17 ; spiralPrint ( R , C , a , k ) ;

Index/key variables: i, k, l
Accumulator variables: count, k, l, m, n
Iterator variables: i
Javascript program:
let N = 5 ; function countZeroes ( mat ) { let row = N - 1 , col = 0 ; let count = 0 ; while ( col < N ) { while ( mat [ row ] [ col ] > 0 ) if ( -- row < 0 ) return count ; count += ( row + 1 ) ; col ++ ; } return count ; } let mat = [ [ 0 , 0 , 0 , 0 , 1 ] , [ 0 , 0 , 0 , 1 , 1 ] , [ 0 , 1 , 1 , 1 , 1 ] , [ 1 , 1 , 1 , 1 , 1 ] , [ 1 , 1 , 1 , 1 , 1 ] ] ; document . write ( countZeroes ( mat ) ) ;

Index/key variables: col, row
Accumulator variables: col, count