optimized 001 cpp solution

Signed-off-by: Arvind Chembarpu <achembarpu@gmail.com>