### SRM 704, D2, 250-Pointer (SwapAndArithmetic)

### James S. Plank

Fri Feb 3 14:42:38 EST 2017

Try this on your own. If you get stuck, return here and read what I've written below.

If you're here, think about how much easier the problem is if you sort the
input. Now, go back and try to solve it again, and if you get stuck again,
come back.

What you want to do is sort the vector. You can do that most easily with the
**sort()** method from the STL **algorithms** library. You need to
include **algorithms**, and then you can sort the vector with **sort(x.begin(), x.end())**.
Then, the easiest thing to do is try to discover if the vector is not an arithmetic
sequence.
The way that I did that was to:

- First return "Possible" if
**x** only has one element.
- Then, I stored the difference between the first two elements of
**x** into a
variable **diff**.
- Then, I checked every adjacenct pair of elements in
**x**. If the difference
between any of these is *not* equal to **diff**, then you can return "Impossible."
- If you have checked all adjacenct pairs of elements, then you can return "Possible."