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 . ; Drivers code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int minimumLength ( int x , int y , int z ) { return 1 + abs ( x - y ) + abs ( y - z ) ; } int main ( ) { int x = 3 , y = 1 , z = 2 ; cout << minimumLength ( x , y , z ) ; return 0 ; }