Maximize Fish over Limited Hours
Updated
Problem statement
You are given initial hourly fish yields yields for several ponds and a number of fishing hours hours. In each hour, choose exactly one pond, collect its current yield, and decrease that pond's future yield by one without going below zero.
Return the maximum total fish that can be collected. Your solution should combine the work for whole yield levels instead of using a heap to simulate one hour at a time.
Function
maximizeFish(yields: int[], hours: long) → longExamples
Example 1
yields = [90,100]hours = 100return = 7075The optimal schedule always takes a currently largest yield; aggregating the top one hundred available positive yields gives 7075.
Example 2
yields = [2,1]hours = 5return = 4The positive collections are 2, 1, and 1; remaining hours contribute zero.
Constraints
1 <= yields.length <= 2000000 <= yields[i] <= 10000000001 <= hours <= 100000000000000- The answer fits signed 64-bit arithmetic.
More ByteDance Phone Screen questions
- Largest Number Below N from Reusable DigitsPHONE SCREEN · Seen Nov 2026
- Log Analyzer: Busiest Service in a Rolling WindowPHONE SCREEN · Seen Nov 2026
- Majority ElementPHONE SCREEN · Seen Nov 2026
- Valid ParenthesesPHONE SCREEN · Seen Nov 2026
- Binary Tree Target-Sum PathsPHONE SCREEN · Seen Nov 2026
- Longest Increasing SubsequencePHONE SCREEN · Seen Nov 2026
- Alien DictionaryPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Lexicographically Smallest Topological OrderPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Maximum Number of Events That Can Be AttendedPHONE SCREEN · Seen Nov 2026
- Implement Multi-Head AttentionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Aggressive CowsAmazon · PHONE SCREEN
- Maximize the Minimum Cone DistanceSumo Logic · PHONE SCREEN
- Minimize Maximum Group DifferenceDRW · OADRW interview questions
- Minimum-Cost Solar Rooftop AllocationDeloitte · OADeloitte interview questions
- Maximize Number of Produced CarsMicrosoft · OAMicrosoft interview questions
- Aggressive CowsPeopleStrong · OAPeopleStrong interview questions
- Spread Cows Across StallsExpedia · OAExpedia interview questions
- Split Array to Minimize the Largest SumNation with NaMo · PHONE SCREEN
- Median Across Sorted ArraysGoogle · PHONE SCREENGoogle interview questions
- IPOTekion · PHONE SCREENTekion interview questions
ByteDance interview experiences
- ByteDance TikTok USDS SWE Intern Interview: 1 Experience
- ByteDance MLE New Grad Interviews: 1 Experience
- ByteDance Security SRE Intern Phone Screens: 1 Experience
- ByteDance USDS New Grad SWE Phone Screen: 1 Experience
- ByteDance New Grad Data Engineer Video Interviews: 1 Experience
- ByteDance Trust & Safety Research Scientist Intern: 1 Experience