Oracle Interview Question

Coding challenge was hard and difficult to Crack