Pizza Discount Days
Updated
Problem statement
A pizza shop has two deals. You may use each deal as many times as you like:
- Two-day deal: buy one pizza on some day and one more pizza on the next day.
- Same-day pair: buy two pizzas on the same day.
You are buying pizzas for n days in a row. On day i (counting from 0) you must buy exactly pizzas[i] pizzas, not more and not fewer. Every pizza you buy must come from one of the deals. A two-day deal cannot start on the last day, because there is no next day.
Return true if you can buy exactly the right number of pizzas on every day using only the deals, and false otherwise.
Function
canBuyWithDeals(pizzas: int[]) → booleanExamples
Example 1
pizzas = [1,3,3,1]return = trueStart a two-day deal on day 0: one pizza on day 0 and one on day 1. Day 1 still needs 2, so buy one same-day pair. Day 2 needs 3: buy one same-day pair and start a two-day deal, which also gives day 3 its single pizza. Every day gets exactly its count, so the answer is true.
Example 2
pizzas = [3,0,1]return = falseDay 0 needs 3 pizzas. Same-day pairs give an even number, so day 0 must start at least one two-day deal. But each two-day deal started on day 0 also gives a pizza on day 1, and day 1 needs 0. So the answer is false.
Example 3
pizzas = [2,3]return = falseA two-day deal cannot start on day 1, the last day. So every deal puts exactly 2 pizzas into days 0 and 1 together: a pair on one day, or a two-day deal on days 0 and 1. The total of the two days is then always even, but 2 + 3 = 5 is odd. The answer is false.
Constraints
1 <= pizzas.length <= 20000 <= pizzas[i] <= 10^4
More Nutanix Online Assessment questions
- Good SubsequencesOA · Seen Jul 2026
- Min Cost to Connect All PointsOA · Seen Jun 2026
- Digit Changes for a Multiple of 9OA · Seen Aug 2025
- Gas Station Loop StartOA · Seen Aug 2025
- Number of Players (for MTS2)OA · Seen Oct 2024
- Work Schedules (for MTS2)OA · Seen Oct 2024
- Minimum Operations to Convert ArrayOA · Seen Apr 2024
- No Adjacent CharactersOA · Seen Apr 2024
- Build a BST From a ListOA · Seen Nov 2022
- Delete Even-Valued Nodes From a Linked ListOA · Seen Nov 2022
Similar questions at other companies
- Catch Fish with Reusable BaitsSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
- Server InvestmentRippling · OARippling interview questions
- Book Reading EveningsGoogle · OAGoogle interview questions
- Maximum Apples That Fit in a BoxVirtu Financial · OAVirtu Financial interview questions
- Minimum Project Bid CostNVIDIA · OANVIDIA interview questions
- Minimum AmountBelvedere Trading · OA
- Maximum Income from Asset TradingJefferies · OA
- Maximum Three-Server Difficulty ScoreVisa · OAVisa interview questions
- Economical TripAccenture · OAAccenture interview questions
- Best Time to Buy and Sell StockFlexTrade · OAFlexTrade interview questions