dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <bits/stdc++.h>
using namespace std ; int longestsubarray ( int arr [ ] , int n , int k ) { int current_count = 0 ; int max_count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] % k == 0 ) current_count ++ ; else current_count = 0 ; max_count = max ( current_count , max_count ) ; } return max_count ; } int main ( ) { int arr [ ] = { 2 , 5 , 11 , 32 , 64 , 88 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int k = 8 ; cout << longestsubarray ( arr , n , k ) ; return 0 ; }

Index/key variables: i
Accumulator variables: current_count, i, stdc
Iterator variables: i
C++ program:
#include " iostream "
#include " unordered _ map "
using namespace std ; void removeElements ( int arr [ ] , int n , int k ) { unordered_map < int , int > mp ; for ( int i = 0 ; i < n ; ++ i ) { mp [ arr [ i ] ] ++ ; } for ( int i = 0 ; i < n ; ++ i ) { if ( mp [ arr [ i ] ] >= k ) { cout << arr [ i ] << " ▁ " ; } } } int main ( ) { int arr [ ] = { 1 , 2 , 2 , 3 , 2 , 3 , 4 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int k = 2 ; removeElements ( arr , n , k ) ; return 0 ; }

Index/key variables: i
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool check ( string s ) { for ( int i = 0 ; i < s . length ( ) - 1 ; i ++ ) if ( s [ i ] == s [ i + 1 ] ) return true ; return false ; } int main ( ) { string s = " xzyyz " ; if ( check ( s ) ) cout << " YES " << endl ; else cout << " NO " << endl ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include " iostream "
#include " unordered _ map "
using namespace std ; void RemoveElements ( int arr [ ] , int n , int k ) { unordered_map < int , int > mp ; for ( int i = 0 ; i < n ; ++ i ) { mp [ arr [ i ] ] ++ ; } for ( int i = 0 ; i < n ; ++ i ) { if ( mp [ arr [ i ] ] <= k ) { cout << arr [ i ] << " ▁ " ; } } } int main ( int argc , char const * argv [ ] ) { int arr [ ] = { 1 , 2 , 2 , 3 , 2 , 3 , 4 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int k = 2 ; RemoveElements ( arr , n , k ) ; return 0 ; }

Index/key variables: i
Iterator variables: i
C++ program:
#include " climits "
#include " iostream "
#include " unordered _ map "
using namespace std ; int findSmallestAfterDel ( int arr [ ] , int m , int del [ ] , int n ) { unordered_map < int , int > mp ; for ( int i = 0 ; i < n ; ++ i ) { mp [ del [ i ] ] ++ ; } int smallestElement = INT_MAX ; for ( int i = 0 ; i < m ; ++ i ) { if ( mp . find ( arr [ i ] ) != mp . end ( ) ) { mp [ arr [ i ] ] -- ; if ( mp [ arr [ i ] ] == 0 ) mp . erase ( arr [ i ] ) ; } else smallestElement = min ( smallestElement , arr [ i ] ) ; } return smallestElement ; } int main ( ) { int array [ ] = { 5 , 12 , 33 , 4 , 56 , 12 , 20 } ; int m = sizeof ( array ) / sizeof ( array [ 0 ] ) ; int del [ ] = { 12 , 4 , 56 , 5 } ; int n = sizeof ( del ) / sizeof ( del [ 0 ] ) ; cout << findSmallestAfterDel ( array , m , del , n ) ; return 0 ; }

Index/key variables: i
Iterator variables: i
C++ program:
#include " climits "
#include " iostream "
#include " unordered _ map "
using namespace std ; int findlargestAfterDel ( int arr [ ] , int m , int del [ ] , int n ) { unordered_map < int , int > mp ; for ( int i = 0 ; i < n ; ++ i ) { mp [ del [ i ] ] ++ ; } int largestElement = INT_MIN ; for ( int i = 0 ; i < m ; ++ i ) { if ( mp . find ( arr [ i ] ) != mp . end ( ) ) { mp [ arr [ i ] ] -- ; if ( mp [ arr [ i ] ] == 0 ) mp . erase ( arr [ i ] ) ; } else largestElement = max ( largestElement , arr [ i ] ) ; } return largestElement ; } int main ( ) { int array [ ] = { 5 , 12 , 33 , 4 , 56 , 12 , 20 } ; int m = sizeof ( array ) / sizeof ( array [ 0 ] ) ; int del [ ] = { 12 , 33 , 56 , 5 } ; int n = sizeof ( del ) / sizeof ( del [ 0 ] ) ; cout << findlargestAfterDel ( array , m , del , n ) ; return 0 ; }

Index/key variables: i
Iterator variables: i
C++ program:
#include <iostream>
using namespace std ; int countAnomalies ( int arr [ ] , int n , int k ) { int res = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int j ; for ( j = 0 ; j < n ; j ++ ) if ( i != j && abs ( arr [ i ] - arr [ j ] ) <= k ) break ; if ( j == n ) res ++ ; } return res ; } int main ( ) { int arr [ ] = { 7 , 1 , 8 } , k = 5 ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << countAnomalies ( arr , n , k ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: i, j, res
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int majorityInMatrix ( int arr [ N ] [ M ] ) { unordered_map < int , int > mp ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < M ; j ++ ) { mp [ arr [ i ] [ j ] ] ++ ; } } int countMajority = 0 ; for ( auto itr = mp . begin ( ) ; itr != mp . end ( ) ; itr ++ ) { if ( itr -> second >= ( ( N * M ) / 2 ) ) { countMajority ++ ; } } return countMajority ; } int main ( ) { int mat [ N ] [ M ] = { { 1 , 2 , 2 } , { 1 , 3 , 2 } , { 1 , 2 , 6 } } ; cout << majorityInMatrix ( mat ) << endl ; return 0 ; }

Index/key variables: M, N, i, j
Accumulator variables: countMajority, i, itr, j, stdc
Iterator variables: i, itr, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int colMaxDiff ( int mat [ N ] [ N ] ) { int max_diff = INT_MIN ; for ( int i = 0 ; i < N ; i ++ ) { int max_val = mat [ 0 ] [ i ] , min_val = mat [ 0 ] [ i ] ; for ( int j = 1 ; j < N ; j ++ ) { max_val = max ( max_val , mat [ j ] [ i ] ) ; min_val = min ( min_val , mat [ j ] [ i ] ) ; } max_diff = max ( max_diff , max_val - min_val ) ; } return max_diff ; } int main ( ) { int mat [ N ] [ N ] = { { 1 , 2 , 3 , 4 , 5 } , { 5 , 3 , 5 , 4 , 0 } , { 5 , 6 , 7 , 8 , 9 } , { 0 , 6 , 3 , 4 , 12 } , { 9 , 7 , 12 , 4 , 3 } , } ; cout << " Max ▁ difference ▁ : ▁ " << colMaxDiff ( mat ) << endl ; return 0 ; }

Index/key variables: N, i, j
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <iostream>
using namespace std ; int search ( int ar [ ] , int size ) { int a = 0 , b = size - 1 ; int mid ; while ( ( b - a ) > 1 ) { mid = ( a + b ) / 2 ; if ( ( ar [ a ] - a ) != ( ar [ mid ] - mid ) ) b = mid ; else if ( ( ar [ b ] - b ) != ( ar [ mid ] - mid ) ) a = mid ; } return ( ar [ a ] + 1 ) ; } int main ( ) { int ar [ ] = { 1 , 2 , 3 , 4 , 5 , 6 , 8 } ; int size = sizeof ( ar ) / sizeof ( ar [ 0 ] ) ; cout << " Missing ▁ number : " << search ( ar , size ) ; }

Index/key variables: a, b, mid
C++ program:
#include <bits/stdc++.h>
using namespace std ; int deleteElement ( int A [ ] , int L , int R , int N ) { int i , j = 0 ; for ( i = 0 ; i < N ; i ++ ) { if ( i <= L i >= R ) { A [ j ] = A [ i ] ; j ++ ; } } return j ; } int main ( ) { int A [ ] = { 5 , 8 , 11 , 15 , 26 , 14 , 19 , 17 , 10 , 14 } ; int L = 2 , R = 7 ; int n = sizeof ( A ) / sizeof ( A [ 0 ] ) ; int res_size = deleteElement ( A , L , R , n ) ; for ( int i = 0 ; i < res_size ; i ++ ) cout << A [ i ] << " ▁ " ; return 0 ; }

Index/key variables: i, j
Accumulator variables: i, j, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool compare ( const pair < int , int > & a , const pair < int , int > & b ) { if ( a . first == b . first ) return a . second < b . second ; return a . first < b . first ; } int findInd ( vector < pair < int , int > > & preSum , int n , int val ) { int l = 0 ; int h = n - 1 ; int mid ; int ans = -1 ; while ( l <= h ) { mid = ( l + h ) / 2 ; if ( preSum [ mid ] . first <= val ) { ans = mid ; l = mid + 1 ; } else h = mid - 1 ; } return ans ; } int LongestSub ( int arr [ ] , int n , int x ) { int i ; for ( i = 0 ; i < n ; i ++ ) arr [ i ] -= x ; int maxlen = 0 ; vector < pair < int , int > > preSum ; int sum = 0 ; int minInd [ n ] ; for ( i = 0 ; i < n ; i ++ ) { sum = sum + arr [ i ] ; preSum . push_back ( { sum , i } ) ; } sort ( preSum . begin ( ) , preSum . end ( ) , compare ) ; minInd [ 0 ] = preSum [ 0 ] . second ; for ( i = 1 ; i < n ; i ++ ) { minInd [ i ] = min ( minInd [ i - 1 ] , preSum [ i ] . second ) ; } sum = 0 ; for ( i = 0 ; i < n ; i ++ ) { sum = sum + arr [ i ] ; if ( sum >= 0 ) maxlen = i + 1 ; else { int ind = findInd ( preSum , n , sum ) ; if ( ind != -1 && minInd [ ind ] < i ) maxlen = max ( maxlen , i - minInd [ ind ] ) ; } } return maxlen ; } int main ( ) { int arr [ ] = { -2 , 1 , 6 , -3 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int x = 3 ; cout << LongestSub ( arr , n , x ) ; return 0 ; }

Index/key variables: i, ind, mid, n
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <iostream>
using namespace std ; int findmissing ( int ar [ ] , int N ) { int l = 0 , r = N - 1 ; while ( l <= r ) { int mid = ( l + r ) / 2 ; if ( ar [ mid ] != mid + 1 && ar [ mid - 1 ] == mid ) return mid + 1 ; if ( ar [ mid ] != mid + 1 ) r = mid - 1 ; else l = mid + 1 ; } return -1 ; } int main ( ) { int arr [ ] = { 1 , 2 , 3 , 4 , 5 , 7 , 8 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << findmissing ( arr , N ) ; return 0 ; }

Index/key variables: mid
C++ program:
#include <bits/stdc++.h>
using namespace std ; int findFirst ( int arr [ ] , int n , int x ) { sort ( arr , arr + n ) ; int * ptr = lower_bound ( arr , arr + n , x ) ; return ( * ptr != x ) ? -1 : ( ptr - arr ) ; } int main ( ) { int x = 20 , arr [ ] = { 10 , 30 , 20 , 50 , 20 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << findFirst ( arr , n , x ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int findFirst ( int arr [ ] , int n , int x ) { int count = 0 ; bool isX = false ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] == x ) isX = true ; else if ( arr [ i ] < x ) count ++ ; } return ( isX == false ) ? -1 : count ; } int main ( ) { int x = 20 , arr [ ] = { 10 , 30 , 20 , 50 , 20 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << findFirst ( arr , n , x ) ; return 0 ; }

Index/key variables: i
Accumulator variables: count, i, stdc
Iterator variables: i
Boolean variables: isX
C++ program:
#include <iostream>
using namespace std ; int findDuplicate ( int arr [ ] ) { int slow = arr [ 0 ] ; int fast = arr [ 0 ] ; do { slow = arr [ slow ] ; fast = arr [ arr [ fast ] ] ; } while ( slow != fast ) ; int ptr1 = arr [ 0 ] ; int ptr2 = slow ; while ( ptr1 != ptr2 ) { ptr1 = arr [ ptr1 ] ; ptr2 = arr [ ptr2 ] ; } return ptr1 ; } int main ( ) { int arr [ ] = { 1 , 3 , 2 , 1 } ; cout << findDuplicate ( arr ) << endl ; return 0 ; }

Index/key variables: fast, ptr1, ptr2, slow
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define MAX_CHAR  26
void printGreaterCount ( string str ) { int len = str . length ( ) ; int ans [ len ] = { 0 } , count [ MAX_CHAR ] = { 0 } ; for ( int i = len - 1 ; i >= 0 ; i -- ) { count [ str [ i ] - ' a ' ] ++ ; for ( int j = str [ i ] - ' a ' + 1 ; j < MAX_CHAR ; j ++ ) ans [ i ] += count [ j ] ; } for ( int i = 0 ; i < len ; i ++ ) cout << ans [ i ] << " ▁ " ; } int main ( ) { string str = " abcd " ; printGreaterCount ( str ) ; return 0 ; }

Index/key variables: MAX_CHAR, i, j, len
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; void printPairs ( int arr [ ] , int n , int sum ) { unordered_map < int , int > m ; for ( int i = 0 ; i < n ; i ++ ) { int rem = sum - arr [ i ] ; if ( m . find ( rem ) != m . end ( ) ) { int count = m [ rem ] ; for ( int j = 0 ; j < count ; j ++ ) cout << " ( " << rem << " , ▁ " << arr [ i ] << " ) " << endl ; } m [ arr [ i ] ] ++ ; } } int main ( ) { int arr [ ] = { 1 , 5 , 7 , -1 , 5 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int sum = 6 ; printPairs ( arr , n , sum ) ; return 0 ; }

Index/key variables: i, rem
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maxProduct ( int arr [ ] , int n ) { if ( n < 4 ) return -1 ; int maxA = INT_MIN , maxB = INT_MIN , maxC = INT_MIN , maxD = INT_MIN ; int minA = INT_MAX , minB = INT_MAX , minC = INT_MAX , minD = INT_MAX ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] > maxA ) { maxD = maxC ; maxC = maxB ; maxB = maxA ; maxA = arr [ i ] ; } else if ( arr [ i ] > maxB ) { maxD = maxC ; maxC = maxB ; maxB = arr [ i ] ; } else if ( arr [ i ] > maxC ) { maxD = maxC ; maxC = arr [ i ] ; } else if ( arr [ i ] > maxD ) maxD = arr [ i ] ; if ( arr [ i ] < minA ) { minD = minC ; minC = minB ; minB = minA ; minA = arr [ i ] ; } else if ( arr [ i ] < minB ) { minD = minC ; minC = minB ; minB = arr [ i ] ; } else if ( arr [ i ] < minC ) { minD = minC ; minC = arr [ i ] ; } else if ( arr [ i ] < minD ) minD = arr [ i ] ; } int x = maxA * maxB * maxC * maxD ; int y = minA * minB * minC * minD ; int z = minA * minB * maxA * maxB ; return max ( x , max ( y , z ) ) ; } int main ( ) { int arr [ ] = { 1 , -4 , 3 , -6 , 7 , 0 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int max = maxProduct ( arr , n ) ; if ( max == -1 ) cout << " No ▁ Quadruple ▁ Exists " ; else cout << " Maximum ▁ product ▁ is ▁ " << max ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countTripletsLessThanL ( int n , int L , int * arr ) { sort ( arr , arr + n ) ; int ways = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { for ( int k = j + 1 ; k < n ; k ++ ) { int mostDistantDistance = arr [ k ] - arr [ i ] ; if ( mostDistantDistance <= L ) { ways ++ ; } } } } return ways ; } int main ( ) { int arr [ ] = { 1 , 2 , 3 , 4 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int L = 3 ; int ans = countTripletsLessThanL ( n , L , arr ) ; cout << " Total ▁ Number ▁ of ▁ ways ▁ = ▁ " << ans << " STRNEWLINE " ; return 0 ; }

Index/key variables: i, k
Accumulator variables: i, j, k, stdc, ways
Iterator variables: i, j, k
C++ program:
#include <bits/stdc++.h>
using namespace std ; int binary_lower ( int value , int arr [ ] , int n ) { int start = 0 ; int end = n - 1 ; int ans = -1 ; int mid ; while ( start <= end ) { mid = ( start + end ) / 2 ; if ( arr [ mid ] >= value ) { end = mid - 1 ; ans = mid ; } else { start = mid + 1 ; } } return ans ; } int countTriplet ( int arr [ ] , int n , int k ) { int count = 0 ; sort ( arr , arr + n ) ; for ( int i = 2 ; i < n ; i ++ ) { int cur = binary_lower ( arr [ i ] - k , arr , n ) ; if ( cur <= i - 2 ) { count += ( ( i - cur ) * ( i - cur - 1 ) ) / 2 ; } } return count ; } int main ( ) { int arr [ ] = { 1 , 1 , 2 , 2 , 3 } ; int k = 1 ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << countTriplet ( arr , n , k ) << endl ; return 0 ; }

Index/key variables: i, mid
Accumulator variables: count, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define MAXN  1000
struct Node { int start , end ; int length ; int insertionEdge [ 26 ] ; int suffixEdge ; } ; Node root1 , root2 ; Node tree [ MAXN ] ; int currNode ; string s ; int ptr ; void insert ( int currIndex ) { int temp = currNode ; while ( true ) { int currLength = tree [ temp ] . length ; if ( currIndex - currLength >= 1 && ( s [ currIndex ] == s [ currIndex - currLength - 1 ] ) ) break ; temp = tree [ temp ] . suffixEdge ; } if ( tree [ temp ] . insertionEdge [ s [ currIndex ] - ' a ' ] != 0 ) { currNode = tree [ temp ] . insertionEdge [ s [ currIndex ] - ' a ' ] ; return ; } ptr ++ ; tree [ temp ] . insertionEdge [ s [ currIndex ] - ' a ' ] = ptr ; tree [ ptr ] . end = currIndex ; tree [ ptr ] . length = tree [ temp ] . length + 2 ; tree [ ptr ] . start = tree [ ptr ] . end - tree [ ptr ] . length + 1 ; currNode = ptr ; temp = tree [ temp ] . suffixEdge ; if ( tree [ currNode ] . length == 1 ) { tree [ currNode ] . suffixEdge = 2 ; return ; } while ( true ) { int currLength = tree [ temp ] . length ; if ( currIndex - currLength >= 1 && ( s [ currIndex ] == s [ currIndex - currLength - 1 ] ) ) break ; temp = tree [ temp ] . suffixEdge ; } tree [ currNode ] . suffixEdge = tree [ temp ] . insertionEdge [ s [ currIndex ] - ' a ' ] ; } int main ( ) { root1 . length = -1 ; root1 . suffixEdge = 1 ; root2 . length = 0 ; root2 . suffixEdge = 1 ; tree [ 1 ] = root1 ; tree [ 2 ] = root2 ; ptr = 2 ; currNode = 1 ; s = " forgeeksskeegfor " ; for ( int i = 0 ; i < s . size ( ) ; i ++ ) insert ( i ) ; int last = ptr ; for ( int i = tree [ last ] . start ; i <= tree [ last ] . end ; i ++ ) cout << s [ i ] ; return 0 ; }

Index/key variables: MAXN, currIndex, currNode, i, last, ptr, temp
Accumulator variables: i, ptr, stdc
Iterator variables: i
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Node { char data ; struct Node * next ; } ; char maxChar ( struct Node * head ) { struct Node * p = head ; int max = -1 ; char res ; while ( p != NULL ) { struct Node * q = p -> next ; int count = 1 ; while ( q != NULL ) { if ( p -> data == q -> data ) count ++ ; q = q -> next ; } if ( max < count ) { res = p -> data ; max = count ; } p = p -> next ; } return res ; } void push ( struct Node * * head_ref , char new_data ) { struct Node * new_node = new Node ; new_node -> data = new_data ; new_node -> next = ( * head_ref ) ; ( * head_ref ) = new_node ; } int main ( ) { struct Node * head = NULL ; char str [ ] = " skeegforskeeg " ; int i ; for ( i = 0 ; str [ i ] != ' \0' ; i ++ ) push ( & head , str [ i ] ) ; cout << maxChar ( head ) ; return 0 ; }

Index/key variables: i
Accumulator variables: count, i, stdc
Iterator variables: i
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; int missingNum ( int arr [ ] , int n ) { int minvalue = * min_element ( arr , arr + n ) ; int xornum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { xornum ^= ( minvalue ) ^ arr [ i ] ; minvalue ++ ; } return xornum ^ minvalue ; } int main ( ) { int arr [ ] = { 13 , 12 , 11 , 15 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << missingNum ( arr , n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, minvalue, stdc, xornum
Iterator variables: i
C++ program:
#include <iostream>
using namespace std ; int findLastIndex ( string & str , char x ) { int index = -1 ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) if ( str [ i ] == x ) index = i ; return index ; } int main ( ) { string str = " geeksforgeeks " ; char x = ' e ' ; int index = findLastIndex ( str , x ) ; if ( index == -1 ) cout << " Character ▁ not ▁ found " ; else cout << " Last ▁ index ▁ is ▁ " << index ; return 0 ; }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
C++ program:
#include <iostream>
using namespace std ; int findLastIndex ( string & str , char x ) { for ( int i = str . length ( ) - 1 ; i >= 0 ; i -- ) if ( str [ i ] == x ) return i ; return -1 ; } int main ( ) { string str = " geeksforgeeks " ; char x = ' e ' ; int index = findLastIndex ( str , x ) ; if ( index == -1 ) cout << " Character ▁ not ▁ found " ; else cout << " Last ▁ index ▁ is ▁ " << index ; return 0 ; }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countMaxSetBits ( int left , int right ) { while ( ( left | ( left + 1 ) ) <= right ) left |= left + 1 ; return left ; } int main ( ) { int l = 1 , r = 5 ; cout << countMaxSetBits ( l , r ) << " STRNEWLINE " ; l = 1 , r = 10 ; cout << countMaxSetBits ( l , r ) ; return 0 ; }

Accumulator variables: left, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Node { int key ; Node * left , * right ; } ; Node * newNode ( int item ) { Node * temp = new Node ; temp -> key = item ; temp -> left = temp -> right = NULL ; return temp ; } Node * insert ( Node * node , int key ) { if ( node == NULL ) return newNode ( key ) ; if ( key < node -> key ) node -> left = insert ( node -> left , key ) ; else if ( key > node -> key ) node -> right = insert ( node -> right , key ) ; return node ; } int findFloor ( Node * root , int key ) { Node * curr = root , * ans = NULL ; while ( curr ) { if ( curr -> key <= key ) { ans = curr ; curr = curr -> right ; } else curr = curr -> left ; } if ( ans ) return ans -> key ; return -1 ; } int main ( ) { int N = 25 ; Node * root = insert ( root , 19 ) ; insert ( root , 2 ) ; insert ( root , 1 ) ; insert ( root , 3 ) ; insert ( root , 12 ) ; insert ( root , 9 ) ; insert ( root , 21 ) ; insert ( root , 19 ) ; insert ( root , 25 ) ; printf ( " % d " , findFloor ( root , N ) ) ; return 0 ; }

Accumulator variables: stdc
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; int compareStrings ( string str1 , string str2 ) { int i = 0 ; while ( str1 [ i ] == str2 [ i ] && str1 [ i ] != ' \0' ) i ++ ; if ( str1 [ i ] > str2 [ i ] ) return -1 ; return ( str1 [ i ] < str2 [ i ] ) ; } int searchStr ( string arr [ ] , string str , int first , int last ) { if ( first > last ) return -1 ; int mid = ( last + first ) / 2 ; if ( arr [ mid ] . empty ( ) ) { int left = mid - 1 ; int right = mid + 1 ; while ( true ) { if ( left < first && right > last ) return -1 ; if ( right <= last && ! arr [ right ] . empty ( ) ) { mid = right ; break ; } if ( left >= first && ! arr [ left ] . empty ( ) ) { mid = left ; break ; } right ++ ; left -- ; } } if ( compareStrings ( str , arr [ mid ] ) == 0 ) return mid ; if ( compareStrings ( str , arr [ mid ] ) < 0 ) return searchStr ( arr , str , mid + 1 , last ) ; return searchStr ( arr , str , first , mid - 1 ) ; } int main ( ) { string arr [ ] = { " for " , " " , " " , " " , " geeks " , " ide " , " " , " practice " , " " , " " , " quiz " , " " , " " } ; string str = " quiz " ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << searchStr ( arr , str , 0 , n - 1 ) ; return 0 ; }

Index/key variables: i, left, mid, right
Accumulator variables: i, left, right, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool comp ( vector < int > v1 , vector < int > v2 ) { return v1 [ 0 ] * v1 [ 1 ] > v2 [ 0 ] * v2 [ 1 ] ; } int countPlates ( vector < vector < int > > & plates , int n ) { int maximum_plates = 1 ; vector < int > dp ( n , 1 ) ; for ( int i = 1 ; i < n ; i ++ ) { int cur = dp [ i ] ; for ( int j = i - 1 ; j >= 0 ; j -- ) { if ( plates [ i ] [ 0 ] < plates [ j ] [ 0 ] && plates [ i ] [ 1 ] < plates [ j ] [ 1 ] ) { if ( cur + dp [ j ] > dp [ i ] ) { dp [ i ] = cur + dp [ j ] ; maximum_plates = max ( maximum_plates , dp [ i ] ) ; } } } } return maximum_plates ; } int main ( ) { vector < vector < int > > plates = { { 6 , 4 } , { 5 , 7 } , { 1 , 2 } , { 3 , 3 } , { 7 , 9 } } ; int n = plates . size ( ) ; sort ( plates . begin ( ) , plates . end ( ) , comp ) ; cout << countPlates ( plates , n ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countReduction ( int num ) { int ans = 0 ; while ( num >= 10 ) { int temp = num ; num = 1 ; while ( temp > 0 ) { int digit = temp % 10 ; temp = temp / 10 ; num *= digit ; } ans ++ ; } return ans ; } bool compare ( int x , int y ) { int x1 = countReduction ( x ) ; int y1 = countReduction ( y ) ; if ( x1 < y1 ) return true ; return false ; } void sortArray ( int a [ ] , int n ) { sort ( a , a + n , compare ) ; for ( int i = 0 ; i < n ; i ++ ) { cout << a [ i ] << " ▁ " ; } } int main ( ) { int arr [ ] = { 39 , 999 , 4 , 9876 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; sortArray ( arr , N ) ; return 0 ; }

Index/key variables: i
Accumulator variables: ans, i, num, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; string canSortString ( string S , int N ) { int flag = 1 ; int i , j ; for ( i = N - 2 ; i >= 0 ; i -- ) { if ( S [ i ] == '1' && S [ i + 1 ] == '1' ) { break ; } } for ( int j = i ; j >= 0 ; j -- ) { if ( S [ j ] == '0' && S [ j + 1 ] == '0' ) { flag = 0 ; break ; } } if ( flag == 0 ) { return " No " ; } else { return " Yes " ; } } int main ( ) { string S = "10101011011" ; int N = S . length ( ) ; cout << canSortString ( S , N ) ; return 0 ; }

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