~/problems
Problems
Basics first, then the classics, then company-style assessments. Every problem has tests you run right here; multi-level ones unlock as you go. See the roadmap.
Geometry primitives
Cross product for orientation, segment intersection, convex hull.
Notes
- Cross product:
cross(o, a, b) = (a.x - o.x)*(b.y - o.y) - (a.y - o.y)*(b.x - o.x). Positive means a left turn (counter-clockwise), 0 means collinear. - Segment intersection: use orientation tests plus a collinear/on-segment special case.
- Convex hull (monotone chain): sort the points and build the lower and upper hulls, popping while the turn is not left. O(n log n).
- Max points on a line: for each anchor point, count normalized slopes
(dy/g, dx/g)with the sign fixed.
Gotchas: use integer arithmetic when possible, since floats and slopes cause precision bugs.
5 problems
Advanced & competitive
Geometry Cross products, orientation, polygons.
- Basics: polygon area with the shoelace formula basics py · c++ · java easy
- Which triangular pen is the sheep in? py · c++ · java easy
- Maximum Points on a Line py · c++ · java medium
- Fence around the trees py · c++ · java medium
- Which side of a line? py · c++ · java easy