Dsa
Strings
Medium
Semantic Version Maximizer
A log file contains various strings. Some are valid semantic versions in the format 'MAJOR.MINOR.PATCH' (e.g., 1.12.3). MAJOR, MINOR, and PATCH are non-negative integers. Extract all valid versions from the text (they are delimited by spaces or start/end of string) and print the highest one according to versioning rules (compare MAJOR, then MINOR, then PATCH).
Example:
Input: v1.2.3 version 1.10.0 update 1.10.2-beta
Output: 1.10.0
(Note: 1.10.2-beta is invalid because of the hyphen; only X.Y.Z is allowed.)
Key concepts
parsingsortingregex-like
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now