Trains the technique from
LeetCode 1475Final Prices With a Special Discount in a ShopThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A workshop keeps its jobs in one queue and bills them in queue order. hours holds the hours booked against each job, position by position.
One settlement rule applies to every job. Read further along the queue from that job and stop at the first job whose booked hours are no more than this job's booked hours; that many hours come off this job's bill. If no later job qualifies, the job is billed exactly as booked.
The rule is worked out for each job from the booked figures alone, so a credit given to one job never changes what any other job is credited, and a job is never credited against itself.
Return the bill for every job, in queue order.
Example 1
Job 0 stops at the 5 in position 1, so it is billed 9 - 5. Job 1 stops at the equal 5 in position 2 and is billed 5 - 5. Job 2 stops at the 4 in position 4 and is billed 5 - 4. Job 3 stops at that same 4 and is billed 12 - 4. Job 4 has nothing after it, so its 4 hours stand.
Example 2
Every job further along the queue is booked for more hours than the one before it, so no job finds a qualifying job and each is billed as booked.
Example 3
Both 12-hour jobs stop at a 3 that follows them and are billed 9. The 3 in position 1 stops at the equal 3 in position 3 and is billed 0, while the last job keeps its 3 hours.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def job_hour_credits(hours: list[int]) -> list[int]:public int[] jobHourCredits(int[] hours)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.