Visa Inc. Interview Question

complete or shorten the given code