This is a verified interview question from Trilogy. Candidates reporting seeing this problem in recent Online Assessments (OAs) and onsite rounds. Mastering "Banking System with Cashback - Trilogy" covers key patterns like System Design.
"You've been asked to program a bot for a popular bank that will automate the management of incoming requests. Every request has its own timestamp in seconds, and it is guaranteed that all requests come sequentially, i.e. the timestamp is strictly increasing. There are two types of incoming requests: - deposit <timestamp> <holder_id> <amount> — request to deposit <amount> amount of money in the <holder_id> account; - withdraw <timestamp> <holder_id> <amount> — request to withdraw <amount> amount of money from the <holder_id> account. As a bonus, bank also provides a cashback policy — 2% of the withdrawn amount rounded down to the nearest integer will be returned to the account exactly 24 hours after the request timestamp. If the cashback and deposit/withdrawal happen at the same timestamp, assume cashback happens earlier. Your system should also handle invalid requests. There are two types of invalid requests: - invalid account number; - withdrawal of a larger amount of money than is currently available. For the given list of initial balances and requests, return the state of balances straight after the last request has been processed, or an array of a single element [-<request_id>], where <request_id> is the 1-based index of the first invalid request (please note the minus sign), where <request_id> is the 1-based index of the first invalid request. Note that cashback requests which haven't happened before the last request should be ignored."
Join thousands of developers practicing for Trilogy.