Code RoomConstant-time string equality
EasyPrep Room Coding #1554

Constant-time string equality

CodingSecurityEntry–Mid~12 min

Implement a constant-time string equality check used to compare secrets (tokens, MACs) without leaking timing. Given two strings `a` and `b`, return True if they are equal. Your comparison must not short-circuit on the first differing character; if the lengths differ you may return False immediately (length is not secret here). Do not use Python's built-in `==`, `hmac`, or `secrets` comparison helpers.

Implement
constant_time_equal(a: str, b: str) → bool
Examples
in["abc","abc"]outtrue
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 12 min
InputExpectedGot
["abc","abc"]truenot run yetsample