Question
You are given two arrays A and B of N strings each, and an array C of N positive integers. They describe N monthly expenses
You are given two arrays A and B of N strings each, and an array C of N positive integers. They describe N monthly expenses (numbered from 0 to N-1) set up on an account. The Kth expense charges the account with an amount C[K] at the end of each month, starting from month A[K] and ending in month B[K] (inclusive). The format of each string is "MM-YYYY" (where MM denotes month, between 01 and 12, and YYYY denotes year, between 1900 and 2100), for example: "06-2021". What is the minimum monthly income needed for all of these charges to be paid? We cannot go into debt. In other words, the amount of money that remains in the account at the end of each month (after all the payments) should not drop below 0. The monthly income starts in the earliest month given in array A. The income is transfered onto the account at the beginning of the month, i.e. income for a given month is always on the account before any of the charges are payed. The balance that remains in the account at the end of the month can be used in the following months. Write a function: def solution (A, B, ) that, given arrays A and B consisting of N strings each and an array C consisting of N positive integers, representing the expenses as described above, returns the minimum monthly income needed to cover all of the expenses. Examples: 1. Given A = ["03-2021", "04-2021", "05-20211"], B = ["03-2021", "05-2021", "05-2021"], and C = [20, 10, 15], the function should return 20. The total expenses are: 20 (in March), 10 (in April) and 25 (in May). Starting with income 20 (in March), the total balance at the end of each month will be: 0 (in March), 10 (in April) and 5 (in May). 2. Given A = ["10-2020", "01-2020", "02-2020", "06-2021"], B = ["07-2021", "03-2020", "10-2020", "07-2021"], and C = [1, 10, 2, 90], the function should return 13. 3. Given A = ["01-1900", "12-2099", "11-2099", "01-1901"], B = ["12-1901", 1"2-2099", "12-2100", "01-1902"] and C = [1, 1000, 998, 1], the function should return 7. Write an efficient algorithm for the following assumptions: N is an integer within the range [1...100000]; each element of array C is an integer within the range [1...1000];
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started