codeparrot/xlcost-text-to-code huggingface dataset:
Area of the Largest Triangle inscribed in a Hexagon | C # Program to find the biggest triangle which can be inscribed within the hexagon ; Function to find the area of the triangle ; side cannot be negative ; area of the triangle ; Driver code
using System ; class GFG { static double trianglearea ( double a ) { if ( a < 0 ) return - 1 ; double area = ( 3 * Math . Sqrt ( 3 ) * Math . Pow ( a , 2 ) ) / 4 ; return Math . Round ( area , 4 ) ; } public static void Main ( ) { double a = 6 ; Console . WriteLine ( trianglearea ( a ) ) ; } }
Equation of ellipse from its focus , directrix , and eccentricity | C # program to find equation of an ellipse using focus and directrix . ; Function to find equation of ellipse . ; Driver Code
class solution { static void equation_ellipse ( float x1 , float y1 , float a , float b , float c , float e ) { float t = a * a + b * b ; float a1 = t - e * ( a * a ) ; float b1 = t - e * ( b * b ) ; float c1 = ( - 2 * t * x1 ) - ( 2 * e * c * a ) ; float d1 = ( - 2 * t * y1 ) - ( 2 * e * c * b ) ; float e1 = - 2 * e * a * b ; float f1 = ( - e * c * c ) + ( t * x1 * x1 ) + ( t * y1 * y1 ) ; System . Console . WriteLine ( " Equation ▁ of ▁ ellipse ▁ is ▁ " ) ; System . Console . WriteLine ( a1 + " ▁ x ^ 2 ▁ + ▁ " + b1 + " ▁ y ^ 2 ▁ + ▁ " + c1 + " ▁ x ▁ + ▁ " + d1 + " ▁ y ▁ + ▁ " + e1 + " ▁ xy ▁ + ▁ " + f1 + " ▁ = ▁ 0" ) ; } public static void Main ( ) { float x1 = 1 , y1 = 1 , a = 1 , b = - 1 , c = 3 , e = ( float ) 0.5 * ( float ) 0.5 ; equation_ellipse ( x1 , y1 , a , b , c , e ) ; } }
Create loops of even and odd values in a binary tree | C # implementation to create odd and even loops in a binary tree ; structure of a node ; Utility function to create a new node ; preorder traversal to place the node pointer in the respective even_ptrs or odd_ptrs list ; place node ptr in even_ptrs list if node contains even number ; else place node ptr in odd_ptrs list ; function to create the even and odd loops ; forming even loop ; for the last element ; Similarly forming odd loop ; traversing the loop from any random node in the loop ; Driver code ; Binary tree formation ; traversing odd loop from any random odd node ; traversing even loop from any random even node
using System ; using System . Collections . Generic ; class GFG { public class Node { public int data ; public Node left , right , abtr ; } ; static Node newNode ( int data ) { Node node = new Node ( ) ; node . data = data ; node . left = node . right = node . abtr = null ; return node ; } static List < Node > even_ptrs = new List < Node > ( ) ; static List < Node > odd_ptrs = new List < Node > ( ) ; static void preorderTraversal ( Node root ) { if ( root == null ) return ; if ( root . data % 2 == 0 ) ( even_ptrs ) . Add ( root ) ; else ( odd_ptrs ) . Add ( root ) ; preorderTraversal ( root . left ) ; preorderTraversal ( root . right ) ; } static void createLoops ( Node root ) { preorderTraversal ( root ) ; int i ; for ( i = 1 ; i < even_ptrs . Count ; i ++ ) even_ptrs [ i - 1 ] . abtr = even_ptrs [ i ] ; even_ptrs [ i - 1 ] . abtr = even_ptrs [ 0 ] ; for ( i = 1 ; i < odd_ptrs . Count ; i ++ ) odd_ptrs [ i - 1 ] . abtr = odd_ptrs [ i ] ; odd_ptrs [ i - 1 ] . abtr = odd_ptrs [ 0 ] ; } static void traverseLoop ( Node start ) { Node curr = start ; do { Console . Write ( curr . data + " ▁ " ) ; curr = curr . abtr ; } while ( curr != start ) ; } public static void Main ( String [ ] args ) { Node root = null ; root = newNode ( 1 ) ; root . left = newNode ( 2 ) ; root . right = newNode ( 3 ) ; root . left . left = newNode ( 4 ) ; root . left . right = newNode ( 5 ) ; root . right . left = newNode ( 6 ) ; root . right . right = newNode ( 7 ) ; createLoops ( root ) ; Console . Write ( " Odd ▁ nodes : ▁ " ) ; traverseLoop ( root . right ) ; Console . Write ( " STRNEWLINE Even ▁ nodes : ▁ " ) ; traverseLoop ( root . left ) ; } }
Area of circle which is inscribed in equilateral triangle | C # program to find the area of circle which is inscribed in equilateral triangle ; Function return the area of circle inscribed in equilateral triangle ; Driver code
using System ; class GFG { static double PI = 3.14 ; static double circle_inscribed ( int a ) { return PI * ( a * a ) / 12 ; } public static void Main ( ) { int a = 4 ; Console . WriteLine ( circle_inscribed ( a ) ) ; } }
Program to find the Volume of an irregular tetrahedron | C # implementation of above approach ; Function to find the volume ; Steps to calculate volume of a Tetrahedron using formula ; Driver code ; edge lengths
using System ; class GFG { static void findVolume ( double u , double v , double w , double U , double V , double W , double b ) { double uPow = Math . Pow ( u , 2 ) ; double vPow = Math . Pow ( v , 2 ) ; double wPow = Math . Pow ( w , 2 ) ; double UPow = Math . Pow ( U , 2 ) ; double VPow = Math . Pow ( V , 2 ) ; double WPow = Math . Pow ( W , 2 ) ; double a = 4 * ( uPow * vPow * wPow ) - uPow * Math . Pow ( ( vPow + wPow - UPow ) , 2 ) - vPow * Math . Pow ( ( wPow + uPow - VPow ) , 2 ) - wPow * Math . Pow ( ( uPow + vPow - WPow ) , 2 ) + ( vPow + wPow - UPow ) * ( wPow + uPow - VPow ) * ( uPow + vPow - WPow ) ; double vol = Math . Sqrt ( a ) ; vol /= b ; Console . Write ( System . Math . Round ( vol , 4 ) ) ; } public static void Main ( ) { double u = 1000 , v = 1000 , w = 1000 ; double U = 3 , V = 4 , W = 5 ; double b = 12 ; findVolume ( u , v , w , U , V , W , b ) ; } }
Check if it is possible to create a polygon with a given angle | C # implementation of above approach ; Function to check whether it is possible to make a regular polygon with a given angle . ; N denotes the number of sides of polygons possible ; Driver code ; function to print the required answer
using System ; class GFG { static void makePolygon ( double a ) { double n = 360 / ( 180 - a ) ; if ( n == ( int ) n ) Console . WriteLine ( " YES " ) ; else Console . WriteLine ( " NO " ) ; } static void Main ( ) { double a = 90 ; makePolygon ( a ) ; } }
Finding Quadrant of a Coordinate with respect to a Circle | C # Program to find the quadrant of a given coordinate with respect to the centre of a circle ; Thus function returns the quadrant number ; Coincides with center ; Outside circle ; 1 st quadrant ; 2 nd quadrant ; 3 rd quadrant ; 4 th quadrant ; Driver Code ; Coordinates of centre ; Radius of circle ; Coordinates of the given point
using System ; class GFG { static int getQuadrant ( int X , int Y , int R , int PX , int PY ) { if ( PX == X && PY == Y ) return 0 ; int val = ( int ) Math . Pow ( ( PX - X ) , 2 ) + ( int ) Math . Pow ( ( PY - Y ) , 2 ) ; if ( val > Math . Pow ( R , 2 ) ) return - 1 ; if ( PX > X && PY >= Y ) return 1 ; if ( PX <= X && PY > Y ) return 2 ; if ( PX < X && PY <= Y ) return 3 ; if ( PX >= X && PY < Y ) return 4 ; return 0 ; } public static void Main ( ) { int X = 0 , Y = 3 ; int R = 2 ; int PX = 1 , PY = 4 ; int ans = getQuadrant ( X , Y , R , PX , PY ) ; if ( ans == - 1 ) Console . WriteLine ( " Lies ▁ Outside " + " ▁ the ▁ circle " ) ; else if ( ans == 0 ) Console . WriteLine ( " Coincides ▁ " + " with ▁ centre " ) ; else Console . WriteLine ( ans + " ▁ Quadrant " ) ; } }
Hexadecagonal number | C # program to find Nth hexadecagon number ; Function to calculate hexadecagonal number ; Drivers Code
using System ; class GFG { static long hexadecagonalNum ( long n ) { return ( ( 14 * n * n ) - 12 * n ) / 2 ; } public static void Main ( ) { long n = 5 ; Console . WriteLine ( n + " th ▁ " + " Hexadecagonal ▁ number ▁ : ▁ " + hexadecagonalNum ( n ) ) ; n = 9 ; Console . WriteLine ( n + " th ▁ " + " Hexadecagonal ▁ number ▁ : ▁ " + hexadecagonalNum ( n ) ) ; } }
Find first non matching leaves in two binary trees | C # program to find first leaves that are not same . ; Tree node ; Utility method to create a new node ; Prints the first non - matching leaf node in two trees if it exists , else prints nothing . ; If any of the tree is empty ; Create two stacks for preorder traversals ; If traversal of one tree is over and other tree still has nodes . ; Do iterative traversal of first tree and find first lead node in it as " temp1" ; pushing right childfirst so that left child comes first while popping . ; Do iterative traversal of second tree and find first lead node in it as " temp2" ; If we found leaves in both trees ; Driver code
using System ; using System . Collections . Generic ; class GfG { public class Node { public int data ; public Node left , right ; } static Node newNode ( int x ) { Node temp = new Node ( ) ; temp . data = x ; temp . left = null ; temp . right = null ; return temp ; } static bool isLeaf ( Node t ) { return ( ( t . left == null ) && ( t . right == null ) ) ; } static void findFirstUnmatch ( Node root1 , Node root2 ) { if ( root1 == null root2 == null ) return ; Stack < Node > s1 = new Stack < Node > ( ) ; Stack < Node > s2 = new Stack < Node > ( ) ; s1 . Push ( root1 ) ; s2 . Push ( root2 ) ; while ( s1 . Count != 0 s2 . Count != 0 ) { if ( s1 . Count == 0 s2 . Count == 0 ) return ; Node temp1 = s1 . Peek ( ) ; s1 . Pop ( ) ; while ( temp1 != null && isLeaf ( temp1 ) != true ) { s1 . Push ( temp1 . right ) ; s1 . Push ( temp1 . left ) ; temp1 = s1 . Peek ( ) ; s1 . Pop ( ) ; } Node temp2 = s2 . Peek ( ) ; s2 . Pop ( ) ; while ( temp2 != null && isLeaf ( temp2 ) != true ) { s2 . Push ( temp2 . right ) ; s2 . Push ( temp2 . left ) ; temp2 = s2 . Peek ( ) ; s2 . Pop ( ) ; } if ( temp1 != null && temp2 != null ) { if ( temp1 . data != temp2 . data ) { Console . WriteLine ( temp1 . data + " ▁ " + temp2 . data ) ; return ; } } } } public static void Main ( String [ ] args ) { Node root1 = newNode ( 5 ) ; root1 . left = newNode ( 2 ) ; root1 . right = newNode ( 7 ) ; root1 . left . left = newNode ( 10 ) ; root1 . left . right = newNode ( 11 ) ; Node root2 = newNode ( 6 ) ; root2 . left = newNode ( 10 ) ; root2 . right = newNode ( 15 ) ; findFirstUnmatch ( root1 , root2 ) ; } }
Maximum points of intersection n circles | C # program to find maximum umber of intersections of n circles ; for the calculation of 2 * ( nC2 ) ; Driver Code
using System ; class GFG { static int intersection ( int n ) { return n * ( n - 1 ) ; } public static void Main ( ) { Console . WriteLine ( intersection ( 3 ) ) ; } }
Find the perimeter of a cylinder | C # program to find perimeter of cylinder ; Function to calculate perimeter ; Driver program to test above function
using System ; class GFG { static int perimeter ( int diameter , int height ) { return 2 * ( diameter + height ) ; } public static void Main ( String [ ] args ) { int diameter = 5 ; int height = 10 ; Console . Write ( " Perimeter ▁ = ▁ " + perimeter ( diameter , height ) + " ▁ units STRNEWLINE " ) ; } }
Find all possible coordinates of parallelogram | C # program to all possible points of a parallelogram ; Driver code ; coordinates of A ; coordinates of B ; coordinates of C
using System ; public class ParallelogramPoints { public static void Main ( ) { int ax = 5 , ay = 0 ; int bx = 1 , by = 1 ; int cx = 2 , cy = 5 ; Console . WriteLine ( ax + bx - cx + " , ▁ " + ( ay + by - cy ) ) ; Console . WriteLine ( ax + cx - bx + " , ▁ " + ( ay + cy - by ) ) ; Console . WriteLine ( cx + bx - ax + " , ▁ " + ( cy + by - ax ) ) ; } }
Check whether a given point lies inside a rectangle or not | C # program to Check whether a given point lies inside a rectangle or not ; A utility function to calculate area of triangle formed by ( x1 , y1 ) , ( x2 , y2 ) and ( x3 , y3 ) ; A function to check whether point P ( x , y ) lies inside the rectangle formed by A ( x1 , y1 ) , B ( x2 , y2 ) , C ( x3 , y3 ) and D ( x4 , y4 ) ; Calculate area of rectangle ABCD ; Calculate area of triangle PAB ; Calculate area of triangle PBC ; Calculate area of triangle PCD ; Calculate area of triangle PAD ; Check if sum of A1 , A2 , A3 and A4is same as A ; Driver code ; Let us check whether the point P ( 10 , 15 ) lies inside the rectangle formed by A ( 0 , 10 ) , B ( 10 , 0 ) , C ( 0 , - 10 ) , D ( - 10 , 0 )
using System ; class GFG { static float area ( int x1 , int y1 , int x2 , int y2 , int x3 , int y3 ) { return ( float ) Math . Abs ( ( x1 * ( y2 - y3 ) + x2 * ( y3 - y1 ) + x3 * ( y1 - y2 ) ) / 2.0 ) ; } static bool check ( int x1 , int y1 , int x2 , int y2 , int x3 , int y3 , int x4 , int y4 , int x , int y ) { float A = area ( x1 , y1 , x2 , y2 , x3 , y3 ) + area ( x1 , y1 , x4 , y4 , x3 , y3 ) ; float A1 = area ( x , y , x1 , y1 , x2 , y2 ) ; float A2 = area ( x , y , x2 , y2 , x3 , y3 ) ; float A3 = area ( x , y , x3 , y3 , x4 , y4 ) ; float A4 = area ( x , y , x1 , y1 , x4 , y4 ) ; return ( A == A1 + A2 + A3 + A4 ) ; } public static void Main ( ) { if ( check ( 0 , 10 , 10 , 0 , 0 , - 10 , - 10 , 0 , 10 , 15 ) ) Console . Write ( " yes " ) ; else Console . Write ( " no " ) ; } }
Get maximum left node in binary tree | C # program to print maximum element in left node . ; A Binary Tree Node ; Get max of left element using Inorder traversal ; Return maximum of three values 1 ) Recursive max in left subtree 2 ) Value in left node 3 ) Recursive max in right subtree ; Utility function to create a new tree node ; Driver code ; Let us create binary tree shown in above diagram ; 7 / \ 6 5 / \ / \ 4 3 2 1
using System ; class GfG { class Node { public int data ; public Node left , right ; } static int maxOfLeftElement ( Node root ) { int res = int . MinValue ; if ( root == null ) return res ; if ( root . left != null ) res = root . left . data ; return Math . Max ( maxOfLeftElement ( root . left ) , Math . Max ( res , maxOfLeftElement ( root . right ) ) ) ; } static Node newNode ( int data ) { Node temp = new Node ( ) ; temp . data = data ; temp . left = null ; temp . right = null ; return temp ; } public static void Main ( String [ ] args ) { Node root = newNode ( 7 ) ; root . left = newNode ( 6 ) ; root . right = newNode ( 5 ) ; root . left . left = newNode ( 4 ) ; root . left . right = newNode ( 3 ) ; root . right . left = newNode ( 2 ) ; root . right . right = newNode ( 1 ) ; Console . WriteLine ( maxOfLeftElement ( root ) ) ; } }
Pizza cut problem ( Or Circle Division by Lines ) | C # program to find maximum no of pieces by given number of cuts ; Function for finding maximum pieces with n cuts . ; Driver Program to test above function
using System ; class GFG { static int findMaximumPieces ( int n ) { return 1 + n * ( n + 1 ) / 2 ; } public static void Main ( ) { Console . Write ( findMaximumPieces ( 3 ) ) ; } }
Optimum location of point to minimize total distance | C # program to find optimum location and total cost ; structure defining a point ; structure defining a line of ax + by + c = 0 form ; method to get distance of point ( x , y ) from point p ; Utility method to compute total distance of all points when choose point on given line has x - coordinate value as X ; calculating Y of chosen point by line equation ; Utility method to find minimum total distance ; loop until difference between low and high become less than EPS ; mid1 and mid2 are representative x co - ordiantes of search space ; if mid2 point gives more total distance , skip third part ; if mid1 point gives more total distance , skip first part ; compute optimum distance cost by sending average of low and high as X ; method to find optimum cost ; converting 2D array input to point array ; Driver Code
using System ; class GFG { static double sq ( double x ) { return ( ( x ) * ( x ) ) ; } static int EPS = ( int ) ( 1e-6 ) + 1 ; static int N = 5 ; public class point { public int x , y ; public point ( ) { } public point ( int x , int y ) { this . x = x ; this . y = y ; } } ; public class line { public int a , b , c ; public line ( int a , int b , int c ) { this . a = a ; this . b = b ; this . c = c ; } } ; static double dist ( double x , double y , point p ) { return Math . Sqrt ( sq ( x - p . x ) + sq ( y - p . y ) ) ; } static double compute ( point [ ] p , int n , line l , double X ) { double res = 0 ; double Y = - 1 * ( l . c + l . a * X ) / l . b ; for ( int i = 0 ; i < n ; i ++ ) res += dist ( X , Y , p [ i ] ) ; return res ; } static double findOptimumCostUtil ( point [ ] p , int n , line l ) { double low = - 1e6 ; double high = 1e6 ; while ( ( high - low ) > EPS ) { double mid1 = low + ( high - low ) / 3 ; double mid2 = high - ( high - low ) / 3 ; double dist1 = compute ( p , n , l , mid1 ) ; double dist2 = compute ( p , n , l , mid2 ) ; if ( dist1 < dist2 ) high = mid2 ; else low = mid1 ; } return compute ( p , n , l , ( low + high ) / 2 ) ; } static double findOptimumCost ( int [ , ] points , line l ) { point [ ] p = new point [ N ] ; for ( int i = 0 ; i < N ; i ++ ) p [ i ] = new point ( points [ i , 0 ] , points [ i , 1 ] ) ; return findOptimumCostUtil ( p , N , l ) ; } public static void Main ( String [ ] args ) { line l = new line ( 1 , - 1 , - 3 ) ; int [ , ] points = { { - 3 , - 2 } , { - 1 , 0 } , { - 1 , 2 } , { 1 , 2 } , { 3 , 4 } } ; Console . WriteLine ( findOptimumCost ( points , l ) ) ; } }
Height of Factor Tree for a given number | C # program for the above approach ; Function to find the height of the Factor Tree of the integer N ; Stores the height of Factor Tree ; Loop to iterate over values of N ; Stores if there exist a factor of N or not ; Loop to find the smallest factor of N ; If i is a factor of N ; Increment the height ; If there are no factors of N i . e , N is prime , break loop ; Return Answer ; Driver code
using System ; class GFG { static int factorTree ( int N ) { int height = 0 ; while ( N > 1 ) { bool flag = false ; for ( int i = 2 ; i <= Math . Sqrt ( N ) ; i ++ ) { if ( N % i == 0 ) { N = N / i ; flag = true ; break ; } } height ++ ; if ( ! flag ) { break ; } } return height ; } static void Main ( ) { int N = 48 ; Console . Write ( factorTree ( N ) ) ; } }
Maximize the largest number K such that bitwise and of K till N is 0 | package whatever do not write package name here ; Function to find maximum value of k which makes bitwise AND zero . ; Finding the power less than N ; Driver Code
using System ; class GFG { static int findMaxK ( int N ) { int p = ( int ) ( Math . Log ( N ) / Math . Log ( 2 ) ) ; return ( int ) Math . Pow ( 2 , p ) ; } public static void Main ( String [ ] args ) { int N = 5 ; Console . Write ( findMaxK ( N ) - 1 ) ; } }
Count of Ks in the Array for a given range of indices after array updates for Q queries | C # program for the above approach ; Function to build the segment tree ; Base case ; Since the count of zero is required set leaf node as 1 ; If the value in array is not zero , store 0 in the leaf node ; Find the mid ; Recursive call for left subtree ; Recursive call for right subtree ; Parent nodes contains the count of zero in range tl to tr ; Function to find the count of 0 s in range l to r ; Base Case ; Case when no two segment are combining ; Finding the mid ; When it is required to combine left subtree and right subtree to get the range l to r ; Function that updates the segment tree nodes ; Base Case ; If array element is 0 ; If array element is not 0 ; Otherwise ; Find the mid ; Update the tree or count which is stored in parent node ; Function to solve all the queries ; When query type is 1 ; When query type is 2 ; Driver Code
using System ; class GFG { static int [ ] a ; static int [ ] seg_tree ; static int [ , ] query ; static void build_tree ( int v , int tl , int tr ) { if ( tl != tr ) { if ( a [ tl ] == 0 ) seg_tree [ v ] = 1 ; else seg_tree [ v ] = 0 ; } else { int tm = ( tl + tr ) / 2 ; build_tree ( v * 2 , tl , tm ) ; build_tree ( v * 2 + 1 , tm + 1 , tr ) ; seg_tree [ v ] = seg_tree [ v * 2 ] + seg_tree [ v * 2 + 1 ] ; } } static int frequency_zero ( int v , int tl , int tr , int l , int r ) { if ( l > r ) return 0 ; if ( l == tl && r == tr ) { return seg_tree [ v ] ; } int tm = ( tl + tr ) / 2 ; return frequency_zero ( v * 2 , tl , tm , l , Math . Min ( r , tm ) ) + frequency_zero ( v * 2 + 1 , tm + 1 , tr , Math . Max ( l , tm + 1 ) , r ) ; } static void update ( int v , int tl , int tr , int pos , int new_val ) { if ( tl == tr ) { if ( new_val == 0 ) seg_tree [ v ] = 1 ; else seg_tree [ v ] = 0 ; } else { int tm = ( tl + tr ) / 2 ; if ( pos <= tm ) update ( v * 2 , tl , tm , pos , new_val ) ; else update ( v * 2 + 1 , tm + 1 , tr , pos , new_val ) ; seg_tree [ v ] = seg_tree [ v * 2 ] + seg_tree [ v * 2 + 1 ] ; } } static void solve ( int n , int q ) { int [ ] qu = { 5 , 3 , 6 } ; seg_tree = new int [ 4 * n + 1 ] ; Array . Fill ( seg_tree , 0 ) ; build_tree ( 1 , 0 , n - 1 ) ; for ( int i = 0 ; i < qu . Length ; i ++ ) { Console . WriteLine ( qu [ i ] ) ; } for ( int i = q ; i < q ; i ++ ) { if ( query [ i - 1 , 0 ] == 1 ) { int l = query [ i - 1 , 1 ] ; int r = query [ i - 1 , 2 ] ; Console . WriteLine ( frequency_zero ( 1 , 0 , n - 1 , l , r ) ) ; } else { a [ query [ i - 1 , 1 ] ] = query [ i - 1 , 2 ] ; int pos = query [ i - 1 , 1 ] ; int new_val = query [ i - 1 , 2 ] ; update ( 1 , 0 , n - 1 , pos , new_val ) ; } } } static void Main ( ) { a = new int [ ] { 9 , 5 , 7 , 6 , 9 , 0 , 0 , 0 , 0 , 5 , 6 , 7 , 3 , 9 , 0 , 7 , 0 , 9 , 0 } ; int Q = 5 ; query = new int [ , ] { { 1 , 5 , 14 } , { 2 , 6 , 1 } , { 1 , 0 , 8 } , { 2 , 13 , 0 } , { 1 , 6 , 18 } } ; int N = a . Length ; solve ( N , Q ) ; } }
Find a number in minimum steps | C # program to find a number in minimum steps ; To represent data of a node in tree ; Prints level of node n ; Create a queue and insert root ; Do level order traversal ; Remove a node from queue ; To astatic void infinite loop ; Check if dequeued number is same as n ; Insert children of dequeued node to queue ; Driver code
using System ; using System . Collections . Generic ; public class GFG { static readonly int InF = 99999 ; public class number { public int no ; public int level ; public number ( ) { } public number ( int n , int l ) { this . no = n ; this . level = l ; } } ; static void findnthnumber ( int n ) { Queue < number > q = new Queue < number > ( ) ; number r = new number ( 0 , 1 ) ; q . Enqueue ( r ) ; while ( q . Count != 0 ) { number temp = q . Peek ( ) ; q . Dequeue ( ) ; if ( temp . no >= InF temp . no <= - InF ) break ; if ( temp . no == n ) { Console . Write ( " Found ▁ number ▁ n ▁ at ▁ level ▁ " + ( temp . level - 1 ) ) ; break ; } q . Enqueue ( new number ( temp . no + temp . level , temp . level + 1 ) ) ; q . Enqueue ( new number ( temp . no - temp . level , temp . level + 1 ) ) ; } } public static void Main ( String [ ] args ) { findnthnumber ( 13 ) ; } }
Check if all 3 Candy bags can be emptied by removing 2 candies from any one bag and 1 from the other two repeatedly |  ; If total candies are not multiple of 4 then its not possible to be left with 0 candies ; If minimum candies of three bags are less than number of operations required then the task is not possible ; Driver Code
using System ; public class GFG { static bool can_empty ( int a , int b , int c ) { if ( ( a + b + c ) % 4 != 0 ) return false ; else { int m = Math . Min ( a , Math . Min ( b , c ) ) ; if ( m < ( ( a + b + c ) / 4 ) ) return false ; } return true ; } static public void Main ( ) { int a = 4 , b = 2 , c = 2 ; Console . WriteLine ( can_empty ( a , b , c ) ? " true " : " false " ) ; a = 3 ; b = 4 ; c = 2 ; Console . WriteLine ( can_empty ( a , b , c ) ? " true " : " false " ) ; } }
Difference between maximum and minimum average of all K | C # program for the above approach ; Function to find the difference between averages of the maximum and the minimum subarrays of length k ; Stores min and max sum ; Iterate through starting points ; Sum up next K elements ; Update max and min moving sum ; Return the difference between max and min average ; Driver Code ; Given Input ; Function Call
using System ; class GFG { static double Avgdifference ( double [ ] arr , int N , int K ) { double min = 1000000 , max = - 1 ; for ( int i = 0 ; i <= N - K ; i ++ ) { double sum = 0 ; for ( int j = 0 ; j < K ; j ++ ) { sum += arr [ i + j ] ; } if ( min > sum ) min = sum ; if ( max < sum ) max = sum ; } return ( max - min ) / K ; } public static void Main ( String [ ] args ) { double [ ] arr = { 3 , 8 , 9 , 15 } ; int N = arr . Length ; int K = 2 ; Console . Write ( Avgdifference ( arr , N , K ) ) ; } }