Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Remove Stars and Left Characters
00:00
5 left

Remove Stars and Left Characters

MediumPython

Problem

Given a string, remove all stars and the character to the left of each star (e.g., 'ab*c' becomes 'ac').

Process the string from left to right. When a star appears, remove the nearest character that remains in the result, if one exists, and do not include the star.

Input and Output

Implement remove_stars(s), which accepts a string and returns the resulting string. The input contains lowercase English letters and * characters.

Constraints

  • 1 <= len(s) <= 10^5
  • s contains only lowercase English letters and *
  • A star with no surviving character to its left is simply removed

Function Signature

def remove_stars(s):
Interviewer

Your question is Remove Stars and Left Characters. Start with the requirements in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePython 3
You need to log in / sign up to run or submit.Ln 2
Run your code to see test output here.