How to build a string with no repeating character from three (or N) separate list of characters?

kanjiowl

I have been working on a problem that can be described as the following.

You are given 3 lists of characters.

L1 = [a,b ,c,d ]

L2 = [e,f ,g ,a]

L3 = [m, n, o, g, k]

How many strings can you make by taking a character from each list?

You are allowed to pick only one character from each list (length of the string should be 3). The resultant string should not have any characters repeating. Each list is guaranteed to be containing unique letters. The order of list you pick from does not matter.

Nina Scholz

You could create the Cartesian product of multiple arrays and then filter the array by counting unique items in a set.

var data = [['a', 'b', 'c', 'd'], ['e', 'f', 'g', 'a'], ['m', 'n', 'o', 'g', 'k']],
    result = data
        .reduce((a, b) => a.reduce((r, v) => r.concat(b.map(w => [].concat(v, w))), []))
        .filter(a => new Set(a).size === a.length);

console.log(result.map(a => a.join(' ')));
.as-console-wrapper { max-height: 100% !important; top: 0; }

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to separate a string of repeating characters?

From Dev

Remove repeating characters from string

From Dev

Separate characters and numbers from a string

From Dev

How can I separate Characters, Integers and Operators from string in php?

From Dev

How can I separate the arbitrary characters from a string object in java

From Dev

How to get separate out characters from within a string

From Dev

How to access separate characters in a string?

From Dev

How to separate a string with duplicated characters

From Dev

How to find an index of a string(first three character) from an array

From Dev

How to insert a character every N characters in a string in C++

From Dev

How to remove all characters from a string before a specific character

From Dev

How to separate a string and re build it

From Dev

How to trim n characters from a string in PHP?

From Dev

Most repeating character in a string

From Dev

Character repeating in a string

From Dev

Repeating characters in words in a string

From Dev

Separate alphabetic characters from a string with javascript

From Dev

Separate single characters from an string using .split

From Dev

Separate alphabetic characters from a string with javascript

From Dev

how do I return list with separate character

From Dev

How should I separate following three string?

From Dev

Replce repeating set of character from end of string using regex

From Dev

sed: replace character at the beginning of a string of n characters

From Dev

Using R how to separate a string based on characters

From Dev

How to separate a string into substrings of two characters

From Dev

How to separate a string into multiple lines of individual characters

From Dev

Regex to extract three characters from string python

From Dev

Check that string contains a character from set of characters

From Dev

How to delete the very last character from every string in a list of strings

Related Related

  1. 1

    How to separate a string of repeating characters?

  2. 2

    Remove repeating characters from string

  3. 3

    Separate characters and numbers from a string

  4. 4

    How can I separate Characters, Integers and Operators from string in php?

  5. 5

    How can I separate the arbitrary characters from a string object in java

  6. 6

    How to get separate out characters from within a string

  7. 7

    How to access separate characters in a string?

  8. 8

    How to separate a string with duplicated characters

  9. 9

    How to find an index of a string(first three character) from an array

  10. 10

    How to insert a character every N characters in a string in C++

  11. 11

    How to remove all characters from a string before a specific character

  12. 12

    How to separate a string and re build it

  13. 13

    How to trim n characters from a string in PHP?

  14. 14

    Most repeating character in a string

  15. 15

    Character repeating in a string

  16. 16

    Repeating characters in words in a string

  17. 17

    Separate alphabetic characters from a string with javascript

  18. 18

    Separate single characters from an string using .split

  19. 19

    Separate alphabetic characters from a string with javascript

  20. 20

    how do I return list with separate character

  21. 21

    How should I separate following three string?

  22. 22

    Replce repeating set of character from end of string using regex

  23. 23

    sed: replace character at the beginning of a string of n characters

  24. 24

    Using R how to separate a string based on characters

  25. 25

    How to separate a string into substrings of two characters

  26. 26

    How to separate a string into multiple lines of individual characters

  27. 27

    Regex to extract three characters from string python

  28. 28

    Check that string contains a character from set of characters

  29. 29

    How to delete the very last character from every string in a list of strings

HotTag

Archive