BackmediumStringsCred

Generate Anagrammed IDs Solution

Problem Statement

Given a list of strings representing tool types, a list of strings representing returned statuses, and a list of integers representing collection IDs, generate a list of unique identifiers by anagramming the concatenation of each tool type, returned status, and collection ID.

Example 1
Input
tool_types = ['abc', 'def'], statuses = ['123', '456'], collection_ids = [1, 2]
Output
['abc123', 'bac123', 'cab123', 'def456', 'fed456', 'dfe456']

Explanation: Step 1: Concatenate each tool type, status, and collection ID to form a string. For example, 'abc123' is formed by concatenating 'abc', '123', and 1. Step 2: Generate all permutations of the concatenated string. For 'abc123', the permutations are ['abc123', 'bac123', 'cab123']. Step 3: Collect all unique permutations from each string.

Example 2
Input
tool_types = ['abc', 'def'], statuses = ['123', '456'], collection_ids = [1, 1]
Output
['abc123', 'bac123', 'cab123', 'abc123', 'bac123', 'cab123']

Explanation: Step 1: Concatenate each tool type, status, and collection ID to form a string. For example, 'abc123' is formed by concatenating 'abc', '123', and 1. Step 2: Generate all permutations of the concatenated string. For 'abc123', the permutations are ['abc123', 'bac123', 'cab123']. Step 3: Collect all unique permutations from each string.

Constraints

  • 1 ≤ N ≤ 10^5
  • Each tool name has a maximum length of 10 characters
  • Each status (success/error) is exactly 8 characters long (including the spaces)
  • Each collection ID is a positive integer with up to 6 digits
Live Compiler1 Free Run Available
Loading Editor...
Test Cases & Output
Click "Run" to test your 1 free compile trial!

🚀 Practice this problem

Run code, get AI hints & track streak

Sign Up Free

Generate Anagrammed IDs — Problem Statement & Solution Guide

StringsMediumTOOL RETURNED ID
TimeO(n*m)
|
SpaceO(m)

Problem Description

Given a list of strings representing tool types, a list of strings representing returned statuses, and a list of integers representing collection IDs, generate a list of unique identifiers by anagramming the concatenation of each tool type, returned status, and collection ID.

Examples

Example 1

Input

tool_types = ['abc', 'def'], statuses = ['123', '456'], collection_ids = [1, 2]

Output

['abc123', 'bac123', 'cab123', 'def456', 'fed456', 'dfe456']

Explanation: Step 1: Concatenate each tool type, status, and collection ID to form a string. For example, 'abc123' is formed by concatenating 'abc', '123', and 1. Step 2: Generate all permutations of the concatenated string. For 'abc123', the permutations are ['abc123', 'bac123', 'cab123']. Step 3: Collect all unique permutations from each string.

Example 2

Input

tool_types = ['abc', 'def'], statuses = ['123', '456'], collection_ids = [1, 1]

Output

['abc123', 'bac123', 'cab123', 'abc123', 'bac123', 'cab123']

Explanation: Step 1: Concatenate each tool type, status, and collection ID to form a string. For example, 'abc123' is formed by concatenating 'abc', '123', and 1. Step 2: Generate all permutations of the concatenated string. For 'abc123', the permutations are ['abc123', 'bac123', 'cab123']. Step 3: Collect all unique permutations from each string.

Constraints

  • 1 ≤ N ≤ 10^5
  • Each tool name has a maximum length of 10 characters
  • Each status (success/error) is exactly 8 characters long (including the spaces)
  • Each collection ID is a positive integer with up to 6 digits

Optimal Approach & Strategy

A more efficient approach would be to store the tool names and their corresponding IDs in a hash map. Then, use the map to generate the anagrammed IDs based on the tool name and returned status, resulting in a time complexity of O(n).

Brute Force Approach

A direct approach to solving this problem would be to generate permutations of each tool name with its corresponding status and ID. However, this approach is inefficient with a time complexity of O(n^6) due to the large number of permutations generated.

Verified Code Solutions

No solution currently available for JavaScript. Select another language tab above.

Asked in Top Tech Interviews

Cred

Solve in Interative Editor

Ready to test your code? Open our built-in compiler, run custom test suites, and see detailed complexity analysis reports instantly.