dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
class Node { constructor ( key ) { this . key = key ; this . left = this . right = null ; } } class Res { constructor ( ) { this . res = false ; } } var root ; function count ( node ) { if ( node == null ) return 0 ; return count ( node . left ) + count ( node . right ) + 1 ; } function checkRec ( root , n , res ) { if ( root == null ) return 0 ; var c = checkRec ( root . left , n , res ) + 1 + checkRec ( root . right , n , res ) ; if ( c == n - c ) res . res = true ; return c ; } function check ( root ) { var n = count ( root ) ; res = new Res ( ) ; checkRec ( root , n , res ) ; return res . res ; } root = new Node ( 5 ) ; root . left = new Node ( 1 ) ; root . right = new Node ( 6 ) ; root . left . left = new Node ( 3 ) ; root . right . left = new Node ( 7 ) ; root . right . right = new Node ( 4 ) ; if ( check ( root ) == true ) document . write ( " " ) ; else document . write ( " " ) ;

Boolean variables: res
Class/struct names: Node, Res
Javascript program:
let N = 3 ; let M = 4 ; function printDistance ( mat ) { let ans = new Array ( N ) ; for ( let i = 0 ; i < N ; i ++ ) { ans [ i ] = new Array ( M ) ; for ( let j = 0 ; j < M ; j ++ ) { ans [ i ] [ j ] = Number . MAX_VALUE ; } } for ( let i = 0 ; i < N ; i ++ ) for ( let j = 0 ; j < M ; j ++ ) { for ( let k = 0 ; k < N ; k ++ ) for ( let l = 0 ; l < M ; l ++ ) { if ( mat [ k ] [ l ] == 1 ) ans [ i ] [ j ] = Math . min ( ans [ i ] [ j ] , Math . abs ( i - k ) + Math . abs ( j - l ) ) ; } } for ( let i = 0 ; i < N ; i ++ ) { for ( let j = 0 ; j < M ; j ++ ) document . write ( ans [ i ] [ j ] + " " ) ; document . write ( " " ) ; } } let mat = [ [ 0 , 0 , 0 , 1 ] , [ 0 , 0 , 1 , 1 ] , [ 0 , 1 , 1 , 0 ] ] printDistance ( mat ) ;

