Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello, Please help me prepare for an upcoming test by answering this problem in Python3. Thanks! You've been asked to program a bot for a

Hello,
Please help me prepare for an upcoming test by answering this problem in Python3. Thanks!
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
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 request to deposit camount> amount of money in the account; withdraw -request to withdraw amount of money from the 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 cashbask 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 [- ] (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. Example Example 1 For balances = [1000, 1500] and requests = ["withdraw 1613327630 2 480", "withdran 1613327644 2 800", "withdraw 1614105244 1 100", "deposit 1614108844 2 200", "withdraw 1614108865 2 150'], the output should be solution(balances, requests) [990, 295] Explanation Here are the states of balances after each request: . initially: [1000, 1500]: "withdraw 1615327630 2 480": [1000, . 1020]. "withdraw 1613327644 2 800" : [1900, 220]; . At 161341403e the 2nd account will receive the cashback of 480* 0.02 = 9.6 which is 5 rounded down to 9: [1200, 229): . At 1613414044 the 2nd account will receive the . . cashback of 800 * 0.02 = 16 : [1800, 245] : "withdraw 1614105244 1 100": [990, 245] "deposit 1614108844 2 200" : [9009 445] "withdraw 1614108845 2 150": [980, 295]. which is the answer. . Cashbacks for the last two withdrawals happen at 1614191644 and 1614195245 which is after the last request timestamp 1614108845 so they are ignored. Example 2 Example 2 For balances [20, 1000, 500, 40, 90] and requests = ["deposit 1613327630 3 400", withdraw 1613327635 1 20", "withdraw 1613327651 1 50", "deposit 1613327655 1 50"] , the output should be solution(balances, requests) = [-3] Explanation Here are the states of balances after each request: . initially: [20, 1000, 500, 40, 90]; "deposit 1613327630 3 400" : [20, 11000, 900, 40, 90] "withdraw 1613327635 1 20" : [0, 1000, 900, 40, 90]; "withdraw 1613327651 1 50": it is not possible to withdraw 50 from the 1st account, so the request is invalid. the rest of the requests are not processed Input/Output [execution time limit] 4 seconds (Py3) Input/Output [execution time limit] 4 seconds (py3) . [input] array.integer balances Array of integers, where balances[i] is the amount of money in the (i + 1)th account. Guaranteed constraints: 100 1 s balances.length os balances[i] s 105 [input] array.string requests Array of requests in the order they should be processed. Each request is guaranteed to be in the format described above. It is guaranteed that requests come sequentially, i.e. the timestamp strictly increases Guaranteed constraints: 1 s requests.length S 100. . [output] array.integer The balances after executing all of the requests or array with a single integer - the index

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Databases And Information Systems 25th European Conference Adbis 2021 Tartu Estonia August 24 26 2021 Proceedings Lncs 12843

Authors: Ladjel Bellatreche ,Marlon Dumas ,Panagiotis Karras ,Raimundas Matulevicius

1st Edition

3030824713, 978-3030824716

More Books

Students also viewed these Databases questions

Question

define EFFECTIVE PARTICIPATION

Answered: 1 week ago