I was just working on an easy "Can Place Flowers" problem (https://leetcode.com/problems/can-place-flowers). I thought it was a simple DP problem, where I would just iterate the given list, and choose between planting or not planting a flower at position i. But this is actually a problem you solve with a greedy approach.
My question is, how do you know when to use dynamic programming vs. just a greedy approach like this one? How come this doesn't need dynamic programming? In other words, I'm confused why such a greedy approach works for this problem. I'd appreciate it a lot if anyone explained their intuition for such a problem.