codeparrot/xlcost-text-to-code huggingface dataset:
Split array into subarrays at minimum cost by minimizing count of repeating elements in each subarray | C # program for the above approach ; Function to find the minimum cost of splitting the array into subarrays ; Get the maximum element ; [ ] dp will store the minimum cost upto index i ; Initialize the result array ; Initialise the first element ; Create the frequency array ; Update the frequency ; Counting the cost of the duplicate element ; Minimum cost of operation from 0 to j ; Total cost of the array ; Driver Code ; Given cost K ; Function Call
using System ; using System . Linq ; class GFG { static long findMinCost ( int [ ] a , int k , int n ) { int max_ele = a . Max ( ) ; long [ ] dp = new long [ n + 1 ] ; for ( int i = 1 ; i <= n ; ++ i ) dp [ i ] = int . MaxValue ; dp [ 0 ] = 0 ; for ( int i = 0 ; i < n ; ++ i ) { int [ ] freq = new int [ max_ele + 1 ] ; for ( int j = i ; j < n ; ++ j ) { freq [ a [ j ] ] ++ ; int cost = 0 ; for ( int x = 0 ; x <= max_ele ; ++ x ) { cost += ( freq [ x ] == 1 ) ? 0 : freq [ x ] ; } dp [ j + 1 ] = Math . Min ( dp [ i ] + cost + k , dp [ j + 1 ] ) ; } } return dp [ n ] ; } public static void Main ( String [ ] args ) { int [ ] arr = { 1 , 2 , 1 , 1 , 1 } ; int K = 2 ; int n = arr . Length ; Console . Write ( findMinCost ( arr , K , n ) ) ; } }
Find subarray with given sum | Set 2 ( Handles Negative Numbers ) | C # program to print subarray with sum as given sum ; Function to print subarray with sum as given sum ; cur_sum to keep track of cummulative sum till that point ; check whether cur_sum - sum = 0 , if 0 it means the sub array is starting from index 0 - so stop ; if hashMap already has the value , means we already have subarray with the sum - so stop ; if value is not present then add to hashmap ; if end is - 1 : means we have reached end without the sum ; Driver code
using System ; using System . Collections . Generic ; public class GFG { public static void subArraySum ( int [ ] arr , int n , int sum ) { int cur_sum = 0 ; int start = 0 ; int end = - 1 ; Dictionary < int , int > hashMap = new Dictionary < int , int > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { cur_sum = cur_sum + arr [ i ] ; if ( cur_sum - sum == 0 ) { start = 0 ; end = i ; break ; } if ( hashMap . ContainsKey ( cur_sum - sum ) ) { start = hashMap [ cur_sum - sum ] + 1 ; end = i ; break ; } hashMap [ cur_sum ] = i ; } if ( end == - 1 ) { Console . WriteLine ( " No ▁ subarray ▁ with ▁ given ▁ sum ▁ exists " ) ; } else { Console . WriteLine ( " Sum ▁ found ▁ between ▁ indexes ▁ " + start + " ▁ to ▁ " + end ) ; } } public static void Main ( string [ ] args ) { int [ ] arr = new int [ ] { 10 , 2 , - 2 , - 20 , 10 } ; int n = arr . Length ; int sum = - 10 ; subArraySum ( arr , n , sum ) ; } }
Write Code to Determine if Two Trees are Identical | C # program to see if two trees are identical ; A binary tree node ; Given two trees , return true if they are structurally identical ; 1. both empty ; 2. both non - empty -> compare them ; 3. one empty , one not -> false ; Driver program to test identicalTrees ( ) function
using System ; public class Node { public int data ; public Node left , right ; public Node ( int item ) { data = item ; left = right = null ; } } public class BinaryTree { public Node root1 , root2 ; public virtual bool identicalTrees ( Node a , Node b ) { if ( a == null && b == null ) { return true ; } if ( a != null && b != null ) { return ( a . data == b . data && identicalTrees ( a . left , b . left ) && identicalTrees ( a . right , b . right ) ) ; } return false ; } public static void Main ( string [ ] args ) { BinaryTree tree = new BinaryTree ( ) ; tree . root1 = new Node ( 1 ) ; tree . root1 . left = new Node ( 2 ) ; tree . root1 . right = new Node ( 3 ) ; tree . root1 . left . left = new Node ( 4 ) ; tree . root1 . left . right = new Node ( 5 ) ; tree . root2 = new Node ( 1 ) ; tree . root2 . left = new Node ( 2 ) ; tree . root2 . right = new Node ( 3 ) ; tree . root2 . left . left = new Node ( 4 ) ; tree . root2 . left . right = new Node ( 5 ) ; if ( tree . identicalTrees ( tree . root1 , tree . root2 ) ) { Console . WriteLine ( " Both ▁ trees ▁ are ▁ identical " ) ; } else { Console . WriteLine ( " Trees ▁ are ▁ not ▁ identical " ) ; } } }
Queries to find Kth greatest character in a range [ L , R ] from a string with updates | C # Program to implement the above approach ; Maximum Size of a String ; Fenwick Tree to store the frequencies of 26 alphabets ; Size of the String . ; Function to update Fenwick Tree for char c at index val ; Add val to current node Fenwick Tree ; Move index to parent node in update View ; Function to get sum of frequencies of character c till index ; Stores the sum ; Add current element of Fenwick tree to sum ; Move index to parent node in getSum View ; Function to create the Fenwick tree ; Function to print the kth largest character in the range of l to r ; Stores the count of characters ; Stores the required character ; Calculate frequency of C in the given range ; Increase count ; If count exceeds K ; Required character found ; Function to update character at pos by character s ; 0 based index system ; Driver Code ; Makes the String 1 - based indexed ; Number of queries ; Construct the Fenwick Tree
using System ; class GFG { static int maxn = 100005 ; static int [ , ] BITree = new int [ 26 , maxn ] ; static int N ; static void update_BITree ( int index , char C , int val ) { while ( index <= N ) { BITree [ C - ' a ' , index ] += val ; index += ( index & - index ) ; } } static int sum_BITree ( int index , char C ) { int s = 0 ; while ( index > 0 ) { s += BITree [ C - ' a ' , index ] ; index -= ( index & - index ) ; } return s ; } static void buildTree ( String str ) { for ( int i = 1 ; i <= N ; i ++ ) { update_BITree ( i , str [ i ] , 1 ) ; } Console . WriteLine ( ) ; } static char printchar ( String str , int l , int r , int k ) { int count = 0 ; char ans = ( char ) 0 ; for ( char C = ' z ' ; C >= ' a ' ; C -- ) { int times = sum_BITree ( r , C ) - sum_BITree ( l - 1 , C ) ; count += times ; if ( count >= k ) { ans = C ; break ; } } return ans ; } static void updateTree ( String str , int pos , char s ) { int index = pos ; update_BITree ( index , str [ index ] , - 1 ) ; str = str . Substring ( 0 , index ) + s + str . Substring ( index + 1 ) ; update_BITree ( index , s , 1 ) ; } public static void Main ( String [ ] args ) { String str = " abcddef " ; N = str . Length ; str = ' / ' + str ; int Q = 3 ; buildTree ( str ) ; Console . Write ( printchar ( str , 1 , 2 , 2 ) + " STRNEWLINE " ) ; updateTree ( str , 4 , ' g ' ) ; Console . Write ( printchar ( str , 1 , 5 , 4 ) + " STRNEWLINE " ) ; } }
Generate a string from an array of alphanumeric strings based on given conditions | C # program for the above approach ; Function to generate required string ; To store the result ; Split name and number ; Stores the maximum number less than or equal to the length of name ; Check for number by parsing it to integer if it is greater than max number so far ; Check if no such number is found then we append X to the result . ; Otherwise ; Append max index of the name ; Return the readonly string ; Driver Code ; Function Call
using System ; using System . Text ; class GFG { public static String generatePassword ( String [ ] s , char T ) { StringBuilder result = new StringBuilder ( ) ; foreach ( String currentString in s ) { String [ ] person = currentString . Split ( ' : ' ) ; String name = person [ 0 ] ; String number = person [ 1 ] ; int n = name . Length ; int max = 0 ; for ( int i = 0 ; i < number . Length ; i ++ ) { int temp = Int32 . Parse ( String . Join ( " " , number [ i ] ) ) ; if ( temp > max && temp <= n ) max = temp ; } if ( max == 0 ) result . Append ( T ) ; else result . Append ( String . Join ( " " , name [ max - 1 ] ) ) ; } return result . ToString ( ) ; } public static void Main ( String [ ] args ) { String [ ] arr = { " Geeks : 89167" , " gfg : 68795" } ; char T = ' X ' ; Console . WriteLine ( generatePassword ( arr , T ) ) ; } }
Minimum number of edges required to be removed from an Undirected Graph to make it acyclic | C # program to implement the above approach ; Stores the adjacency list ; Stores if a vertex is visited or not ; Function to perform DFS Traversal to count the number and size of all connected components ; Mark the current node as visited ; Traverse the adjacency list of the current node ; For every unvisited node ; Recursive DFS call ; Function to add undirected edge in the graph ; Function to calculate minimum number of edges to be removed ; Create Adjacency list ; Iterate over all the nodes ; Print the readonly count ; Driver Code
using System ; using System . Collections . Generic ; class GFG { static List < int > [ ] vec = new List < int > [ 100001 ] ; static bool [ ] vis = new bool [ 100001 ] ; static int cc = 1 ; static void dfs ( int node ) { vis [ node ] = true ; foreach ( int x in vec [ node ] ) { if ( ! vis [ x ] ) { cc ++ ; dfs ( x ) ; } } } static void addEdge ( int u , int v ) { vec [ u ] . Add ( v ) ; vec [ v ] . Add ( u ) ; } static void minEdgeRemoved ( int N , int M , int [ , ] Edges ) { for ( int i = 0 ; i < M ; i ++ ) { addEdge ( Edges [ i , 0 ] , Edges [ i , 1 ] ) ; } int k = 0 ; for ( int i = 1 ; i <= N ; i ++ ) { if ( ! vis [ i ] ) { cc = 1 ; dfs ( i ) ; k ++ ; } } Console . Write ( M - N + k + " STRNEWLINE " ) ; } public static void Main ( String [ ] args ) { int N = 3 , M = 2 ; int [ , ] Edges = { { 1 , 2 } , { 2 , 3 } } ; for ( int i = 0 ; i < vec . Length ; i ++ ) vec [ i ] = new List < int > ( ) ; minEdgeRemoved ( N , M , Edges ) ; } }
Check if a Binary Tree consists of a pair of leaf nodes with sum K | C # program to implement the above approach ; Stores if a pair exists or not ; Struct binary tree node ; Creates a new node ; Function to check if a pair of leaf nodes exists with sum K ; Checks if root is null ; Checks if the current node is a leaf node ; Checks for a valid pair of leaf nodes ; Insert value of current node into the set ; Traverse left and right subtree ; Driver Code ; Construct binary tree ; Stores the leaf nodes
using System ; using System . Collections . Generic ; class GFG { static bool pairFound = false ; class Node { public int data ; public Node left , right ; } ; static Node newNode ( int data ) { Node temp = new Node ( ) ; temp . data = data ; temp . left = temp . right = null ; return temp ; } static void pairSum ( Node root , int target , HashSet < int > S ) { if ( root == null ) return ; if ( root . left == null && root . right == null ) { if ( S . Contains ( target - root . data ) ) { Console . Write ( target - root . data + " ▁ " + root . data ) ; pairFound = true ; return ; } else S . Add ( root . data ) ; } pairSum ( root . left , target , S ) ; pairSum ( root . right , target , S ) ; } public static void Main ( String [ ] args ) { Node root = newNode ( 1 ) ; root . left = newNode ( 2 ) ; root . left . left = newNode ( 4 ) ; root . left . right = newNode ( 5 ) ; root . right = newNode ( 3 ) ; root . right . left = newNode ( 6 ) ; root . right . right = newNode ( 7 ) ; root . right . right . right = newNode ( 8 ) ; HashSet < int > S = new HashSet < int > ( ) ; int K = 13 ; pairSum ( root , K , S ) ; if ( pairFound == false ) Console . Write ( " - 1" ) ; } }
Maximum non | C # program for the above approach ; Function to print the maximum rooks and their positions ; Initialize row and col array ; Marking the location of already placed rooks ; Print number of non - attacking rooks that can be placed ; To store the placed rook location ; Print lexographically smallest order ; Driver Code ; Size of board ; Number of rooks already placed ; Position of rooks ; Function call
using System ; class GFG { private static void countRooks ( int n , int k , int [ , ] pos ) { int [ ] row = new int [ n ] ; int [ ] col = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { row [ i ] = 0 ; col [ i ] = 0 ; } for ( int i = 0 ; i < k ; i ++ ) { row [ pos [ i , 0 ] - 1 ] = 1 ; col [ pos [ i , 1 ] - 1 ] = 1 ; } int res = n - k ; Console . WriteLine ( res + " ▁ " ) ; int ri = 0 , ci = 0 ; while ( res -- > 0 ) { while ( row [ ri ] == 1 ) { ri ++ ; } while ( col [ ci ] == 1 ) { ci ++ ; } Console . WriteLine ( ( ri + 1 ) + " ▁ " + ( ci + 1 ) + " ▁ " ) ; ri ++ ; ci ++ ; } } public static void Main ( String [ ] args ) { int N = 4 ; int K = 2 ; int [ , ] pos = { { 1 , 4 } , { 2 , 2 } } ; countRooks ( N , K , pos ) ; } }
Minimum insertions to form a palindrome with permutations allowed | C # program to find minimum number of insertions to make a string palindrome ; Function will return number of characters to be added ; To store string length ; To store number of characters occurring odd number of times ; To store count of each character ; To store occurrence of each character ; To count characters with odd occurrence ; As one character can be odd return res - 1 but if string is already palindrome return 0 ; Driver program
using System ; public class GFG { static int minInsertion ( String str ) { int n = str . Length ; int res = 0 ; int [ ] count = new int [ 26 ] ; for ( int i = 0 ; i < n ; i ++ ) count [ str [ i ] - ' a ' ] ++ ; for ( int i = 0 ; i < 26 ; i ++ ) { if ( count [ i ] % 2 == 1 ) res ++ ; } return ( res == 0 ) ? 0 : res - 1 ; } public static void Main ( ) { string str = " geeksforgeeks " ; Console . WriteLine ( minInsertion ( str ) ) ; } }
Generate a string which differs by only a single character from all given strings | C # program to implement the above approach ; Function to check if a given string differs by a single character from all the strings in an array ; Traverse over the strings ; Stores the count of characters differing from the strings ; If differs by more than one character ; Function to find the string which only differ at one position from the all given strings of the array ; Size of the array ; Length of a string ; Replace i - th character by all possible characters ; Check if it differs by a single character from all other strings ; If desired string is obtained ; Print the answer ; Driver code ; Function call
using System ; class GFG { static bool check ( String ans , String [ ] s , int n , int m ) { for ( int i = 1 ; i < n ; ++ i ) { int count = 0 ; for ( int j = 0 ; j < m ; ++ j ) { if ( ans [ j ] != s [ i ] [ j ] ) count ++ ; } if ( count > 1 ) return false ; } return true ; } static String findString ( String [ ] s ) { int n = s . Length ; String ans = s [ 0 ] ; int m = ans . Length ; int flag = 0 ; for ( int i = 0 ; i < m ; ++ i ) { for ( int j = 0 ; j < 26 ; ++ j ) { String x = ans ; x = x . Replace ( x [ i ] , ( char ) ( j + ' a ' ) ) ; if ( check ( x , s , n , m ) ) { ans = x ; flag = 1 ; break ; } } if ( flag == 1 ) break ; } if ( flag == 0 ) return " - 1" ; else return ans ; } public static void Main ( String [ ] args ) { String [ ] s = { " geeks " , " teeds " } ; Console . WriteLine ( findString ( s ) ) ; } }
Minimum increments of Non | C # Program to implement the above approach ; Function to return to the minimum number of operations required to make the array non - decreasing ; Stores the count of operations ; If arr [ i ] > arr [ i + 1 ] , add arr [ i ] - arr [ i + 1 ] to the answer Otherwise , add 0 ; Driver Code
using System ; class GFG { public static int getMinOps ( int [ ] arr ) { int ans = 0 ; for ( int i = 0 ; i < arr . Length - 1 ; i ++ ) { ans += Math . Max ( arr [ i ] - arr [ i + 1 ] , 0 ) ; } return ans ; } public static void Main ( String [ ] args ) { int [ ] arr = { 1 , 3 , 1 , 2 , 4 } ; Console . WriteLine ( getMinOps ( arr ) ) ; } }
Maximum difference between frequency of two elements such that element having greater frequency is also greater | C # program to find maximum difference between frequency of any two element such that element with greater frequency is also greater in value . ; Return the maximum difference between frequencies of any two elements such that element with greater frequency is also greater in value . ; Finding the frequency of each element . ; finding difference such that element having greater frequency is also greater in value . ; Driver Code
using System ; using System . Collections . Generic ; class GFG { static int maxdiff ( int [ ] arr , int n ) { Dictionary < int , int > freq = new Dictionary < int , int > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( freq . ContainsKey ( arr [ i ] ) ) freq [ arr [ i ] ] ++ ; else freq . Add ( arr [ i ] , 1 ) ; } int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { if ( freq [ arr [ i ] ] > freq [ arr [ j ] ] && arr [ i ] > arr [ j ] ) ans = Math . Max ( ans , freq [ arr [ i ] ] - freq [ arr [ i ] ] ) ; else if ( freq [ arr [ i ] ] < freq [ arr [ j ] ] && arr [ i ] < arr [ j ] ) ans = Math . Max ( ans , freq [ arr [ j ] ] - freq [ arr [ i ] ] ) ; } } return ans ; } public static void Main ( String [ ] args ) { int [ ] arr = { 3 , 1 , 3 , 2 , 3 , 2 } ; int n = arr . Length ; Console . WriteLine ( maxdiff ( arr , n ) ) ; } }
Maximum difference between frequency of two elements such that element having greater frequency is also greater | Efficient C # program to find maximum difference between frequency of any two elements such that element with greater frequency is also greater in value . ; Return the maximum difference between frequencies of any two elements such that element with greater frequency is also greater in value . ; Finding the frequency of each element . ; Sorting the distinct element ; Iterate through all sorted distinct elements . For each distinct element , maintaining the element with minimum frequency than that element and also finding the maximum frequency difference ; Driver code
using System . Collections . Generic ; using System ; class GFG { static int maxdiff ( int [ ] arr , int n ) { Dictionary < int , int > freq = new Dictionary < int , int > ( ) ; List < int > dist = new List < int > ( ) ; int j = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( freq . ContainsKey ( arr [ i ] ) == false ) { dist . Add ( arr [ i ] ) ; j ++ ; } if ( freq . ContainsKey ( arr [ i ] ) ) freq [ arr [ i ] ] ++ ; else freq [ arr [ i ] ] = 1 ; } dist . Sort ( ) ; int min_freq = n + 1 ; int ans = 0 ; for ( int i = 0 ; i < j ; i ++ ) { int cur_freq = freq [ dist [ i ] ] ; ans = Math . Max ( ans , cur_freq - min_freq ) ; min_freq = Math . Min ( min_freq , cur_freq ) ; } return ans ; } public static void Main ( String [ ] args ) { int [ ] arr = { 3 , 1 , 3 , 2 , 3 , 2 } ; int n = arr . Length ; Console . WriteLine ( maxdiff ( arr , n ) ) ; } }
Maximum Sum possible by selecting X elements from a Matrix based on given conditions | C # program to implement the above approach ; Function to calculate the maximum possible sum by selecting X elements from the Matrix ; Generate prefix sum of the matrix ; Initialize [ , ] dp ; Maximum possible sum by selecting 0 elements from the first i rows ; If a single row is present ; If elements from the current row is not selected ; Iterate over all possible selections from current row ; Return maximum possible sum ; Driver Code
using System ; class GFG { static int n , m , X ; public static int maxSum ( int [ , ] grid ) { int [ , ] prefsum = new int [ n , m ] ; for ( int i = 0 ; i < n ; i ++ ) { for ( int x = 0 ; x < m ; x ++ ) { if ( x == 0 ) prefsum [ i , x ] = grid [ i , x ] ; else prefsum [ i , x ] = prefsum [ i , x - 1 ] + grid [ i , x ] ; } } int [ , ] dp = new int [ n , X + 1 ] ; for ( int i = 1 ; i < n ; i ++ ) for ( int j = 1 ; j <= X ; ++ j ) dp [ i , j ] = int . MinValue ; for ( int i = 0 ; i < n ; i ++ ) dp [ i , 0 ] = 0 ; for ( int i = 1 ; i <= Math . Min ( m , X ) ; ++ i ) { dp [ 0 , i ] = dp [ 0 , i - 1 ] + grid [ 0 , i - 1 ] ; } for ( int i = 1 ; i < n ; ++ i ) { for ( int j = 1 ; j <= X ; ++ j ) { dp [ i , j ] = dp [ i - 1 , j ] ; for ( int x = 1 ; x <= Math . Min ( j , m ) ; x ++ ) { dp [ i , j ] = Math . Max ( dp [ i , j ] , dp [ i - 1 , j - x ] + prefsum [ i , x - 1 ] ) ; } } } return dp [ n - 1 , X ] ; } public static void Main ( String [ ] args ) { n = 4 ; m = 4 ; X = 6 ; int [ , ] grid = { { 3 , 2 , 6 , 1 } , { 1 , 9 , 2 , 4 } , { 4 , 1 , 3 , 9 } , { 3 , 8 , 2 , 1 } } ; int ans = maxSum ( grid ) ; Console . WriteLine ( ans ) ; } }
Difference between highest and least frequencies in an array | C # Code for Difference between highest and least frequencies in an array ; sort the array ; checking consecutive elements ; Driver program to test above function
using System ; class GFG { static int findDiff ( int [ ] arr , int n ) { Array . Sort ( arr ) ; int count = 0 , max_count = 0 , min_count = n ; for ( int i = 0 ; i < ( n - 1 ) ; i ++ ) { if ( arr [ i ] == arr [ i + 1 ] ) { count += 1 ; continue ; } else { max_count = Math . Max ( max_count , count ) ; min_count = Math . Min ( min_count , count ) ; count = 0 ; } } return ( max_count - min_count ) ; } public static void Main ( ) { int [ ] arr = { 7 , 8 , 4 , 5 , 4 , 1 , 1 , 7 , 7 , 2 , 5 } ; int n = arr . Length ; Console . WriteLine ( findDiff ( arr , n ) ) ; } }
Minimum Decrements on Subarrays required to reduce all Array elements to zero | C # program to implement the above approach ; Function to count the minimum number of subarrays that are required to be decremented by 1 ; Base Case ; Initializing ans to first element ; For A [ i ] > A [ i - 1 ] , operation ( A [ i ] - A [ i - 1 ] ) is required ; Return the count ; Driver Code
using System ; class GFG { static int min_operations ( int [ ] A , int n ) { if ( n == 0 ) return 0 ; int ans = A [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { if ( A [ i ] > A [ i - 1 ] ) { ans += A [ i ] - A [ i - 1 ] ; } } return ans ; } public static void Main ( ) { int n = 5 ; int [ ] A = { 1 , 2 , 3 , 2 , 1 } ; Console . WriteLine ( min_operations ( A , n ) ) ; } }
Difference between highest and least frequencies in an array | C # code to find the difference between highest and least frequencies ; Put all elements in a hash map ; Find counts of maximum and minimum frequent elements ; Driver code
using System ; using System . Collections . Generic ; class GFG { static int findDiff ( int [ ] arr , int n ) { Dictionary < int , int > mp = new Dictionary < int , int > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( mp . ContainsKey ( arr [ i ] ) ) { var val = mp [ arr [ i ] ] ; mp . Remove ( arr [ i ] ) ; mp . Add ( arr [ i ] , val + 1 ) ; } else { mp . Add ( arr [ i ] , 1 ) ; } } int max_count = 0 , min_count = n ; foreach ( KeyValuePair < int , int > entry in mp ) { max_count = Math . Max ( max_count , entry . Value ) ; min_count = Math . Min ( min_count , entry . Value ) ; } return ( max_count - min_count ) ; } public static void Main ( String [ ] args ) { int [ ] arr = { 7 , 8 , 4 , 5 , 4 , 1 , 1 , 7 , 7 , 2 , 5 } ; int n = arr . Length ; Console . WriteLine ( findDiff ( arr , n ) ) ; } }