Solved Consider the following algorithm which takes an array | Chegg.com

Responsive image
source