Code RoomCommand line argument parsing
EasyPrep Room Coding #4740

Command line argument parsing

CodingAlgorithms & data structuresEntry–Mid~16 min

A deploy tool reads its own argument vector rather than pulling in a parser. Scan argv left to right. A token that is exactly "--" closes option scanning, and every token after it is a plain argument. Until then: a token starting with "--" is a long option, where "--name=value" splits on its first "=" only (the value may be empty) and "--name" alone is worth "true"; a token starting with a single dash and holding at least one more character is a bundle whose every remaining character is a switch worth "true". Anything else, a lone "-" included, is a plain argument and sets nothing. Setting a name twice keeps the newer value at the older position. Return one "name=value" string per distinct name, ordered by where each name first appeared.

Implement
resolve_cli_options(argv: list[str]) → list[str]
Examples
in[["deploy","--env=staging","-vq","--dry-run","--","--force","app.zip"]]out["env=staging","v=true","q=true","dry-run=true"]
in[["--tag=rc1","--tag=rc2","-t"]]out["tag=rc2","t=true"]
in[["--path=/opt/tools=bin"]]out["path=/opt/tools=bin"]
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 16 min
InputExpectedGot
[["deploy","--env=staging","-vq","--dry-run","--","--force","app.zip"]]["env=staging","v=true","q=true","dry-run=true"]not run yetsample
[["--tag=rc1","--tag=rc2","-t"]]["tag=rc2","t=true"]not run yetsample
[["--path=/opt/tools=bin"]]["path=/opt/tools=bin"]not run yetsample