Google Online Assesment Question - SWE 2021

Minimum Difference

Given a string of 'b's and 'w's. We can take as many characters as we want from the start and can append it in end of string, but sequence of characters should remain same. What can be minimum number of characters we need to flip('b' to 'w' or 'w' to 'b') in order to make string an alternate sequence of 'b's and 'w's , i.e. "bwbwbwbwb" or "wbwbw" ...

TestCases :

  • "wwb" - 0
  • "bwwwbbbbb" - 3
  • "wwwwwbbww" - 3
  • "bbwbww" - 2
  • "bww" - 0
  • "wbbww" - 1

I don't remember other test cases. If anyone have detailed question please share. Feel free to share your approaches.

Comments (1)