Code RoomSemantic version comparison
HardPrep Room Coding #319

Semantic version comparison

CodingNetworking & APIsMid–Senior~28 min

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.

0:00 of about 28 min
InputExpectedGot
["1.0.0","1.0.1"]-1not run yetsample