dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
let N = 3 ; let M = 4 ; function FindColumn ( mat ) { let row = 0 , col = M - 1 ; let flag = 0 ; while ( row < N && col >= 0 ) { if ( mat [ row ] [ col ] == 1 ) { col -- ; flag = 1 ; } else { row ++ ; } } col ++ ; if ( flag != 0 ) return col + 1 ; else return - 1 ; } let mat = [ [ 0 , 0 , 0 , 1 ] , [ 0 , 1 , 1 , 1 ] , [ 0 , 0 , 1 , 1 ] ] ; document . write ( FindColumn ( mat ) ) ;

Index/key variables: col, row
Accumulator variables: col, row
Javascript program:
function findNumbers ( N , M ) { let m = M ; let remLen = new Map ( ) ; let len , remainder = 0 ; for ( len = 1 ; len <= N + 1 ; ++ len ) { remainder = M % N ; if ( ! remLen . has ( remainder ) ) { remLen . set ( remainder , len ) ; } else { break ; } M = M * 10 + m ; M = M % N ; } let LenA = len ; let LenB = remLen . get ( remainder ) ; for ( let i = 0 ; i < LenB ; ++ i ) document . write ( m ) ; document . write ( " " ) ; for ( let i = 0 ; i < LenA ; ++ i ) document . write ( m ) ; } let N = 8 , M = 2 ; findNumbers ( N , M ) ;

Iterator variables: i, len
Javascript program:
var prefix_2D = Array ( 2005 ) ; function subMatrixSum ( i , j , len ) { return prefix_2D [ i ] [ j ] - prefix_2D [ i ] [ j - len ] - prefix_2D [ i - len ] [ j ] + prefix_2D [ i - len ] [ j - len ] ; } function numberOfWays ( a , b , n , m , k ) { for ( i = 1 ; i <= n ; i ++ ) { for ( j = 1 ; j <= m ; j ++ ) { if ( a [ i - 1 ] == b [ j - 1 ] ) prefix_2D [ i ] [ j ] = 1 ; else prefix_2D [ i ] [ j ] = 0 ; } } for ( i = 1 ; i <= n ; i ++ ) { for ( j = 1 ; j <= m ; j ++ ) { prefix_2D [ i ] [ j ] += prefix_2D [ i ] [ j - 1 ] ; } } for ( i = 1 ; i <= n ; i ++ ) { for ( j = 1 ; j <= m ; j ++ ) { prefix_2D [ i ] [ j ] += prefix_2D [ i - 1 ] [ j ] ; } } var answer = 0 ; for ( i = 1 ; i <= n ; i ++ ) { for ( j = 1 ; j <= m ; j ++ ) { var low = 1 ; var high = Math . min ( i , j ) ; while ( low < high ) { var mid = ( low + high ) >> 1 ; if ( subMatrixSum ( i , j , mid ) >= k ) { high = mid ; } else { low = mid + 1 ; } } if ( subMatrixSum ( i , j , low ) >= k ) { answer += ( Math . min ( i , j ) - low + 1 ) ; } } } return answer ; } var N = 2 , M = 3 ; var A = [ 1 , 2 ] ; var B = [ 1 , 2 , 3 ] ; for ( i = 0 ; i < 205 ; i ++ ) prefix_2D [ i ] = Array ( 205 ) . fill ( 0 ) ; var K = 1 ; document . write ( numberOfWays ( A , B , N , M , K ) ) ;

Index/key variables: i, j
Accumulator variables: answer, i, j
Iterator variables: i, j
Javascript program:
function findSmallest ( s ) { let len = s . length ; let loccur = new Array ( 26 ) ; loccur . fill ( - 1 ) ; for ( let i = len - 1 ; i >= 0 ; -- i ) { let chI = s [ i ] . charCodeAt ( ) - ' ' . charCodeAt ( ) ; if ( loccur [ chI ] == - 1 ) { loccur [ chI ] = i ; } } let sorted_s = s ; sorted_s . sort ( ) ; for ( let i = 0 ; i < len ; ++ i ) { if ( s [ i ] != sorted_s [ i ] ) { let chI = sorted_s [ i ] . charCodeAt ( ) - ' ' . charCodeAt ( ) ; let last_occ = loccur [ chI ] ; let temp = s [ i ] ; s [ i ] = s [ last_occ ] ; s [ last_occ ] = temp ; break ; } } return s . join ( " " ) ; } let s = " " ; document . write ( findSmallest ( s . split ( ' ' ) ) ) ;

