Forming smallest array with given constraints | C # program to find the length of smallest array begin with x , having y , ends with z and having absolute difference between adjacent elements <= 1. ; Return the size of smallest array with given constraint . ; Driver Code
using System ; class GFG { static int minimumLength ( int x , int y , int z ) { return 1 + Math . Abs ( x - y ) + Math . Abs ( y - z ) ; } public static void Main ( ) { int x = 3 , y = 1 , z = 2 ; Console . WriteLine ( minimumLength ( x , y , z ) ) ; } }