This is a very interesting problem and can be a bit tricky for a beginner in programming. This problem required a good understanding of the Array concept.
The following 3 approaches are discussed from brute force -> better -> best.
let's get started....