I want to know how to solve this above problem if the given elements not just 3 but an array whose length <= 10^5
I think you don’t need to reverse at all…
You can do this using memoized recursion…
Look at my solution I used recursion. But you can use memoization to optimize.