FastPrepFastPrep
Problem Brief

Remove Anagram 🍋

INTERNOA
See Amazon online assessment and hiring insights

A collection of distinct item identifiers must be retrieved from a repository of merchandise listed on Amazon’s platform. In the dataset, duplicate variations of the item IDs exist where the sequence of letters differs (e.g., "code" and "ecode" refer to the same product). To generate the unique set, all anagram duplicates should be eliminated. Two words are considered anagrams if they contain the same characters in the same frequencies, just arranged differently. For instance, "aaagmnrs" is an anagram of "anagrams". Given an array of strings, filter out every entry that is an anagram of a preceding entry, then provide the resultant list in alphabetically sorted order.

Design a method that returns the refined list of strings after discarding anagram duplicates in sorted sequence.

Function Description

Complete the function removeAnagram in the editor below.

removeAnagram has the following parameter:

  1. inputStrings, a list of strings representing product IDs.

Returns

String Array

Note: Each string inputString[i] is made up of characters in the range ASCII[a-z].

1Example 1

Input
inputStrings = ["code", "doce", "ecod", "framer", "frame"]
Output
["code", "frame", "framer"]
Explanation
"code" and "doce" are anagrams since they contain the same letters in a different order. The function keeps the first occurrence ("code") and removes "doce". "code" and "ecod" are also anagrams. The algorithm retains the first instance ("code") and discards "ecod". "code" and "framer" are not anagrams (different letters), so both remain in the list. "framer" and "frame" are not anagrams because "framer" has an extra 'r'. Thus, both stay in the final list. Finally, the remaining strings are sorted in ascending order, resulting in: ["code", "frame", "framer"].

Constraints

Limits and guarantees your solution can rely on.

  • 0 <= num <= 1000
  • 0 <= m <= num; where m represents the size of output list
  • 1 <= length of inputStrings[i] <= 1000
  • 0 <= i < num
  • public String[] removeAnagram(String[] inputStrings) {
      // write your code here
    }
    
    Input

    inputStrings

    ["code", "doce", "ecod", "framer", "frame"]

    Output

    ["code", "frame", "framer"]

    Sign in to submit your solution.