There are exactly two assignments of the cushions. Their resulting seat heights are either and , or and .
Print Yes if either pair is equal. Otherwise print No.
These assignments include every way to use both cushions with one cushion on each chair. Therefore the algorithm accepts exactly when an allowed assignment gives equal heights.
Time and extra space: .
A common mistake is checking only the first assignment. Equal chair heights alone are also insufficient when the cushions have different thicknesses.