RippleHire interview question

Logic based java question