Apple Interview Question

Design an algorithm