you give integer array height represent height building brick laddersyou start journey build 0 building possibly brick ladderswhile move building building i1 0indexedif current building height greater equal building height need ladder bricksIf current building height building height use ladder hi1 hi bricksreturn furth building index 0indexed reach use give ladder brick optimally example 1input height 427691412 brick 5 ladder 1output 4explanation starting building 0 follow step go build 1 ladder brick 4 2 go build 2 5 brick you use brick ladder 2 7 go build 3 ladder brick 7 6 go build 4 ladder you use brick ladder 6 9it impossible building 4 brick laddersExample 2input height 4122731820319 brick 10 ladder 2Output 7example 3input height 143193 brick 17 ladder 0output 3 Constraints1 heightslength 1051 heightsi 1060 brick 1090 ladder heightslength