Sorting · Hard
A geometry tool outlines the smallest convex region containing a set of recorded locations. Its export lists only corner vertices, not duplicate records or intermediate points along a straight boundary edge. The task is geometric computation, not a UI or map integration.
Return the number of distinct convex-hull vertices after excluding duplicate coordinates and collinear interior points.
Input
Call
- Implement solve(input) and return the result. The provided adapter handles JSON input and output.
Input shape
{ points: [integer, integer][] }
Fields
- points contains two-dimensional integer coordinates [x,y] in arbitrary order. Duplicate coordinates may occur at different indexes.
Output
Return value
- Return an integer vertex count. Zero, one or two distinct points return that same count.
- If all points are collinear and at least two are distinct, return two. Exclude points lying between the endpoints of a straight hull edge.
Constraints
- 0 <= points.length <= 100000; coordinates are integers from -1000000 to 1000000.
- Squared distances and cross products fit safe JSON integers. Do not mutate points or its nested pairs.
Examples
Example 1
{
"points": [
[
0,
0
],
[
2,
0
],
[
2,
2
],
[
0,
2
],
[
1,
0
],
[
1,
1
]
]
}Returns
4Example 2
{
"points": [
[
0,
0
],
[
1,
1
],
[
2,
2
],
[
1,
1
]
]
}Returns
2Required complexity
O(n log(n + 1)) time and O(n) auxiliary space