All practice tasks

Coding (Algo)

Count the Outer Boundary Corners

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

4

Example 2

{
  "points": [
    [
      0,
      0
    ],
    [
      1,
      1
    ],
    [
      2,
      2
    ],
    [
      1,
      1
    ]
  ]
}

Returns

2

Required complexity

O(n log(n + 1)) time and O(n) auxiliary space

What this task practices

Count the Outer Boundary Corners is a coding (algo) interview exercise that trains prompt interpretation, explicit assumptions, a concrete response, and a clear explanation of tradeoffs. The catalog marks it as hard difficulty. It focuses on Technical Reasoning, Testing, Validation. The signed-in workspace provides the tools for the round and evaluates the attempt against task-specific criteria. Reference solutions, hidden checks, evaluator instructions, and candidate work remain private.

Sign in to startThe workspace and evaluation open after sign in.