Index/key variables: chI, i, last_occ
Iterator variables: i
Javascript program:
let N = 4 ; let M = 5 ; function preProcess ( mat , aux ) { for ( let i = 0 ; i < M ; i ++ ) aux [ 0 ] [ i ] = mat [ 0 ] [ i ] ; for ( let i = 1 ; i < N ; i ++ ) for ( let j = 0 ; j < M ; j ++ ) aux [ i ] [ j ] = mat [ i ] [ j ] + aux [ i - 1 ] [ j ] ; for ( let i = 0 ; i < N ; i ++ ) for ( let j = 1 ; j < M ; j ++ ) aux [ i ] [ j ] += aux [ i ] [ j - 1 ] ; } function sumQuery ( aux , tli , tlj , rbi , rbj ) { let res = aux [ rbi ] [ rbj ] ; if ( tli > 0 ) res = res - aux [ tli - 1 ] [ rbj ] ; if ( tlj > 0 ) res = res - aux [ rbi ] [ tlj - 1 ] ; if ( tli > 0 && tlj > 0 ) res = res + aux [ tli - 1 ] [ tlj - 1 ] ; return res ; } function check ( mid , aux , K ) { let satisfies = true ; for ( let x = 0 ; x < N ; x ++ ) { for ( let y = 0 ; y < M ; y ++ ) { if ( x + mid - 1 <= N - 1 && y + mid - 1 <= M - 1 ) { if ( sumQuery ( aux , x , y , x + mid - 1 , y + mid - 1 ) > K ) satisfies = false ; } } } return ( satisfies == true ) ; } function maximumSquareSize ( mat , K ) { let aux = new Array ( N ) ; for ( let i = 0 ; i < N ; i ++ ) { aux [ i ] = new Array ( M ) ; } preProcess ( mat , aux ) ; let low = 1 , high = Math . min ( N , M ) ; let mid ; while ( high - low > 1 ) { mid = Math . floor ( ( low + high ) / 2 ) ; if ( check ( mid , aux , K ) ) { low = mid ; } else high = mid ; } if ( check ( high , aux , K ) ) return high ; return low ; } let K = 30 ; let mat = [ [ 1 , 2 , 3 , 4 , 6 ] , [ 5 , 3 , 8 , 1 , 2 ] , [ 4 , 6 , 7 , 5 , 5 ] , [ 2 , 4 , 8 , 9 , 4 ] ] ; document . write ( maximumSquareSize ( mat , K ) ) ;

Index/key variables: i, j, rbi, rbj
Accumulator variables: i, j, x, y
Iterator variables: i, j, x, y
Boolean variables: satisfies
Javascript program:
let segment_tree = new Array ( 4 * 1000000 ) ; function build ( A , start , end , node ) { if ( start == end ) segment_tree [ node ] = A [ start ] ; else { let mid = parseInt ( ( start + end ) / 2 , 10 ) ; segment_tree [ node ] = Math . max ( build ( A , start , mid , 2 * node + 1 ) , build ( A , mid + 1 , end , 2 * node + 2 ) ) ; } return segment_tree [ node ] ; } function query ( start , end , l , r , node ) { if ( start > r end < l ) return - 1 ; if ( start >= l && end <= r ) return segment_tree [ node ] ; let mid = parseInt ( ( start + end ) / 2 , 10 ) ; return Math . max ( query ( start , mid , l , r , 2 * node + 1 ) , query ( mid + 1 , end , l , r , 2 * node + 2 ) ) ; } function longestSubArray ( A , N , K ) { let res = 1 ; let preSum = new Array ( N + 1 ) ; preSum [ 0 ] = A [ 0 ] ; for ( let i = 0 ; i < N ; i ++ ) preSum [ i + 1 ] = preSum [ i ] + A [ i ] ; build ( A , 0 , N - 1 , 0 ) ; for ( let i = 0 ; i < N ; i ++ ) { let start = i , end = N - 1 , mid , max_index = i ; while ( start <= end ) { mid = parseInt ( ( start + end ) / 2 , 10 ) ; let max_element = query ( 0 , N - 1 , i , mid , 0 ) ; let expected_sum = ( mid - i + 1 ) * max_element ; let actual_sum = preSum [ mid + 1 ] - preSum [ i ] ; if ( expected_sum - actual_sum <= K ) { start = mid + 1 ; max_index = Math . max ( max_index , mid ) ; } else { end = mid - 1 ; } } res = Math . max ( res , max_index - i + 1 ) ; } return res ; } let arr = [ 2 , 0 , 4 , 6 , 7 ] , K = 6 ; let N = arr . length ; document . write ( longestSubArray ( arr , N , K ) ) ;

