If the difference between any two consecutive elements of the prefix array is greater than 1 then there will be no such string possible that satisfies the given array Also , string cannot have more than 26 distinct characters
if ( diff > 1 diff < 0 A [ i ] > 26 ) { S = " - 1" ; return S ; }