← All questions
MediumCoding

Count Good Meals

Asked atSwiggy
1Give yourself 5 minutes
2Answer out loud, not in your head
3Then compare with the answer below
0
Stuck? Show a way to structure it+
  1. 01Precompute relevant powers of two.
  2. 02Scan values left to right.
  3. 03For each power, add the count of power minus value.
  4. 04Insert the current value after counting.
  5. 05Take modulo after additions.

Reference answer

Then expect these follow-ups

  • How do you choose the highest power safely?

    Tests: follow-up reasoning

  • What changes if sums must be prime instead?

    Tests: constraint adaptation

Free to read · better with Enzo

Practice this out loud with Enzo

Enzo runs it as a mock interview, pushes back with follow-ups, and grades you on the rubric.

Next question