BAE Systems interview question

Basic programming task to implement an algorithm