Editorial for SAC '22 Code Challenge 5 P2 - Querying Extensions


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.

Author: maxcruickshanks

Subtask 1

It suffices to hard code the output for every N and left or right.

Time Complexity: O(1)

Subtask 2

Realize that this is a parity problem:

  1. If N1(mod2), then the output is the same as the original swaying direction.
  2. Otherwise, if N0(mod2), then the output is the opposite of the original swaying direction.

Output the direction based on the two cases.

Time Complexity: O(1)


Comments

There are no comments at the moment.