Maximize Earnings by Adding Working Days
Company: Citadel
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Implement `maximum_earnings(schedule, k, pay, bonus)`.
`schedule` is a string of `0` and `1`, where `1` means a working day and `0` means a day off. You may change at most `k` zeroes into ones; existing working days cannot become days off.
Each working day earns `pay`. It also earns `bonus` if the immediately preceding day in this schedule is a working day after all changes. The first day has no preceding day within the schedule. Return the maximum total earnings over the full schedule.
For this interface, `k` is a nonnegative integer and `pay` and `bonus` are nonnegative integers in the same monetary unit. Represent these integers and the returned total using the decimal strings described below. You may use fewer changes than `k`, and cannot change more days off than exist. An empty schedule earns zero. No maximum schedule length or payment bound is specified.
### Exact integer representation
This console represents integer values as canonical decimal strings so they retain their exact values in every supported language. This is an input/output representation convention; it does not impose a maximum integer magnitude.
- `k`, `pay`, and `bonus` are strings representing nonnegative integers. `schedule` remains the binary schedule string described above.
- Return the maximum earnings as a canonical decimal string. An empty schedule returns `"0"`.
- A canonical nonnegative decimal string is `"0"` or a sequence of ASCII digits beginning with `1` through `9`. It has no sign, leading zeroes, or whitespace.
- Earnings are exact integer amounts in the stated monetary unit. Do not use rounding, fixed-width overflow, or a remainder modulo another number.
### Examples
```text
maximum_earnings("101", "1", "10", "5") -> "40"
```
Changing the middle day gives three working days and two adjacent working-day pairs: 30 in base pay and 10 in bonuses.
```text
maximum_earnings("000", "2", "10", "5") -> "25"
```
Two adjacent working days earn 20 in base pay and one bonus of 5. Separate working days would earn no adjacency bonus.
Overview: Maximize schedule earnings by changing at most k days off into working days, balancing fixed daily pay with bonuses for consecutive working days.
Read the full Citadel Software Engineer interview experience this question came from
Implement `maximum_earnings(schedule, k, pay, bonus)`.
`schedule` is a string of `0` and `1`, where `1` means a working day and `0` means a day off. You may change at most `k` zeroes into ones; existing working days cannot become days off.
Each working day earns `pay`. It also earns `bonus` if the immediately preceding day in this schedule is a working day after all changes. The first day has no preceding day within the schedule. Return the maximum total earnings over the full schedule.
For this interface, `k` is a nonnegative integer and `pay` and `bonus` are nonnegative integers in the same monetary unit. Represent these integers and the returned total using the decimal strings described below. You may use fewer changes than `k`, and cannot change more days off than exist. An empty schedule earns zero. No maximum schedule length or payment bound is specified.
### Exact integer representation
This console represents integer values as canonical decimal strings so they retain their exact values in every supported language. This is an input/output representation convention; it does not impose a maximum integer magnitude.
- `k`, `pay`, and `bonus` are strings representing nonnegative integers. `schedule` remains the binary schedule string described above.
- Return the maximum earnings as a canonical decimal string. An empty schedule returns `"0"`.
- A canonical nonnegative decimal string is `"0"` or a sequence of ASCII digits beginning with `1` through `9`. It has no sign, leading zeroes, or whitespace.
- Earnings are exact integer amounts in the stated monetary unit. Do not use rounding, fixed-width overflow, or a remainder modulo another number.
### Examples
```text
maximum_earnings("101", "1", "10", "5") -> "40"
```
Changing the middle day gives three working days and two adjacent working-day pairs: 30 in base pay and 10 in bonuses.
```text
maximum_earnings("000", "2", "10", "5") -> "25"
```
Two adjacent working days earn 20 in base pay and one bonus of 5. Separate working days would earn no adjacency bonus.
Constraints
- schedule is any finite binary string, including empty.
- k, pay and bonus are canonical nonnegative decimal strings with no maximum magnitude specified.
- Change at most k zeroes to ones; earnings cover all resulting working days and immediate-predecessor pairs.
- Return a canonical nonnegative decimal string; an empty schedule earns "0".
Examples
Input: ('101', '1', '10', '5')
Expected Output: '40'
Explanation: Source example: bridge the middle gap for three days and two adjacency bonuses.
Input: ('000', '2', '10', '5')
Expected Output: '25'
Explanation: Source example: choose two adjacent working days.
Hints
- The first schedule position has no preceding day in the schedule.
- An allowance larger than the number of days off does not permit additional changes.