Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Remove Anagrams From Strings

MediumPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Remove Anagrams From Strings. Start with the requirements on the right.

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.

Problem

BILL may normalize word sequences while processing labels in BILL Spend & Expense. Given a list of lowercase strings, remove every string that is an anagram of the immediately preceding retained string. Preserve the first string from each consecutive anagram group and keep the original order.

Two strings are anagrams when they contain the same characters with the same frequencies, regardless of order.

Formal Specification

Implement remove_anagrams(words), where words is a list of lowercase strings. Return a new list containing the first word from each consecutive group of anagrams. The original spelling and order of retained words must be preserved. An empty input must return an empty list.

Constraints

  • 0 <= len(words) <= 10^4
  • 1 <= len(words[i]) <= 20
  • Each string contains only lowercase English letters
  • Return a new list without modifying the input

Function Signature

def remove_anagrams(words):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output