Index/key variables: i, node, start
Accumulator variables: i
Iterator variables: i
Javascript program:
function countNums ( l , r ) { let cnt = 0 ; for ( let i = l ; i <= r ; i ++ ) { let lastDigit = ( i % 10 ) ; if ( ( lastDigit % 10 ) == 2 || ( lastDigit % 10 ) == 3 || ( lastDigit % 10 ) == 9 ) { cnt ++ ; } } return cnt ; } let l = 11 , r = 33 ; document . write ( countNums ( l , r ) ) ;

Accumulator variables: cnt, i
Iterator variables: i
Javascript program:
function findMinimumK ( a , n , s ) { var maximum = a [ 0 ] ; for ( i = 0 ; i < n ; i ++ ) { maximum = Math . max ( maximum , a [ i ] ) ; } var low = 1 , high = maximum + 1 ; var ans = high ; while ( low <= high ) { var mid = parseInt ( ( low + high ) / 2 ) ; var sum = 0 ; for ( i = 0 ; i < n ; i ++ ) { sum += parseInt ( ( a [ i ] / mid ) ) ; } if ( sum > s ) low = mid + 1 ; else { ans = Math . min ( ans , mid ) ; high = mid - 1 ; } } return ans ; } var a = [ 10 , 7 , 8 , 10 , 12 , 19 ] ; var n = a . length ; var s = 27 ; document . write ( findMinimumK ( a , n , s ) ) ;

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Javascript program:
let SparseTable = new Array ( 100001 ) ; for ( let i = 0 ; i < 100001 ; i ++ ) { SparseTable [ i ] = new Array ( 51 ) ; for ( let j = 0 ; j < 51 ; j ++ ) { SparseTable [ i ] [ j ] = 0 ; } } function buildSparseTable ( a , n ) { for ( let i = 0 ; i < n ; i ++ ) { SparseTable [ i ] [ 0 ] = a [ i ] ; } for ( let j = 1 ; j <= 19 ; j ++ ) { for ( let i = 0 ; i <= n - ( 1 << j ) ; i ++ ) { SparseTable [ i ] [ j ] = __gcd ( SparseTable [ i ] [ j - 1 ] , SparseTable [ i + ( 1 << ( j - 1 ) ) ] [ j - 1 ] ) ; } } } function queryForGCD ( L , R ) { let returnValue ; let j = Math . floor ( Math . log ( R - L + 1 ) ) ; returnValue = __gcd ( SparseTable [ L ] [ j ] , SparseTable [ R - ( 1 << j ) + 1 ] [ j ] ) ; return returnValue ; } function nextPosition ( tempGCD , startPointer , prevEndPointer , n ) { let high = n - 1 ; let low = prevEndPointer ; let mid = prevEndPointer ; let nextPos = prevEndPointer ; while ( high >= low ) { mid = ( ( high + low ) >> 1 ) ; if ( queryForGCD ( startPointer , mid ) == tempGCD ) { nextPos = mid ; low = mid + 1 ; } else { high = mid - 1 ; } } return nextPos + 1 ; } function calculateSum ( a , n ) { buildSparseTable ( a , n ) ; let endPointer , startPointer , prevEndPointer , tempGCD ; let tempAns = 0 ; for ( let i = 0 ; i < n ; i ++ ) { endPointer = i ; startPointer = i ; prevEndPointer = i ; tempGCD = a [ i ] ; while ( endPointer < n ) { endPointer = nextPosition ( tempGCD , startPointer , prevEndPointer , n ) ; tempAns += ( ( endPointer - prevEndPointer ) * tempGCD ) ; prevEndPointer = endPointer ; if ( endPointer < n ) { tempGCD = __gcd ( tempGCD , a [ endPointer ] ) ; } } } return tempAns ; } function __gcd ( a , b ) { return b == 0 ? a : __gcd ( b , a % b ) ; } let n = 6 ; let a = [ 2 , 2 , 2 , 3 , 5 , 5 ] ; document . write ( calculateSum ( a , n ) ) ;

