dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Node { char data ; Node * left , * right ; } ; Node * newNode ( char data ) { Node * temp = new Node ( ) ; temp -> data = data ; temp -> left = temp -> right = NULL ; return temp ; } bool checkPalindrome ( string s ) { int low = 0 , high = ( int ) s . size ( ) - 1 ; while ( low < high ) { if ( s [ low ] != s [ high ] ) return false ; low ++ ; high -- ; } return true ; } void lexicographicallySmall ( Node * root , string s , string & finalAns ) { if ( root == NULL ) return ; s += root -> data ; if ( ! root -> left and ! root -> right ) { if ( checkPalindrome ( s ) ) { if ( finalAns == " $ " ) finalAns = s ; else finalAns = min ( finalAns , s ) ; } return ; } lexicographicallySmall ( root -> left , s , finalAns ) ; lexicographicallySmall ( root -> right , s , finalAns ) ; } void getPalindromePath ( Node * root ) { string finalAns = " $ " ; lexicographicallySmall ( root , " " , finalAns ) ; if ( finalAns == " $ " ) cout << " No ▁ Palindromic ▁ Path ▁ exists " ; else cout << finalAns ; } int main ( ) { Node * root = newNode ( ' a ' ) ; root -> left = newNode ( ' c ' ) ; root -> left -> left = newNode ( ' a ' ) ; root -> left -> right = newNode ( ' g ' ) ; root -> right = newNode ( ' b ' ) ; root -> right -> left = newNode ( ' b ' ) ; root -> right -> right = newNode ( ' x ' ) ; root -> right -> left -> right = newNode ( ' a ' ) ; getPalindromePath ( root ) ; return 0 ; }

Index/key variables: high, low
Accumulator variables: high, low, s, stdc
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Node { int key ; struct Node * left , * right ; } ; struct Node * newNode ( int key ) { struct Node * n = ( struct Node * ) malloc ( sizeof ( struct Node * ) ) ; if ( n != NULL ) { n -> key = key ; n -> left = NULL ; n -> right = NULL ; return n ; } else { cout << " Memory ▁ allocation ▁ failed ! " << endl ; exit ( 1 ) ; } } int findMirrorRec ( int target , struct Node * left , struct Node * right ) { if ( left == NULL right == NULL ) return 0 ; if ( left -> key == target ) return right -> key ; if ( right -> key == target ) return left -> key ; int mirror_val = findMirrorRec ( target , left -> left , right -> right ) ; if ( mirror_val ) return mirror_val ; findMirrorRec ( target , left -> right , right -> left ) ; } int findMirror ( struct Node * root , int target ) { if ( root == NULL ) return 0 ; if ( root -> key == target ) return target ; return findMirrorRec ( target , root -> left , root -> right ) ; } int main ( ) { struct Node * root = newNode ( 1 ) ; root -> left = newNode ( 2 ) ; root -> left -> left = newNode ( 4 ) ; root -> left -> left -> right = newNode ( 7 ) ; root -> right = newNode ( 3 ) ; root -> right -> left = newNode ( 5 ) ; root -> right -> right = newNode ( 6 ) ; root -> right -> left -> left = newNode ( 8 ) ; root -> right -> left -> right = newNode ( 9 ) ; int target = root -> left -> left -> key ; int mirror = findMirror ( root , target ) ; if ( mirror ) cout << " Mirror ▁ of ▁ Node ▁ " << target << " ▁ is ▁ Node ▁ " << mirror << endl ; else cout << " Mirror ▁ of ▁ Node ▁ " << target << " ▁ is ▁ NULL ! ▁ " << endl ; }

