在一次 Adobe 技术面试中,面试官直接甩出了这样一道题:
Problem Description
You are given the following parameters:
- BasePay (integer): the base salary paid for each working day.
- Bonus (integer): the extra salary paid for every consecutive working day (i.e., if a worker also worked the previous day, they receive an additional Bonus).
- schedule (binary string of length n): represents n days, where '1' means the worker is scheduled to work, and '0' means rest.
- k (integer): the maximum number of rest days ('0') that can be changed into work days ('1').
The worker’s total salary is calculated as:
- On every working day ('1'), add BasePay.
- If today and yesterday are both working days ("11"), add Bonus for the current day.
- You can change at most k rest days ('0') into work days ('1').
Your task is to determine the maximum possible total salary after optimally changing up to k rest days.
Example
BasePay = 100
Bonus = 50
schedule = "101001"
k = 2
Output: 550
Explanation:
Original schedule "101001" gives salary = 450.
If we flip the 4th day → "101101", salary increases.
With up to 2 flips, the maximum achievable salary is 550.
中文简单翻译
题目描述:
- 工人每天上班都会拿 基础工资 BasePay。
- 如果今天和昨天连续上班,则今天还能额外拿 奖金 Bonus。
- 给定一个二进制字符串 schedule 表示排班('1' 上班,'0' 休息)。
- 你最多可以把 k 个休息日改成上班日。
任务:计算工人能拿到的 最大工资。
面试的真实难点
这道题看似是模拟工资计算,实际考察的是 动态规划 / 贪心 的建模能力。
- 你要决定哪些 '0' 值得翻转,才能带来最多的连续工作日和奖金;
- 同时还要避免“浪费”翻转次数。
很多候选人在这里就卡住了——因为不仅要算清楚,还得写出正确高效的代码。
CSOAHelp 能帮你什么?
在真实面试中,你没法随时暂停思考太久。但有了 CSOAHelp 实时辅助:
- 它能帮你快速写出基础的代码框架;
- 在关键逻辑处自动生成 注释和提示;
- 如果你一时想不起来 DP 的状态转移,CSOAHelp 可以实时给你辅助方案,帮你避免冷场。
一句话:你专注于思路讲解,CSOAHelp 替你守护代码实现。
如果你也在准备大厂的算法与系统设计面试,欢迎添加微信,即可领取北美面试求职通关秘诀。我们也有代面试,面试辅助,OA代写等服务助您早日上岸~
