educative.io

Educative

Formula for Re-arrange Sorted Array in Max/Min Form

In the optimal solution for Re-arrange Sorted Array in Max/Min Form problem, I see we use a formula, in the interview how I can arrive at such formula ?

I know this was asked many months ago but I will answer hoping it helps someone else looking at it. The formula that we use here is actually basic maths that we learnt in grade school. That is:

Divisor * Quotient + Remainder = Dividend

This means that:
Dividend / Divisor = Remainder
Dividend % Divisor = Quotient