MRSOOL Interview Question

Simple/medium problem from leet code