codeparrot/xlcost-text-to-code huggingface dataset:
Generate an array consisting of most frequent greater elements present on the right side of each array element | C # program for the above approach ; Function to generate an array containing the most frequent greater element on the right side of each array element ; Stores the generated array ; Traverse the array arr [ ] ; Store the result for the current index and its frequency ; Iterate over the right subarray ; Store the frequency of the current array element ; If the frequencies are equal ; Update ans to smaller of the two elements ; If count of new element is more than count of ans ; Insert answer in the array ; Print the resultant array ; Driver Code ; Given Input
using System ; using System . Collections . Generic ; class GFG { static void findArray ( int [ ] arr , int n ) { List < int > v = new List < int > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { int ans = - 1 , old_c = 0 ; for ( int j = i + 1 ; j < n ; j ++ ) { if ( arr [ j ] > arr [ i ] ) { int curr_c = 0 ; for ( int k = j ; k < n ; k ++ ) { if ( arr [ k ] == arr [ j ] ) { curr_c ++ ; } } ; if ( curr_c == old_c ) { if ( arr [ j ] < ans ) ans = arr [ j ] ; } if ( curr_c > old_c ) { ans = arr [ j ] ; old_c = curr_c ; } } } v . Add ( ans ) ; } for ( int i = 0 ; i < v . Count ; i ++ ) Console . Write ( v [ i ] + " ▁ " ) ; } public static void Main ( ) { int [ ] arr = { 4 , 5 , 2 , 25 , 10 , 5 , 10 , 3 , 10 , 5 } ; int size = arr . Length ; findArray ( arr , size ) ; } }
Smallest index that splits an array into two subarrays with equal product | C # program for the above approach ; Function to find the smallest index that splits the array into two subarrays with equal product ; Stores the product of the array ; Traverse the given array ; Stores the product of left and the right subarrays ; Traverse the given array ; Update the products ; Check if product is equal ; Print resultant index ; If no partition exists , then print - 1. ; Driver Code
using System ; class GFG { static void prodEquilibrium ( int [ ] arr , int N ) { int product = 1 ; for ( int i = 0 ; i < N ; i ++ ) { product *= arr [ i ] ; } int left = 1 ; int right = product ; for ( int i = 0 ; i < N ; i ++ ) { left = left * arr [ i ] ; right = right / arr [ i ] ; if ( left == right ) { Console . WriteLine ( i + 1 + " STRNEWLINE " ) ; return ; } } Console . WriteLine ( - 1 + " STRNEWLINE " ) ; } public static void Main ( string [ ] args ) { int [ ] arr = { 1 , 2 , 3 , 3 , 2 , 1 } ; int N = arr . Length ; prodEquilibrium ( arr , N ) ; } }
Count triplets from a sorted array having difference between adjacent elements equal to D | C # program for the above approach ; Function to count the number of triplets having difference between adjacent elements equal to D ; Stores the frequency of array elements ; Stores the count of resultant triplets ; Traverse the array ; Check if arr [ i ] - D and arr [ i ] - 2 * D exists in the Hashmap or not ; Update the value of ans ; Increase the frequency of the current element ; Return the resultant count ; Driver Code
using System ; using System . Collections . Generic ; class GFG { static int countTriplets ( int D , int [ ] arr ) { Dictionary < int , int > freq = new Dictionary < int , int > ( ) ; int ans = 0 ; for ( int i = 0 ; i < arr . Length ; i ++ ) { if ( freq . ContainsKey ( arr [ i ] - D ) && freq . ContainsKey ( arr [ i ] - 2 * D ) ) { ans += freq [ arr [ i ] - D ] * freq [ arr [ i ] - 2 * D ] ; } if ( ! freq . ContainsKey ( arr [ i ] ) ) freq [ arr [ i ] ] = 0 ; freq [ arr [ i ] ] ++ ; } return ans ; } public static void Main ( ) { int [ ] arr = { 1 , 2 , 4 , 5 , 7 , 8 , 10 } ; int D = 1 ; Console . WriteLine ( countTriplets ( D , arr ) ) ; } }
Find the array element having equal sum of Prime Numbers on its left and right | C # program for the above approach ; Function to find an index in the array having sum of prime numbers to its left and right equal ; Stores the maximum value present in the array ; Stores all positive elements which are <= max_value ; If 1 is present ; Remove 1 ; Sieve of Eratosthenes to store all prime numbers which are <= max_value in the Map ; Erase non - prime numbers ; Stores the sum of prime numbers from left ; Stores the sum of prime numbers to the left of each index ; Stores the sum of prime numbers to the left of the current index ; Add current value to the prime sum if the current value is prime ; Stores the sum of prime numbers from right ; Stores the sum of prime numbers to the right of each index ; Stores the sum of prime numbers to the right of the current index ; Add current value to the prime sum if the current value is prime ; Traverse through the two arrays to find the index ; Compare the values present at the current index ; Return the index where both the values are same ; No index is found . ; Driver Code ; Given array arr [ ] ; Size of Array ; Function Call
using System ; using System . Collections . Generic ; class GFG { static int find_index ( int [ ] arr , int N ) { int max_value = Int32 . MinValue ; for ( int i = 0 ; i < N ; i ++ ) { max_value = Math . Max ( max_value , arr [ i ] ) ; } Dictionary < int , int > store = new Dictionary < int , int > ( ) ; for ( int i = 1 ; i <= max_value ; i ++ ) { if ( ! store . ContainsKey ( i ) ) store [ i ] = 0 ; store [ i ] ++ ; } if ( store . ContainsKey ( 1 ) ) { store . Remove ( 1 ) ; } for ( int i = 2 ; i <= Math . Sqrt ( max_value ) ; i ++ ) { int multiple = 2 ; while ( ( i * multiple ) <= max_value ) { if ( store . ContainsKey ( i * multiple ) ) { store . Remove ( i * multiple ) ; } multiple ++ ; } } int prime_sum_from_left = 0 ; int [ ] first_array = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { first_array [ i ] = prime_sum_from_left ; if ( store . ContainsKey ( arr [ i ] ) ) { prime_sum_from_left += arr [ i ] ; } } int prime_sum_from_right = 0 ; int [ ] second_array = new int [ N ] ; for ( int i = N - 1 ; i >= 0 ; i -- ) { second_array [ i ] = prime_sum_from_right ; if ( store . ContainsKey ( arr [ i ] ) ) { prime_sum_from_right += arr [ i ] ; } } for ( int i = 0 ; i < N ; i ++ ) { if ( first_array [ i ] == second_array [ i ] ) { return i ; } } return - 1 ; } public static void Main ( ) { int [ ] arr = { 11 , 4 , 7 , 6 , 13 , 1 , 5 } ; int N = arr . Length ; Console . WriteLine ( find_index ( arr , N ) ) ; } }
Convert an array to reduced form | Set 3 ( Binary Search ) | C # program for the above approach ; Function to find the reduced form of the given array arr [ ] ; Stores the sorted form of the the given array arr [ ] ; Sort the array brr [ ] ; Traverse the given array arr [ ] ; Perform the Binary Search ; Calculate the value of mid ; Print the current index and break ; Update the value of l ; Update the value of r ; Driver Code
using System ; class GFG { static void convert ( int [ ] arr , int n ) { int [ ] brr = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) brr [ i ] = arr [ i ] ; Array . Sort ( brr ) ; for ( int i = 0 ; i < n ; i ++ ) { int l = 0 , r = n - 1 , mid ; while ( l <= r ) { mid = ( l + r ) / 2 ; if ( brr [ mid ] == arr [ i ] ) { Console . Write ( mid + " ▁ " ) ; break ; } else if ( brr [ mid ] < arr [ i ] ) { l = mid + 1 ; } else { r = mid - 1 ; } } } } public static void Main ( string [ ] args ) { int [ ] arr = { 10 , 20 , 15 , 12 , 11 , 50 } ; int N = arr . Length ; convert ( arr , N ) ; } }
Find the array element having equal count of Prime Numbers on its left and right | C # program for the above approach ; Function to find the index of the array such that the count of prime numbers to its either ends are same ; Store the maximum value in the array ; Traverse the array arr [ ] ; Stores all the numbers ; Iterate over the range [ 1 , Max ] ; Increment the value of st [ i ] ; Removes 1 from the map St ; Perform Sieve of Prime Numbers ; While i * j is less than the maxValue ; If i * j is in map St ; Erase the value ( i * j ) ; Increment the value of j ; Stores the count of prime from index 0 to i ; Stores the count of prime numbers ; Traverse the array arr [ ] ; If arr [ i ] is present in the map st ; Stores the count of prime from index i to N - 1 ; Stores the count of prime numbers ; Iterate over the range [ 0 , N - 1 ] in reverse order ; If arr [ i ] is in map st ; Iterate over the range [ 0 , N - 1 ] ; If prefix [ i ] is equal to the Suffix [ i ] ; Return - 1 if no such index is present ; Driver code
using System ; using System . Collections . Generic ; public class GFG { static int findIndex ( int [ ] arr , int N ) { int maxValue = Int32 . MinValue ; for ( int i = 0 ; i < N ; i ++ ) { maxValue = Math . Max ( maxValue , arr [ i ] ) ; } Dictionary < int , int > St = new Dictionary < int , int > ( ) ; for ( int i = 1 ; i <= maxValue ; i ++ ) { St . Add ( i , 1 ) ; } if ( St . ContainsKey ( 1 ) ) { St . Remove ( 1 ) ; } for ( int i = 2 ; i <= Math . Sqrt ( maxValue ) ; i ++ ) { int j = 2 ; while ( ( i * j ) <= maxValue ) { if ( St . ContainsKey ( i * j ) ) { St . Remove ( i * j ) ; } j ++ ; } } int LeftCount = 0 ; int [ ] Prefix = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { Prefix [ i ] = LeftCount ; if ( St . ContainsKey ( arr [ i ] ) ) { LeftCount ++ ; } } int RightCount = 0 ; int [ ] Suffix = new int [ N ] ; for ( int i = N - 1 ; i >= 0 ; i -- ) { Suffix [ i ] = RightCount ; if ( St . ContainsKey ( arr [ i ] ) ) { RightCount ++ ; } } for ( int i = 0 ; i < N ; i ++ ) { if ( Prefix [ i ] == Suffix [ i ] ) { return i ; } } return - 1 ; } static public void Main ( ) { int [ ] arr = { 2 , 3 , 4 , 7 , 5 , 10 , 1 , 8 } ; int N = arr . Length ; Console . WriteLine ( findIndex ( arr , N ) ) ; } }
Numbers of pairs from an array whose average is also present in the array | C # program for the above approach ; Function to count the number of pairs from the array having sum S ; Stores the total count of pairs whose sum is 2 * S ; Generate all possible pairs and check their sums ; If the sum is S , then increment the count ; Return the total count of pairs ; Function to count of pairs having whose average exists in the array ; Initialize the count ; Use set to remove duplicates ; Add elements in the set ; For every sum , count all possible pairs ; Return the total count ; Driver Code
using System ; using System . Collections . Generic ; public class GFG { public static int getCountPairs ( int [ ] arr , int N , int S ) { int count = 0 ; for ( int i = 0 ; i < arr . Length ; i ++ ) { for ( int j = i + 1 ; j < arr . Length ; j ++ ) { if ( ( arr [ i ] + arr [ j ] ) == S ) count ++ ; } } return count ; } public static int countPairs ( int [ ] arr , int N ) { int count = 0 ; HashSet < int > S = new HashSet < int > ( ) ; for ( int i = 0 ; i < N ; i ++ ) S . Add ( arr [ i ] ) ; foreach ( int ele in S ) { int sum = 2 * ele ; count += getCountPairs ( arr , N , sum ) ; } return count ; } public static void Main ( String [ ] args ) { int [ ] arr = { 4 , 2 , 5 , 1 , 3 , 5 } ; int N = arr . Length ; Console . Write ( countPairs ( arr , N ) ) ; } }
Sort array of strings after sorting each string after removing characters whose frequencies are not a powers of 2 | C # program for the above approach ; Function to check if N is power of 2 or not ; Base Case ; Return true if N is power of 2 ; Function to print array of strings in ascending order ; Sort strings in ascending order ; Print the array ; Function to sort the strings after modifying each string according to the given conditions ; Store the frequency of each characters of the string ; Stores the required array of strings ; Traverse the array of strings ; Temporary string ; Stores frequency of each alphabet of the string ; Update frequency of S [ i ] [ j ] ; Traverse the map freq ; Check if the frequency of i . first is a power of 2 ; Update string st ; Clear the map ; Null string ; Sort the string in descending order ; Update res ; Print the array of strings ; Driver Code
using System ; using System . Collections . Generic ; public class GFG { static bool isPowerOfTwo ( int n ) { if ( n == 0 ) return false ; return ( Math . Ceiling ( Math . Log ( n ) / Math . Log ( 2 ) ) == Math . Floor ( Math . Log ( n ) / Math . Log ( 2 ) ) ) ; } static void printArray ( List < string > res ) { ( res ) . Sort ( ) ; for ( int i = 0 ; i < res . Count ; i ++ ) { Console . Write ( res [ i ] + " ▁ " ) ; } } static void sortedStrings ( string [ ] S , int N ) { Dictionary < char , int > freq = new Dictionary < char , int > ( ) ; List < string > res = new List < string > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { string st = " " ; for ( int j = 0 ; j < S [ i ] . Length ; j ++ ) { if ( ! freq . ContainsKey ( S [ i ] [ j ] ) ) freq . Add ( S [ i ] [ j ] , 0 ) ; freq [ S [ i ] [ j ] ] ++ ; } foreach ( KeyValuePair < char , int > ch in freq ) { if ( isPowerOfTwo ( freq [ ch . Key ] ) ) { for ( int j = 0 ; j < freq [ ch . Key ] ; j ++ ) { st += ch . Key ; } } } freq . Clear ( ) ; if ( st . Length == 0 ) continue ; char [ ] myCharArr = st . ToCharArray ( ) ; Array . Sort ( myCharArr ) ; string ns = " " ; for ( int j = myCharArr . Length - 1 ; j >= 0 ; -- j ) ns += myCharArr [ j ] ; res . Add ( ns ) ; } printArray ( res ) ; } static public void Main ( ) { string [ ] arr = { " aaacbb " , " geeks " , " aaa " } ; int N = arr . Length ; sortedStrings ( arr , N ) ; } }
Modify string by replacing all occurrences of given characters by specified replacing characters | C # program for the above approach ; Function to modify given string by replacing characters ; Store the size of string and the number of pairs ; Initialize 2 character arrays ; Traverse the string s Update arrays arr [ ] and brr [ ] ; Traverse the array of pairs p ; a -> Character to be replaced b -> Replacing character ; Iterate over the range [ 0 , 25 ] ; If it is equal to current character , then replace it in the array b ; Print the array brr [ ] ; Driver code
using System ; public class GFG { static void replaceCharacters ( string s , char [ , ] p ) { int n = s . Length , k = p . GetLength ( 0 ) ; char [ ] arr = new char [ 26 ] ; char [ ] brr = new char [ 26 ] ; for ( int i = 0 ; i < n ; i ++ ) { arr [ s [ i ] - ' a ' ] = s [ i ] ; brr [ s [ i ] - ' a ' ] = s [ i ] ; } for ( int j = 0 ; j < k ; j ++ ) { char a = p [ j , 0 ] , b = p [ j , 1 ] ; for ( int i = 0 ; i < 26 ; i ++ ) { if ( arr [ i ] == a ) { brr [ i ] = b ; } } } for ( int i = 0 ; i < n ; i ++ ) { Console . Write ( brr [ s [ i ] - ' a ' ] ) ; } } static public void Main ( ) { String S = " aabbgg " ; char [ , ] P = { { ' a ' , ' b ' } , { ' b ' , ' g ' } , { ' g ' , ' a ' } } ; replaceCharacters ( S , P ) ; } }
Smallest Semi | C # program for the above approach ; Function to find all the prime numbers using Sieve of Eratosthenes ; Set 0 and 1 as non - prime ; If p is a prime ; Set all multiples of p as non - prime ; Function to find the smallest semi - prime number having a difference between any of its two divisors at least N ; Stores the prime numbers ; Fill the prime array ; Initialize the first divisor ; Find the value of the first prime number ; Initialize the second divisor ; Find the second prime number ; Print the semi - prime number ; Driver code
using System ; class GFG { static int MAX = 100001 ; static void SieveOfEratosthenes ( bool [ ] prime ) { prime [ 0 ] = false ; prime [ 1 ] = false ; for ( int p = 2 ; p * p < MAX ; p ++ ) { if ( prime [ p ] == true ) { for ( int i = p * p ; i < MAX ; i += p ) prime [ i ] = false ; } } } static void smallestSemiPrime ( int n ) { bool [ ] prime = new bool [ MAX ] ; for ( int i = 0 ; i < prime . Length ; i ++ ) { prime [ i ] = true ; } SieveOfEratosthenes ( prime ) ; int num1 = n + 1 ; while ( prime [ num1 ] != true ) { num1 ++ ; } int num2 = num1 + n ; while ( prime [ num2 ] != true ) { num2 ++ ; } Console . Write ( num1 * num2 ) ; } static void Main ( ) { int N = 2 ; smallestSemiPrime ( N ) ; } }
Check if a number can be represented as product of two positive perfect cubes | C # program for the above approach ; Function to check if N can be represented as the product of two perfect cubes or not ; Stores the perfect cubes ; Traverse the Map ; Stores the first number ; Stores the second number ; Search the pair for the first number to obtain product N from the Map ; If N cannot be represented as the product of the two positive perfect cubes ; Driver Code
using System ; using System . Collections . Generic ; class GFG { static void productOfTwoPerfectCubes ( int N ) { Dictionary < int , int > cubes = new Dictionary < int , int > ( ) ; for ( int i = 1 ; i * i * i <= N ; i ++ ) { cubes . Add ( i * i * i , i ) ; } foreach ( KeyValuePair < int , int > kvp in cubes ) { int firstNumber = kvp . Key ; if ( N % kvp . Key == 0 ) { int secondNumber = N / kvp . Key ; if ( cubes . ContainsKey ( secondNumber ) ) { Console . Write ( " Yes " ) ; return ; } } } Console . Write ( " No " ) ; } public static void Main ( ) { int N = 216 ; productOfTwoPerfectCubes ( N ) ; } }
Check if a number can be represented as product of two positive perfect cubes | C # program for the above approach ; Function to check if the number N can be represented as the product of two perfect cubes or not ; If cube of cube_root is N ; Otherwise , print No ; Driver Code
using System ; using System . Collections . Generic ; using System . Linq ; class GFG { public static void productOfTwoPerfectCubes ( double N ) { double cube_root ; cube_root = Math . Round ( Math . Cbrt ( N ) ) ; if ( cube_root * cube_root * cube_root == N ) { Console . Write ( " Yes " ) ; return ; } else { Console . Write ( " No " ) ; return ; } } static public void Main ( ) { double N = 216 ; productOfTwoPerfectCubes ( N ) ; } }
Size of smallest square that contains N non | C # program for the above approach ; Function to check if side of square X can pack all the N rectangles or not ; Find the number of rectangle it can pack ; If val is atleast N , then return true ; Otherwise , return false ; Function to find the size of the smallest square that can contain N rectangles of dimensions W * H ; Stores the lower bound ; Stores the upper bound ; Iterate until i is less than j ; Calculate the mid value ; If the current size of square cam contain N rectangles ; Otherwise , update i ; Return the minimum size of the square required ; Driver Code ; Function Call
using System ; class GFG { static bool bound ( int w , int h , int N , int x ) { int val = ( x / w ) * ( x / h ) ; if ( val >= N ) return true ; else return false ; } static int FindSquare ( int N , int W , int H ) { int i = 1 ; int j = W * H * N ; while ( i < j ) { int mid = i + ( j - i ) / 2 ; if ( bound ( W , H , N , mid ) ) j = mid ; else i = mid + 1 ; } return j ; } public static void Main ( ) { int W = 2 ; int H = 3 ; int N = 10 ; Console . WriteLine ( FindSquare ( N , W , H ) ) ; } }
Count integers up to N that are equal to at least 2 nd power of any integer exceeding 1 | C # program for the above approach ; Function to count the integers up to N that can be represented as a ^ b , where a & b > 1 ; Initialize a HashSet ; Iterating over the range [ 2 , sqrt ( N ) ] ; Generate all possible power of x ; Multiply x by i ; If the generated number lies in the range [ 1 , N ] then insert it in HashSet ; Print the total count ; Driver Code
using System ; using System . Collections . Generic ; class GFG { static void printNumberOfPairs ( int N ) { HashSet < int > st = new HashSet < int > ( ) ; for ( int i = 2 ; i * i <= N ; i ++ ) { int x = i ; while ( x <= N ) { x *= i ; if ( x <= N ) { st . Add ( x ) ; } } } Console . WriteLine ( st . Count ) ; } public static void Main ( string [ ] args ) { int N = 10000 ; printNumberOfPairs ( N ) ; } }
Maximize product of lengths of strings having no common characters | C # program for the above approach ; Function to count the number of set bits in the integer n ; Stores the count of set bits in n ; Return the count ; Function to find the maximum product of pair of strings having no common characters ; Stores the integer equivalent of the strings ; Traverse the array of strings ; Traverse the current string ; Store the current bit position in bits [ i ] ; Store the required result ; Traverse the array , bits [ ] to get all unique pairs ( i , j ) ; Check whether the strings have no common characters ; Update the overall maximum product ; Print the maximum product ; Driver code
using System ; public class GFG { public static int countSetBits ( int n ) { int count = 0 ; while ( n > 0 ) { count += n & 1 ; n >>= 1 ; } return count ; } public static void maximumProduct ( string [ ] words ) { int [ ] bits = new int [ words . Length ] ; for ( int i = 0 ; i < words . Length ; i ++ ) { for ( int j = 0 ; j < words [ i ] . Length ; j ++ ) { bits [ i ] = bits [ i ] | 1 << ( words [ i ] [ j ] - ' a ' ) ; } } int result = 0 ; for ( int i = 0 ; i < bits . Length ; i ++ ) { for ( int j = i + 1 ; j < bits . Length ; j ++ ) { if ( ( bits [ i ] & bits [ j ] ) == 0 ) { int L = countSetBits ( bits [ i ] ) ; int R = countSetBits ( bits [ j ] ) ; result = Math . Max ( L * R , result ) ; } } } Console . WriteLine ( result ) ; } static public void Main ( ) { string [ ] arr = { " abcw " , " baz " , " foo " , " bar " , " xtfn " , " abcdef " } ; maximumProduct ( arr ) ; } }
Modify a sentence by reversing order of occurrences of all Palindrome Words | C # implementation of the above approach ; Function to check if a string S is a palindrome ; Function to print the modified string after reversing teh order of occurrences of all palindromic words in the sentence ; Stores the palindromic words ; Stores the words in the list ; Traversing the list ; If current word is a palindrome ; Update newlist ; Reverse the newlist ; Traverse the list ; If current word is a palindrome ; Update lis [ i ] ; Increment j ; Print the updated sentence ; Driver Code
using System ; using System . Collections . Generic ; class GFG { static bool palindrome ( string str ) { int st = 0 ; int ed = str . Length - 1 ; while ( st < ed ) { if ( str [ st ] == str [ ed ] ) { st ++ ; ed -- ; } else return false ; } return true ; } static void printReverse ( string sentence ) { List < string > newlist = new List < string > ( ) ; List < string > lis = new List < string > ( ) ; string temp = " " ; foreach ( char x in sentence ) { if ( x == ' ▁ ' ) { lis . Add ( temp ) ; temp = " " ; } else temp += x ; } lis . Add ( temp ) ; foreach ( string x in lis ) { if ( palindrome ( x ) ) newlist . Add ( x ) ; } newlist . Reverse ( ) ; int j = 0 ; for ( int i = 0 ; i < lis . Count ; i ++ ) { if ( palindrome ( lis [ i ] ) ) { lis [ i ] = newlist [ j ] ; j = j + 1 ; } } foreach ( string x in lis ) Console . Write ( x + " ▁ " ) ; } public static void Main ( ) { string sentence = " mom ▁ and ▁ dad ▁ went ▁ to ▁ eye ▁ hospital " ; printReverse ( sentence ) ; } }
Convert an array into another by repeatedly removing the last element and placing it at any arbitrary index | C # program for the above approach ; Function to count the minimum number of operations required to convert the array A [ ] into array B [ ] ; Stores the index in the first permutation A [ ] which is same as the subsequence in B [ ] ; Find the first i elements in A [ ] which is a subsequence in B [ ] ; If element A [ i ] is same as B [ j ] ; Return the count of operations required ; Driver Code
using System ; class GFG { static int minCount ( int [ ] A , int [ ] B , int N ) { int i = 0 ; for ( int j = 0 ; j < N ; j ++ ) { if ( A [ i ] == B [ j ] ) { i ++ ; } } return N - i ; } public static void Main ( string [ ] args ) { int [ ] A = { 1 , 2 , 3 , 4 , 5 } ; int [ ] B = { 1 , 5 , 2 , 3 , 4 } ; int N = A . Length ; Console . WriteLine ( minCount ( A , B , N ) ) ; } }