• + 0 comments

    My golang solution.... It doesn't pass all the test cases. Can anyone spot the logic error?

    Thanks in advance

    func poisonousPlants(p []int32) int32 {
    	// Write your code here
    	var days int32
    	isDead := make([]bool, len(p))
    	var aPlantDied bool
    
    	aPlantDied = true
    
    	for aPlantDied {
    		aPlantDied = false
    		for idx := len(p) - 1; idx > 0; idx-- {
    			if p[idx-1] < p[idx] && !isDead[idx-1]  {
    				isDead[idx-1] = true
    				aPlantDied = true
    			} else {
    				continue
    			}
    		}
    		days++
    	}
    
    	return days
    
    }
    	return days
    
    }