You are not logged in. Please login at to post your questions!


MAXCANDY - Editorial

Maximum Candies

Tags: Dynamic Programming, Recursion with memoization.


Author: Shami.
Tester: Kaustav

It may be tempting to solve this problem with greedy strategy but, as the example shows, it gives the wrong answer.

To reach (i, j), there are two options (i-1, j) or (i, j-1) (for legal values of i and j). Let’s just iterate through both of them and take the maximum.

Just don’t forget to cache the values, or it will become an exponential time algorithm!

Top Down (Recursion with memoization)

Bottom up (DP)

asked 12 Jan, 14:09

mmmreddy's gravatar image

accept rate: 0%

toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:


question asked: 12 Jan, 14:09

question was seen: 110 times

last updated: 12 Jan, 14:09