What will be the answer of
1 1 7 with d=1?
Will it be -1 or something else?
6 steps is the answer.
the average is 3 so u need to make all elemnts 3 so start from the i=0 to i < n-d
i=0, make 1 3 so takes 3 steps , and make a[i+1] 1-2=-1 then u have array 3 -1 7
for i=1 make -1 to 3 and 7 will become 3 , thereby all elemnts are 3,3,3.
total steps=2+4=6
can we make intermediate numbers negative?
what I wish to ask is - can I do it like this
1 1 7
2 0 7
2 4 3
3 3 3
You should try to copy paste someone else’s AC code and run this test case against it. That way, you wont have to wait for someone to answer as sometimes people get busy and answers have to wait.
1 Like
Yes, its fine. as long as indices have diff of 1 and answer is minimum.
But best way is 1 1 7==>1 5 3 ==>3 3 3 .
1 Like