Oracle interview question

DSA problem with medium difficulty