Bentley Systems Interview Question

Write an algorithm in psuedocode