Accumulator variables: stdc
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool balanced ( int small [ ] , int caps [ ] ) { for ( int i = 0 ; i < 26 ; i ++ ) { if ( small [ i ] != 0 && ( caps [ i ] == 0 ) ) return 0 ; else if ( ( small [ i ] == 0 ) && ( caps [ i ] != 0 ) ) return 0 ; } return 1 ; } void smallestBalancedSubstring ( string s ) { int small [ 26 ] ; int caps [ 26 ] ; memset ( small , 0 , sizeof ( small ) ) ; memset ( caps , 0 , sizeof ( caps ) ) ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( s [ i ] >= 65 && s [ i ] <= 90 ) caps [ s [ i ] - ' A ' ] ++ ; else small [ s [ i ] - ' a ' ] ++ ; } unordered_map < char , int > mp ; for ( int i = 0 ; i < 26 ; i ++ ) { if ( small [ i ] && ! caps [ i ] ) mp [ char ( i + ' a ' ) ] = 1 ; else if ( caps [ i ] && ! small [ i ] ) mp [ char ( i + ' A ' ) ] = 1 ; } memset ( small , 0 , sizeof ( small ) ) ; memset ( caps , 0 , sizeof ( caps ) ) ; int i = 0 , st = 0 ; int start = -1 , end = -1 ; int minm = INT_MAX ; while ( i < s . length ( ) ) { if ( mp [ s [ i ] ] ) { while ( st < i ) { if ( s [ st ] >= 65 && s [ st ] <= 90 ) caps [ s [ st ] - ' A ' ] -- ; else small [ s [ st ] - ' a ' ] -- ; st ++ ; } i += 1 ; st = i ; } else { if ( s [ i ] >= 65 && s [ i ] <= 90 ) caps [ s [ i ] - ' A ' ] ++ ; else small [ s [ i ] - ' a ' ] ++ ; while ( 1 ) { if ( s [ st ] >= 65 && s [ st ] <= 90 && caps [ s [ st ] - ' A ' ] > 1 ) { caps [ s [ st ] - ' A ' ] -- ; st ++ ; } else if ( s [ st ] >= 97 && s [ st ] <= 122 && small [ s [ st ] - ' a ' ] > 1 ) { small [ s [ st ] - ' a ' ] -- ; st ++ ; } else break ; } if ( balanced ( small , caps ) ) { if ( minm > ( i - st + 1 ) ) { minm = i - st + 1 ; start = st ; end = i ; } } i += 1 ; } } if ( start == -1 end == -1 ) cout << -1 << endl ; else { string ans = " " ; for ( int i = start ; i <= end ; i ++ ) ans += s [ i ] ; cout << ans << endl ; } } int main ( ) { string s = " azABaabba " ; smallestBalancedSubstring ( s ) ; return 0 ; }

Index/key variables: i, st
Accumulator variables: ans, i, st, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct TrieNode { TrieNode * child [ 256 ] ; TrieNode ( ) { child [ 0 ] = child [ 1 ] = NULL ; } } ; void insertTrie ( TrieNode * root , string str ) { int M = str . length ( ) ; for ( int i = 0 ; i < M ; i ++ ) { if ( ! root -> child [ str [ i ] ] ) { root -> child [ str [ i ] ] = new TrieNode ( ) ; } root = root -> child [ str [ i ] ] ; } } int findStrLen ( TrieNode * root , string str ) { int M = str . length ( ) ; int len = 0 ; for ( int i = 0 ; i < M ; i ++ ) { if ( root -> child [ str [ i ] ] ) { len ++ ; root = root -> child [ str [ i ] ] ; } else { return len ; } } return len ; } void findMaxLenPair ( vector < string > & arr , int N ) { int idx = -1 ; int len = 0 ; TrieNode * root = new TrieNode ( ) ; insertTrie ( root , arr [ 0 ] ) ; for ( int i = 1 ; i < N ; i ++ ) { int temp = findStrLen ( root , arr [ i ] ) ; if ( temp > len ) { len = temp ; idx = i ; } insertTrie ( root , arr [ i ] ) ; } for ( int i = 0 ; i < N ; i ++ ) { int M = arr [ i ] . length ( ) ; if ( i != idx && M >= len ) { bool found = true ; for ( int j = 0 ; j < len ; j ++ ) { if ( arr [ i ] [ j ] != arr [ idx ] [ j ] ) { found = false ; break ; } } if ( found ) { cout << " ( " << arr [ i ] << " , ▁ " << arr [ idx ] << " ) " ; return ; } } } } int main ( ) { vector < string > arr = { " geeksforgeeks " , " geeks " , " geeksforcse " } ; int N = arr . size ( ) ; findMaxLenPair ( arr , N ) ; }

