codeparrot/xlcost-text-to-code huggingface dataset:
Count composite fibonacci numbers from given array | C # program to implement the above approach ; Function to find all Fibonacci numbers up to Max ; Store all Fibonacci numbers upto Max ; Stores previous element of Fibonacci sequence ; Stores previous element of Fibonacci sequence ; Insert prev into hashmap ; Insert all the Fibonacci numbers up to Max ; Insert curr into hashmap ; Stores curr into temp ; Update curr ; Update prev ; Function to find all Composite numbers up to Max ; isPrime [ i ] : Stores if i is a prime number or not ; Calculate all prime numbers up to Max using Sieve of Eratosthenes ; If P is a prime number ; Set all multiple of P as non - prime ; Update isPrime ; Function to find the numbers which is both a composite and Fibonacci number ; Stores the largest element of the array ; Traverse the array [ ] arr ; Update Max ; isPrim [ i ] check i is a prime number or not ; Stores all the Fibonacci numbers ; Traverse the array [ ] arr ; current element is not a composite number ; If current element is a Fibonacci and composite number ; Print current element ; Driver Code
using System ; using System . Collections . Generic ; class GFG { static bool [ ] isPrime ; static HashSet < int > createhashmap ( int Max ) { HashSet < int > hashmap = new HashSet < int > ( ) ; int curr = 1 ; int prev = 0 ; hashmap . Add ( prev ) ; while ( curr < Max ) { hashmap . Add ( curr ) ; int temp = curr ; curr = curr + prev ; prev = temp ; } return hashmap ; } static void SieveOfEratosthenes ( int Max ) { isPrime = new bool [ Max ] ; for ( int i = 0 ; i < Max ; i ++ ) isPrime [ i ] = true ; isPrime [ 0 ] = false ; isPrime [ 1 ] = false ; for ( int p = 2 ; p * p <= Max ; p ++ ) { if ( isPrime [ p ] ) { for ( int i = p * p ; i <= Max ; i += p ) { isPrime [ i ] = false ; } } } } static void cntFibonacciPrime ( int [ ] arr , int N ) { int Max = arr [ 0 ] ; for ( int i = 1 ; i < N ; i ++ ) { Max = Math . Max ( Max , arr [ i ] ) ; } SieveOfEratosthenes ( Max ) ; HashSet < int > hashmap = createhashmap ( Max ) ; for ( int i = 0 ; i < N ; i ++ ) { if ( arr [ i ] == 1 ) continue ; if ( ( hashmap . Contains ( arr [ i ] ) ) && ! isPrime [ arr [ i ] ] ) { Console . Write ( arr [ i ] + " ▁ " ) ; } } } public static void Main ( String [ ] args ) { int [ ] arr = { 13 , 55 , 7 , 3 , 5 , 21 , 233 , 144 , 89 } ; int N = arr . Length ; cntFibonacciPrime ( arr , N ) ; } }
Reduce a given number to form a key by the given operations | C # program of the above approach ; Function to find the key of the given number ; Convert the integer to String ; Iterate the num - string to get the result ; Check if digit is even or odd ; Iterate until odd sum is obtained by adding consecutive digits ; Check if sum becomes odd ; Add the result in ans ; Assign the digit index to num string ; If the number is odd ; Iterate until odd sum is obtained by adding consecutive digits ; Check if sum becomes even ; Add the result in ans ; assign the digit index to main numstring ; Check if all digits are visited or not ; Driver Code
using System ; class GFG { static int key ( int N ) { String num = " " + N ; int ans = 0 ; int j = 0 ; for ( j = 0 ; j < num . Length ; j ++ ) { if ( ( num [ j ] - 48 ) % 2 == 0 ) { int add = 0 ; int i ; for ( i = j ; j < num . Length ; j ++ ) { add += num [ j ] - 48 ; if ( add % 2 == 1 ) break ; } if ( add == 0 ) { ans *= 10 ; } else { int digit = ( int ) Math . Floor ( Math . Log10 ( add ) + 1 ) ; ans *= ( int ) ( Math . Pow ( 10 , digit ) ) ; ans += add ; } i = j ; } else { int add = 0 ; int i ; for ( i = j ; j < num . Length ; j ++ ) { add += num [ j ] - 48 ; if ( add % 2 == 0 ) { break ; } } if ( add == 0 ) { ans *= 10 ; } else { int digit = ( int ) Math . Floor ( Math . Log10 ( add ) + 1 ) ; ans *= ( int ) ( Math . Pow ( 10 , digit ) ) ; ans += add ; } i = j ; } } if ( j + 1 >= num . Length ) { return ans ; } else { return ans += num [ num . Length - 1 ] - 48 ; } } public static void Main ( String [ ] args ) { int N = 1667848271 ; Console . Write ( key ( N ) ) ; } }
Sentinel Linear Search | C # implementation of the approach ; Function to search x in the given array ; Last element of the array ; Element to be searched is placed at the last index ; Put the last element back ; Driver code
using System ; class GFG { static void sentinelSearch ( int [ ] arr , int n , int key ) { int last = arr [ n - 1 ] ; arr [ n - 1 ] = key ; int i = 0 ; while ( arr [ i ] != key ) i ++ ; arr [ n - 1 ] = last ; if ( ( i < n - 1 ) || ( arr [ n - 1 ] == key ) ) Console . WriteLine ( key + " ▁ is ▁ present " + " ▁ at ▁ index ▁ " + i ) ; else Console . WriteLine ( " Element ▁ Not ▁ found " ) ; } public static void Main ( ) { int [ ] arr = { 10 , 20 , 180 , 30 , 60 , 50 , 110 , 100 , 70 } ; int n = arr . Length ; int key = 180 ; sentinelSearch ( arr , n , key ) ; } }
Maximum possible middle element of the array after deleting exactly k elements | C # implementation of the approach ; Function to calculate maximum possible middle value of the array after deleting exactly k elements ; Initialize answer as - 1 ; Calculate range of elements that can give maximum possible middle value of the array since index of maximum possible middle value after deleting exactly k elements from array will lie in between low and high ; Find maximum element of the array in range low and high ; since indexing is 1 based so check element at index i - 1 ; Return the maximum possible middle value of the array after deleting exactly k elements from the array ; Driver Code
using System ; class GFG { static int maximum_middle_value ( int n , int k , int [ ] arr ) { int ans = - 1 ; int low = ( n + 1 - k ) / 2 ; int high = ( n + 1 - k ) / 2 + k ; for ( int i = low ; i <= high ; i ++ ) { ans = Math . Max ( ans , arr [ i - 1 ] ) ; } return ans ; } static public void Main ( ) { int n = 5 , k = 2 ; int [ ] arr = { 9 , 5 , 3 , 7 , 10 } ; Console . WriteLine ( maximum_middle_value ( n , k , arr ) ) ; n = 9 ; k = 3 ; int [ ] arr1 = { 2 , 4 , 3 , 9 , 5 , 8 , 7 , 6 , 10 } ; Console . WriteLine ( maximum_middle_value ( n , k , arr1 ) ) ; } }
Ternary Search | CSharp program to illustrate recursive approach to ternary search ; Function to perform Ternary Search ; Find the mid1 and mid2 ; Check if key is present at any mid ; Since key is not present at mid , check in which region it is present then repeat the Search operation in that region ; The key lies in between l and mid1 ; The key lies in between mid2 and r ; The key lies in between mid1 and mid2 ; Key not found ; Driver code ; Get the array Sort the array if not sorted ; Starting index ; length of array ; Key to be searched in the array ; Search the key using ternarySearch ; Print the result ; Key to be searched in the array ; Search the key using ternarySearch ; Print the result
using System ; class GFG { static int ternarySearch ( int l , int r , int key , int [ ] ar ) { if ( r >= l ) { int mid1 = l + ( r - l ) / 3 ; int mid2 = r - ( r - l ) / 3 ; if ( ar [ mid1 ] == key ) { return mid1 ; } if ( ar [ mid2 ] == key ) { return mid2 ; } if ( key < ar [ mid1 ] ) { return ternarySearch ( l , mid1 - 1 , key , ar ) ; } else if ( key > ar [ mid2 ] ) { return ternarySearch ( mid2 + 1 , r , key , ar ) ; } else { return ternarySearch ( mid1 + 1 , mid2 - 1 , key , ar ) ; } } return - 1 ; } public static void Main ( ) { int l , r , p , key ; int [ ] ar = { 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 } ; l = 0 ; r = 9 ; key = 5 ; p = ternarySearch ( l , r , key , ar ) ; Console . WriteLine ( " Index ▁ of ▁ " + key + " ▁ is ▁ " + p ) ; key = 50 ; p = ternarySearch ( l , r , key , ar ) ; Console . WriteLine ( " Index ▁ of ▁ " + key + " ▁ is ▁ " + p ) ; } }
Minimum number of points to be removed to get remaining points on one side of axis | C # program to find minimum points to be moved so that all points are on same side . ; Structure to store the coordinates of a point . ; Function to find the minimum number of points ; Number of points on the left of Y - axis . ; Number of points on the right of Y - axis . ; Number of points above X - axis . ; Number of points below X - axis . ; Driver Code
using System ; class GFG { public class Point { public int x , y ; public Point ( int x , int y ) { this . x = x ; this . y = y ; } } ; static int findmin ( Point [ ] p , int n ) { int a = 0 , b = 0 , c = 0 , d = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( p [ i ] . x <= 0 ) a ++ ; else if ( p [ i ] . x >= 0 ) b ++ ; if ( p [ i ] . y >= 0 ) c ++ ; else if ( p [ i ] . y <= 0 ) d ++ ; } return Math . Min ( Math . Min ( a , b ) , Math . Min ( c , d ) ) ; } public static void Main ( String [ ] args ) { Point [ ] p = { new Point ( 1 , 1 ) , new Point ( 2 , 2 ) , new Point ( - 1 , - 1 ) , new Point ( - 2 , 2 ) } ; int n = p . Length ; Console . WriteLine ( findmin ( p , n ) ) ; } }
Maximum number of pair reductions possible on a given triplet | C # program for the above approach ; Function to count the maximum number of pair reductions possible on a given triplet ; Convert them into an array ; Stores count of operations ; Sort the array ; If the first two array elements reduce to 0 ; Apply the operations ; Increment count ; Print the maximum count ; Driver Code ; Given triplet
using System ; class GFG { static void maxOps ( int a , int b , int c ) { int [ ] arr = { a , b , c } ; int count = 0 ; while ( 1 != 0 ) { Array . Sort ( arr ) ; if ( arr [ 0 ] == 0 && arr [ 1 ] == 0 ) break ; arr [ 1 ] -= 1 ; arr [ 2 ] -= 1 ; count += 1 ; } Console . WriteLine ( count ) ; } public static void Main ( String [ ] args ) { int a = 4 , b = 3 , c = 2 ; maxOps ( a , b , c ) ; } }
Case | C # implementation of the approach ; Function to return the sorted string ; To store the frequencies of the lowercase and the uppercase characters in the given string ; If current character is lowercase then increment its frequency in the lower [ ] array ; Else increment in the upper [ ] array ; Pointers that point to the smallest lowercase and the smallest uppercase characters respectively in the given string ; For every character in the given string ; If the current character is lowercase then replace it with the smallest lowercase character available ; Decrement the frequency of the used character ; Else replace it with the smallest uppercase character available ; Decrement the frequency of the used character ; Return the sorted string ; Driver code
using System ; class GFG { static int MAX = 26 ; static string getSortedString ( char [ ] s , int n ) { int [ ] lower = new int [ MAX ] ; int [ ] upper = new int [ MAX ] ; int i = 0 , j = 0 ; for ( i = 0 ; i < n ; i ++ ) { if ( char . IsLower ( s [ i ] ) ) lower [ s [ i ] - ' a ' ] ++ ; else if ( char . IsUpper ( s [ i ] ) ) upper [ s [ i ] - ' A ' ] ++ ; } i = 0 ; while ( i < MAX && lower [ i ] == 0 ) i ++ ; while ( j < MAX && upper [ j ] == 0 ) j ++ ; for ( int k = 0 ; k < n ; k ++ ) { if ( char . IsLower ( s [ k ] ) ) { while ( lower [ i ] == 0 ) i ++ ; s [ k ] = ( char ) ( i + ' a ' ) ; lower [ i ] -- ; } else if ( char . IsUpper ( s [ k ] ) ) { while ( upper [ j ] == 0 ) j ++ ; s [ k ] = ( char ) ( j + ' A ' ) ; upper [ j ] -- ; } } return String . Join ( " " , s ) ; } public static void Main ( String [ ] args ) { String s = " gEeksfOrgEEkS " ; int n = s . Length ; Console . WriteLine ( getSortedString ( s . ToCharArray ( ) , n ) ) ; } }
Print characters and their frequencies in order of occurrence | C # implementation to print the character and its frequency in order of its occurrence ; function to print the character and its frequency in order of its occurrence ; size of the string ' str ' ; ' freq [ ] ' implemented as hash table ; accumulate frequency of each character in ' str ' ; traverse ' str ' from left to right ; if frequency of character str . charAt ( i ) is not equal to 0 ; print the character along with its frequency ; update frequency of str . charAt ( i ) to 0 so that the same character is not printed again ; Driver program to test above
using System ; class GFG { static int SIZE = 26 ; static void printCharWithFreq ( String str ) { int n = str . Length ; int [ ] freq = new int [ SIZE ] ; for ( int i = 0 ; i < n ; i ++ ) freq [ str [ i ] - ' a ' ] ++ ; for ( int i = 0 ; i < n ; i ++ ) { if ( freq [ str [ i ] - ' a ' ] != 0 ) { Console . Write ( str [ i ] ) ; Console . Write ( freq [ str [ i ] - ' a ' ] + " ▁ " ) ; freq [ str [ i ] - ' a ' ] = 0 ; } } } public static void Main ( ) { String str = " geeksforgeeks " ; printCharWithFreq ( str ) ; } }
Reverse words in a given string | C # program to reverse a string s = input ( )
using System ; public class ReverseWords { public static void Main ( ) { string [ ] s = " i ▁ like ▁ this ▁ program ▁ very ▁ much " . Split ( ' ▁ ' ) ; string ans = " " ; for ( int i = s . Length - 1 ; i >= 0 ; i -- ) { ans += s [ i ] + " ▁ " ; } Console . Write ( " Reversed ▁ String : STRNEWLINE " ) ; Console . Write ( ans . Substring ( 0 , ans . Length - 1 ) ) ; } }
Segregate Prime and Non | C # program for the above approach ; Function to generate prime numbers using Sieve of Eratosthenes ; If prime [ p ] is unchanged , then it is a prime ; Update all multiples of p ; Function to segregate the primes and non - primes ; Generate all primes till 10 ^ ; Initialize left and right ; Traverse the array ; Increment left while array element at left is prime ; Decrement right while array element at right is non - prime ; If left < right , then swap arr [ left ] and arr [ right ] ; Swap arr [ left ] and arr [ right ] ; Print segregated array ; Driver code ; Function Call
using System ; class GFG { public static void SieveOfEratosthenes ( bool [ ] prime , int n ) { for ( int p = 2 ; p * p <= n ; p ++ ) { if ( prime [ p ] == true ) { for ( int i = p * p ; i <= n ; i += p ) prime [ i ] = false ; } } } public static void segregatePrimeNonPrime ( bool [ ] prime , int [ ] arr , int N ) { SieveOfEratosthenes ( prime , 10000000 ) ; int left = 0 , right = N - 1 ; while ( left < right ) { while ( prime [ arr [ left ] ] ) left ++ ; while ( ! prime [ arr [ right ] ] ) right -- ; if ( left < right ) { int temp = arr [ left ] ; arr [ left ] = arr [ right ] ; arr [ right ] = temp ; left ++ ; right -- ; } } for ( int i = 0 ; i < N ; i ++ ) Console . Write ( arr [ i ] + " ▁ " ) ; } public static void Main ( String [ ] args ) { bool [ ] prime = new bool [ 10000001 ] ; for ( int i = 0 ; i < prime . Length ; i ++ ) prime [ i ] = true ; int [ ] arr = { 2 , 3 , 4 , 6 , 7 , 8 , 9 , 10 } ; int N = arr . Length ; segregatePrimeNonPrime ( prime , arr , N ) ; } }
Calculate depth of a full Binary tree from Preorder | C # program to find height of full binary tree using preorder ; function to return max of left subtree height or right subtree height ; calc height of left subtree ( In preorder left subtree is processed before right ) ; calc height of right subtree ; Wrapper over findDepthRec ( ) ; Driver program
using System ; class GFG { static int findDepthRec ( char [ ] tree , int n , int index ) { if ( index >= n tree [ index ] == ' l ' ) return 0 ; index ++ ; int left = findDepthRec ( tree , n , index ) ; index ++ ; int right = findDepthRec ( tree , n , index ) ; return Math . Max ( left , right ) + 1 ; } static int findDepth ( char [ ] tree , int n ) { int index = 0 ; return ( findDepthRec ( tree , n , index ) ) ; } static public void Main ( ) { char [ ] tree = " nlnnlll " . ToCharArray ( ) ; int n = tree . Length ; Console . WriteLine ( findDepth ( tree , n ) ) ; } }
Largest number in BST which is less than or equal to N | C # code to find the largest value smaller than or equal to N ; Node structure ; To create new BST Node ; To insert a new node in BST ; if tree is empty return new node ; if key is less then or greater then node value then recur down the tree ; return the ( unchanged ) node pointer ; function to find max value less then N ; Base cases ; If root 's value is smaller,  try in right subtree ; If root 's key is greater, return  value from left subtree. ; Driver code ; creating following BST 5 / \ 2 12 / \ / \ 1 3 9 21 / \ 19 25
using System ; class GFG { class Node { public int key ; public Node left , right ; } static Node newNode ( int item ) { Node temp = new Node ( ) ; temp . key = item ; temp . left = null ; temp . right = null ; return temp ; } static 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 ; } static int findMaxforN ( Node root , int N ) { if ( root == null ) return - 1 ; if ( root . key == N ) return N ; else if ( root . key < N ) { int k = findMaxforN ( root . right , N ) ; if ( k == - 1 ) return root . key ; else return k ; } else if ( root . key > N ) return findMaxforN ( root . left , N ) ; return - 1 ; } public static void Main ( String [ ] args ) { int N = 4 ; Node root = null ; root = insert ( root , 25 ) ; insert ( root , 2 ) ; insert ( root , 1 ) ; insert ( root , 3 ) ; insert ( root , 12 ) ; insert ( root , 9 ) ; insert ( root , 21 ) ; insert ( root , 19 ) ; insert ( root , 25 ) ; Console . WriteLine ( findMaxforN ( root , N ) ) ; } }
Maximum element between two nodes of BST | C # program to find maximum element in the path between two Nodes of Binary Search Tree . ; Create and return a pointer of new Node . ; Insert a new Node in Binary Search Tree . ; Return the maximum element between a Node and its given ancestor . ; Traversing the path between ansector and Node and finding maximum element . ; Return maximum element in the path between two given Node of BST . ; Finding the LCA of Node x and Node y ; Checking if both the Node lie on the left side of the parent p . ; Checking if both the Node lie on the right side of the parent p . ; Return the maximum of maximum elements occur in path from ancestor to both Node . ; Driver Code ; Creating the root of Binary Search Tree ; Inserting Nodes in Binary Search Tree
public class Solution { public class Node { public Node left , right ; public int data ; } public static Node createNode ( int x ) { Node p = new Node ( ) ; p . data = x ; p . left = p . right = null ; return p ; } public static void insertNode ( Node root , int x ) { Node p = root , q = null ; while ( p != null ) { q = p ; if ( p . data < x ) { p = p . right ; } else { p = p . left ; } } if ( q == null ) { p = createNode ( x ) ; } else { if ( q . data < x ) { q . right = createNode ( x ) ; } else { q . left = createNode ( x ) ; } } } public static int maxelpath ( Node q , int x ) { Node p = q ; int mx = - 1 ; while ( p . data != x ) { if ( p . data > x ) { mx = Math . Max ( mx , p . data ) ; p = p . left ; } else { mx = Math . Max ( mx , p . data ) ; p = p . right ; } } return Math . Max ( mx , x ) ; } public static int maximumElement ( Node root , int x , int y ) { Node p = root ; while ( ( x < p . data && y < p . data ) || ( x > p . data && y > p . data ) ) { if ( x < p . data && y < p . data ) { p = p . left ; } else if ( x > p . data && y > p . data ) { p = p . right ; } } return Math . Max ( maxelpath ( p , x ) , maxelpath ( p , y ) ) ; } public static void Main ( string [ ] args ) { int [ ] arr = new int [ ] { 18 , 36 , 9 , 6 , 12 , 10 , 1 , 8 } ; int a = 1 , b = 10 ; int n = arr . Length ; Node root = createNode ( arr [ 0 ] ) ; for ( int i = 1 ; i < n ; i ++ ) { insertNode ( root , arr [ i ] ) ; } Console . WriteLine ( maximumElement ( root , a , b ) ) ; } }
Threaded Binary Tree | Insertion | C # program Insertion in Threaded Binary Search Tree . ; True if left pointer points to predecessor in Inorder Traversal ; True if right pointer points to successor in Inorder Traversal ; Insert a Node in Binary Threaded Tree ; Searching for a Node with given value ; Parent of key to be inserted ; If key already exists , return ; Update parent pointer ; Moving on left subtree . ; Moving on right subtree . ; Create a new node ; Returns inorder successor using rthread ; If rthread is set , we can quickly find ; Else return leftmost child of right subtree ; Printing the threaded tree ; Reach leftmost node ; One by one print successors ; Driver Program
public class solution { public class Node { public Node left , right ; public int info ; public bool lthread ; public bool rthread ; } public static Node insert ( Node root , int ikey ) { Node ptr = root ; Node par = null ; while ( ptr != null ) { if ( ikey == ( ptr . info ) ) { Console . Write ( " Duplicate ▁ Key ▁ ! STRNEWLINE " ) ; return root ; } par = ptr ; if ( ikey < ptr . info ) { if ( ptr . lthread == false ) { ptr = ptr . left ; } else { break ; } } else { if ( ptr . rthread == false ) { ptr = ptr . right ; } else { break ; } } } Node tmp = new Node ( ) ; tmp . info = ikey ; tmp . lthread = true ; tmp . rthread = true ; if ( par == null ) { root = tmp ; tmp . left = null ; tmp . right = null ; } else if ( ikey < ( par . info ) ) { tmp . left = par . left ; tmp . right = par ; par . lthread = false ; par . left = tmp ; } else { tmp . left = par ; tmp . right = par . right ; par . rthread = false ; par . right = tmp ; } return root ; } public static Node inorderSuccessor ( Node ptr ) { if ( ptr . rthread == true ) { return ptr . right ; } ptr = ptr . right ; while ( ptr . lthread == false ) { ptr = ptr . left ; } return ptr ; } public static void inorder ( Node root ) { if ( root == null ) { Console . Write ( " Tree ▁ is ▁ empty " ) ; } Node ptr = root ; while ( ptr . lthread == false ) { ptr = ptr . left ; } while ( ptr != null ) { Console . Write ( " { 0 : D } ▁ " , ptr . info ) ; ptr = inorderSuccessor ( ptr ) ; } } public static void Main ( string [ ] args ) { Node root = null ; root = insert ( root , 20 ) ; root = insert ( root , 10 ) ; root = insert ( root , 30 ) ; root = insert ( root , 5 ) ; root = insert ( root , 16 ) ; root = insert ( root , 14 ) ; root = insert ( root , 17 ) ; root = insert ( root , 13 ) ; inorder ( root ) ; } }
Threaded Binary Search Tree | Deletion |  ; True if left pointer points to predecessor in Inorder Traversal ; True if right pointer points to predecessor in Inorder Traversal
public class Node { public Node left , right ; public int info ; public bool lthread ; public bool rthread ; } ;
Check horizontal and vertical symmetry in binary matrix | C # program to find if a matrix is symmetric . ; Initializing as both horizontal and vertical symmetric . ; Checking for Horizontal Symmetry . We compare first row with last row , second row with second last row and so on . ; Checking each cell of a column . ; check if every cell is identical ; Checking for Vertical Symmetry . We compare first column with last column , second xolumn with second last column and so on . ; Checking each cell of a row . ; check if every cell is identical ; Driver Code
using System ; public class GFG { static void checkHV ( int [ , ] arr , int N , int M ) { bool horizontal = true ; bool vertical = true ; for ( int i = 0 , k = N - 1 ; i < N / 2 ; i ++ , k -- ) { for ( int j = 0 ; j < M ; j ++ ) { if ( arr [ i , j ] != arr [ k , j ] ) { horizontal = false ; break ; } } } for ( int i = 0 , k = M - 1 ; i < M / 2 ; i ++ , k -- ) { for ( int j = 0 ; j < N ; j ++ ) { if ( arr [ i , j ] != arr [ k , j ] ) { horizontal = false ; break ; } } } if ( ! horizontal && ! vertical ) Console . WriteLine ( " NO " ) ; else if ( horizontal && ! vertical ) Console . WriteLine ( " HORIZONTAL " ) ; else if ( vertical && ! horizontal ) Console . WriteLine ( " VERTICAL " ) ; else Console . WriteLine ( " BOTH " ) ; } static public void Main ( ) { int [ , ] mat = { { 1 , 0 , 1 } , { 0 , 0 , 0 } , { 1 , 0 , 1 } } ; checkHV ( mat , 3 , 3 ) ; } }