Forming smallest array with given constraints | Java 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 . ; Drivers code
import java . io . * ; 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 ( String [ ] args ) { int x = 3 , y = 1 , z = 2 ; System . out . println ( minimumLength ( x , y , z ) ) ; } }