Help Needed

Can this problem be solved using DP? I have an idea for this but couldn’t get an AC
#my idea
def dp(d,k):





if d>=k:


if d>=k-1:




This question doesn’t exibit any DP feature i.e overlapping subproblems and optimal substructure. So, it can’t have a DP solution.

Moreover, DP is an optimization technique applied on maximization, minimization or counting problems. This question just asks whether it has a solution or not.

Yes this question can be treated as DP but real crux of this problem is solving each testcase in O(1).
Treating this question as Knapsack Problem this is the solution by my friend using DP: Solution: 42874088 | CodeChef .

Hope this will be helpful to you!

Just to save your space and typing:

Thank you for your response. But I would like to know why my approach is not working. Can you help me with that

i have also did this problem with dp : Solution: 42873088 | CodeChef,
can you tell the idea to solve in O(1) time