Back to problems

Lexicographically Smallest String After Substring Operation

Algorithm · Point72 · Medium

You are handed a string s that contains nothing but lowercase English letters. Pick any non-empty substring of s — a contiguous run of one or more characters — and then move every character inside that run one letter earlier in the alphabet, applying the change exactly once to each character: for instance, 'b' turns into 'a' and 'c' turns into 'b'. The alphabet is circular, so stepping 'a' backward produces 'z'. Characters located outside the chosen run are left completely…

Checking your access…