Index/key variables: i, idx, j
Accumulator variables: i, j, len, stdc
Iterator variables: i, j
Boolean variables: found
Class/struct names: TrieNode
C++ program:
#include <bits/stdc++.h>
using namespace std ; void transformString ( string str1 , string str2 ) { int N = str1 . length ( ) ; vector < int > convChar [ 26 ] ; vector < int > str1array [ 26 ] ; for ( int i = 0 ; i < 26 ; i ++ ) { vector < int > v ; convChar [ i ] = v ; str1array [ i ] = v ; } map < int , char > convertMap ; for ( int i = 0 ; i < N ; i ++ ) { str1array [ str1 [ i ] - ' a ' ] . push_back ( i ) ; } for ( int i = 0 ; i < N ; i ++ ) { if ( str1 [ i ] < str2 [ i ] ) { cout << -1 << endl ; return ; } else if ( str1 [ i ] == str2 [ i ] ) continue ; else { convChar [ str2 [ i ] - ' a ' ] . push_back ( i ) ; convertMap [ i ] = str2 [ i ] ; } } int ret = 0 ; vector < vector < int > > retv ; for ( int i = 25 ; i >= 0 ; i -- ) { vector < int > v = convChar [ i ] ; if ( v . size ( ) == 0 ) continue ; ret ++ ; vector < int > v1 = str1array [ i ] ; if ( v1 . size ( ) == 0 ) { cout << -1 << endl ; return ; } bool isScompleted = false ; for ( int j = 0 ; j < v1 . size ( ) ; j ++ ) { if ( convertMap . find ( v1 [ j ] ) != convertMap . end ( ) ) { char a = convertMap [ v1 [ j ] ] ; if ( a > i + ' a ' ) continue ; else { v . push_back ( v1 [ j ] ) ; isScompleted = true ; retv . push_back ( v ) ; break ; } } else { v . push_back ( v1 [ j ] ) ; isScompleted = true ; retv . push_back ( v ) ; break ; } } if ( ! isScompleted ) { cout << -1 << endl ; return ; } } cout << ret << endl ; } int main ( ) { string A = " abcab " ; string B = " aabab " ; transformString ( A , B ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: i, j, ret, stdc
Iterator variables: i, j
Boolean variables: isScompleted
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Node { int data ; Node * left , * right ; } ; Node * newNode ( int data ) { Node * node = new Node ; node -> data = data ; node -> left = node -> right = NULL ; return ( node ) ; } int largestSubtreeUtil ( Node * root , string & str , int & maxSize , Node * & maxNode ) { if ( root == NULL ) return 0 ; string left = " " , right = " " ; int ls = largestSubtreeUtil ( root -> left , left , maxSize , maxNode ) ; int rs = largestSubtreeUtil ( root -> right , right , maxSize , maxNode ) ; int size = ls + rs + 1 ; if ( left . compare ( right ) == 0 ) { if ( size > maxSize ) { maxSize = size ; maxNode = root ; } } str . append ( " ▁ " ) . append ( left ) . append ( " ▁ " ) ; str . append ( " ▁ " ) . append ( to_string ( root -> data ) ) . append ( " ▁ " ) ; str . append ( " ▁ " ) . append ( right ) . append ( " ▁ " ) ; return size ; } int largestSubtree ( Node * node , Node * & maxNode ) { int maxSize = 0 ; string str = " " ; largestSubtreeUtil ( node , str , maxSize , maxNode ) ; return maxSize ; } int main ( ) { Node * root = newNode ( 50 ) ; root -> left = newNode ( 10 ) ; root -> right = newNode ( 60 ) ; root -> left -> left = newNode ( 5 ) ; root -> left -> right = newNode ( 20 ) ; root -> right -> left = newNode ( 70 ) ; root -> right -> left -> left = newNode ( 65 ) ; root -> right -> left -> right = newNode ( 80 ) ; root -> right -> right = newNode ( 70 ) ; root -> right -> right -> left = newNode ( 65 ) ; root -> right -> right -> right = newNode ( 80 ) ; Node * maxNode = NULL ; int maxSize = largestSubtree ( root , maxNode ) ; cout << " Largest ▁ Subtree ▁ is ▁ rooted ▁ at ▁ node ▁ " << maxNode -> data << " and its size is " << maxSize ; return 0 ; }

Accumulator variables: stdc
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; set < string > visited ; string ans ; void dfs ( string curr , int D ) { for ( int x = 0 ; x < D ; ++ x ) { char chr = x + '0' ; string neighbour = curr + chr ; if ( visited . find ( neighbour ) == visited . end ( ) ) { visited . insert ( neighbour ) ; dfs ( neighbour . substr ( 1 ) , D ) ; ans . push_back ( chr ) ; } } } string reqString ( int N , int D ) { if ( N == 1 && D == 1 ) return "0" ; visited . clear ( ) ; ans . clear ( ) ; string start ; for ( int i = 0 ; i < N - 1 ; i ++ ) start . append ( "0" ) ; dfs ( start , D ) ; ans . append ( start ) ; return ans ; } int main ( ) { int N = 2 ; int D = 2 ; cout << reqString ( N , D ) << ' ' ; return 0 ; }

Accumulator variables: i, stdc
Iterator variables: i, x
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool isScramble ( string S1 , string S2 ) { if ( S1 . length ( ) != S2 . length ( ) ) { return false ; } int n = S1 . length ( ) ; if ( n == 0 ) { return true ; } if ( S1 == S2 ) { return true ; } string copy_S1 = S1 , copy_S2 = S2 ; sort ( copy_S1 . begin ( ) , copy_S1 . end ( ) ) ; sort ( copy_S2 . begin ( ) , copy_S2 . end ( ) ) ; if ( copy_S1 != copy_S2 ) { return false ; } for ( int i = 1 ; i < n ; i ++ ) { if ( isScramble ( S1 . substr ( 0 , i ) , S2 . substr ( 0 , i ) ) && isScramble ( S1 . substr ( i , n - i ) , S2 . substr ( i , n - i ) ) ) { return true ; } if ( isScramble ( S1 . substr ( 0 , i ) , S2 . substr ( n - i , i ) ) && isScramble ( S1 . substr ( i , n - i ) , S2 . substr ( 0 , n - i ) ) ) { return true ; } } return false ; } int main ( ) { string S1 = " coder " ; string S2 = " ocred " ; if ( isScramble ( S1 , S2 ) ) { cout << " Yes " ; } else { cout << " No " ; } return 0 ; }

Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; string findAns ( string s ) { int digit ; vector < int > odd ; vector < int > even ; for ( auto c : s ) { digit = c - '0' ; if ( digit & 1 ) odd . push_back ( digit ) ; else even . push_back ( digit ) ; } int i = 0 ; int j = 0 ; string ans = " " ; while ( i < odd . size ( ) and j < even . size ( ) ) { if ( odd [ i ] < even [ j ] ) ans += ( char ) ( odd [ i ++ ] + '0' ) ; else ans += ( char ) ( even [ j ++ ] + '0' ) ; } while ( i < odd . size ( ) ) ans += ( char ) ( odd [ i ++ ] + '0' ) ; while ( j < even . size ( ) ) ans += ( char ) ( even [ j ++ ] + '0' ) ; while ( ans [ 0 ] == '0' ) { ans . erase ( ans . begin ( ) ) ; } return ans ; } int main ( ) { string s = "894687536" ; cout << findAns ( s ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: ans, i, j, stdc
Iterator variables: c
C++ program:
#include <bits/stdc++.h>
using namespace std ; int bcdToDecimal ( string s ) { int len = s . length ( ) , check = 0 , check0 = 0 ; int num = 0 , sum = 0 , mul = 1 , rev = 0 ; for ( int i = len - 1 ; i >= 0 ; i -- ) { sum += ( s [ i ] - '0' ) * mul ; mul *= 2 ; check ++ ; if ( check == 4 i == 0 ) { if ( sum == 0 && check0 == 0 ) { num = 1 ; check0 = 1 ; } else { num = num * 10 + sum ; } check = 0 ; sum = 0 ; mul = 1 ; } } while ( num > 0 ) { rev = rev * 10 + ( num % 10 ) ; num /= 10 ; } if ( check0 == 1 ) return rev - 1 ; return rev ; } int main ( ) { string s = "100000101000" ; cout << bcdToDecimal ( s ) ; return 0 ; }

Index/key variables: i
Accumulator variables: check, i, mul, num, stdc, sum
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Node { int data ; struct Node * left , * right ; } ; Node * newNode ( int data ) { Node * temp = new Node ; temp -> data = data ; temp -> left = temp -> right = NULL ; return ( temp ) ; } bool countSingleRec ( Node * root , int & count ) { if ( root == NULL ) return true ; bool left = countSingleRec ( root -> left , count ) ; bool right = countSingleRec ( root -> right , count ) ; if ( left == false right == false ) return false ; if ( root -> left && root -> data != root -> left -> data ) return false ; if ( root -> right && root -> data != root -> right -> data ) return false ; count ++ ; return true ; } int countSingle ( Node * root ) { int count = 0 ; countSingleRec ( root , count ) ; return count ; } int main ( ) { Node * root = newNode ( 5 ) ; root -> left = newNode ( 4 ) ; root -> right = newNode ( 5 ) ; root -> left -> left = newNode ( 4 ) ; root -> left -> right = newNode ( 4 ) ; root -> right -> right = newNode ( 5 ) ; cout << " Count ▁ of ▁ Single ▁ Valued ▁ Subtrees ▁ is ▁ " << countSingle ( root ) ; return 0 ; }

Accumulator variables: count, stdc
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countSwap ( string s ) { int n = s . length ( ) ; int count = 0 ; for ( int i = 0 ; i < n / 2 ; i ++ ) { int left = i ; int right = n - left - 1 ; while ( left < right ) { if ( s [ left ] == s [ right ] ) { break ; } else { right -- ; } } if ( left == right ) { return -1 ; } for ( int j = right ; j < n - left - 1 ; j ++ ) { swap ( s [ j ] , s [ j + 1 ] ) ; count ++ ; } } return count ; } int main ( ) { string s = " geeksfgeeks " ; int ans1 = countSwap ( s ) ; reverse ( s . begin ( ) , s . end ( ) ) ; int ans2 = countSwap ( s ) ; cout << max ( ans1 , ans2 ) ; return 0 ; }

Index/key variables: j, left, right
Accumulator variables: count, i, j, right, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; void strBitwiseXOR ( string * arr , int n ) { string result ; int max_len = INT_MIN ; for ( int i = 0 ; i < n ; i ++ ) { max_len = max ( max_len , ( int ) arr [ i ] . size ( ) ) ; reverse ( arr [ i ] . begin ( ) , arr [ i ] . end ( ) ) ; } for ( int i = 0 ; i < n ; i ++ ) { string s ; for ( int j = 0 ; j < max_len - arr [ i ] . size ( ) ; j ++ ) s += '0' ; arr [ i ] = arr [ i ] + s ; } for ( int i = 0 ; i < max_len ; i ++ ) { int pres_bit = 0 ; for ( int j = 0 ; j < n ; j ++ ) pres_bit = pres_bit ^ ( arr [ j ] [ i ] - '0' ) ; result += ( pres_bit + '0' ) ; } reverse ( result . begin ( ) , result . end ( ) ) ; cout << result ; } int main ( ) { string arr [ ] = { "1000" , "10001" , "0011" } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; strBitwiseXOR ( arr , n ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: i, j, result, s, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int sticks [ ] = { 6 , 7 , 4 , 6 , 5 , 4 , 6 , 5 , 2 , 4 , 4 , 3 , 6 , 6 , 6 , 5 , 7 , 6 , 5 , 3 , 5 , 4 , 6 , 4 , 3 , 4 } ; int number [ ] = { 6 , 2 , 5 , 5 , 4 , 5 , 6 , 3 , 7 , 6 } ; int countSticks ( string str ) { int cnt = 0 ; for ( int i = 0 ; str [ i ] ; i ++ ) { char ch = str [ i ] ; if ( ch >= ' A ' && ch <= ' Z ' ) { cnt += sticks [ ch - ' A ' ] ; } else { cnt += number [ ch - '0' ] ; } } return cnt ; } int main ( ) { string str = " GEEKSFORGEEKS " ; cout << countSticks ( str ) ; return 0 ; }

Index/key variables: i
Accumulator variables: cnt, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void PrintMatchingCamelCase ( vector < string > arr , string pattern ) { string cctdString = " " ; for ( int i = 0 ; i < arr . size ( ) ; i ++ ) { cctdString += arr [ i ] ; if ( i != arr . size ( ) - 1 ) cctdString . push_back ( ' ; ' ) ; } unordered_map < string , vector < string > > maps ; int charPos = 0 ; int wordPos = 0 ; string strr = " " ; for ( ; charPos < cctdString . length ( ) ; charPos ++ ) { if ( cctdString [ charPos ] >= ' A ' && cctdString [ charPos ] <= ' Z ' ) { strr += cctdString [ charPos ] ; if ( maps . find ( strr ) != maps . end ( ) ) { vector < string > temp ; temp . insert ( temp . end ( ) , maps [ strr ] . begin ( ) , maps [ strr ] . end ( ) ) ; temp . push_back ( arr [ wordPos ] ) ; maps [ strr ] = temp ; } else { vector < string > vec = { arr [ wordPos ] } ; maps [ strr ] = vec ; } } else if ( cctdString [ charPos ] == ' ; ' ) { wordPos ++ ; strr = " " ; } } if ( maps . find ( pattern ) != maps . end ( ) ) { for ( int i = 0 ; i < maps [ pattern ] . size ( ) ; i ++ ) { cout << maps [ pattern ] [ i ] << endl ; } } else { cout << " No ▁ Match ▁ Found " << endl ; } } int main ( ) { vector < string > arr = { " Hi " , " Hello " , " HelloWorld " , " HiTech " , " HiGeek " , " HiTechWorld " , " HiTechCity " , " HiTechLab " } ; string pattern = " HT " ; PrintMatchingCamelCase ( arr , pattern ) ; }

Index/key variables: charPos, i, pattern, strr, wordPos
Accumulator variables: cctdString, charPos, i, stdc, strr, wordPos
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; string remainingDigit ( string S , int N ) { int del [ ] = { 0 , 0 } ; int count [ ] = { 0 , 0 } ; queue < int > q ; for ( int i = 0 ; i < N ; i ++ ) { int x = S [ i ] == '1' ? 1 : 0 ; count [ x ] ++ ; q . push ( x ) ; } while ( count [ 0 ] > 0 && count [ 1 ] > 0 ) { int t = q . front ( ) ; q . pop ( ) ; if ( del [ t ] > 0 ) { del [ t ] -- ; count [ t ] -- ; } else { del [ t ^ 1 ] ++ ; q . push ( t ) ; } } if ( count [ 0 ] > 0 ) return "0" ; return "1" ; } int main ( ) { string S = "1010100100000" ; int N = S . length ( ) ; cout << remainingDigit ( S , N ) ; }

Index/key variables: i, t, x
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Node { int key ; struct Node * left , * right ; } ; Node * newNode ( int key ) { Node * temp = new Node ; temp -> key = key ; temp -> left = temp -> right = NULL ; return ( temp ) ; } void findLeafDown ( Node * root , int lev , int * minDist ) { if ( root == NULL ) return ; if ( root -> left == NULL && root -> right == NULL ) { if ( lev < ( * minDist ) ) * minDist = lev ; return ; } findLeafDown ( root -> left , lev + 1 , minDist ) ; findLeafDown ( root -> right , lev + 1 , minDist ) ; } int findThroughParent ( Node * root , Node * x , int * minDist ) { if ( root == NULL ) return -1 ; if ( root == x ) return 0 ; int l = findThroughParent ( root -> left , x , minDist ) ; if ( l != -1 ) { findLeafDown ( root -> right , l + 2 , minDist ) ; return l + 1 ; } int r = findThroughParent ( root -> right , x , minDist ) ; if ( r != -1 ) { findLeafDown ( root -> left , r + 2 , minDist ) ; return r + 1 ; } return -1 ; } int minimumDistance ( Node * root , Node * x ) { int minDist = INT_MAX ; findLeafDown ( x , 0 , & minDist ) ; findThroughParent ( root , x , & minDist ) ; return minDist ; } int main ( ) { Node * root = newNode ( 1 ) ; root -> left = newNode ( 12 ) ; root -> right = newNode ( 13 ) ; root -> right -> left = newNode ( 14 ) ; root -> right -> right = newNode ( 15 ) ; root -> right -> left -> left = newNode ( 21 ) ; root -> right -> left -> right = newNode ( 22 ) ; root -> right -> right -> left = newNode ( 23 ) ; root -> right -> right -> right = newNode ( 24 ) ; root -> right -> left -> left -> left = newNode ( 1 ) ; root -> right -> left -> left -> right = newNode ( 2 ) ; root -> right -> left -> right -> left = newNode ( 3 ) ; root -> right -> left -> right -> right = newNode ( 4 ) ; root -> right -> right -> left -> left = newNode ( 5 ) ; root -> right -> right -> left -> right = newNode ( 6 ) ; root -> right -> right -> right -> left = newNode ( 7 ) ; root -> right -> right -> right -> right = newNode ( 8 ) ; Node * x = root -> right ; cout << " The ▁ closest ▁ leaf ▁ to ▁ the ▁ node ▁ with ▁ value ▁ " << x -> key << " ▁ is ▁ at ▁ a ▁ distance ▁ of ▁ " << minimumDistance ( root , x ) << endl ; return 0 ; }

Accumulator variables: stdc
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; typedef long long ll ; string getTime ( string s , int n ) { string res ; int h = stoi ( s . substr ( 0 , 2 ) ) ; int m = stoi ( s . substr ( 3 , 2 ) ) ; int rev_h = ( h % 10 ) * 10 + ( ( h % 100 ) - ( h % 10 ) ) / 10 ; string rev_hs = to_string ( rev_h ) ; if ( h == 23 && m >= 32 ) { res = " - 1" ; } else if ( m < rev_h ) { string temp ; if ( h < 10 ) temp = "0" ; temp = temp + to_string ( h ) ; if ( rev_h < 10 ) res = res + temp + " : 0" + rev_hs ; else res = res + temp + " : " + rev_hs ; } else { h ++ ; rev_h = ( h % 10 ) * 10 + ( ( h % 100 ) - ( h % 10 ) ) / 10 ; rev_hs = to_string ( rev_h ) ; string temp ; if ( h < 10 ) temp = "0" ; temp = temp + to_string ( h ) ; if ( rev_h < 10 ) res = res + temp + " : 0" + rev_hs ; else res = res + temp + " : " + rev_hs ; } return res ; } int main ( ) { string s = "21:12" ; int n = s . length ( ) ; cout << getTime ( s , n ) ; return 0 ; }

Accumulator variables: h, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int CountSubstring ( char str [ ] , int n ) { int ans = ( n * ( n + 1 ) ) / 2 ; int a_index = 0 ; int b_index = 0 ; int c_index = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( str [ i ] == ' a ' ) { a_index = i + 1 ; ans -= min ( b_index , c_index ) ; } else if ( str [ i ] == ' b ' ) { b_index = i + 1 ; ans -= min ( a_index , c_index ) ; } else { c_index = i + 1 ; ans -= min ( a_index , b_index ) ; } } return ans ; } int main ( ) { char str [ ] = " babac " ; int n = strlen ( str ) ; cout << CountSubstring ( str , n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: ans, i, stdc
Iterator variables: i