Once again not an easy question (TLE on brute force) + English is horrible - lets fix this please.


  • -1
    G

    I used a naive o(n^2) solution for this and got TLE. This indicates that this is not an easy problem.
    It should be classified as medium.


  • 0

    @galster Actually, the problem is labeled as easy because the locations of heaters are already given, so the nearest heater from a house can be immediately determined by looking at left and right via binary search.

    If we generalize the input by only giving the number of heaters without specifying their locations (which means you have to wisely pick good locations), that would probably be a medium problem. Actually, someone was asked this generalized problem in real interview. I have posted the generalized version in this post.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.