@Himanshu I wrote something similar but just adding a case. If we set flowerbed[idx] = 1 then can directly jump to idx + 2 position. Wecan observe the increase in run time.

public class Solution { public boolean canPlaceFlowers(int[] flowerbed, int n) { for(int idx=0; idx<flowerbed.length && n > 0; idx++) { if(flowerbed[idx]==0 && (idx == 0 || flowerbed[idx-1]==0) && (idx == flowerbed.length-1 || flowerbed[idx+1]==0)) { n--; flowerbed[idx]=1; idx++; } } return (n == 0); } }Can Place Flowers