Question is :

When I tried it shows wrong ans and memory limit >256 ie{356MB}

I used one for loop to n

and cnt extraspace

Question is :

When I tried it shows wrong ans and memory limit >256 ie{356MB}

I used one for loop to n

and cnt extraspace

pls post question link

Final answer = (value smallest element * size of array) + index of smallest element.

it was hiring test

I can take only screenshot:

My Code was:

```
for (int i = 0; i < n;) {
if (a[i] == 0) {
break;
}
else {
a[i] -= 1;
cnt += 1;
}
if (i % n == 1) {
i = 0;
} else {
i++;
}
}
```

((min - 1)*lenght of arr) + index of min+1

can you explain your reasoning?

we can traverse the complete arr (min-1) and then we can go till the index of the min element

example 4 5 3 8 here we can traverse the whole arr twice making it 2 3 1 6 and we get 8(len of arr * (min ele-1)) coins then we can only go till the min ele(i.e 1) so we get 3(index of min ele +1) more coins

so total 11 coins…