Approach #1: Hash Set [Accepted]
If a card has the same value
x on the front and back, it is impossible to win with
x. Otherwise, it has two different values, and if we win with
x, we can put
x face down on the rest of the cards.
Remember all values
same that occur twice on a single card. Then for every value
x on any card that isn't in
x is a candidate answer. If we have no candidate answers, the final answer is zero.
Time Complexity: , where is the length of
backs). We scan through the arrays.
Space Complexity: .
Analysis written by: @awice.