Oracle | Candy Crush 1D variation

Difficulty: MEDIUMCategory: InterviewExperienceFrequency: 1Asked On 2020-07-26Added By Anonymous
Source: Link

Company: Oracle
Role: ic-1, ic-2
Interview Stage: Phone Screen
Location: unknown
Year: unknown

Original Post Content:

~~Edit: Found it, thanks @nitindhemiwal : https://www.Geeks4Geeks.org/recursively-remove-adjacent-duplicates-given-string/~~

Edit2: Actually it's not it, we want the shortest, not just any.

---

A friend had this question in an Oracle interview:

Input: An array of characters, example: [a,a,b,b,b,a,c]
Ouput: Smallest length reduced form after removing duplicates step by step: [c]

aabbbac ---remove all b---> aaac ---remove all a---> c
abccbaa ---remove all c---> abbaa ---remove all b---> aaa --> ""
aabccba ---remove all c---> aabba ---remove all b---> aaa -> []
aabbcca -> aacca -> aaa -> ""
aaaacddddcappp -> aaaaccappp -> aaaaappp -> ""

Does anyone know if it's similar to an existing leetcode question? I couldn't find the solution, but interviewer hinted that it's about using a stack.

Comments