Practice Maximum Fruits Harvested After at Most K Steps
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Maximum Fruits Harvested After at Most K Steps
Problem Statement
Fruits are available at some positions on an infinite x-axis. You are given a 2D integer array fruits where fruits[i] = [positioni, amounti] depicts amounti fruits at the position positioni. fruits is already sorted by positioni in ascending order, and each positioni is unique. You are also given an integer startPos and an integer k. Initially, you are at the position startPos. From any position, you can either walk to the left or right. It takes one step to move one unit on the x-axis, and you can walk at most k steps in total. For every position you reach, you harvest all the fruits at that position, and the fruits will disappear from that position. Return the maximum total number of fruits you can harvest.
Source: Maximum Fruits Harvested After at Most K Steps on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
fruits = [[2,8],[6,3],[8,6]], startPos = 5, k = 4
9
# Example 2
fruits = [[0,9],[4,1],[5,7],[6,2],[7,4],[10,9]], startPos = 5, k = 4
14
# Example 3
fruits = [[0,3],[6,4],[8,5]], startPos = 3, k = 2
0
Constraints
Related LeetCode Problems
Practice more problems similar to Maximum Fruits Harvested After at Most K Steps.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.