Maximum Cashback From Non-Adjacent Flash Sale Days
Last updated: November 29, 2026
Quick Overview
A seller gets a cashback amount for each day they run a flash sale, but platform rules forbid running sales on two consecutive days. Given the cashback per day, return the maximum total cashback.
Flipkart
November 29, 20260
0
0 solved
A seller gets a cashback amount for each day they run a flash sale, but platform rules forbid running sales on two consecutive days. Given the cashback per day, return the maximum total cashback.
An entry level dynamic programming question used in Flipkart phone screens for new grads. The interviewer checks that you define a clean recurrence, reduce it to O(1) space, and do not fall for a greedy 'pick the biggest days' approach.
What the Interviewer Expects
- Show why greedy picking of the largest values fails
- Define dp[i] as best total using days 0..i
- Write the recurrence dp[i] = max(dp[i-1], dp[i-2] + cash[i])
- Reduce memory to two variables
- Handle empty input and a single day
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you also return which days were chosen?
- What if days form a cycle, so the first and last day are also adjacent?
- What if the rule becomes 'at least two days gap between sales'?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Input: list of non-negative integers, cashback per day.
- Pick a subset of days with no two adjacent to maximize the sum.
- Output: the max sum (0 for no days)....
High-Level Design
Greedy fails: for [6, 10, 6], taking the biggest day (10) blocks both neighbors and yields 10, while days 0 and 2 give 12. Instead define dp[i] = best total using days 0..i. On day i you eithe...