WAP to find the minimum number of steps required for increasing or decreasing array to reach either 0 or N. Given an integer N and 2 arrays increasing[] and decreasing[] each having elements from 1 to N. Once 0 or N is achieved, do not increament or decreament the numbers in array.
Example 1:
Input:
N=7 Increasing[]= {2,3} Decreasing[]={5,6}
Output: 6
Explaination:
- Increasing[]= {3,4} Decreasing[]={4,5}
- Increasing[]= {4,5} Decreasing[]={3,4}
- Increasing[]= {5,6} Decreasing[]={2,3}
- Increasing[]= {6,7} Decreasing[]={1,2}
- Increasing[]= {7,7} Decreasing[]={0,1}
- Increasing[]= {7,7} Decreasing[]={0,0}
Published By : Kopal Jaiswal