DEV Community

Cover image for [Devmates.co] Candy Crash 📈Bloomberg
Alex Wawl 🐼
Alex Wawl 🐼

Posted on

1 1

[Devmates.co] Candy Crash 📈Bloomberg

Hello👋,
My name is Alex and I'm maker of Devmates.co. 😊

We are resolving daily coding problems which asked by top tech companies together. We share our solutions, give some help if anyone stuck, support each other and just hangout together in the internet. 🍻☕️💬

I get this problem from our members or just searching them in the internet(leetcode forums, Glassdoor, teamblind, etc.). Sometimes this problem can be very easy, sometimes too 👷‍♂️hard, everything depends on skills but we are trying to resolve all of them and Have Fun. 🙌

Today I want to share problem which was asked by 📈Bloomberg.

Problem:

Given a string, reduce the string by removing 3 or more consecutive identical characters. You should greedily remove characters from left to right.

Example:

Input: "aaabbbc"
Output: "c"
Why?:

  1. Remove 3 'a': "aaabbbc" => "bbbc"
  2. Remove 3 'b': "bbbc" => "c"

Input: "aabbbacd"
Output: "cd"
Why?:

  1. Remove 3 'b': "aabbbacd" => "aaacd"
  2. Remove 3 'a': "aaacd" => "cd"

Input: "aabbccddeeedcba"
Output: ""
Why?:

  1. Remove 3 'e': "aabbccddeeedcba" => "aabbccdddcba"
  2. Remove 3 'd': "aabbccdddcba" => "aabbcccba"
  3. Remove 3 'c': "aabbcccba" => "aabbba"
  4. Remove 3 'b': "aabbba" => "aaa"
  5. Remove 3 'a': "aaa" => ""

Input: "aabbccddeeedcba"
Output: ""
Why?:

  1. Remove 3 'e': "aabbccddeeedcba" => "aabbccdddcba"
  2. Remove 3 'd': "aabbccdddcba" => "aabbcccba"
  3. Remove 3 'c': "aabbcccba" => "aabbba"
  4. Remove 3 'b': "aabbba" => "aaa"
  5. Remove 3 'a': "aaa" => ""

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

AWS Q Developer image

Your AI Code Assistant

Generate and update README files, create data-flow diagrams, and keep your project fully documented. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE