Marqeta interview question

Leetcode style coding question, on pair programmed on hackerrank