you want build obstacle course you give 0indexed integer array obstacle length n obstaclesi describe height ith obstacleFor index 0 n 1 inclusive find length long obstacle course obstacle thatyou choose number obstacle 0 inclusiveYou include ith obstacle courseYou choose obstacle order appear obstaclesEvery obstacle tall height obstacle immediately itreturn array ans length n ansi length long obstacle course index describe Example 1input obstacle 1232output 1233explanation the long valid obstacle course position 0 1 1 length 1 1 12 12 length 2 2 123 123 length 3 3 1232 122 length 3example 2input obstacle 221output 121explanation the long valid obstacle course position 0 2 2 length 1 1 22 22 length 2 2 221 1 length 1example 3input obstacle 315642output 112322explanation the long valid obstacle course position 0 3 3 length 1 1 31 1 length 1 2 315 35 length 2 15 valid 3 3156 356 length 3 156 valid 4 31564 34 length 2 14 valid 5 315642 12 length 2 Constraintsn obstacleslength1 n 1051 obstaclesi 107