Compare two programs for equivalence
OptiverQuantitative Trader · Online AssessmentLast updated
This question evaluates program-equivalence reasoning skills, including understanding of language semantics (mutation, ordering stability, integer overflow/underflow, integer-division behavior), competency in comparing time and space complexity, and the ability to design property-based tests and edge cases.
You are given two short programs (or functions) that process an integer array A (|A| ≤ 10^ 5). Determine whether they are functionally equivalent for all valid inputs under specified preconditions (e.g., 32-bit signed arithmetic with overflow defined or prohibited). If they are not equivalent, produce a concrete counterexample input. Compare their time and space complexities, identify hidden differences (such as mutation, stability of ordering, overflow/underflow behavior, integer division semantics), and design a set of property-based tests and edge cases to validate your conclusion.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.