Given n triangles (3 coordinates each) that tile a 2D region without overlap, write a function that returns the triangle containing a query point, or -1.
Asked in the round 4 stage. For SQL, evaluate all rows in query_points against the triangles in triangles. Points on shared boundaries should be assigned to the lowest matching triangle_id; incomplete query coordinates should return -1.
point_id and triangle_id-1 when no triangle contains the pointpoint_id ascending| Column | Type | Description |
|---|---|---|
| triangle_idPK | INT | Unique triangle identifier |
| x1 | NUMERIC | X coordinate of the first vertex |
| y1 | NUMERIC | Y coordinate of the first vertex |
| x2 | NUMERIC | X coordinate of the second vertex |
| y2 | NUMERIC | Y coordinate of the second vertex |
| x3 | NUMERIC | X coordinate of the third vertex |
| y3 | NUMERIC | Y coordinate of the third vertex |
| Column | Type | Description |
|---|---|---|
| point_idPK | INT | Unique query point identifier |
| x | NUMERIC | X coordinate of the query point |
| y | NUMERIC | Y coordinate of the query point |