Code RoomValidate certificate chain
EasyPrep Room Coding #4818

Validate certificate chain

CodingSecurityAlgorithms & data structuresEntry–Mid~16 min

A deployment tool inspects the certificate chains its services present before it will trust them. Each chain is a list of entries written as a subject name, a greater-than sign, then the name of the issuer that signed that subject, for example leaf>intermediate. Names never contain a greater-than sign and are compared exactly. A chain is in order when the issuer named by every entry is the subject of the next entry, and the last entry is self-issued, meaning its subject and its issuer are the same name. Return one verdict per chain in the order the chains arrive: empty for a chain holding no entries, ordered when the chain is in order, reversed when reversing the entries would put it in order, unanchored when the entries link correctly but the final one is not self-issued, and broken for anything else. Test those verdicts in that order.

Implement
chain_order_report(chains: list[list[str]]) → list[str]
Examples
in[[["leaf>intermediate","intermediate>root","root>root"],["root>root","intermediate>root","leaf>intermediate"],["leaf>intermediate","intermediate>root"]]]out["ordered","reversed","unanchored"]
in[[["api.example>issuing-ca","issuing-ca>root-ca","root-ca>root-ca"],["api.example>issuing-ca","other-ca>root-ca","root-ca>root-ca"],[]]]out["ordered","broken","empty"]
in[[["mid>root","leaf>mid"]]]out["broken"]
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
[[["leaf>intermediate","intermediate>root","root>root"],["root>root","intermediate>root","leaf>intermediate"],["leaf>intermediate","intermediate>root"]]]["ordered","reversed","unanchored"]not run yetsample
[[["api.example>issuing-ca","issuing-ca>root-ca","root-ca>root-ca"],["api.example>issuing-ca","other-ca>root-ca","root-ca>root-ca"],[]]]["ordered","broken","empty"]not run yetsample
[[["mid>root","leaf>mid"]]]["broken"]not run yetsample