How do I create array of objects of alternating color?
Array modifier has a UV offset option. If you shift each instance by one in U in the modifier:

then, you can use this information in the shader:

In this example, the step value is 5.
We divide X from the UV by five, take the floor of the division then modulo it by two to alternate the colors.
So that: