@DanielDong This solution is basically doing one range max query per square. To speed it up just replace the linear algorithm for rmq with a segment tree. However there are two twists (1) The update here is for a range, not a single point so the usual update routine needs to be modified to keep the log runtime. (2) The coordinates can go up to 10^8 and the segment tree will blow up memory. Meanwhile since there are fewer than 1000 squares we can "compress" the coordinates. I see some BST based solutions that are very elegant but in a real interview, I might just go head and do the segment tree because it's more intuitive. Again, a quadratic solution probably won't cut it in an interview - you'll surely be asked to improve it.