codeparrot/xlcost-text-to-code huggingface dataset:
Longest subsequence having maximum sum | C # program to implement the above approach ; Function to find the longest subsequence from the given array with maximum sum ; Stores the largest element of the array ; If Max is less than 0 ; Print the largest element of the array ; Traverse the array ; If arr [ i ] is greater than or equal to 0 ; Print elements of the subsequence ; Driver Code
using System ; class GFG { static void longestSubWithMaxSum ( int [ ] arr , int N ) { int Max = arr [ 0 ] ; for ( int i = 1 ; i < N ; i ++ ) { if ( Max < arr [ i ] ) Max = arr [ i ] ; } if ( Max < 0 ) { Console . Write ( Max ) ; return ; } for ( int i = 0 ; i < N ; i ++ ) { if ( arr [ i ] >= 0 ) { Console . Write ( arr [ i ] + " ▁ " ) ; } } } public static void Main ( String [ ] args ) { int [ ] arr = { 1 , 2 , - 4 , - 2 , 3 , 0 } ; int N = arr . Length ; longestSubWithMaxSum ( arr , N ) ; } }
Print first K distinct Moran numbers from a given array |  ; Function to calculate the sum of digits of a number ; Stores the sum of digits ; Add the digit to sum ; Remove digit ; Returns the sum of digits ; Function to check if a number is prime or not ; If r has any divisor ; Set r as non - prime ; Function to check if a number is moran number ; Calculate sum of digits ; Check if n is divisible by the sum of digits ; Calculate the quotient ; If the quotient is prime ; Function to print the first K Moran numbers from the array ; Sort the given array ; Initialise a set ; Traverse the array from the end ; If the current array element is a Moran number ; Insert into the set ; Driver Code
using System ; using System . Collections ; using System . Collections . Generic ; class GFG { static int digiSum ( int a ) { int sum = 0 ; while ( a != 0 ) { sum += a % 10 ; a = a / 10 ; } return sum ; } static bool isPrime ( int r ) { bool s = true ; for ( int i = 2 ; i * i <= r ; i ++ ) { if ( r % i == 0 ) { s = false ; break ; } } return s ; } static bool isMorannumber ( int n ) { int dup = n ; int sum = digiSum ( dup ) ; if ( n % sum == 0 ) { int c = n / sum ; if ( isPrime ( c ) ) { return true ; } } return false ; } static void FirstKMorannumber ( int [ ] a , int n , int k ) { int X = k ; Array . Sort ( a ) ; SortedSet < int > s = new SortedSet < int > ( ) ; for ( int i = n - 1 ; i >= 0 && k > 0 ; i -- ) { if ( isMorannumber ( a [ i ] ) ) { s . Add ( a [ i ] ) ; k -- ; } } if ( k > 0 ) { Console . WriteLine ( X + " ▁ Moran ▁ numbers ▁ are " + " ▁ not ▁ present ▁ in ▁ the ▁ array " ) ; return ; } foreach ( var val in s ) { Console . Write ( val + " , ▁ " ) ; } Console . Write ( " STRNEWLINE " ) ; } public static void Main ( ) { int [ ] A = { 34 , 198 , 21 , 42 , 63 , 45 , 22 , 44 , 43 } ; int K = 4 ; int N = A . Length ; FirstKMorannumber ( A , N , K ) ; } }
Longest Subsequence from a numeric String divisible by K | C # program for the above approach ; Function to if the integer representation of the current string is divisible by K ; Stores the integer representation of the string ; Check if the num is divisible by K ; Function to find the longest subsequence which is divisible by K ; If the number is divisible by K ; If current number is the maximum obtained so far ; Include the digit at current index ; Exclude the digit at current index ; Driver code ; Printing the largest number which is divisible by K ; If no number is found to be divisible by K
using System ; using System . Text ; class GFG { static bool isdivisible ( StringBuilder newstr , long K ) { long num = 0 ; for ( int i = 0 ; i < newstr . Length ; i ++ ) { num = num * 10 + newstr [ i ] - '0' ; } if ( num % K == 0 ) return true ; else return false ; } static void findLargestNo ( String str , StringBuilder newstr , StringBuilder ans , int index , long K ) { if ( index == str . Length ) { if ( isdivisible ( newstr , K ) ) { if ( ( newstr . ToString ( ) . CompareTo ( ans . ToString ( ) ) > 0 && ans . Length == newstr . Length ) newstr . Length > ans . Length ) { ans . EnsureCapacity ( 0 ) ; ans . Append ( newstr ) ; } } return ; } StringBuilder x = new StringBuilder ( newstr . ToString ( ) + str [ index ] ) ; findLargestNo ( str , x , ans , index + 1 , K ) ; findLargestNo ( str , newstr , ans , index + 1 , K ) ; } public static void Main ( String [ ] args ) { String str = "121400" ; StringBuilder ans = new StringBuilder ( ) , newstr = new StringBuilder ( ) ; long K = 8 ; findLargestNo ( str , newstr , ans , 0 , K ) ; if ( ans . ToString ( ) != " " ) Console . WriteLine ( ans ) ; else Console . WriteLine ( - 1 ) ; } }
Counting Rock Samples | TCS Codevita 2020 | C # program of the above approach ; Function to find the rock samples in the ranges ; Iterate over the ranges ; Driver Code ; Function call
using System . Collections . Generic ; using System ; class GFG { static void findRockSample ( int [ , ] ranges , int n , int r , int [ ] arr ) { List < int > a = new List < int > ( ) ; for ( int i = 0 ; i < r ; i ++ ) { int c = 0 ; int l = ranges [ i , 0 ] ; int h = ranges [ i , 1 ] ; for ( int j = 0 ; j < arr . Length ; j ++ ) { if ( l <= arr [ j ] && arr [ j ] <= h ) c += 1 ; } a . Add ( c ) ; } foreach ( var i in a ) { Console . Write ( i + " ▁ " ) ; } } public static void Main ( ) { int n = 5 ; int r = 2 ; int [ ] arr = { 400 , 567 , 890 , 765 , 987 } ; int [ , ] ranges = { { 300 , 380 } , { 800 , 1000 } } ; findRockSample ( ranges , n , r , arr ) ; } }
Depth of the deepest odd level node in Binary Tree | C # program to find depth of the deepest odd level node ; A Tree node ; Utility function to create a new node ; Utility function which returns whether the current node is a leaf or not ; function to return the longest odd level depth if it exists otherwise 0 ; Base case return from here ; increment current level ; if curr_level is odd and its a leaf node ; A wrapper over deepestOddLevelDepth ( ) ; 10 / \ 28 13 / \ 14 15 / \ 23 24 Let us create Binary Tree shown in above example
using System ; class GfG { class Node { public int key ; public Node left , right ; } static Node newNode ( int key ) { Node temp = new Node ( ) ; temp . key = key ; temp . left = null ; temp . right = null ; return ( temp ) ; } static bool isleaf ( Node curr_node ) { return ( curr_node . left == null && curr_node . right == null ) ; } static int deepestOddLevelDepthUtil ( Node curr_node , int curr_level ) { if ( curr_node == null ) return 0 ; curr_level += 1 ; if ( curr_level % 2 != 0 && isleaf ( curr_node ) ) return curr_level ; return Math . Max ( deepestOddLevelDepthUtil ( curr_node . left , curr_level ) , deepestOddLevelDepthUtil ( curr_node . right , curr_level ) ) ; } static int deepestOddLevelDepth ( Node curr_node ) { return deepestOddLevelDepthUtil ( curr_node , 0 ) ; } public static void Main ( String [ ] args ) { Node root = newNode ( 10 ) ; root . left = newNode ( 28 ) ; root . right = newNode ( 13 ) ; root . right . left = newNode ( 14 ) ; root . right . right = newNode ( 15 ) ; root . right . right . left = newNode ( 23 ) ; root . right . right . right = newNode ( 24 ) ; Console . WriteLine ( deepestOddLevelDepth ( root ) ) ; } }
N digit numbers having difference between the first and last digits as K | C # program for the above approach ; Function to store and check the difference of digits ; Base Case ; Last digit of the number to check the difference from the first digit ; Condition to avoid repeated values ; Update the string pt ; Recursive Call ; Update the string pt ; Recursive Call ; Any number can come in between first and last except the zero ; Recursive Call ; Function to place digit of the number ; When N is 1 and K > 0 , then the single number will be the first and last digit it cannot have difference greater than 0 ; This loop place the digit at the starting ; Recursive Call ; Vector to store results ; Generate all the resultant number ; Print the result ; Driver Code ; Function Call
using System ; using System . Collections ; using System . Collections . Generic ; class GFG { static void findNumbers ( string st , ArrayList result , int prev , int n , int K ) { if ( st . Length == n ) { result . Add ( Int32 . Parse ( st ) ) ; return ; } if ( st . Length == n - 1 ) { if ( prev - K >= 0 ) { string pt = " " ; pt += ( char ) ( prev - K + 48 ) ; findNumbers ( st + pt , result , prev - K , n , K ) ; } if ( K != 0 && prev + K < 10 ) { string pt = " " ; pt += ( char ) ( prev + K + 48 ) ; findNumbers ( st + pt , result , prev + K , n , K ) ; } } else { for ( int j = 1 ; j <= 9 ; j ++ ) { string pt = " " ; pt += ( char ) ( j + 48 ) ; findNumbers ( st + pt , result , prev , n , K ) ; } } } static ArrayList numDifference ( int N , int K ) { ArrayList res = new ArrayList ( ) ; string st = " " ; if ( N == 1 && K == 0 ) { res . Add ( 0 ) ; } else if ( N == 1 && K > 0 ) { return res ; } for ( int i = 1 ; i < 10 ; i ++ ) { string temp = " " ; temp += ( char ) ( 48 + i ) ; findNumbers ( st + temp , res , i , N , K ) ; st = " " ; } return res ; } static void numDifferenceUtil ( int N , int K ) { ArrayList res = new ArrayList ( ) ; res = numDifference ( N , K ) ; for ( int i = 0 ; i < res . Count ; i ++ ) { Console . Write ( res [ i ] + " ▁ " ) ; } } public static void Main ( string [ ] args ) { int N = 2 , K = 9 ; numDifferenceUtil ( N , K ) ; } }
Count array elements that can be maximized by adding any permutation of first N natural numbers | C # program for the above approach ; Function to get the count of values that can have the maximum value ; Sort array in decreasing order ; Stores the answer ; mark stores the maximum value till each index i ; Check if arr [ i ] can be maximum ; Update the mark ; Print the total count ; Driver Code ; Given array arr [ ] ; Function call
using System ; using System . Collections ; using System . Linq ; using System . Collections . Generic ; class GFG { static void countMaximum ( int [ ] a , int n ) { a . OrderByDescending ( c => c ) . ToArray ( ) ; int count = 0 ; int mark = 0 ; for ( int i = 0 ; i < n ; ++ i ) { if ( ( a [ i ] + n >= mark ) ) { count += 1 ; } mark = Math . Max ( mark , a [ i ] + i + 1 ) ; } Console . Write ( count ) ; } public static void Main ( string [ ] args ) { int [ ] arr = { 8 , 9 , 6 } ; int N = arr . Length ; countMaximum ( arr , N ) ; } }
Kth character from the Nth string obtained by the given operations | C # program for the above approach ; String reverse ; Function to return Kth character from recursive String ; If N is 1 then return A ; Iterate a loop and generate the recursive String ; Update current String ; Change A to B and B to A ; Reverse the previous String ; Return the kth character ; Driver Code
using System ; class GFG { static String reverse ( String input ) { char [ ] a = input . ToCharArray ( ) ; int l , r = a . Length - 1 ; for ( l = 0 ; l < r ; l ++ , r -- ) { char temp = a [ l ] ; a [ l ] = a [ r ] ; a [ r ] = temp ; } return String . Join ( " " , a ) ; } static char findKthChar ( int n , int k ) { String prev = " A " ; String cur = " " ; if ( n == 1 ) { return ' A ' ; } for ( int j = 2 ; j <= n ; j ++ ) { cur = prev + " B " ; for ( int i = 0 ; i < prev . Length ; i ++ ) { if ( prev [ i ] == ' A ' ) { prev . Replace ( prev [ i ] , ' B ' ) ; } else { prev . Replace ( prev [ i ] , ' A ' ) ; } } prev = reverse ( prev ) ; cur += prev ; prev = cur ; } return cur [ k ] ; } public static void Main ( String [ ] args ) { int N = 4 ; int K = 3 ; Console . Write ( findKthChar ( N , K ) ) ; } }
Maximize length of subarray of equal elements by performing at most K increment operations | C # Program for the above approach ; Function to find the maximum length of subarray of equal elements after performing at most K increments ; Length of array ; Stores the size of required subarray ; Starting point of a window ; Stores the sum of window ; Iterate over array ; Current element ; Remove index of minimum elements from deque which are less than the current element ; Insert current index in deque ; Update current window sum ; Calculate required operation to make current window elements equal ; If cost is less than k ; Shift window start pointer towards right and update current window sum ; Return answer ; Driver Code ; Function call
using System ; using System . Collections . Generic ; class GFG { static int maxSubarray ( int [ ] a , int k ) { int n = a . Length ; int answer = 0 ; int start = 0 ; long s = 0 ; Queue < int > dq = new Queue < int > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { int x = a [ i ] ; while ( dq . Count != 0 && a [ dq . Peek ( ) ] <= x ) dq . Dequeue ( ) ; dq . Enqueue ( i ) ; s += x ; long cost = ( long ) a [ dq . Peek ( ) ] * ( answer + 1 ) - s ; if ( cost <= ( long ) k ) answer ++ ; else { if ( dq . Peek ( ) == start ) dq . Dequeue ( ) ; s -= a [ start ++ ] ; } } return answer ; } public static void Main ( String [ ] args ) { int [ ] a = { 2 , 2 , 4 } ; int k = 10 ; Console . WriteLine ( maxSubarray ( a , k ) ) ; } }
Find depth of the deepest odd level leaf node | C # program to find depth of deepest odd level node ; A binary tree node ; A recursive function to find depth of the deepest odd level leaf ; Base Case ; If this node is a leaf and its level is odd , return its level ; If not leaf , return the maximum value from left and right subtrees ; Main function which calculates the depth of deepest odd level leaf . This function mainly uses depthOfOddLeafUtil ( ) ; Driver Code
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 root ; public virtual int depthOfOddLeafUtil ( Node node , int level ) { if ( node == null ) { return 0 ; } if ( node . left == null && node . right == null && ( level & 1 ) != 0 ) { return level ; } return Math . Max ( depthOfOddLeafUtil ( node . left , level + 1 ) , depthOfOddLeafUtil ( node . right , level + 1 ) ) ; } public virtual int depthOfOddLeaf ( Node node ) { int level = 1 , depth = 0 ; return depthOfOddLeafUtil ( node , level ) ; } public static void Main ( string [ ] args ) { int k = 45 ; BinaryTree tree = new BinaryTree ( ) ; tree . root = new Node ( 1 ) ; tree . root . left = new Node ( 2 ) ; tree . root . right = new Node ( 3 ) ; tree . root . left . left = new Node ( 4 ) ; tree . root . right . left = new Node ( 5 ) ; tree . root . right . right = new Node ( 6 ) ; tree . root . right . left . right = new Node ( 7 ) ; tree . root . right . right . right = new Node ( 8 ) ; tree . root . right . left . right . left = new Node ( 9 ) ; tree . root . right . right . right . right = new Node ( 10 ) ; tree . root . right . right . right . right . left = new Node ( 11 ) ; Console . WriteLine ( tree . depthOfOddLeaf ( tree . root ) + " ▁ is ▁ the ▁ required ▁ depth " ) ; } }
Check if an array can be split into subarrays with GCD exceeding K | C # program for the above approach ; Function to check if it is possible to split an array into subarrays having GCD at least K ; Iterate over the array [ ] arr ; If the current element is less than or equal to k ; If no array element is found to be less than or equal to k ; Driver code ; Given array [ ] arr ; Length of the array ; Given K ; Function call
using System ; class GFG { static String canSplitArray ( int [ ] arr , int n , int k ) { for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] <= k ) { return " No " ; } } return " Yes " ; } public static void Main ( String [ ] args ) { int [ ] arr = { 2 , 4 , 6 , 1 , 8 , 16 } ; int N = arr . Length ; int K = 3 ; Console . WriteLine ( canSplitArray ( arr , N , K ) ) ; } }
Smallest subarray from a given Array with sum greater than or equal to K | Set 2 | C # program for the above approach ; Function to find the smallest subarray sum greater than or equal to target ; Base Case ; If sum of the array is less than target ; If target is equal to the sum of the array ; Required condition ; Driver code
using System ; using System . Collections . Generic ; class GFG { static int smallSumSubset ( List < int > data , int target , int maxVal ) { int sum = 0 ; foreach ( int i in data ) sum += i ; if ( target <= 0 ) return 0 ; else if ( sum < target ) return maxVal ; else if ( sum == target ) return data . Count ; else if ( data [ 0 ] >= target ) return 1 ; else if ( data [ 0 ] < target ) { List < int > temp = new List < int > ( ) ; for ( int i = 1 ; i < data . Count ; i ++ ) temp . Add ( data [ i ] ) ; return Math . Min ( smallSumSubset ( temp , target , maxVal ) , 1 + smallSumSubset ( temp , target - data [ 0 ] , maxVal ) ) ; } return 0 ; } static void Main ( ) { List < int > data = new List < int > ( ) ; data . Add ( 3 ) ; data . Add ( 1 ) ; data . Add ( 7 ) ; data . Add ( 1 ) ; data . Add ( 2 ) ; int target = 11 ; int val = smallSumSubset ( data , target , data . Count + 1 ) ; if ( val > data . Count ) Console . Write ( - 1 ) ; else Console . Write ( val ) ; } }
Maximize cost obtained by removal of substrings " pr " or " rp " from a given String | C # program to implement the above approach ; Function to maintain the case , X >= Y ; To maintain X >= Y ; Replace ' p ' to ' r ' ; Replace ' r ' to ' p ' . ; Function to return the maximum cost ; Stores the length of the String ; To maintain X >= Y . ; Stores the maximum cost ; Stores the count of ' p ' after removal of all " pr " subStrings up to str [ i ] ; Stores the count of ' r ' after removal of all " pr " subStrings up to str [ i ] ; Stack to maintain the order of characters after removal of subStrings ; If subString " pr " is removed ; Increase cost by X ; If any subString " rp " left in the Stack ; If any subString " rp " left in the Stack ; Driver Code
using System ; class GFG { static bool swapXandY ( char [ ] str , int X , int Y ) { int N = str . Length ; X = X + Y ; Y = X - Y ; X = X - Y ; for ( int i = 0 ; i < N ; i ++ ) { if ( str [ i ] == ' p ' ) { str [ i ] = ' r ' ; } else if ( str [ i ] == ' r ' ) { str [ i ] = ' p ' ; } } return true ; } static int maxCost ( String str , int X , int Y ) { int N = str . Length ; if ( Y > X ) { swapXandY ( str . ToCharArray ( ) , X , Y ) ; } int res = 0 ; int countP = 0 ; int countR = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( str [ i ] == ' p ' ) { countP ++ ; } else if ( str [ i ] == ' r ' ) { if ( countP > 0 ) { countP -- ; res += X ; } else countR ++ ; } else { res += Math . Min ( countP , countR ) * Y ; countP = 0 ; countR = 0 ; } } res += Math . Min ( countP , countR ) * Y ; return res ; } public static void Main ( String [ ] args ) { String str = " abppprrr " ; int X = 5 , Y = 4 ; Console . Write ( maxCost ( str , X , Y ) ) ; } }
Check if an array contains only one distinct element | C # program for the above approach ; Function to find if the array contains only one distinct element ; Assume first element to be the unique element ; Traversing the array ; If current element is not equal to X then break the loop and print No ; Compare and print the result ; Driver code ; Function call
using System ; class GFG { public static void uniqueElement ( int [ ] arr ) { int x = arr [ 0 ] ; int flag = 1 ; for ( int i = 0 ; i < arr . Length ; i ++ ) { if ( arr [ i ] != x ) { flag = 0 ; break ; } } if ( flag == 1 ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } static public void Main ( ) { int [ ] arr = { 9 , 9 , 9 , 9 , 9 , 9 , 9 } ; uniqueElement ( arr ) ; } }
Maximum Count of pairs having equal Sum based on the given conditions | C # program to implement the above approach ; Function to find the maximum count of pairs having equal sum ; Size of the array ; Iterate through evey sum of pairs possible from the given array ; Count of pairs with given sum ; Check for a possible pair ; Update count of possible pair ; Update the answer by taking the pair which is maximum for every possible sum ; Return the max possible pair ; Function to return the count of pairs ; Size of the array ; Stores the frequencies ; Count the frequency ; Driver Code
using System ; class GFG { static int maxCount ( int [ ] freq ) { int n = freq . Length - 1 ; int ans = 0 ; for ( int sum = 2 ; sum <= 2 * n ; ++ sum ) { int possiblePair = 0 ; for ( int firElement = 1 ; firElement < ( sum + 1 ) / 2 ; firElement ++ ) { if ( sum - firElement <= n ) { possiblePair += Math . Min ( freq [ firElement ] , freq [ sum - firElement ] ) ; } } if ( sum % 2 == 0 ) { possiblePair += freq [ sum / 2 ] / 2 ; } ans = Math . Max ( ans , possiblePair ) ; } return ans ; } static int countofPairs ( int [ ] a ) { int n = a . Length ; int [ ] freq = new int [ n + 1 ] ; for ( int i = 0 ; i < n ; ++ i ) freq [ a [ i ] ] ++ ; return maxCount ( freq ) ; } public static void Main ( String [ ] args ) { int [ ] a = { 1 , 2 , 4 , 3 , 3 , 5 , 6 } ; Console . Write ( countofPairs ( a ) + " STRNEWLINE " ) ; } }
Maximum Subarray Sum possible by replacing an Array element by its Square | C # program to implement the above approach ; Function to find the maximum subarray sum possible ; Stores sum without squaring ; Stores sum squaring ; Stores the maximum subarray sum ; Either extend the subarray or start a new subarray ; Either extend previous squared subarray or start a new subarray by squaring the current element ; Update maximum subarray sum ; Return answer ; Driver Code ; Function call
using System ; class GFG { public static int getMaxSum ( int [ ] a , int n ) { int [ , ] dp = new int [ n , 2 ] ; dp [ 0 , 0 ] = a [ 0 ] ; dp [ 0 , 1 ] = a [ 0 ] * a [ 0 ] ; int max_sum = Math . Max ( dp [ 0 , 0 ] , dp [ 0 , 1 ] ) ; for ( int i = 1 ; i < n ; i ++ ) { dp [ i , 0 ] = Math . Max ( a [ i ] , dp [ i - 1 , 0 ] + a [ i ] ) ; dp [ i , 1 ] = Math . Max ( dp [ i - 1 , 1 ] + a [ i ] , a [ i ] * a [ i ] ) ; dp [ i , 1 ] = Math . Max ( dp [ i , 1 ] , dp [ i - 1 , 0 ] + a [ i ] * a [ i ] ) ; max_sum = Math . Max ( max_sum , dp [ i , 1 ] ) ; max_sum = Math . Max ( max_sum , dp [ i , 0 ] ) ; } return max_sum ; } public static void Main ( String [ ] args ) { int n = 5 ; int [ ] a = { 1 , - 5 , 8 , 12 , - 8 } ; Console . WriteLine ( getMaxSum ( a , n ) ) ; } }
Smallest Subarray with Sum K from an Array | C # Program to implement the above approach ; Function to find the length of the smallest subarray with sum K ; Stores the frequency of prefix sums in the array ; Initialize len as int . MaxValue ; If sum of array till i - th index is less than K ; No possible subarray exists till i - th index ; Find the exceeded value ; If exceeded value is zero ; Driver Code
using System ; using System . Collections . Generic ; class GFG { static int subArraylen ( int [ ] arr , int n , int K ) { Dictionary < int , int > mp = new Dictionary < int , int > ( ) ; mp . Add ( arr [ 0 ] , 0 ) ; for ( int i = 1 ; i < n ; i ++ ) { arr [ i ] = arr [ i ] + arr [ i - 1 ] ; mp . Add ( arr [ i ] , i ) ; } int len = int . MaxValue ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] < K ) continue ; else { int x = K - arr [ i ] ; if ( x == 0 ) len = Math . Min ( len , i ) ; if ( mp . ContainsValue ( x ) ) continue ; else { len = Math . Min ( len , i ) ; } } } return len ; } public static void Main ( String [ ] args ) { int [ ] arr = { 1 , 2 , 4 , 3 , 2 , 4 , 1 } ; int n = arr . Length ; int K = 7 ; int len = subArraylen ( arr , n , K ) ; if ( len == int . MaxValue ) { Console . Write ( " - 1" ) ; } else { Console . Write ( len + " STRNEWLINE " ) ; } } }