Nagarro Interview Question

based on strings and matrix