Dsa
Greedy
Medium
Pizza Slices
You have a pizza that is divided into `n` slices, and each slice has a certain number of toppings. Your goal is to eat the maximum number of toppings by selecting some of these slices, but you can only eat slices that are not adjacent to each other. Write a function that takes in a list of integers representing the number of toppings on each slice and returns the maximum toppings you can eat without selecting adjacent slices.
Input:
The first line contains an integer `n` (1 ≤ n ≤ 100), the number of pizza slices.
The second line contains `n` integers, where each integer represents the number of toppings on that slice (0 ≤ toppings[i] ≤ 100).
Output:
Return the maximum number of toppings you can eat.
Example:
Input:
5
1 2 3 1 5
Output:
8
In this example, you can select slices 2 and 5 to eat a total of 2 + 5 = 7 toppings.
Key concepts
greedyoptimizationarrays
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now