All practice tasks

Coding (Platform)

Normalized query options

fastify · Easy · request validation

A production API needs a normalized query options repair at its service boundary. A catalog screen receives available facet values after every search. The current state boundary keeps selections that no longer exist, so the UI announces filters that cannot affect the visible result.

Task

Implement the normalized query options contract used by the supplied HTTP adapter. Normalize the query, remove unavailable selections, preserve the order of surviving selections, and derive the active-filter count used by the supplied screen adapter.

Contract

Input is {query, selected, available}. Return {query, selected, activeCount}. Values are strings; matching is exact after trimming each selected value. Duplicate selections keep their first position.

Acceptance criteria

  • Trim the query.
  • Drop blank, duplicate, and unavailable selections.
  • Keep the first-seen order.
  • Set activeCount to selected.length plus one when query is non-empty.
  • Return a deterministic JSON-serializable result for the HTTP adapter.

Constraints

  • Do not mutate caller-owned input.
  • Keep the supplied framework adapter and public contract unchanged.
  • Add candidate tests for at least one boundary not covered by the public cases.

Editable files

  • src/repair.js — Task-specific state or service boundary
  • tests/candidate.test.js — Candidate-authored regression

What this task practices

Normalized query options is a coding (platform) interview exercise that trains prompt interpretation, explicit assumptions, a concrete response, and a clear explanation of tradeoffs. The catalog marks it as easy difficulty. It focuses on State Modeling, Regression Testing, Technical Reasoning. 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.