Bloomberg Interview Question

how to solve the valid transaction algorithm problem