Problem B solution