Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

There are N hospitals, numbered from 0 to N - 1 . You are given a schedule of work in each of the hospitals for

There are N hospitals, numbered from 0 to N-1. You are given a schedule of work in each of the hospitals for the following M days. The schedule is provided in the form of a two-dimensional array A containing N rows, each row representing the schedule of one hospital, and M columns, each column representing one day. Integer A[K][L](for K within the range [0..N-1] and L within the range [0..M-1]) represents the ID of the doctor working at hospital K on day L. Note that sometimes an individual doctor may work at more than one hospital even on the same day.
Write a function:
class Solution { public int solution(int[][] A); }
that, given a matrix A consisting of N rows and M columns representing the hospitals' schedules, finds the number of doctors working at more than one hospital.
Examples:
1. Given A =[[1,2,2],[3,1,4]], the function should return 1.
2. Given A =[[1,1,5,2,3],[4,5,6,4,3],[9,4,4,1,5]], the function should return 4.
3. Given A =[[4,3],[5,5],[6,2]], the function should return 0.
Write an efficient algorithm for the following assumptions:
N and M are integers within the range [1..1,000];
each element of matrix A is an integer within
the range [1..N*M]. You are given a list of all the transactions on a bank account during the year 2020. The account was empty at the beginning of the year (the balance was 0).
Each transaction specifies the amount and the date it was executed. If the amount is negative (less than 0) then it was a card payment, otherwise it was an incoming transfer (amount at least 0). The date of each transaction is in YYYY-MM-DD format: for example, 2020-05-20 represents 20th May 2020.
Additionally, there is a fee for having a card (omitted in the given transaction list), which is 5 per month. This fee is deducted from the account balance at the end of each month unless there were at least three payments made by card for a total cost of at least 100 within that month.
Your task is to compute the final balance of the account at the end of the year 2020
Write a function:
class Solution { public int solution(int[] A, String[] D); }
that, given an array A of N integers representing transaction amounts and an array D of N strings representing transaction dates, returns the final balance of the account at the end of the year 2020. Transaction number K (for K within the range [0..N-1]) was executed on the date represented by D[K] for amount A[K].
Examples:
1. Given A =[100,100,100,-10] and D =["2020-12-31","2020-12-22","2020-12-03","2020-12-29"], the function < should return 230. Total income was equal to 100+100+100-10=290 and the fee was paid every month, so 290-(5*12)=230.
2. Given A =[180,-50,-25,-25] and D =["2020-01-01","2020-01-01","2020-01-01","2020-01-31"], the function should return 25. The income was equal to 180, the expenditure was equal to 100 and the fee was applied in every month except January: 180-100-(5*11)=25.
3. Given A =[1,-1,0,-105,1] and D =["2020-12-31",
"2020-04-04","2020-04-04","2020-04-14","2020-07-12"], the function should return -164. The fee is paid every month. 1-1+0-105+1-(5*12)=-164. Note that in April, even though the total cost of card payments was 106(more than 100), there were only two payments made by card, so the fee was still applied. A transaction of value 0 is considered a positive, incoming transfer.
4. Given A =[100,100,-10,-20,-30] and D =["2020-01-01","2020-02-01","2020-02-11","2020-02-05","2020-02-08"], the function should return 80.
5. Given A =[-60,60,-40,-20] and D =["2020-10-01","2020-02-02","2020-10-10","2020-10-30"], the function should return -115.
Assume that:
N is an integer within the range [1..100];
each element of array A is an integer within the range [-1,000..1,000];
D contains strings in YYYY-MM-DD format, representing dates in the range 2020-01-01 to 2020-12-31.

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

Pro SQL Server Wait Statistics

Authors: Enrico Van De Laar

1st Edition

1484211391, 9781484211397

More Books

Students also viewed these Databases questions

Question

1. Avoid long-winded statements or nagging.

Answered: 1 week ago

Question

6 Explain the expectancy theory of motivation.

Answered: 1 week ago