392. Generate Word Card Codes
Generate Word Card Codes

A word game arranges several different word cards from left to right. Generate all possible word card codes by choosing exactly one character from each word.

Characters in every code must follow the order of the word cards. Return the codes in the order obtained by considering the characters of each word from left to right.

Method Signature

List<String> generateWordCardCodes(List<String> wordCards)

Parameters

  • wordCards: The words displayed on the cards in their left-to-right order.

Returns

A list containing every code that can be created by choosing one character from each word.

Constraints

  • 1 ≤ wordCards.size() ≤ 4
  • 3 ≤ wordCards.get(i).length() ≤ 4
  • All words in wordCards are different.
  • Each word contains only lowercase English letters.
  • Every character appears at most once within the same word.

Examples

Example 1

generateWordCardCodes(wordCards = ["ace", "fit"])

Returns ["af", "ai", "at", "cf", "ci", "ct", "ef", "ei", "et"].

One character is selected from "ace", followed by one character from "fit".

Example 2

generateWordCardCodes(wordCards = ["lamp"])

Returns ["l", "a", "m", "p"].

Example 3

generateWordCardCodes(wordCards = ["dog", "rice"])

Returns ["dr", "di", "dc", "de", "or", "oi", "oc", "oe", "gr", "gi", "gc", "ge"].



Please use Laptop/Desktop or any other large screen to add/edit code.