Official algorithmic problem description and constraints.
Sofia had an array of π integers π1,π2,β¦,ππ. One day she got bored with it, so she decided to sequentially apply π
π modification operations to it.
Each modification operation is described by a pair of numbers β¨ππ,ππβ© and means that the element of the array with index ππ should be assigned the value ππ, i.e., perform the assignment πππ=ππ. After applying all modification operations sequentially, Sofia discarded the resulting array.
Recently, you found an array of π
π integers π1,π2,β¦,ππ. You are interested in whether this array is Sofia's array. You know the values of the original array, as well as the values π1,π2,β¦,ππ. The values π1,π2,β¦,ππ turned out to be lost.
Is there a sequence π1,π2,β¦,ππ such that the sequential application of modification operations β¨π1,π1,β©,β¨π2,π2,β©,β¦,β¨ππ,ππβ© to the array π1,π2,β¦,ππ transforms it into the array π1,π2,β¦,ππ?
Detailed video explanations, mathematical intuition, and clean C++ implementation code.