Index/key variables: i, j, k, l
Accumulator variables: i, j, k, l
Iterator variables: i, j, k, l
Javascript program:
let preIndex = 0 ; class Node { constructor ( data ) { this . data = data ; this . left = this . right = null ; } } function search ( arr , strt , end , value ) { for ( let i = strt ; i <= end ; i ++ ) { if ( arr [ i ] == value ) return i ; } return - 1 ; } function buildTree ( In , pre , inStrt , inEnd ) { if ( inStrt > inEnd ) return null ; let tNode = new Node ( pre [ preIndex ++ ] ) ; if ( inStrt == inEnd ) return tNode ; let inIndex = search ( In , inStrt , inEnd , tNode . data ) ; tNode . left = buildTree ( In , pre , inStrt , inIndex - 1 ) ; tNode . right = buildTree ( In , pre , inIndex + 1 , inEnd ) ; return tNode ; } function checkPostorder ( node , postOrder , index ) { if ( node == null ) return index ; index = checkPostorder ( node . left , postOrder , index ) ; index = checkPostorder ( node . right , postOrder , index ) ; if ( node . data == postOrder [ index ] ) index ++ ; else return - 1 ; return index ; } let inOrder = [ 4 , 2 , 5 , 1 , 3 ] ; let preOrder = [ 1 , 2 , 4 , 5 , 3 ] ; let postOrder = [ 4 , 5 , 2 , 3 , 1 ] ; let len = inOrder . length ; let root = buildTree ( inOrder , preOrder , 0 , len - 1 ) ; let index = checkPostorder ( root , postOrder , 0 ) ; if ( index == len ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i, index
Accumulator variables: i, index, preIndex
Iterator variables: i
Class/struct names: Node
Javascript program:
function isChangeable ( notes , n ) { let fiveCount = 0 ; let tenCount = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( notes [ i ] == 5 ) fiveCount ++ ; else if ( notes [ i ] == 10 ) { if ( fiveCount > 0 ) { fiveCount -- ; tenCount ++ ; } else return 0 ; } else { if ( fiveCount > 0 && tenCount > 0 ) { fiveCount -- ; tenCount -- ; } else if ( fiveCount >= 3 ) { fiveCount -= 3 ; } else return 0 ; } } return 1 ; } let a = [ 5 , 5 , 5 , 10 , 20 ] ; let n = a . length ; if ( isChangeable ( a , n ) > 0 ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: fiveCount, i, tenCount
Iterator variables: i
Javascript program:
function maxDistance ( arr , n ) { let map = new Map ( ) ; let max_dist = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( ! map . has ( arr [ i ] ) ) map . set ( arr [ i ] , i ) ; else max_dist = Math . max ( max_dist , i - map . get ( arr [ i ] ) ) ; } return max_dist ; } let arr = [ 3 , 2 , 1 , 2 , 1 , 4 , 5 , 8 , 6 , 7 , 4 , 2 ] ; let n = arr . length ; document . write ( maxDistance ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function checkDuplicatesWithinK ( arr , n , k ) { let myset = [ ] ; for ( let i = 0 ; i < n ; i ++ ) { if ( arr . includes ( arr [ i ] ) ) { return true ; } myset . add ( arr [ i ] ) ; if ( i >= k ) { index = array . indexOf ( arr [ i - k ] ) ; array . splice ( index , 1 ) ; } } return false ; } let arr = [ 10 , 5 , 3 , 4 , 3 , 5 , 6 ] ; let n = arr . length ; if ( checkDuplicatesWithinK ( arr , n , 3 ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function mostFrequent ( arr , n ) { arr . sort ( ) ; let max_count = 1 , res = arr [ 0 ] ; let curr_count = 1 ; for ( let i = 1 ; i < n ; i ++ ) { if ( arr [ i ] == arr [ i - 1 ] ) curr_count ++ ; else { if ( curr_count > max_count ) { max_count = curr_count ; res = arr [ i - 1 ] ; } curr_count = 1 ; } } if ( curr_count > max_count ) { max_count = curr_count ; res = arr [ n - 1 ] ; } return res ; } let arr = [ 1 , 5 , 2 , 1 , 3 , 2 , 1 ] ; let n = arr . length ; document . write ( mostFrequent ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: curr_count, i
Iterator variables: i
Javascript program:
function mostFrequent ( arr , n ) { var hash = new Map ( ) ; for ( var i = 0 ; i < n ; i ++ ) { if ( hash . has ( arr [ i ] ) ) hash . set ( arr [ i ] , hash . get ( arr [ i ] ) + 1 ) else hash . set ( arr [ i ] , 1 ) } var max_count = 0 , res = - 1 ; hash . forEach ( ( value , key ) => { if ( max_count < value ) { res = key ; max_count = value ; } } ) ; return res ; } var arr = [ 1 , 5 , 2 , 1 , 3 , 2 , 1 ] ; var n = arr . length ; document . write ( mostFrequent ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function smallestSubsegment ( a , n ) { let left = new Map ( ) ; let count = new Map ( ) ; let mx = 0 ; let mn = - 1 , strindex = - 1 ; for ( let i = 0 ; i < n ; i ++ ) { let x = a [ i ] ; if ( count . get ( x ) == null ) { left . set ( x , i ) ; count . set ( x , 1 ) ; } else count . set ( x , count . get ( x ) + 1 ) ; if ( count . get ( x ) > mx ) { mx = count . get ( x ) ; mn = i - left . get ( x ) + 1 ; strindex = left . get ( x ) ; } else if ( ( count . get ( x ) == mx ) && ( i - left . get ( x ) + 1 < mn ) ) { mn = i - left . get ( x ) + 1 ; strindex = left . get ( x ) ; } } for ( let i = strindex ; i < strindex + mn ; i ++ ) document . write ( a [ i ] + " " ) ; } let A = [ 1 , 2 , 2 , 2 , 1 ] ; let n = A . length ; smallestSubsegment ( A , n ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function findSymPairs ( arr ) { let hM = new Map ( ) ; for ( let i = 0 ; i < arr . length ; i ++ ) { let first = arr [ i ] [ 0 ] ; let sec = arr [ i ] [ 1 ] ; let val = hM . get ( sec ) ; if ( val != null && val == first ) document . write ( " " + sec + " " + first + " " ) ; else hM . set ( first , sec ) ; } } let arr = new Array ( 5 ) ; for ( let i = 0 ; i < arr . length ; i ++ ) { arr [ i ] = new Array ( 2 ) ; for ( let j = 0 ; j < 2 ; j ++ ) { arr [ i ] [ j ] = 0 ; } } arr [ 0 ] [ 0 ] = 11 ; arr [ 0 ] [ 1 ] = 20 ; arr [ 1 ] [ 0 ] = 30 ; arr [ 1 ] [ 1 ] = 40 ; arr [ 2 ] [ 0 ] = 5 ; arr [ 2 ] [ 1 ] = 10 ; arr [ 3 ] [ 0 ] = 40 ; arr [ 3 ] [ 1 ] = 30 ; arr [ 4 ] [ 0 ] = 10 ; arr [ 4 ] [ 1 ] = 5 ; findSymPairs ( arr ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function groupElements ( arr , n ) { let visited = Array ( n ) . fill ( 0 ) ; for ( let i = 0 ; i < n ; i ++ ) { visited [ i ] = false ; } for ( let i = 0 ; i < n ; i ++ ) { if ( ! visited [ i ] ) { document . write ( arr [ i ] + " " ) ; for ( let j = i + 1 ; j < n ; j ++ ) { if ( arr [ i ] == arr [ j ] ) { document . write ( arr [ i ] + " " ) ; visited [ j ] = true ; } } } } } let arr = [ 4 , 6 , 9 , 2 , 3 , 4 , 9 , 6 , 10 , 4 ] ; let n = arr . length ; groupElements ( arr , n ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function aredisjoint ( set1 , set2 ) { for ( let i = 0 ; i < set1 . length ; i ++ ) { for ( let j = 0 ; j < set2 . length ; j ++ ) { if ( set1 [ i ] == set2 [ j ] ) return false ; } } return true ; } let set1 = [ 12 , 34 , 11 , 9 , 3 ] ; let set2 = [ 7 , 2 , 1 , 5 ] ; result = aredisjoint ( set1 , set2 ) ; if ( result ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function aredisjoint ( set1 , set2 ) { let i = 0 , j = 0 ; set1 . sort ( function ( a , b ) { return a - b } ) ; set2 . sort ( function ( a , b ) { return a - b } ) ; while ( i < set1 . length && j < set2 . length ) { if ( set1 [ i ] < set2 [ j ] ) i ++ ; else if ( set1 [ i ] > set2 [ j ] ) j ++ ; else return false ; } return true ; } let set1 = [ 12 , 34 , 11 , 9 , 3 ] ; let set2 = [ 7 , 2 , 1 , 5 ] ; result = aredisjoint ( set1 , set2 ) ; if ( result ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i, j
Accumulator variables: i, j
Javascript program:
function findMissing ( a , b , n , m ) { for ( let i = 0 ; i < n ; i ++ ) { let j ; for ( j = 0 ; j < m ; j ++ ) if ( a [ i ] == b [ j ] ) break ; if ( j == m ) document . write ( a [ i ] + " " ) ; } } let a = [ 1 , 2 , 6 , 3 , 4 , 5 ] ; let b = [ 2 , 4 , 3 , 1 , 0 ] ; let n = a . length ; let m = b . length ; findMissing ( a , b , n , m ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function findMissing ( a , b , n , m ) { let s = new Set ( ) ; for ( let i = 0 ; i < m ; i ++ ) s . add ( b [ i ] ) ; for ( let i = 0 ; i < n ; i ++ ) if ( ! s . has ( a [ i ] ) ) document . write ( a [ i ] + " " ) ; } let a = [ 1 , 2 , 6 , 3 , 4 , 5 ] ; let b = [ 2 , 4 , 3 , 1 , 0 ] ; let n = a . length ; let m = b . length ; findMissing ( a , b , n , m ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function areEqual ( arr1 , arr2 ) { let n = arr1 . length ; let m = arr2 . length ; if ( n != m ) return false ; arr1 . sort ( ) ; arr2 . sort ( ) ; for ( let i = 0 ; i < n ; i ++ ) if ( arr1 [ i ] != arr2 [ i ] ) return false ; return true ; } let arr1 = [ 3 , 5 , 2 , 5 , 2 ] ; let arr2 = [ 2 , 3 , 5 , 5 , 2 ] ; if ( areEqual ( arr1 , arr2 ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function makePermutation ( a , n ) { let count = new Map ( ) ; for ( let i = 0 ; i < n ; i ++ ) { if ( count . has ( a [ i ] ) ) { count . set ( a [ i ] , count . get ( a [ i ] ) + 1 ) ; } else { count . set ( a [ i ] , 1 ) ; } } } function find_maximum ( a , n , k ) { let b = new Map ( ) ; for ( let i = 0 ; i < n ; i ++ ) { let x = a [ i ] ; let d = Math . min ( 1 + i , n - i ) ; if ( ! b . has ( x ) ) b . set ( x , d ) ; else { b . set ( x , Math . min ( d , b . get ( x ) ) ) ; } } let ans = Number . MAX_VALUE ; for ( let i = 0 ; i < n ; i ++ ) { let x = a [ i ] ; if ( x != k - x && b . has ( k - x ) ) ans = Math . min ( Math . max ( b . get ( x ) , b . get ( k - x ) ) , ans ) ; } return ans ; } let a = [ 3 , 5 , 8 , 6 , 7 ] ; let K = 11 ; let n = a . length ; document . write ( find_maximum ( a , n , K ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function isProduct ( arr , n , x ) { for ( var i = 0 ; i < n - 1 ; i ++ ) for ( var j = i + 1 ; i < n ; i ++ ) if ( arr [ i ] * arr [ j ] == x ) return true ; return false ; } var arr = [ 10 , 20 , 9 , 40 ] ; var x = 400 ; var n = arr . length ; isProduct ( arr , n , x ) ? document . write ( " " ) : document . write ( " " ) ; x = 190 ; isProduct ( arr , n , x ) ? document . write ( " " ) : document . write ( " " ) ;

Index/key variables: i, j
Accumulator variables: i
Iterator variables: i, j
Javascript program:
function isProduct ( arr , n , x ) { let hset = new Set ( ) ; if ( n < 2 ) return false ; for ( let i = 0 ; i < n ; i ++ ) { if ( arr [ i ] == 0 ) { if ( x == 0 ) return true ; else continue ; } if ( x % arr [ i ] == 0 ) { if ( hset . has ( x / arr [ i ] ) ) return true ; hset . add ( arr [ i ] ) ; } } return false ; } let arr = [ 10 , 20 , 9 , 40 ] ; let x = 400 ; let n = arr . length ; if ( isProduct ( arr , arr . length , x ) ) document . write ( " " + " " ) ; else document . write ( " " + " " ) ; x = 190 ; if ( isProduct ( arr , arr . length , x ) ) document . write ( " " + " " ) ; else document . write ( " " + " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function findGreatest ( arr , n ) { let result = - 1 ; for ( let i = 0 ; i < n ; i ++ ) for ( let j = 0 ; j < n - 1 ; j ++ ) for ( let k = j + 1 ; k < n ; k ++ ) if ( arr [ j ] * arr [ k ] == arr [ i ] ) result = Math . max ( result , arr [ i ] ) ; return result ; } let arr = [ 30 , 10 , 9 , 3 , 35 ] ; let n = arr . length ; document . write ( findGreatest ( arr , n ) ) ;

Index/key variables: i, j, k
Accumulator variables: i, j, k
Iterator variables: i, j, k
Javascript program:
function findGreatest ( arr , n ) { let m = new Map ( ) ; for ( let i = 0 ; i < n ; i ++ ) { if ( m . has ( arr [ i ] ) ) { m . set ( arr [ i ] , m [ arr [ i ] ] + 1 ) ; } else { m . set ( arr [ i ] , m . get ( arr [ i ] ) ) ; } } arr . sort ( function ( a , b ) { return a - b ; } ) ; for ( let i = n - 1 ; i > 1 ; i -- ) { for ( let j = 0 ; j < i && arr [ j ] <= Math . sqrt ( arr [ i ] ) ; j ++ ) { if ( arr [ i ] % arr [ j ] == 0 ) { let result = Math . floor ( arr [ i ] / arr [ j ] ) ; if ( result != arr [ j ] && m [ result ] == null m [ result ] > 0 ) { return arr [ i ] ; } else if ( result == arr [ j ] && m [ result ] > 1 ) { return arr [ i ] ; } } } } return - 1 ; } let arr = [ 17 , 2 , 1 , 15 , 30 ] ; let n = arr . length ; document . write ( findGreatest ( arr , n ) ) ;

Index/key variables: i, j, result
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function minRemove ( a , b , n , m ) { let countA = new Map ( ) ; let countB = new Map ( ) ; for ( let i = 0 ; i < n ; i ++ ) { if ( countA . has ( a [ i ] ) ) countA . set ( a [ i ] , countA . get ( a [ i ] ) + 1 ) ; else countA . set ( a [ i ] , 1 ) ; } for ( let i = 0 ; i < m ; i ++ ) { if ( countB . has ( b [ i ] ) ) countB . set ( b [ i ] , countB . get ( b [ i ] ) + 1 ) ; else countB . set ( b [ i ] , 1 ) ; } let res = 0 ; for ( let x of countA . keys ( ) ) if ( countB . has ( x ) ) res += Math . min ( countB . get ( x ) , countA . get ( x ) ) ; return res ; } let a = [ 1 , 2 , 3 , 4 ] ; let b = [ 2 , 3 , 4 , 5 , 8 ] ; let n = a . length ; let m = b . length ; document . write ( minRemove ( a , b , n , m ) ) ;

Index/key variables: i
Accumulator variables: i, res
Iterator variables: i, x
Javascript program:
function countItems ( list1 , m , list2 , n ) { var count = 0 ; for ( var i = 0 ; i < m ; i ++ ) for ( var j = 0 ; j < n ; j ++ ) if ( list1 [ i ] [ 0 ] === list2 [ j ] [ 0 ] && ( list1 [ i ] [ 1 ] != list2 [ j ] [ 1 ] ) ) count ++ ; return count ; } var list1 = [ [ " " , 60 ] , [ " " , 20 ] , [ " " , 50 ] , [ " " , 30 ] ] ; var list2 = [ [ " " , 20 ] , [ " " , 15 ] , [ " " , 40 ] , [ " " , 60 ] ] ; var m = list1 . length ; var n = list2 . length ; document . write ( " " + countItems ( list1 , m , list2 , n ) ) ;

Index/key variables: i, j
Accumulator variables: count, i, j
Iterator variables: i, j
Javascript program:
class Node { constructor ( item ) { this . data = item ; this . left = this . right = null ; } } var root ; function isFullTree ( node ) { if ( node == null ) return true ; if ( node . left == null && node . right == null ) return true ; if ( ( node . left != null ) && ( node . right != null ) ) return ( isFullTree ( node . left ) && isFullTree ( node . right ) ) ; return false ; } root = new Node ( 10 ) ; root . left = new Node ( 20 ) ; root . right = new Node ( 30 ) ; root . left . right = new Node ( 40 ) ; root . left . left = new Node ( 50 ) ; root . right . left = new Node ( 60 ) ; root . left . left . left = new Node ( 80 ) ; root . right . right = new Node ( 70 ) ; root . left . left . right = new Node ( 90 ) ; root . left . right . left = new Node ( 80 ) ; root . left . right . right = new Node ( 90 ) ; root . right . left . left = new Node ( 80 ) ; root . right . left . right = new Node ( 90 ) ; root . right . right . left = new Node ( 80 ) ; root . right . right . right = new Node ( 90 ) ; if ( isFullTree ( root ) ) document . write ( " " ) ; else document . write ( " " ) ;

Class/struct names: Node
Javascript program:
function makePermutation ( a , n ) { var count = new Map ( ) ; for ( var i = 0 ; i < n ; i ++ ) { if ( count . has ( a [ i ] ) ) count . set ( a [ i ] , count . get ( a [ i ] ) + 1 ) else count . set ( a [ i ] , 1 ) } var next_missing = 1 ; for ( var i = 0 ; i < n ; i ++ ) { if ( count . get ( a [ i ] ) != 1 a [ i ] > n a [ i ] < 1 ) { count . set ( a [ i ] , count . get ( a [ i ] ) - 1 ) ; while ( count . has ( next_missing ) ) next_missing ++ ; a [ i ] = next_missing ; count . set ( next_missing , 1 ) ; } } } var A = [ 2 , 2 , 3 , 3 ] ; var n = A . length ; makePermutation ( A , n ) ; for ( var i = 0 ; i < n ; i ++ ) document . write ( A [ i ] + " " ) ;

Index/key variables: i
Accumulator variables: i, next_missing
Iterator variables: i
Javascript program:
function getPairsCount ( arr , n , sum ) { let count = 0 ; for ( let i = 0 ; i < n ; i ++ ) for ( let j = i + 1 ; j < n ; j ++ ) if ( arr [ i ] + arr [ j ] == sum ) count ++ ; return count ; } let arr = [ 1 , 5 , 7 , - 1 , 5 ] ; let n = arr . length ; let sum = 6 ; document . write ( " " + getPairsCount ( arr , n , sum ) ) ;

Index/key variables: i, j
Accumulator variables: count, i, j
Iterator variables: i, j
Javascript program:
function linearSearch ( a , n , key ) { for ( var i = 0 ; i < n ; i ++ ) { if ( a [ i ] == key ) return true ; } return false ; } var arr = [ 2 , 3 , 4 , 10 , 40 ] ; var x = 10 ; var n = arr . length ; if ( linearSearch ( arr , n , x ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function countPairs ( arr1 , arr2 , m , n , x ) { let count = 0 ; for ( let i = 0 ; i < m ; i ++ ) for ( let j = 0 ; j < n ; j ++ ) if ( ( arr1 [ i ] + arr2 [ j ] ) == x ) count ++ ; return count ; } let arr1 = [ 1 , 3 , 5 , 7 ] ; let arr2 = [ 2 , 3 , 5 , 8 ] ; let m = arr1 . length ; let n = arr2 . length ; let x = 10 ; document . write ( " " + countPairs ( arr1 , arr2 , m , n , x ) ) ;

Index/key variables: i, j
Accumulator variables: count, i, j
Iterator variables: i, j
Javascript program:
function isPresent ( arr , low , high , value ) { while ( low <= high ) { let mid = Math . floor ( ( low + high ) / 2 ) ; if ( arr [ mid ] == value ) return true ; else if ( arr [ mid ] > value ) high = mid - 1 ; else low = mid + 1 ; } return false ; } function countPairs ( arr1 , arr2 , m , n , x ) { let count = 0 ; for ( let i = 0 ; i < m ; i ++ ) { let value = x - arr1 [ i ] ; if ( isPresent ( arr2 , 0 , n - 1 , value ) ) count ++ ; } return count ; } let arr1 = [ 1 , 3 , 5 , 7 ] ; let arr2 = [ 2 , 3 , 5 , 8 ] ; let m = arr1 . length ; let n = arr2 . length ; let x = 10 ; document . write ( " " + countPairs ( arr1 , arr2 , m , n , x ) ) ;

Index/key variables: i, mid
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function countPairs ( arr1 , arr2 , m , n , x ) { let count = 0 ; let us = new Set ( ) ; for ( let i = 0 ; i < m ; i ++ ) us . add ( arr1 [ i ] ) ; for ( let j = 0 ; j < n ; j ++ ) if ( us . has ( x - arr2 [ j ] ) ) count ++ ; return count ; } let arr1 = [ 1 , 3 , 5 , 7 ] ; let arr2 = [ 2 , 3 , 5 , 8 ] ; let m = arr1 . length ; let n = arr2 . length ; let x = 10 ; document . write ( " " + countPairs ( arr1 , arr2 , m , n , x ) ) ;

Index/key variables: i, j
Accumulator variables: count, i, j
Iterator variables: i, j
Javascript program:
function countPairs ( arr1 , arr2 , m , n , x ) { let count = 0 ; let l = 0 , r = n - 1 ; while ( l < m && r >= 0 ) { if ( ( arr1 [ l ] + arr2 [ r ] ) == x ) { l ++ ; r -- ; count ++ ; } else if ( ( arr1 [ l ] + arr2 [ r ] ) < x ) l ++ ; else r -- ; } return count ; } let arr1 = [ 1 , 3 , 5 , 7 ] ; let arr2 = [ 2 , 3 , 5 , 8 ] ; let m = arr1 . length ; let n = arr2 . length ; let x = 10 ; document . write ( " " + countPairs ( arr1 , arr2 , m , n , x ) ) ;

Index/key variables: l, r
Accumulator variables: count, l, r
Javascript program:
var N = 4 , i , j , min ; document . write ( " " + N + " " ) ; for ( i = 1 ; i <= N ; i ++ ) { for ( j = 1 ; j <= N ; j ++ ) { min = i < j ? i : j ; document . write ( N - min + 1 ) ; } document . write ( " " ) ; }

Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
let arr = [ 10 , 2 , - 2 , - 20 , 10 ] ; let k = - 10 ; let n = arr . length ; let res = 0 ; for ( let i = 0 ; i < n ; i ++ ) { let sum = 0 ; for ( let j = i ; j < n ; j ++ ) { sum += arr [ j ] ; if ( sum == k ) res ++ ; } } document . write ( res ) ;

Index/key variables: j
Accumulator variables: i, j, res, sum
Iterator variables: i, j
Javascript program:
function findSubarraySum ( arr , n , sum ) { let prevSum = new Map ( ) ; let res = 0 ; let currsum = 0 ; for ( let i = 0 ; i < n ; i ++ ) { currsum += arr [ i ] ; if ( currsum == sum ) res ++ ; if ( prevSum . has ( currsum - sum ) ) res += prevSum . get ( currsum - sum ) ; let count = prevSum . get ( currsum ) ; if ( count == null ) prevSum . set ( currsum , 1 ) ; else prevSum . set ( currsum , count + 1 ) ; } return res ; } let arr = [ 10 , 2 , - 2 , - 20 , 10 ] ; let sum = - 10 ; let n = arr . length ; document . write ( findSubarraySum ( arr , n , sum ) ) ;

Index/key variables: i
Accumulator variables: currsum, i, res
Iterator variables: i
Javascript program:
function countPairs ( arr , n ) { var result = 0 ; for ( i = 0 ; i < n ; i ++ ) { for ( j = i + 1 ; j < n ; j ++ ) { var product = arr [ i ] * arr [ j ] ; for ( k = 0 ; k < n ; k ++ ) { if ( arr [ k ] == product ) { result ++ ; break ; } } } } return result ; } var arr = [ 6 , 2 , 4 , 12 , 5 , 3 ] ; var n = arr . length ; document . write ( countPairs ( arr , n ) ) ;

Index/key variables: i, j, k
Accumulator variables: i, j, k, result
Iterator variables: i, j, k
Javascript program:
function countPairs ( arr , n ) { var result = 0 ; var Hash = new Set ( ) ; for ( i = 0 ; i < n ; i ++ ) { Hash . add ( arr [ i ] ) ; } for ( i = 0 ; i < n ; i ++ ) { for ( j = i + 1 ; j < n ; j ++ ) { var product = arr [ i ] * arr [ j ] ; if ( Hash . has ( product ) ) { result ++ ; } } } return result ; } var arr = [ 6 , 2 , 4 , 12 , 5 , 3 ] ; var n = arr . length ; document . write ( countPairs ( arr , n ) ) ;

Index/key variables: i, j
Accumulator variables: i, j, result
Iterator variables: i, j