Back to problems

Remove All Adjacent Duplicates in String II

Algorithm · ByteDance · Medium

You are given a string s together with an integer k. Whenever the current string contains a run of k consecutive, identical characters, that whole run may be deleted. Once a run is removed, the characters that were on its left and right become neighbors, which can in turn form a fresh run of k equal characters. Apply this deletion rule over and over, for as long as any qualifying run exists, and return whatever string is left when no run of k equal adjacent characters…

Checking your access…