All Questions
Tagged with combinatorics javascript
25 questions
2
votes
1
answer
152
views
Combinations of elements in array
I wrote this code to get all possible arrangements for an array containing 3 elements:
...
2
votes
1
answer
252
views
In how many different ways can a group of 9 people be divided into 3 groups, with each group containing 3 people?
To divide 9 persons into 3 groups, when the ordering of groups is not important can be done in
(9C3 * 6C3 * 3C3) / (3!) = 280 ways
Here, we divide by (3!) because the ordering of 3 groups is not ...
2
votes
2
answers
1k
views
Generate all possible unique combinations of positive numbers these have sum equal to N
This is my function to generate all possible unique combinations of positive numbers these have sum equal to N.
For example:
If the input is 4
The output should ...
4
votes
1
answer
103
views
Outputting flavor text depending on inputted strings
I have this program that takes two strings from the user, stores them in mixArray, then "mixes" them with mixItUp() and outputs ...
3
votes
2
answers
354
views
Challenge: phone keypad to letters - return all possible strings
The challenge:
Given a mapping of digits to letters (as in a phone number), and a digit string, return all possible letters the number could represent. You can assume each valid number in the ...
4
votes
1
answer
3k
views
Generate all possible combination of n-pair parentheses
The task is taken from LeetCode
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.
For example, given n = 3, a solution set is:
...
4
votes
2
answers
975
views
PermCheck Codility
The following code gets 100% on the PermCheck task on Codility. It should be O(N).
The question is:
A non-empty array A consisting of N integers is given.
A permutation is a sequence ...
2
votes
2
answers
131
views
Forming all multiples of 3 using the given digits
I'm working on this kata from Codewars. The task is:
Given a certain number, how many multiples of three could you obtain with its digits?
Supose that you have the number 362. The numbers that can be ...
4
votes
1
answer
4k
views
n choose k combination in JavaScript
I was asked to solve a problem for \$\binom{n}{k}\$. I did the following implementation and am wondering if there's any feedback.
Input:
n = Integer
...
3
votes
2
answers
911
views
Heap's algorithm implementation - permutations
I wrote an implementation of Heap's permutation algorithm in JavaScript (ES2015):
...
3
votes
2
answers
532
views
Finding Permutations of Numbers
I'm trying to solve this challenge, which consists of finding the next biggest number formed by the digits of the passed in number. If it is impossible to find a number larger than the passed in ...
1
vote
1
answer
608
views
Characters set permutations with repetitions
The code bellow generates all the permutation(with repetitions) for given character set. Is there any better(simpler, more performant) way to do that?
...
3
votes
3
answers
602
views
Searching a string for any permutation of words
Given a string and an array of words, return all indexes in string for which a concatenation of all words in the array,
in any order (so ["eensie", "weensy", "spider"] has six orderings) can be ...
6
votes
1
answer
400
views
`r` permutations of `n`
I have written this snippet to find r-permutations of n, i.e. if I have an array of n=3 {0,1,2}, then r=2 permutations will be {{0, 1}, {0, 2}, {1, 0}, {1, 2}, {2, 0}, {2, 1}}.
Can somebody review it ...
6
votes
2
answers
1k
views
Simple Factorial Interview Task
I did this code for an interview. Can you tell me how it looks? I didn't get the job, so I'm wondering what I could do better in my code.
...