Code Room
CodingHardcod-g1147
Subject Networking protocolsLevel Mid–Senior~28 minCommon in Networking & APIs interviewsIndustries Software development, IT services

Question

Implement Semantic Versioning precedence comparison. Each version is 'MAJOR.MINOR.PATCH' optionally followed by '-' and a prerelease string of dot-separated identifiers. Compare core numbers numerically left to right. A version WITH a prerelease has LOWER precedence than the same core WITHOUT one. Prerelease identifiers compare left to right: numeric identifiers compare numerically and rank below alphanumeric ones; alphanumeric compare lexically; if all shared identifiers are equal, the version with MORE identifiers is greater. Return -1, 0, or 1 for v1 < v2, ==, or >.

Implement
semver_compare(v1: str, v2: str) → int
Examples
in["1.0.0","1.0.1"]out-1
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.