Fortinet interview question

Write code for the problem [i just made up]