1001. Constant-Time String Compare

Hard · String

Implement a constant-time string comparison.

Why: a naive == short-circuits at the first differing byte. An attacker can measure the response time and leak the secret one byte at a time. Your function must always inspect every byte and finish in time proportional to the string length, not where the strings diverge.

Input (stdin, JSON): { "a": "abc123def", "b": "abc124def" }

Output (stdout): "true" if the strings are byte-identical, else "false".

Constraints: do not return early on mismatch. Aim for one pass.

Examples

Example 1
Input: {"a":"hello","b":"hello"}
Output: true
Explanation: Identical strings.
Example 2
Input: {"a":"hello","b":"hellp"}
Output: false
Explanation: Differ in last char.

Constraints