RBC interview question

could you write codes for this problem?