Skip to content

Practice Eat Pizzas!

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#3457
LeetCode Problem

Eat Pizzas!

Problem Statement

Divide all pizzas into groups of four, eating one group per day. For a group sorted as W <= X <= Y <= Z, gain Z on odd-numbered days, starting with day 1, and Y on even-numbered days. Every pizza is used once and the number of pizzas is divisible by four. Return the maximum total weight gain.

Source: Eat Pizzas! on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
pizzas = [1,2,3,4,5,6,7,8]
Output
14

# Example 2

Input
pizzas = [2,1,1,1,1,1,1,1]
Output
3

Constraints

4 <= n == pizzas.length <= 2 * 10^5
1 <= pizzas[i] <= 10^5
n is a multiple of 4.

Related LeetCode Problems

Practice more problems similar to Eat Pizzas!.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.