Appian interview question

How would you code this solution