Code RoomMatch wildcard certificates
EasyPrep Room Coding #4808

Match wildcard certificates

CodingAlgorithms & data structuresEntry–Mid~14 min

An edge proxy checks whether it already holds a certificate for an arriving request. patterns lists the hostnames the installed certificates cover, and hosts lists the hostnames requests came in on. A hostname is one or more labels joined by dots, and every label is a non empty run of lowercase letters, digits or hyphens. The leftmost label of a pattern may be exactly one asterisk. No other label of a pattern is an asterisk, and no host carries one. A pattern with no asterisk covers a host only when the two read identically. A wildcard pattern covers a host when the host has the same number of labels and every label after the leftmost is identical, so "*.example.com" covers "api.example.com" but covers neither "example.com" nor "eu.api.example.com". Return one boolean per host, in the order given, true when at least one pattern covers that host.

Implement
cert_host_coverage(patterns: list[str], hosts: list[str]) → list[bool]
Examples
in[["*.example.com","example.com"],["api.example.com","example.com","eu.api.example.com","example.org"]]out[true,true,false,false]
in[["cdn-1.assets.net","*.assets.net"],["cdn-1.assets.net","cdn-2.assets.net","assets.net"]]out[true,true,false]
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 14 min
InputExpectedGot
[["*.example.com","example.com"],["api.example.com","example.com","eu.api.example.com","example.org"]][true,true,false,false]not run yetsample
[["cdn-1.assets.net","*.assets.net"],["cdn-1.assets.net","cdn-2.assets.net","assets.net"]][true,true,false]not run yetsample