codeparrot/xlcost-text-to-code huggingface dataset:
Print string of odd length in ' X ' format | C # program to print the given pattern ; Function to print the given string in respective pattern ; Print characters at corresponding places satisfying the two conditions ; Print blank space at rest of places ; Driver code
using System ; public class GFG { static void printPattern ( string str , int len ) { for ( int i = 0 ; i < len ; i ++ ) { for ( int j = 0 ; j < len ; j ++ ) { if ( ( i == j ) || ( i + j == len - 1 ) ) Console . Write ( str [ j ] ) ; else Console . Write ( " ▁ " ) ; } Console . WriteLine ( ) ; } } static public void Main ( ) { String str = " geeksforgeeks " ; int len = str . Length ; printPattern ( str , len ) ; } }
Find the longest substring with k unique characters in a given string | C # program to find the longest substring with k unique characters in a given string ; This function calculates number of unique characters using a associative array count [ ] . Returns true if no . of characters are less than required else returns false . ; Return true if k is greater than or equal to val ; Finds the maximum substring with exactly k unique chars ; Associative array to store the count of characters ; Traverse the string , Fills the associative array count [ ] and count number of unique characters ; If there are not enough unique characters , show an error message . ; Otherwise take a window with first element in it . start and end variables . ; Also initialize values for result longest window ; Initialize associative array count [ ] with zero ; put the first character ; Start from the second character and add characters in window according to above explanation ; Add the character ' s [ i ] ' to current window ; If there are more than k unique characters in current window , remove from left side ; Update the max window size if required ; Driver code
using System ; public class GFG { static int MAX_CHARS = 26 ; static bool isValid ( int [ ] count , int k ) { int val = 0 ; for ( int i = 0 ; i < MAX_CHARS ; i ++ ) { if ( count [ i ] > 0 ) { val ++ ; } } return ( k >= val ) ; } static void kUniques ( string s , int k ) { int u = 0 ; int n = s . Length ; int [ ] count = new int [ MAX_CHARS ] ; Array . Fill ( count , 0 ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( count [ s [ i ] - ' a ' ] == 0 ) { u ++ ; } count [ s [ i ] - ' a ' ] ++ ; } if ( u < k ) { Console . Write ( " Not ▁ enough ▁ unique ▁ characters " ) ; return ; } int curr_start = 0 , curr_end = 0 ; int max_window_size = 1 ; int max_window_start = 0 ; Array . Fill ( count , 0 ) ; count [ s [ 0 ] - ' a ' ] ++ ; for ( int i = 1 ; i < n ; i ++ ) { count [ s [ i ] - ' a ' ] ++ ; curr_end ++ ; while ( ! isValid ( count , k ) ) { count [ s [ curr_start ] - ' a ' ] -- ; curr_start ++ ; } if ( curr_end - curr_start + 1 > max_window_size ) { max_window_size = curr_end - curr_start + 1 ; max_window_start = curr_start ; } } Console . WriteLine ( " Max ▁ substring ▁ is ▁ : ▁ " + s . Substring ( max_window_start , max_window_size ) + " ▁ with ▁ length ▁ " + max_window_size ) ; } static public void Main ( ) { string s = " aabacbebebe " ; int k = 3 ; kUniques ( s , k ) ; } }
Function to find Number of customers who could not get a computer | C # program to find number of customers who couldn 't get a resource. ; n is number of computers in cafe . ' seq ' is given sequence of customer entry , exit events ; seen [ i ] = 0 , indicates that customer ' i ' is not in cafe seen [ 1 ] = 1 , indicates that customer ' i ' is in cafe but computer is not assigned yet . seen [ 2 ] = 2 , indicates that customer ' i ' is in cafe and has occupied a computer . ; Initialize result which is number of customers who could not get any computer . ; To keep track of occupied computers ; Traverse the input sequence ; Find index of current character in seen [ 0. . .25 ] ; If First occurrence of ' seq [ i ] ' ; set the current character as seen ; If number of occupied computers is less than n , then assign a computer to new customer ; Set the current character as occupying a computer ; Else this customer cannot get a computer , increment result ; If this is second occurrence of ' seq [ i ] ' ; Decrement occupied only if this customer was using a computer ; Driver Code
using System ; class GFG { static int MAX_CHAR = 26 ; static int runCustomerSimulation ( int n , char [ ] seq ) { char [ ] seen = new char [ MAX_CHAR ] ; int res = 0 ; int occupied = 0 ; for ( int i = 0 ; i < seq . Length ; i ++ ) { int ind = seq [ i ] - ' A ' ; if ( seen [ ind ] == 0 ) { seen [ ind ] = ( char ) 1 ; if ( occupied < n ) { occupied ++ ; seen [ ind ] = ( char ) 2 ; } else res ++ ; } else { if ( seen [ ind ] == 2 ) occupied -- ; seen [ ind ] = ( char ) 0 ; } } return res ; } public static void Main ( String [ ] args ) { Console . WriteLine ( runCustomerSimulation ( 2 , " ABBAJJKZKZ " . ToCharArray ( ) ) ) ; Console . WriteLine ( runCustomerSimulation ( 3 , " GACCBDDBAGEE " . ToCharArray ( ) ) ) ; Console . WriteLine ( runCustomerSimulation ( 3 , " GACCBGDDBAEE " . ToCharArray ( ) ) ) ; Console . WriteLine ( runCustomerSimulation ( 1 , " ABCBCA " . ToCharArray ( ) ) ) ; Console . WriteLine ( runCustomerSimulation ( 1 , " ABCBCADEED " . ToCharArray ( ) ) ) ; } }
Check if characters of a given string can be rearranged to form a palindrome | C # Implementation of the above approach ; bitvector to store the record of which character appear odd and even number of times ; Driver Code
using System ; public class GFG { static bool canFormPalindrome ( string a ) { int bitvector = 0 , mask = 0 ; for ( int i = 0 ; i < a . Length ; i ++ ) { int x = a [ i ] - ' a ' ; mask = 1 << x ; bitvector = bitvector ^ mask ; } return ( bitvector & ( bitvector - 1 ) ) == 0 ; } static public void Main ( ) { if ( canFormPalindrome ( " geeksforgeeks " ) ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }
Print all pairs of anagrams in a given array of strings | C # program to Print all pairs of anagrams in a given array of strings ; function to check whether two strings are anagram of each other ; Create two count arrays and initialize all values as 0 ; For each character in input strings , increment count in the corresponding count array ; If both strings are of different length . Removing this condition will make the program fail for strings like " aaca " and " aca " ; See if there is any non - zero value in count array ; This function prints all anagram pairs in a given array of strings ; Driver program to test to pront printDups
using System ; class GFG { static int NO_OF_CHARS = 256 ; static bool areAnagram ( String str1 , String str2 ) { int [ ] count = new int [ NO_OF_CHARS ] ; int i ; for ( i = 0 ; i < str1 . Length && i < str2 . Length ; i ++ ) { count [ str1 [ i ] ] ++ ; count [ str2 [ i ] ] -- ; } if ( str1 . Length != str2 . Length ) return false ; for ( i = 0 ; i < NO_OF_CHARS ; i ++ ) if ( count [ i ] != 0 ) return false ; return true ; } static void findAllAnagrams ( String [ ] arr , int n ) { for ( int i = 0 ; i < n ; i ++ ) for ( int j = i + 1 ; j < n ; j ++ ) if ( areAnagram ( arr [ i ] , arr [ j ] ) ) Console . WriteLine ( arr [ i ] + " ▁ is ▁ anagram ▁ of ▁ " + arr [ j ] ) ; } public static void Main ( ) { String [ ] arr = { " geeksquiz " , " geeksforgeeks " , " abcd " , " forgeeksgeeks " , " zuiqkeegs " } ; int n = arr . Length ; findAllAnagrams ( arr , n ) ; } }
Program to print all palindromes in a given range | C # Program to print all palindromes in a given range ; A function to check if n is palindrome ; Find reverse of n ; If n and rev are same , then n is palindrome ; prints palindrome between min and max ; Driver Code
using System ; class GFG { public static int isPalindrome ( int n ) { int rev = 0 ; for ( int i = n ; i > 0 ; i /= 10 ) { rev = rev * 10 + i % 10 ; } return ( n == rev ) ? 1 : 0 ; } public static void countPal ( int min , int max ) { for ( int i = min ; i <= max ; i ++ ) { if ( isPalindrome ( i ) == 1 ) { Console . Write ( i + " ▁ " ) ; } } } public static void Main ( string [ ] args ) { countPal ( 100 , 2000 ) ; } }
Length of the longest substring without repeating characters | C # program to find the length of the longest substring without repeating characters ; Result ; Note : Default values in visited are false ; If current character is visited Break the loop ; Else update the result if this window is larger , and mark current character as visited . ; Remove the first character of previous window ; Driver code
using System ; class GFG { static int longestUniqueSubsttr ( string str ) { int n = str . Length ; int res = 0 ; for ( int i = 0 ; i < n ; i ++ ) { bool [ ] visited = new bool [ 256 ] ; for ( int j = i ; j < n ; j ++ ) { if ( visited [ str [ j ] ] == true ) break ; else { res = Math . Max ( res , j - i + 1 ) ; visited [ str [ j ] ] = true ; } } visited [ str [ i ] ] = false ; } return res ; } static void Main ( ) { string str = " geeksforgeeks " ; Console . WriteLine ( " The ▁ input ▁ string ▁ is ▁ " + str ) ; int len = longestUniqueSubsttr ( str ) ; Console . WriteLine ( " The ▁ length ▁ of ▁ the ▁ longest ▁ " + " non - repeating ▁ character ▁ " + " substring ▁ is ▁ " + len ) ; } }
Length of the longest substring without repeating characters | Creating a set to store the last positions of occurrence ; starting the initial point of window to index 0 ; Checking if we have already seen the element or not ; If we have seen the number , move the start pointer to position after the last occurrence ; Updating the last seen value of the character ; Driver code
using System ; using System . Collections . Generic ; class GFG { static int longestUniqueSubsttr ( string s ) { Dictionary < char , int > seen = new Dictionary < char , int > ( ) ; int maximum_length = 0 ; int start = 0 ; for ( int end = 0 ; end < s . Length ; end ++ ) { if ( seen . ContainsKey ( s [ end ] ) ) { start = Math . Max ( start , seen [ s [ end ] ] + 1 ) ; } seen [ s [ end ] ] = end ; maximum_length = Math . Max ( maximum_length , end - start + 1 ) ; } return maximum_length ; } static void Main ( ) { string s = " geeksforgeeks " ; Console . WriteLine ( " The ▁ input ▁ string ▁ is ▁ " + s ) ; int length = longestUniqueSubsttr ( s ) ; Console . WriteLine ( " The ▁ length ▁ of ▁ the ▁ longest ▁ non - repeating ▁ character ▁ substring ▁ is ▁ " + length ) ; } }
Find the smallest window in a string containing all characters of another string | Function ; Answer Length of ans ; Starting index of ans ; Creating map ; References of Window ; Traversing the window ; Calculations ; Condition matching ; Sorting ans ; Sliding I Calculation for removing I ; Driver code
using System ; class GFG { static String Minimum_Window ( char [ ] s , char [ ] t ) { int [ ] m = new int [ 256 ] ; int ans = int . MaxValue ; int start = 0 ; int count = 0 , i = 0 ; for ( i = 0 ; i < t . Length ; i ++ ) { if ( m [ t [ i ] ] == 0 ) count ++ ; m [ t [ i ] ] ++ ; } i = 0 ; int j = 0 ; while ( j < s . Length ) { m [ s [ j ] ] -- ; if ( m [ s [ j ] ] == 0 ) count -- ; if ( count == 0 ) { while ( count == 0 ) { if ( ans > j - i + 1 ) { ans = Math . Min ( ans , j - i + 1 ) ; start = i ; } m [ s [ i ] ] ++ ; if ( m [ s [ i ] ] > 0 ) count ++ ; i ++ ; } } j ++ ; } if ( ans != int . MaxValue ) return String . Join ( " " , s ) . Substring ( start , ans ) ; else return " - 1" ; } public static void Main ( String [ ] args ) { String s = " ADOBECODEBANC " ; String t = " ABC " ; Console . Write ( " - - > Smallest ▁ window ▁ that ▁ contain ▁ all ▁ character ▁ : ▁ " ) ; Console . Write ( Minimum_Window ( s . ToCharArray ( ) , t . ToCharArray ( ) ) ) ; } }
Run Length Encoding | C # program to implement run length encoding ; Count occurrences of current character ; Print character and its count ; Driver code
using System ; class GFG { public class RunLength_Encoding { public static void printRLE ( String str ) { int n = str . Length ; for ( int i = 0 ; i < n ; i ++ ) { int count = 1 ; while ( i < n - 1 && str [ i ] == str [ i + 1 ] ) { count ++ ; i ++ ; } Console . Write ( str [ i ] ) ; Console . Write ( count ) ; } } public static void Main ( String [ ] args ) { String str = " wwwwaaadexxxxxxywww " ; printRLE ( str ) ; } } }
Print list items containing all characters of a given word | C # program to print all strings that contain all characters of a word ; Prints list items having all characters of word ; Since calloc is used , map [ ] is initialized as 0 ; Set the values in map ; Get the length ( ) of given word ; Check each item of list if has all characters of word ; unset the bit so that strings like sss not printed ; Set the values in map for next item ; Driver code
using System ; class GFG { static int NO_OF_CHARS = 256 ; static void print ( string [ ] list , string word , int list_size ) { int [ ] map = new int [ NO_OF_CHARS ] ; int i , j , count , word_size ; for ( i = 0 ; i < word . Length ; i ++ ) map [ word [ i ] ] = 1 ; word_size = word . Length ; for ( i = 0 ; i < list_size ; i ++ ) { for ( j = 0 , count = 0 ; j < list [ i ] . Length ; j ++ ) { if ( map [ list [ i ] [ j ] ] > 0 ) { count ++ ; map [ list [ i ] [ j ] ] = 0 ; } } if ( count == word_size ) Console . WriteLine ( list [ i ] ) ; for ( j = 0 ; j < word . Length ; j ++ ) map [ word [ j ] ] = 1 ; } } public static void Main ( string [ ] args ) { string str = " sun " ; string [ ] list = { " geeksforgeeks " , " unsorted " , " sunday " , " just " , " sss " } ; print ( list , str , 5 ) ; } }
Given a string , find its first non | C # program to find first non - repeating character ; calculate count of characters in the passed string ; The method returns index of first non - repeating character in a string . If all characters are repeating then returns - 1 ; Driver code
using System ; using System . Globalization ; class GFG { static int NO_OF_CHARS = 256 ; static char [ ] count = new char [ NO_OF_CHARS ] ; static void getCharCountArray ( string str ) { for ( int i = 0 ; i < str . Length ; i ++ ) count [ str [ i ] ] ++ ; } static int firstNonRepeating ( string str ) { getCharCountArray ( str ) ; int index = - 1 , i ; for ( i = 0 ; i < str . Length ; i ++ ) { if ( count [ str [ i ] ] == 1 ) { index = i ; break ; } } return index ; } public static void Main ( ) { string str = " geeksforgeeks " ; int index = firstNonRepeating ( str ) ; Console . WriteLine ( index == - 1 ? " Either ▁ " + " all ▁ characters ▁ are ▁ repeating ▁ or ▁ string ▁ " + " is ▁ empty " : " First ▁ non - repeating ▁ character " + " ▁ is ▁ " + str [ index ] ) ; } }
Divide a string in N equal parts | C # program to divide a string in n equal parts ; Method to print n equal parts of str ; Check if string can be divided in n equal parts ; Calculate the size of parts to find the division points ; Driver Code ; length od string is 28 ; Print 4 equal parts of the string
using System ; class GFG { static void divideString ( String str , int n ) { int str_size = str . Length ; int part_size ; if ( str_size % n != 0 ) { Console . Write ( " Invalid ▁ Input : ▁ String ▁ size " + " is ▁ not ▁ divisible ▁ by ▁ n " ) ; return ; } part_size = str_size / n ; for ( int i = 0 ; i < str_size ; i ++ ) { if ( i % part_size == 0 ) Console . WriteLine ( ) ; Console . Write ( str [ i ] ) ; } } static void Main ( ) { String str = " a _ simple _ divide _ string _ quest " ; divideString ( str , 4 ) ; } }
Boggle ( Find all possible words in a board of characters ) | Set 1 | C # program for Boggle game ; Let the given dictionary be following ; A given function to check if a given string is present in dictionary . The implementation is naive for simplicity . As per the question dictionary is given to us . ; Linearly search all words ; A recursive function to print all words present on boggle ; Mark current cell as visited and append current character to str ; If str is present in dictionary , then print it ; Traverse 8 adjacent cells of boggle [ i , j ] ; Erase current character from string and mark visited of current cell as false ; Prints all words present in dictionary . ; Mark all characters as not visited ; Initialize current string ; Consider every character and look for all words starting with this character ; Driver Code
using System ; using System . Collections . Generic ; class GFG { static readonly String [ ] dictionary = { " GEEKS " , " FOR " , " QUIZ " , " GUQ " , " EE " } ; static readonly int n = dictionary . Length ; static readonly int M = 3 , N = 3 ; static bool isWord ( String str ) { for ( int i = 0 ; i < n ; i ++ ) if ( str . Equals ( dictionary [ i ] ) ) return true ; return false ; } static void findWordsUtil ( char [ , ] boggle , bool [ , ] visited , int i , int j , String str ) { visited [ i , j ] = true ; str = str + boggle [ i , j ] ; if ( isWord ( str ) ) Console . WriteLine ( str ) ; for ( int row = i - 1 ; row <= i + 1 && row < M ; row ++ ) for ( int col = j - 1 ; col <= j + 1 && col < N ; col ++ ) if ( row >= 0 && col >= 0 && ! visited [ row , col ] ) findWordsUtil ( boggle , visited , row , col , str ) ; str = " " + str [ str . Length - 1 ] ; visited [ i , j ] = false ; } static void findWords ( char [ , ] boggle ) { bool [ , ] visited = new bool [ M , N ] ; String str = " " ; for ( int i = 0 ; i < M ; i ++ ) for ( int j = 0 ; j < N ; j ++ ) findWordsUtil ( boggle , visited , i , j , str ) ; } public static void Main ( String [ ] args ) { char [ , ] boggle = { { ' G ' , ' I ' , ' Z ' } , { ' U ' , ' E ' , ' K ' } , { ' Q ' , ' S ' , ' E ' } } ; Console . WriteLine ( " Following ▁ words ▁ of ▁ " + " dictionary ▁ are ▁ present " ) ; findWords ( boggle ) ; } }
Remove all subtrees consisting only of even valued nodes from a Binary Tree | C # program for the above approach ; Node of the tree ; Function to create a new node ; Function to print tree level wise ; Base Case ; Create an empty queue for level order traversal ; Enqueue Root ; Print front of queue and remove it from queue ; If left child is present ; Otherwise ; If right child is present ; Otherwise ; Function to remove subtrees ; Base Case ; Search for required condition in left and right half ; If the node is even and leaf node ; Driver Code ; Function Call ; Print answer
using System ; using System . Collections . Generic ; public class GFG { class node { public int data ; public node left , right ; } ; static node newNode ( int key ) { node temp = new node ( ) ; temp . data = key ; temp . left = temp . right = null ; return ( temp ) ; } static void printLevelOrder ( node root ) { if ( root == null ) return ; Queue < node > q = new Queue < node > ( ) ; q . Enqueue ( root ) ; while ( q . Count != 0 ) { node temp = q . Peek ( ) ; Console . Write ( temp . data + " ▁ " ) ; q . Dequeue ( ) ; if ( temp . left != null ) { q . Enqueue ( temp . left ) ; } else if ( temp . right != null ) { Console . Write ( " null ▁ " ) ; } if ( temp . right != null ) { q . Enqueue ( temp . right ) ; } else if ( temp . left != null ) { Console . Write ( " null ▁ " ) ; } } } static node pruneTree ( node root ) { if ( root == null ) { return null ; } root . left = pruneTree ( root . left ) ; root . right = pruneTree ( root . right ) ; if ( root . data % 2 == 0 && root . right == null && root . left == null ) return null ; return root ; } public static void Main ( String [ ] args ) { node root = newNode ( 1 ) ; root . left = newNode ( 2 ) ; root . left . left = newNode ( 8 ) ; root . left . right = newNode ( 10 ) ; root . right = newNode ( 7 ) ; root . right . left = newNode ( 12 ) ; root . right . right = newNode ( 5 ) ; node newRoot = pruneTree ( root ) ; printLevelOrder ( newRoot ) ; } }
Count total ways to reach destination from source in an undirected Graph | C # program to count total number of ways to reach destination in a graph ; Utility Function to count total ways ; Base condition When reach to the destination ; Make vertex visited ; Recursive function , for count ways ; Backtracking Make vertex unvisited ; Return total ways ; Function to count total ways to reach destination ; Loop to make all vertex unvisited , Initially ; Make source visited ; Print total ways
using System ; class GFG { static int countWays ( int [ , ] mtrx , int vrtx , int i , int dest , bool [ ] visited ) { if ( i == dest ) { return 1 ; } int total = 0 ; for ( int j = 0 ; j < vrtx ; j ++ ) { if ( mtrx [ i , j ] == 1 && ! visited [ j ] ) { visited [ j ] = true ; total += countWays ( mtrx , vrtx , j , dest , visited ) ; visited [ j ] = false ; } } return total ; } static int totalWays ( int [ , ] mtrx , int vrtx , int src , int dest ) { bool [ ] visited = new bool [ vrtx ] ; for ( int i = 0 ; i < vrtx ; i ++ ) { visited [ i ] = false ; } visited [ src ] = true ; return countWays ( mtrx , vrtx , src , dest , visited ) ; } public static void Main ( ) { int vrtx = 11 ; int [ , ] mtrx = { { 0 , 1 , 0 , 0 , 0 , 0 , 1 , 0 , 0 , 0 , 0 } , { 1 , 0 , 1 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 } , { 0 , 1 , 0 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 } , { 0 , 1 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 } , { 0 , 0 , 0 , 0 , 0 , 1 , 0 , 0 , 0 , 1 , 0 } , { 0 , 0 , 0 , 0 , 1 , 0 , 1 , 0 , 0 , 1 , 0 } , { 1 , 0 , 0 , 0 , 0 , 1 , 0 , 1 , 0 , 0 , 0 } , { 0 , 0 , 0 , 0 , 0 , 0 , 1 , 0 , 1 , 0 , 0 } , { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 , 0 , 1 , 0 } , { 0 , 0 , 0 , 0 , 1 , 1 , 0 , 0 , 1 , 0 , 0 } , { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 , 0 } } ; int src = 3 ; int dest = 9 ; Console . Write ( totalWays ( mtrx , vrtx , src - 1 , dest - 1 ) ) ; } }
Print path from given Source to Destination in 2 | C # program for printing a path from given source to destination ; Function to print the path ; Base condition ; Pop stores elements ; Recursive call for printing stack In reverse order ; Function to store the path into The stack , if path exist ; Base condition ; Push current elements ; Condition to check whether reach to the Destination or not ; Increment ' x ' ordinate of source by ( 2 * x + y ) Keeping ' y ' constant ; Increment ' y ' ordinate of source by ( 2 * y + x ) Keeping ' x ' constant ; Pop current elements form stack ; If no path exists ; Utility function to check whether path exist or not ; To store x co - ordinate ; To store y co - ordinate ; Function to find the path ; Print - 1 , if path doesn 't exist ; Driver code ; Function call
using System ; using System . Collections . Generic ; class GFG { static void printExistPath ( Stack < int > sx , Stack < int > sy , int last ) { if ( sx . Count == 0 sy . Count == 0 ) { return ; } int x = sx . Peek ( ) ; int y = sy . Peek ( ) ; sx . Pop ( ) ; sy . Pop ( ) ; printExistPath ( sx , sy , last ) ; if ( sx . Count == last - 1 ) { Console . Write ( " ( " + x + " , ▁ " + y + " ) " ) ; } else { Console . Write ( " ( " + x + " , ▁ " + y + " ) - > " ) ; } } static bool storePath ( int srcX , int srcY , int destX , int destY , Stack < int > sx , Stack < int > sy ) { if ( srcX > destX srcY > destY ) { return false ; } sx . Push ( srcX ) ; sy . Push ( srcY ) ; if ( srcX == destX && srcY == destY ) { printExistPath ( sx , sy , sx . Count ) ; return true ; } if ( storePath ( ( 2 * srcX ) + srcY , srcY , destX , destY , sx , sy ) ) { return true ; } if ( storePath ( srcX , ( 2 * srcY ) + srcX , destX , destY , sx , sy ) ) { return true ; } sx . Pop ( ) ; sy . Pop ( ) ; return false ; } static bool isPathExist ( int srcX , int srcY , int destX , int destY ) { Stack < int > sx = new Stack < int > ( ) ; Stack < int > sy = new Stack < int > ( ) ; return storePath ( srcX , srcY , destX , destY , sx , sy ) ; } static void printPath ( int srcX , int srcY , int destX , int destY ) { if ( ! isPathExist ( srcX , srcY , destX , destY ) ) { Console . Write ( " - 1" ) ; } } public static void Main ( String [ ] args ) { int srcX = 5 , srcY = 8 ; int destX = 83 , destY = 21 ; printPath ( srcX , srcY , destX , destY ) ; } }