RBC Interview Question

could you write codes for this problem?