Solution for three stack array