Bentley Systems interview question

Write an algorithm in psuedocode