Geometric Algorithms IV

Geometric problems are hard (even when they are labeled as “medium” in LC). The complications arise primarily from the floating-point calculations, over and underflow, as well as the precise equations that one must come up with. This problem Separate Squares I - LeetCode requires a binary search in space 10^9. For each iteration, we calculate the areas above and below. Hence the total time is of the order LogN * N. But there are a few things to keep in mind: 1/ Start by transforming all the input from int to double. This will avoid any over and underflow calculation 2/ Break down into smaller subroutines, for debugging 3/ Remember that when dealing with floating-points, to say that A == B, what you really need to do is ensure that |A – B| <= T where T is some threshold (in our case T = 0.00001) You can use LLM such as OpenAI ChatGPT o1 (with advanced reasoning) for debugging. For example, you can ask it to plot some input in a Cartesian System for debugging purp...