Get started with 60 Hours of Free course right now 

Increasing or decreasing array

Kopal Jaiswal
16 Posts

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:

  1. Increasing[]= {3,4} Decreasing[]={4,5}
  2. Increasing[]= {4,5} Decreasing[]={3,4}
  3. Increasing[]= {5,6} Decreasing[]={2,3}
  4. Increasing[]= {6,7} Decreasing[]={1,2}
  5. Increasing[]= {7,7} Decreasing[]={0,1}
  6. Increasing[]= {7,7} Decreasing[]={0,0}
Published By : Kopal Jaiswal
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.

Comments