NEC Corporation Interview Question

diamond problem