Correctness, Invariants & Design

Answer & solution
Answer: B with constant extra space; A also possible with a stack (no official key was published)
1. Scanning right to left while retaining the largest value seen reports exactly the elements strictly larger than every element to their right. This is Θ(n) time and O(1) extra working space, yielding the usual B.
2. However A is also achievable in linear time if extra storage is allowed: scan left to right, keep candidate leaders in a decreasing stack, and pop every prior candidate≤the new value before pushing it. Each entry is pushed/popped at most once; the final stack contains the leaders.
3. Since the prompt does not require constant space, traversal direction alone does not make B uniquely correct.
4. Teaching check: Right-to-left scanning initializes the current maximum with the rightmost element and reports a new element only when it is strictly greater. Equal values do not become leaders if an equal value occurs later. A left-to-right monotone stack is a separate linear-time possibility, explaining the nonunique direction-only options.