Index/key variables: L, endPointer, i, j
Accumulator variables: i, j, tempAns
Iterator variables: i, j
Javascript program:
function partition ( arr , low , high ) { let temp ; let pivot = arr [ high ] ; let i = ( low - 1 ) ; for ( let j = low ; j <= high - 1 ; j ++ ) { if ( arr [ j ] <= pivot ) { i ++ ; temp = arr [ i ] ; arr [ i ] = arr [ j ] ; arr [ j ] = temp ; } } temp = arr [ i + 1 ] ; arr [ i + 1 ] = arr [ high ] ; arr [ high ] = temp ; return ( i + 1 ) ; } function kthSmallest ( a , left , right , k ) { while ( left <= right ) { let pivotIndex = partition ( a , left , right ) ; if ( pivotIndex == k - 1 ) return a [ pivotIndex ] ; else if ( pivotIndex > k - 1 ) right = pivotIndex - 1 ; else left = pivotIndex + 1 ; } return - 1 ; } let arr = [ 10 , 4 , 5 , 8 , 11 , 6 , 26 ] ; let n = arr . length ; let k = 5 ; document . write ( " " + kthSmallest ( arr , 0 , n - 1 , k ) ) ;

Index/key variables: high, i, j, pivotIndex
Accumulator variables: i, j
Iterator variables: j
Javascript program:
function Max_Sum ( arr , n , k ) { let p = n ; arr . sort ( function ( a , b ) { return a - b } ) ; for ( let i = 0 ; i < n ; i ++ ) { if ( arr [ i ] >= k ) { p = i ; break ; } } let maxsum = 0 , a = 0 , b = 0 ; for ( let i = 0 ; i < p ; i ++ ) { for ( let j = i + 1 ; j < p ; j ++ ) { if ( arr [ i ] + arr [ j ] < k && arr [ i ] + arr [ j ] > maxsum ) { maxsum = arr [ i ] + arr [ j ] ; a = arr [ i ] ; b = arr [ j ] ; } } } document . write ( a + " " + b + " " ) ; } let arr = [ 5 , 20 , 110 , 100 , 10 ] ; let k = 85 ; let n = arr . length ; Max_Sum ( arr , n , k ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function isPalindrome ( str , i , j ) { while ( i < j ) { if ( str [ i ] !== str [ j ] ) { return false ; } i ++ ; j -- ; } return true ; } function maxLenPalindrome ( str , n , ch ) { var maxLen = 0 ; for ( var i = 0 ; i < n ; i ++ ) { if ( str [ i ] === ch ) { for ( var j = n - 1 ; j >= i ; j -- ) { if ( str [ j ] === ch ) { if ( isPalindrome ( str , i , j ) ) { maxLen = Math . max ( maxLen , j - i + 1 ) ; break ; } } } } } return maxLen ; } var str = " " ; var n = str . length ; var ch = " " ; document . write ( maxLenPalindrome ( str , n , ch ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
let MAX = 26 ; function countingsort ( s ) { let count = new Array ( MAX ) ; count . fill ( 0 ) ; for ( let i = 0 ; i < s . length ; i ++ ) { count [ s [ i ] . charCodeAt ( ) - ' ' . charCodeAt ( ) ] ++ ; } let index = 0 ; for ( let i = 0 ; i < MAX ; i ++ ) { let j = 0 ; while ( j < count [ i ] ) { s [ index ++ ] = String . fromCharCode ( i + ' ' . charCodeAt ( ) ) ; j ++ ; } } return s . join ( " " ) ; } function isPossible ( v , str ) { str = countingsort ( str . split ( ' ' ) ) ; for ( let i = 0 ; i < v . length - 1 ; i ++ ) { for ( let j = i + 1 ; j < v . length ; j ++ ) { let temp = v [ i ] + v [ j ] ; temp = countingsort ( temp . split ( ' ' ) ) ; if ( temp == str ) { return true ; } } } return false ; } let str = " " ; let v = [ " " , " " , " " , " " , " " ] ; if ( isPossible ( v , str ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i, j
Accumulator variables: i, index, j
Iterator variables: i, j
Javascript program:
let MAX = 256 ; let freq ; function preCalculate ( str , n ) { freq [ str [ 0 ] . charCodeAt ( ) ] [ 0 ] = 1 ; for ( let i = 1 ; i < n ; i ++ ) { let ch = str [ i ] ; for ( let j = 0 ; j < MAX ; j ++ ) { let charToUpdate = String . fromCharCode ( j ) ; if ( charToUpdate == ch ) freq [ j ] [ i ] = freq [ j ] [ i - 1 ] + 1 ; else freq [ j ] [ i ] = freq [ j ] [ i - 1 ] ; } } } function getFrequency ( ch , l , r ) { if ( l == 0 ) return freq [ ch . charCodeAt ( ) ] [ r ] ; else return ( freq [ ch . charCodeAt ( ) ] [ r ] - freq [ ch . charCodeAt ( ) ] [ l - 1 ] ) ; } function firstNonRepeating ( str , n , l , r ) { for ( let i = l ; i < r ; i ++ ) { let ch = str [ i ] ; if ( getFrequency ( ch , l , r ) == 1 ) return ( " " + ch ) ; } return " " ; } let str = " " ; let n = str . length ; let queries = [ [ 0 , 3 ] , [ 2 , 3 ] , [ 5 , 12 ] ] ; let q = queries . length ; freq = new Array ( MAX ) ; for ( let i = 0 ; i < MAX ; i ++ ) { freq [ i ] = new Array ( n ) ; for ( let j = 0 ; j < n ; j ++ ) { freq [ i ] [ j ] = 0 ; } } preCalculate ( str , n ) ; for ( let i = 0 ; i < q ; i ++ ) { document . write ( firstNonRepeating ( str , n , queries [ i ] [ 0 ] , queries [ i ] [ 1 ] ) + " " ) ; }

Index/key variables: i, j, r
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function maxLength ( s , n ) { var ans = - 2147483648 ; var A = [ ] ; var L = [ ] ; var R = [ ] ; var freq = new Array ( n + 5 ) . fill ( 0 ) ; for ( var i = 0 ; i < 26 ; i ++ ) { var count = 0 ; for ( var j = 0 ; j < n ; j ++ ) { if ( s [ j ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) === i ) count ++ ; freq [ j ] = count ; } for ( var j = 1 ; j < n ; j ++ ) { L . push ( 2 * freq [ j - 1 ] - j ) ; R . push ( 2 * freq [ j ] - j ) ; } var max_len = - 2147483648 ; var min_val = 2147483648 ; for ( var j = 0 ; j < L . length ; j ++ ) { min_val = Math . min ( min_val , L [ j ] ) ; A . push ( min_val ) ; var l = 0 , r = j ; while ( l <= r ) { var mid = ( l + r ) >> 1 ; if ( A [ mid ] <= R [ j ] ) { max_len = Math . max ( max_len , j - mid + 1 ) ; r = mid - 1 ; } else { l = mid + 1 ; } } } ans = Math . max ( ans , max_len ) ; A = [ ] ; R = [ ] ; L = [ ] ; } return ans ; } var s = " " ; var n = s . length ; document . write ( maxLength ( s , n ) ) ;

Index/key variables: j, mid
Accumulator variables: count, i, j
Iterator variables: i, j
Javascript program:
let NO_OF_CHARS = 256 ; function firstRepeating ( str ) { let visited = new Array ( NO_OF_CHARS ) ; for ( let i = 0 ; i < NO_OF_CHARS ; i ++ ) visited [ i ] = false ; let res = - 1 ; for ( let i = str . length - 1 ; i >= 0 ; i -- ) { if ( visited [ str [ i ] . charCodeAt ( ) ] == false ) visited [ str [ i ] . charCodeAt ( ) ] = true ; else res = i ; } return res ; } let str = " " ; let index = firstRepeating ( str ) ; if ( index == - 1 ) document . write ( " " + " " ) ; else document . write ( " " + " " + str [ index ] ) ;

Index/key variables: i, index
Accumulator variables: i
Iterator variables: i
Javascript program:
function maxSum ( arr , n , K ) { var maximum = - 1000000000 ; var sum = Array ( n ) . fill ( 0 ) ; for ( var i = n - 1 ; i >= 0 ; i -- ) { if ( i + K < n ) sum [ i ] = sum [ i + K ] + arr [ i ] ; else sum [ i ] = arr [ i ] ; maximum = Math . max ( maximum , sum [ i ] ) ; } return maximum ; } var arr = [ 3 , 6 , 4 , 7 , 2 ] ; var n = arr . length ; var K = 2 ; document . write ( maxSum ( arr , n , K ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function countPairs ( s1 , n1 , s2 , n2 ) { let freq1 = new Array ( 26 ) ; let freq2 = new Array ( 26 ) ; freq1 . fill ( 0 ) ; freq2 . fill ( 0 ) ; let i , count = 0 ; for ( i = 0 ; i < n1 ; i ++ ) freq1 [ s1 [ i ] . charCodeAt ( ) - ' ' . charCodeAt ( ) ] ++ ; for ( i = 0 ; i < n2 ; i ++ ) freq2 [ s2 [ i ] . charCodeAt ( ) - ' ' . charCodeAt ( ) ] ++ ; for ( i = 0 ; i < 26 ; i ++ ) count += ( Math . min ( freq1 [ i ] , freq2 [ i ] ) ) ; return count ; } let s1 = " " , s2 = " " ; let n1 = s1 . length , n2 = s2 . length ; document . write ( countPairs ( s1 , n1 , s2 , n2 ) ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function findpair ( l , r ) { let c = 0 ; for ( let i = l ; i <= r ; i ++ ) { for ( let j = i + 1 ; j <= r ; j ++ ) { if ( j % i == 0 && j != i ) { document . write ( i + " " + j + " " ) ; c = 1 ; break ; } } if ( c == 1 ) break ; } } let l = 1 , r = 10 ; findpair ( l , r ) ;

Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function check ( arr , N , K ) { var unique = new Set ( ) ; for ( var i = 0 ; i < N ; i ++ ) unique . add ( arr [ i ] ) ; if ( unique . size == K ) return true ; return false ; } var arr = [ 1 , 1 , 2 , 3 ] ; var N = arr . length ; var K = 3 ; if ( check ( arr , N , K ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function findSumPairs ( a , n ) { let mpp = new Map ( ) ; for ( let i = 0 ; i < n - 1 ; i ++ ) { for ( let j = i + 1 ; j < n ; j ++ ) { if ( mpp [ a [ i ] + a [ j ] ] ) mpp [ a [ i ] + a [ j ] ] ++ ; else mpp [ a [ i ] + a [ j ] ] = 1 ; } } let occur = 0 ; for ( var it in mpp ) { if ( mpp [ it ] > occur ) { occur = mpp [ it ] ; } } for ( var it in mpp ) { if ( mpp [ it ] == occur ) document . write ( it , ' ' ) ; } } let a = [ 1 , 8 , 3 , 11 , 4 , 9 , 2 , 7 ] ; let len = a . length ; findSumPairs ( a , len ) ;

Index/key variables: i, it, j
Accumulator variables: i, j
Iterator variables: i, it, j
Javascript program:
function minIndex ( arr , n , pos ) { var num = arr [ pos ] ; var i = pos - 1 ; while ( i >= 0 ) { if ( arr [ i ] != num ) break ; i -- ; } return i + 1 ; } var arr = [ 2 , 1 , 1 , 1 , 5 , 2 ] ; var n = arr . length ; var pos = 4 ; document . write ( minIndex ( arr , n , pos ) ) ;

Index/key variables: i, pos
Accumulator variables: i
Javascript program:
function minIndex ( arr , pos ) { var low = 0 ; var high = pos ; var i = pos ; while ( low < high ) { var mid = parseInt ( ( low + high ) / 2 ) ; if ( arr [ mid ] != arr [ pos ] ) { low = mid + 1 ; } else { high = mid - 1 ; i = mid ; if ( mid > 0 && arr [ mid - 1 ] != arr [ pos ] ) { break ; } } } return arr [ low ] == arr [ pos ] ? low : i ; } var arr = [ 2 , 1 , 1 , 1 , 5 , 2 ] ;

Index/key variables: low, mid, pos
Javascript program:
function findAnswer ( str1 , str2 , n ) { var l = 0 , r = 0 ; var ans = 2 ; for ( i = 0 ; i < n ; ++ i ) { if ( str1 . charAt ( i ) != str2 . charAt ( i ) ) { l = i ; break ; } } for ( i = n - 1 ; i >= 0 ; i -- ) { if ( str1 . charAt ( i ) != str2 . charAt ( i ) ) { r = i ; break ; } } if ( r < l ) return 26 * ( n + 1 ) ; else if ( l == r ) return ans ; else { for ( i = l + 1 ; i <= r ; i ++ ) { if ( str1 . charAt ( i ) != str2 . charAt ( i - 1 ) ) { ans -- ; break ; } } for ( i = l + 1 ; i <= r ; i ++ ) { if ( str1 . charAt ( i - 1 ) != str2 . charAt ( i ) ) { ans -- ; break ; } } return ans ; } } var str1 = " " , str2 = " " ; var n = str1 . length ; document . write ( findAnswer ( str1 , str2 , n ) ) ;

Accumulator variables: ans, i
Iterator variables: i
Javascript program:
function findMinDifference ( arr , n ) { let min__ , secondMin , max__ , secondMax ; min__ = secondMax = ( arr [ 0 ] < arr [ 1 ] ) ? arr [ 0 ] : arr [ 1 ] ; max__ = secondMin = ( arr [ 0 ] < arr [ 1 ] ) ? arr [ 1 ] : arr [ 0 ] ; for ( let i = 2 ; i < n ; i ++ ) { if ( arr [ i ] > max__ ) { secondMax = max__ ; max__ = arr [ i ] ; } else if ( arr [ i ] > secondMax ) { secondMax = arr [ i ] ; } else if ( arr [ i ] < min__ ) { secondMin = min__ ; min__ = arr [ i ] ; } else if ( arr [ i ] < secondMin ) { secondMin = arr [ i ] ; } } let diff = Math . min ( max__ - secondMin , secondMax - min__ ) ; return diff ; } let arr = [ 1 , 2 , 4 , 3 , 4 ] ; let n = arr . length ; document . write ( findMinDifference ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function checkDistinct ( x ) { var last = x % 10 ; while ( x > 0 ) { if ( x % 10 != last ) return false ; x = parseInt ( x / 10 ) ; } return true ; } function findCount ( L , R ) { var count = 0 ; for ( i = L ; i <= R ; i ++ ) { if ( checkDistinct ( i ) ) count += 1 ; } return count ; } var L = 10 , R = 50 ; document . write ( findCount ( L , R ) ) ;

Accumulator variables: count, i
Iterator variables: i
Javascript program:
function smallest_pair ( a , n ) { let min = Number . MAX_VALUE , secondMin = Number . MAX_VALUE ; for ( let j = 0 ; j < n ; j ++ ) { if ( a [ j ] < min ) { secondMin = min ; min = a [ j ] ; } else if ( ( a [ j ] < secondMin ) && a [ j ] != min ) secondMin = a [ j ] ; } return ( secondMin + min ) ; } let arr = [ 1 , 2 , 3 ] ; let n = arr . length ; document . write ( smallest_pair ( arr , n ) ) ;

Index/key variables: j
Accumulator variables: j
Iterator variables: j
Javascript program:
function longestsubarray ( arr , n , k ) { let current_count = 0 ; let max_count = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( arr [ i ] % k == 0 ) current_count ++ ; else current_count = 0 ; max_count = Math . max ( current_count , max_count ) ; } return max_count ; } let arr = [ 2 , 5 , 11 , 32 , 64 , 88 ] ; let n = arr . length ; let k = 8 ; document . write ( longestsubarray ( arr , n , k ) ) ;

Index/key variables: i
Accumulator variables: current_count, i
Iterator variables: i
Javascript program:
function removeElements ( arr , n , k ) { let mp = new Map ( ) ; for ( let i = 0 ; i < n ; ++ i ) { if ( ! mp . has ( arr [ i ] ) ) mp . set ( arr [ i ] , 1 ) ; else { let x = mp . get ( arr [ i ] ) ; mp . set ( arr [ i ] , ++ x ) ; } } for ( let i = 0 ; i < n ; ++ i ) { if ( mp . get ( arr [ i ] ) >= k ) document . write ( arr [ i ] + " " ) ; } } let arr = [ 1 , 2 , 2 , 3 , 2 , 3 , 4 ] ; let n = arr . length ; let k = 2 ; removeElements ( arr , n , k ) ;

Index/key variables: i
Iterator variables: i
Javascript program:
function check ( s ) { for ( let i = 0 ; i < s . length - 1 ; i ++ ) if ( s [ i ] == s [ i + 1 ] ) return true ; return false ; } let s = " " ; if ( check ( s ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function RemoveElements ( arr , n , k ) { let mp = new Map ( ) ; for ( let i = 0 ; i < n ; ++ i ) { mp . set ( arr [ i ] , mp . get ( arr [ i ] ) == null ? 1 : mp . get ( arr [ i ] ) + 1 ) ; } for ( let i = 0 ; i < n ; ++ i ) { if ( mp . has ( arr [ i ] ) && mp . get ( arr [ i ] ) <= k ) { document . write ( arr [ i ] + " " ) ; } } } let arr = [ 1 , 2 , 2 , 3 , 2 , 3 , 4 ] ; let n = arr . length ; let k = 2 ; RemoveElements ( arr , n , k ) ;

Index/key variables: i
Iterator variables: i
Javascript program:
function findSmallestAfterDel ( arr , m , del , n ) { let mp = new Map ( ) ; for ( let i = 0 ; i < n ; ++ i ) { if ( mp . has ( del [ i ] ) ) { mp . set ( del [ i ] , mp . get ( del [ i ] ) + 1 ) ; } else { mp . set ( del [ i ] , 1 ) ; } } let smallestElement = Number . MAX_VALUE ; for ( let i = 0 ; i < m ; ++ i ) { if ( mp . has ( arr [ i ] ) ) { mp . set ( arr [ i ] , mp . get ( arr [ i ] ) - 1 ) ; if ( mp . get ( arr [ i ] ) == 0 ) mp . delete ( arr [ i ] ) ; } else smallestElement = Math . min ( smallestElement , arr [ i ] ) ; } return smallestElement ; } let array = [ 5 , 12 , 33 , 4 , 56 , 12 , 20 ] ; let m = array . length ; let del = [ 12 , 4 , 56 , 5 ] ; let n = del . length ; document . write ( findSmallestAfterDel ( array , m , del , n ) ) ;

Index/key variables: i
Iterator variables: i