class Questions::Issue20260309


Question

Given a string s consisting only of ‘a’ and ‘b’, you may swap adjacent characters any number of times. Return the minimum number of adjacent swaps needed to transform s into an alternating string, either “ababab…” or “bababa…”, or return -1 if it’s impossible.