Appian Interview Question

How would you code this solution