We are given two strings P and Q, each consisting of N lowercase English letters. For each position in the strings, we have to choose one letter from either P or Q, in order to construct a new string S, such that the number of distinct letters in S is minimal. Our task is to find the number of distinct letters in the resulting string S.
For example, if P = "ca" and Q = "ab", S can be equal to: "ca", "cb", "aa" or "ab". String "aa" has only one distinct letter ('a'), so the answer is 1 (which is minimal among those strings).
Write a function:
function solution(P, Q);
that, given two strings P and Q, both of length N, returns the minimum number of distinct letters of a string S, that can be constructed from P and Q as described above.
Examples:
1. Given P = "abc", Q = "bcd", your function should return 2. All possible strings S that can be constructed are: "abc", "abd", "acc", "acd", "bbc", "bbd", "bcc", "bcd". The minimum number of distinct letters is 2, which be obtained by constructing the following strings: "acc", "bbc", "bbd", "bcc".
2. Given P = "axxz", Q = "yzwy", your function should return 2. String S must consist of at least two distinct letters in this case. We can construct S = "yxxy", where the number of distinct letters is equal to 2, and this is the only optimal solution.
3. Given P = "bacad", Q = "abada", your function should return 1. We can choose the letter 'a' in each position, so S can be equal to "aaaaa".
4. Given P = "amz", Q = "amz", your function should return 3. The input strings are identical, so the only possible S that can be constructed is "amz", and its number of distinct letters is 3.
Write an efficient algorithm for the following assumptions:
- N is an integer within the range [1..200,000];
- strings P and Q are both of length N;
- strings P and Q are made only of lowercase letters (a−z);
- strings P and Q contain a total of at most 20 distinct letters.
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(P, Q) {
for(let i=0; i<length; i++){
letterMap[i]= [P[i], Q[i]]
}
let numOfDistinct = [];
backtrack([],0)
return numOfDistinct.sort((a,b) => a-b)[0]
function backtrack(arr, index){
if(arr.length === length){
let set = new Set(arr)
numOfDistinct.push(set.size)
return
}
for(let letter of letterMap[index]){
arr.push(letter)
backtrack(arr, index + 1)
arr.pop()
}
}
}
ReferenceError: length is not defined at solution (solution.js:5:20) at solutionWrapper (/tmp/exec_user_tu45t3cp/exec.js:396:28) at /tmp/exec_user_tu45t3cp/exec.js:422:24
ReferenceError: length is not defined at solution (solution.js:5:20) at solutionWrapper (/tmp/exec_user_tu45t3cp/exec.js:396:28) at /tmp/exec_user_tu45t3cp/exec.js:422:24
ReferenceError: length is not defined at solution (solution.js:5:20) at solutionWrapper (/tmp/exec_user_tu45t3cp/exec.js:396:28) at /tmp/exec_user_tu45t3cp/exec.js:422:24
ReferenceError: length is not defined at solution (solution.js:5:20) at solutionWrapper (/tmp/exec_user_tu45t3cp/exec.js:396:28) at /tmp/exec_user_tu45t3cp/exec.js:422:24
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(P, Q) {
for(let i=0; i<length; i++){
letterMap[i]= [P[i], Q[i]]
}
let numOfDistinct = [];
return numOfDistinct.sort((a,b) => a-b)[0]
function backtrack(arr, index){
if(arr.length === length){
let set = new Set(arr)
numOfDistinct.push(set.size)
return
}
for(let letter of letterMap[index]){
arr.push(letter)
backtrack(arr, index + 1)
arr.pop()
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(P, Q) {
for(let i=0; i<length; i++){
letterMap[i]= [P[i], Q[i]]
}
let numOfDistinct = [];
function backtrack(arr, index){
if(arr.length === length){
let set = new Set(arr)
numOfDistinct.push(set.size)
return
}
for(let letter of letterMap[index]){
arr.push(letter)
backtrack(arr, index + 1)
arr.pop()
}
}
backtrack([],0)
return numOfDistinct.sort((a,b) => a-b)[0]
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(P, Q) {
for(let i=0; i<length; i++){
letterMap[i]= [P[i], Q[i]]
}
let numOfDistinct = [];
function backtrack(arr, index){
if(arr.length === length){
let set = new Set(arr)
numOfDistinct.push(set.size)
return
}
for(let letter of letterMap[index]){
arr.push(letter)
backtrack(arr, index + 1)
arr.pop()
}
}
backtrack([],0)
return numOfDistinct.sort((a,b) => a-b)[0]
}
ReferenceError: length is not defined at solution (solution.js:5:20) at solutionWrapper (/tmp/exec_user_6futf4bl/exec.js:396:28) at /tmp/exec_user_6futf4bl/exec.js:422:24
ReferenceError: length is not defined at solution (solution.js:5:20) at solutionWrapper (/tmp/exec_user_6futf4bl/exec.js:396:28) at /tmp/exec_user_6futf4bl/exec.js:422:24
ReferenceError: length is not defined at solution (solution.js:5:20) at solutionWrapper (/tmp/exec_user_6futf4bl/exec.js:396:28) at /tmp/exec_user_6futf4bl/exec.js:422:24
ReferenceError: length is not defined at solution (solution.js:5:20) at solutionWrapper (/tmp/exec_user_6futf4bl/exec.js:396:28) at /tmp/exec_user_6futf4bl/exec.js:422:24
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(P, Q) {
for(let i=0; i<length; i++){
letterMap[i]= [P[i], Q[i]]
}
let numOfDistinct = [];
function backtrack(arr, index){
if(arr.length === length){
let set = new Set(arr)
numOfDistinct.push(set.size)
return
}
for(let letter of letterMap[index]){
arr.push(letter)
backtrack(arr, index + 1)
arr.pop()
}
}
backtrack([],0)
console.log();
return numOfDistinct.sort((a,b) => a-b)[0]
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(P, Q) {
for(let i=0; i<length; i++){
letterMap[i]= [P[i], Q[i]]
}
let numOfDistinct = [];
function backtrack(arr, index){
if(arr.length === length){
let set = new Set(arr)
numOfDistinct.push(set.size)
return
}
for(let letter of letterMap[index]){
arr.push(letter)
backtrack(arr, index + 1)
arr.pop()
}
}
backtrack([],0)
console.log(numOfDistinct);
return numOfDistinct.sort((a,b) => a-b)[0]
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(P, Q) {
for(let i=0; i<length; i++){
letterMap[i]= [P[i], Q[i]]
}
let numOfDistinct = [];
function backtrack(arr, index){
if(arr.length === length){
let set = new Set(arr)
numOfDistinct.push(set.size)
return
}
for(let letter of letterMap[index]){
arr.push(letter)
backtrack(arr, index + 1)
arr.pop()
}
}
backtrack([],0)
console.log(numOfDistinct);
return numOfDistinct.sort((a,b) => a-b)[0]
}
ReferenceError: length is not defined at solution (solution.js:5:20) at solutionWrapper (/tmp/exec_user_b0vi_nfn/exec.js:396:28) at /tmp/exec_user_b0vi_nfn/exec.js:422:24
ReferenceError: length is not defined at solution (solution.js:5:20) at solutionWrapper (/tmp/exec_user_b0vi_nfn/exec.js:396:28) at /tmp/exec_user_b0vi_nfn/exec.js:422:24
ReferenceError: length is not defined at solution (solution.js:5:20) at solutionWrapper (/tmp/exec_user_b0vi_nfn/exec.js:396:28) at /tmp/exec_user_b0vi_nfn/exec.js:422:24
ReferenceError: length is not defined at solution (solution.js:5:20) at solutionWrapper (/tmp/exec_user_b0vi_nfn/exec.js:396:28) at /tmp/exec_user_b0vi_nfn/exec.js:422:24
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(P, Q) {
const set = new Set();
for (let i = 0; i < P.length; i++) {
for (let j = 0; j < Q.length; j++) {
set.add(P[i]);
set.add(Q[j]);
}
}
console.log(set);
return set.size;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(P, Q) {
const set = new Set();
for (let i = 0; i < P.length; i++) {
for (let j = 0; j < Q.length; j++) {
set.add(P[i]);
set.add(Q[j]);
}
}
console.log(set);
return set.size;
}
Set(4) { 'a', 'b', 'c', 'd' }
Set(5) { 'a', 'y', 'z', 'w', 'x' }
Set(4) { 'b', 'a', 'd', 'c' }
Set(3) { 'a', 'm', 'z' }
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(P, Q) {
const combinations = [];
for (let i = 0; i < P.length; i++) {
for (let j = 0; j < Q.length; j++) {
const combination = new Set();
combination.add(P[i]);
combination.add(Q[j]);
combinations.push(combination);
}
}
let minDistinctLetters = Infinity;
for (const combination of combinations) {
const distinctLetters = combination.size;
if (distinctLetters < minDistinctLetters) {
minDistinctLetters = distinctLetters;
}
}
return minDistinctLetters;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(P, Q) {
const combinations = [];
for (let i = 0; i < P.length; i++) {
for (let j = 0; j < Q.length; j++) {
const combination = new Set();
combination.add(P[i]);
combination.add(Q[j]);
combinations.push(combination);
}
}
let minDistinctLetters = Infinity;
for (const combination of combinations) {
const distinctLetters = combination.size;
if (distinctLetters < minDistinctLetters) {
minDistinctLetters = distinctLetters;
}
}
return minDistinctLetters;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(P, Q) {
const combinations = [];
for (let i = 0; i < P.length; i++) {
for (let j = 0; j < Q.length; j++) {
const combination = new Set();
combination.add(P[i]);
combination.add(Q[j]);
combinations.push(combination);
}
}
let minDistinctLetters = Infinity;
for (const combination of combinations) {
const distinctLetters = combination.size;
if (distinctLetters < minDistinctLetters) {
minDistinctLetters = distinctLetters;
}
}
conso
return minDistinctLetters;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(P, Q) {
const combinations = [];
for (let i = 0; i < P.length; i++) {
for (let j = 0; j < Q.length; j++) {
const combination = new Set();
combination.add(P[i]);
combination.add(Q[j]);
combinations.push(combination);
}
}
let minDistinctLetters = Infinity;
for (const combination of combinations) {
const distinctLetters = combination.size;
if (distinctLetters < minDistinctLetters) {
minDistinctLetters = distinctLetters;
}
}
console.log(combinations);
return minDistinctLetters;
}
[ Set(2) { 'a', 'b' }, Set(2) { 'a', 'c' }, Set(2) { 'a', 'd' }, Set(1) { 'b' }, Set(2) { 'b', 'c' }, Set(2) { 'b', 'd' }, Set(2) { 'c', 'b' }, Set(1) { 'c' }, Set(2) { 'c', 'd' } ]
[ Set(2) { 'a', 'y' }, Set(2) { 'a', 'z' }, Set(2) { 'a', 'w' }, Set(2) { 'a', 'y' }, Set(2) { 'x', 'y' }, Set(2) { 'x', 'z' }, Set(2) { 'x', 'w' }, Set(2) { 'x', 'y' }, Set(2) { 'x', 'y' }, Set(2) { 'x', 'z' }, Set(2) { 'x', 'w' }, Set(2) { 'x', 'y' }, Set(2) { 'z', 'y' }, Set(1) { 'z' }, Set(2) { 'z', 'w' }, Set(2) { 'z', 'y' } ]
[ Set(2) { 'b', 'a' }, Set(1) { 'b' }, Set(2) { 'b', 'a' }, Set(2) { 'b', 'd' }, Set(2) { 'b', 'a' }, Set(1) { 'a' }, Set(2) { 'a', 'b' }, Set(1) { 'a' }, Set(2) { 'a', 'd' }, Set(1) { 'a' }, Set(2) { 'c', 'a' }, Set(2) { 'c', 'b' }, Set(2) { 'c', 'a' }, Set(2) { 'c', 'd' }, Set(2) { 'c', 'a' }, Set(1) { 'a' }, Set(2) { 'a', 'b' }, Set(1) { 'a' }, Set(2) { 'a', 'd' }, Set(1) { 'a' }, Set(2) { 'd', 'a' }, Set(2) { 'd', 'b' }, Set(2) { 'd', 'a' }, Set(1) { 'd' }, Set(2) { 'd', 'a' } ]
[ Set(1) { 'a' }, Set(2) { 'a', 'm' }, Set(2) { 'a', 'z' }, Set(2) { 'm', 'a' }, Set(1) { 'm' }, Set(2) { 'm', 'z' }, Set(2) { 'z', 'a' }, Set(2) { 'z', 'm' }, Set(1) { 'z' } ]
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(P, Q) {
const set = new Set();
for (let i = 0; i < P.length; i++) {
for (let j = 0; j < Q.length; j++) {
const combination = P[i] + Q[j];
set.add(combination);
}
}
return set.size;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(P, Q) {
const set = new Set();
for (let i = 0; i < P.length; i++) {
for (let j = 0; j < Q.length; j++) {
const combination = P[i] + Q[j];
set.add(combination);
}
}
return set.size;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(P, Q) {
const set = new Set();
for (let i = 0; i < P.length; i++) {
for (let j = 0; j < Q.length; j++) {
const combination = P[i] + Q[j];
set.add(combination);
}
}
console.log(set);
return set.size;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(P, Q) {
const set = new Set();
for (let i = 0; i < P.length; i++) {
for (let j = 0; j < Q.length; j++) {
const combination = P[i] + Q[j];
set.add(combination);
}
}
console.log(set);
return set.size;
}
Set(9) { 'ab', 'ac', 'ad', 'bb', 'bc', 'bd', 'cb', 'cc', 'cd' }
Set(9) { 'ay', 'az', 'aw', 'xy', 'xz', 'xw', 'zy', 'zz', 'zw' }
Set(12) { 'ba', 'bb', 'bd', 'aa', 'ab', 'ad', 'ca', 'cb', 'cd', 'da', 'db', 'dd' }
Set(9) { 'aa', 'am', 'az', 'ma', 'mm', 'mz', 'za', 'zm', 'zz' }
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(P, Q) {
const combinations = generateCombinations(P, Q);
let minDistinctLetters = Infinity;
for (const combination of combinations) {
const distinctLetters = countDistinct(combination);
if (distinctLetters < minDistinctLetters) {
minDistinctLetters = distinctLetters;
}
}
return minDistinctLetters;
}
function generateCombinations(P, Q) {
const combinations = [];
for (let i = 0; i < P.length; i++) {
for (let j = 0; j < Q.length; j++) {
for (let k = 0; k < P.length; k++) {
const combination = P[i] + Q[j] + P[k];
combinations.push(combination);
}
}
}
return combinations;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(P, Q) {
const combinations = generateCombinations(P, Q);
let minDistinctLetters = Infinity;
for (const combination of combinations) {
const distinctLetters = countDistinct(combination);
if (distinctLetters < minDistinctLetters) {
minDistinctLetters = distinctLetters;
}
}
return minDistinctLetters;
}
function generateCombinations(P, Q) {
const combinations = [];
for (let i = 0; i < P.length; i++) {
for (let j = 0; j < Q.length; j++) {
for (let k = 0; k < P.length; k++) {
const combination = P[i] + Q[j] + P[k];
combinations.push(combination);
}
}
}
return combinations;
}
function countDistinct(str) {
const set = new Set();
for (let i = 0; i < str.length; i++) {
set.add(str[i]);
}
return set.size;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(P, Q) {
const combinations = generateCombinations(P, Q);
let minDistinctLetters = Infinity;
for (const combination of combinations) {
const distinctLetters = countDistinct(combination);
if (distinctLetters < minDistinctLetters) {
minDistinctLetters = distinctLetters;
}
}
return minDistinctLetters;
}
function generateCombinations(P, Q) {
const combinations = [];
for (let i = 0; i < P.length; i++) {
for (let j = 0; j < Q.length; j++) {
for (let k = 0; k < P.length; k++) {
const combination = P[i] + Q[j] + P[k];
combinations.push(combination);
}
}
}
return combinations;
}
function countDistinct(str) {
const set = new Set();
for (let i = 0; i < str.length; i++) {
set.add(str[i]);
}
return set.size;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(P, Q) {
const combinations = generateCombinations(P, Q);
let minDistinctLetters = Infinity;
for (const combination of combinations) {
const distinctLetters = countDistinct(combination);
if (distinctLetters < minDistinctLetters) {
minDistinctLetters = distinctLetters;
}
}
return minDistinctLetters;
}
function generateCombinations(P, Q) {
const combinations = [];
for (let i = 0; i < P.length; i++) {
for (let j = 0; j < Q.length; j++) {
for (let k = 0; k < P.length; k++) {
const combination = P[i] + Q[j] + P[k];
combinations.push(combination);
}
}
}
return combinations;
}
function countDistinct(str) {
const set = new Set();
for (let i = 0; i < str.length; i++) {
set.add(str[i]);
}
return set.size;
}
c
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(P, Q) {
const combinations = generateCombinations(P, Q);
let minDistinctLetters = Infinity;
for (const combination of combinations) {
const distinctLetters = countDistinct(combination);
if (distinctLetters < minDistinctLetters) {
minDistinctLetters = distinctLetters;
}
}
return minDistinctLetters;
}
function generateCombinations(P, Q) {
const combinations = [];
for (let i = 0; i < P.length; i++) {
for (let j = 0; j < Q.length; j++) {
for (let k = 0; k < P.length; k++) {
const combination = P[i] + Q[j] + P[k];
combinations.push(combination);
}
}
}
return combinations;
}
function countDistinct(str) {
const set = new Set();
for (let i = 0; i < str.length; i++) {
set.add(str[i]);
}
return set.size;
}
console.log(combinations);
solution.js:41 console.log(combinations); ^ ReferenceError: combinations is not defined at solution.js:41:13 at solution.js:47:2 at solution.js:48:2 at Script.runInContext (vm.js:144:12) at Script.runInNewContext (vm.js:149:17) at Object.runInNewContext (vm.js:303:38) at getSolution (/tmp/exec_user_vaq6xxhv/exec.js:386:29) at /tmp/exec_user_vaq6xxhv/exec.js:420:34
solution.js:41 console.log(combinations); ^ ReferenceError: combinations is not defined at solution.js:41:13 at solution.js:47:2 at solution.js:48:2 at Script.runInContext (vm.js:144:12) at Script.runInNewContext (vm.js:149:17) at Object.runInNewContext (vm.js:303:38) at getSolution (/tmp/exec_user_vaq6xxhv/exec.js:386:29) at /tmp/exec_user_vaq6xxhv/exec.js:420:34
solution.js:41 console.log(combinations); ^ ReferenceError: combinations is not defined at solution.js:41:13 at solution.js:47:2 at solution.js:48:2 at Script.runInContext (vm.js:144:12) at Script.runInNewContext (vm.js:149:17) at Object.runInNewContext (vm.js:303:38) at getSolution (/tmp/exec_user_vaq6xxhv/exec.js:386:29) at /tmp/exec_user_vaq6xxhv/exec.js:420:34
solution.js:41 console.log(combinations); ^ ReferenceError: combinations is not defined at solution.js:41:13 at solution.js:47:2 at solution.js:48:2 at Script.runInContext (vm.js:144:12) at Script.runInNewContext (vm.js:149:17) at Object.runInNewContext (vm.js:303:38) at getSolution (/tmp/exec_user_vaq6xxhv/exec.js:386:29) at /tmp/exec_user_vaq6xxhv/exec.js:420:34
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(P, Q) {
const combinations = generateCombinations(P, Q);
let minDistinctLetters = Infinity;
for (const combination of combinations) {
const distinctLetters = countDistinct(combination);
if (distinctLetters < minDistinctLetters) {
minDistinctLetters = distinctLetters;
}
}
return minDistinctLetters;
}
function generateCombinations(P, Q) {
const combinations = [];
for (let i = 0; i < P.length; i++) {
for (let j = 0; j < Q.length; j++) {
for (let k = 0; k < P.length; k++) {
const combination = P[i] + Q[j] + P[k];
combinations.push(combination);
}
}
}
return combinations;
}
function countDistinct(str) {
const set = new Set();
for (let i = 0; i < str.length; i++) {
set.add(str[i]);
}
return set.size;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(P, Q) {
const combinations = generateCombinations(P, Q);
let minDistinctLetters = Infinity;
for (const combination of combinations) {
const distinctLetters = countDistinct(combination);
if (distinctLetters < minDistinctLetters) {
minDistinctLetters = distinctLetters;
}
}
return minDistinctLetters;
}
function generateCombinations(P, Q) {
const combinations = [];
for (let i = 0; i < P.length; i++) {
for (let j = 0; j < Q.length; j++) {
for (let k = 0; k < P.length; k++) {
const combination = P[i] + Q[j] + P[k];
combinations.push(combination);
}
}
}
console.log(combinations);
return combinations;
}
function countDistinct(str) {
const set = new Set();
for (let i = 0; i < str.length; i++) {
set.add(str[i]);
}
return set.size;
}
[ 'aba', 'abb', 'abc', 'aca', 'acb', 'acc', 'ada', 'adb', 'adc', 'bba', 'bbb', 'bbc', 'bca', 'bcb', 'bcc', 'bda', 'bdb', 'bdc', 'cba', 'cbb', 'cbc', 'cca', 'ccb', 'ccc', 'cda', 'cdb', 'cdc' ]
[ 'aya', 'ayx', 'ayx', 'ayz', 'aza', 'azx', 'azx', 'azz', 'awa', 'awx', 'awx', 'awz', 'aya', 'ayx', 'ayx', 'ayz', 'xya', 'xyx', 'xyx', 'xyz', 'xza', 'xzx', 'xzx', 'xzz', 'xwa', 'xwx', 'xwx', 'xwz', 'xya', 'xyx', 'xyx', 'xyz', 'xya', 'xyx', 'xyx', 'xyz', 'xza', 'xzx', 'xzx', 'xzz', 'xwa', 'xwx', 'xwx', 'xwz', 'xya', 'xyx', 'xyx', 'xyz', 'zya', 'zyx', 'zyx', 'zyz', 'zza', 'zzx', 'zzx', 'zzz', 'zwa', 'zwx', 'zwx', 'zwz', 'zya', 'zyx', 'zyx', 'zyz' ]
[ 'bab', 'baa', 'bac', 'baa', 'bad', 'bbb', 'bba', 'bbc', 'bba', 'bbd', 'bab', 'baa', 'bac', 'baa', 'bad', 'bdb', 'bda', 'bdc', 'bda', 'bdd', 'bab', 'baa', 'bac', 'baa', 'bad', 'aab', 'aaa', 'aac', 'aaa', 'aad', 'abb', 'aba', 'abc', 'aba', 'abd', 'aab', 'aaa', 'aac', 'aaa', 'aad', 'adb', 'ada', 'adc', 'ada', 'add', 'aab', 'aaa', 'aac', 'aaa', 'aad', 'cab', 'caa', 'cac', 'caa', 'cad', 'cbb', 'cba', 'cbc', 'cba', 'cbd', 'cab', 'caa', 'cac', 'caa', 'cad', 'cdb', 'cda', 'cdc', 'cda', 'cdd', 'cab', 'caa', 'cac', 'caa', 'cad', 'aab', 'aaa', 'aac', 'aaa', 'aad', 'abb', 'aba', 'abc', 'aba', 'abd', 'aab', 'aaa', 'aac', 'aaa', 'aad', 'adb', 'ada', 'adc', 'ada', 'add', 'aab', 'aaa', 'aac', 'aaa', 'aad', ... 25 more items ]
[ 'aaa', 'aam', 'aaz', 'ama', 'amm', 'amz', 'aza', 'azm', 'azz', 'maa', 'mam', 'maz', 'mma', 'mmm', 'mmz', 'mza', 'mzm', 'mzz', 'zaa', 'zam', 'zaz', 'zma', 'zmm', 'zmz', 'zza', 'zzm', 'zzz' ]
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(P, Q) {
const combinations = generateCombinations(P, Q, '', 0, 0);
let minDistinctLetters = Infinity;
for (const combination of combinations) {
const distinctLetters = countDistinct(combination);
if (distinctLetters < minDistinctLetters) {
minDistinctLetters = distinctLetters;
}
}
return minDistinctLetters;
}
function generateCombinations(P, Q, combination, pIndex, qIndex) {
if (combination.length === P.length) {
return [combination];
}
const combinations = [];
if (pIndex < P.length) {
const newCombinationP = combination + P[pIndex];
const subCombinationsP = generateCombinations(P, Q, newCombinationP, pIndex + 1, qIndex);
combinations.push(...subCombinationsP);
}
if (qIndex < Q.length) {
const newCombinationQ = combination + Q[qIndex];
const subCombinationsQ = generateCombinations(P, Q, newCombinationQ, pIndex, qIndex + 1);
combinations.push(...subCombinationsQ);
}
return combinations;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(P, Q) {
const combinations = generateCombinations(P, Q, '', 0, 0);
let minDistinctLetters = Infinity;
for (const combination of combinations) {
const distinctLetters = countDistinct(combination);
if (distinctLetters < minDistinctLetters) {
minDistinctLetters = distinctLetters;
}
}
return minDistinctLetters;
}
function generateCombinations(P, Q, combination, pIndex, qIndex) {
if (combination.length === P.length) {
return [combination];
}
const combinations = [];
if (pIndex < P.length) {
const newCombinationP = combination + P[pIndex];
const subCombinationsP = generateCombinations(P, Q, newCombinationP, pIndex + 1, qIndex);
combinations.push(...subCombinationsP);
}
if (qIndex < Q.length) {
const newCombinationQ = combination + Q[qIndex];
const subCombinationsQ = generateCombinations(P, Q, newCombinationQ, pIndex, qIndex + 1);
combinations.push(...subCombinationsQ);
}
return combinations;
}
ReferenceError: countDistinct is not defined at solution (solution.js:9:29) at solutionWrapper (/tmp/exec_user_4cif5y42/exec.js:396:28) at /tmp/exec_user_4cif5y42/exec.js:422:24
ReferenceError: countDistinct is not defined at solution (solution.js:9:29) at solutionWrapper (/tmp/exec_user_4cif5y42/exec.js:396:28) at /tmp/exec_user_4cif5y42/exec.js:422:24
ReferenceError: countDistinct is not defined at solution (solution.js:9:29) at solutionWrapper (/tmp/exec_user_4cif5y42/exec.js:396:28) at /tmp/exec_user_4cif5y42/exec.js:422:24
ReferenceError: countDistinct is not defined at solution (solution.js:9:29) at solutionWrapper (/tmp/exec_user_4cif5y42/exec.js:396:28) at /tmp/exec_user_4cif5y42/exec.js:422:24
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(P, Q) {
const combinations = generateCombinations(P, Q, '', 0, 0);
let minDistinctLetters = Infinity;
for (const combination of combinations) {
const distinctLetters = countDistinct(combination);
if (distinctLetters < minDistinctLetters) {
minDistinctLetters = distinctLetters;
}
}
return minDistinctLetters;
}
function generateCombinations(P, Q, combination, pIndex, qIndex) {
if (combination.length === P.length) {
return [combination];
}
const combinations = [];
if (pIndex < P.length) {
const newCombinationP = combination + P[pIndex];
const subCombinationsP = generateCombinations(P, Q, newCombinationP, pIndex + 1, qIndex);
combinations.push(...subCombinationsP);
}
if (qIndex < Q.length) {
const newCombinationQ = combination + Q[qIndex];
const subCombinationsQ = generateCombinations(P, Q, newCombinationQ, pIndex, qIndex + 1);
combinations.push(...subCombinationsQ);
}
return combinations;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(P, Q) {
const combinations = generateCombinations(P, Q, '', 0, 0);
let minDistinctLetters = Infinity;
for (const combination of combinations) {
const distinctLetters = countDistinct(combination);
if (distinctLetters < minDistinctLetters) {
minDistinctLetters = distinctLetters;
}
}
return minDistinctLetters;
}
function generateCombinations(P, Q, combination, pIndex, qIndex) {
if (combination.length === P.length) {
return [combination];
}
const combinations = [];
if (pIndex < P.length) {
const newCombinationP = combination + P[pIndex];
const subCombinationsP = generateCombinations(P, Q, newCombinationP, pIndex + 1, qIndex);
combinations.push(...subCombinationsP);
}
if (qIndex < Q.length) {
const newCombinationQ = combination + Q[qIndex];
const subCombinationsQ = generateCombinations(P, Q, newCombinationQ, pIndex, qIndex + 1);
combinations.push(...subCombinationsQ);
}
return combinations;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(P, Q) {
const combinations = generateCombinations(P, Q, '', 0, 0);
let minDistinctLetters = Infinity;
for (const combination of combinations) {
const distinctLetters = countDistinct(combination);
if (distinctLetters < minDistinctLetters) {
minDistinctLetters = distinctLetters;
}
}
return minDistinctLetters;
}
function generateCombinations(P, Q, combination, pIndex, qIndex) {
if (combination.length === P.length) {
return [combination];
}
const combinations = [];
if (pIndex < P.length) {
const newCombinationP = combination + P[pIndex];
const subCombinationsP = generateCombinations(P, Q, newCombinationP, pIndex + 1, qIndex);
combinations.push(...subCombinationsP);
}
if (qIndex < Q.length) {
const newCombinationQ = combination + Q[qIndex];
const subCombinationsQ = generateCombinations(P, Q, newCombinationQ, pIndex, qIndex + 1);
combinations.push(...subCombinationsQ);
}
const set = new Set();
for (let i = 0; i < str.length; i++) {
set.add(str[i]);
}
return set.size;
}
ReferenceError: str is not defined at generateCombinations (solution.js:38:23) at generateCombinations (solution.js:27:30) at generateCombinations (solution.js:27:30) at solution (solution.js:5:26) at solutionWrapper (/tmp/exec_user_vs8nlzs6/exec.js:396:28) at /tmp/exec_user_vs8nlzs6/exec.js:422:24
ReferenceError: str is not defined at generateCombinations (solution.js:38:23) at generateCombinations (solution.js:27:30) at generateCombinations (solution.js:27:30) at generateCombinations (solution.js:27:30) at solution (solution.js:5:26) at solutionWrapper (/tmp/exec_user_vs8nlzs6/exec.js:396:28) at /tmp/exec_user_vs8nlzs6/exec.js:422:24
ReferenceError: str is not defined at generateCombinations (solution.js:38:23) at generateCombinations (solution.js:27:30) at generateCombinations (solution.js:27:30) at generateCombinations (solution.js:27:30) at generateCombinations (solution.js:27:30) at solution (solution.js:5:26) at solutionWrapper (/tmp/exec_user_vs8nlzs6/exec.js:396:28) at /tmp/exec_user_vs8nlzs6/exec.js:422:24
ReferenceError: str is not defined at generateCombinations (solution.js:38:23) at generateCombinations (solution.js:27:30) at generateCombinations (solution.js:27:30) at solution (solution.js:5:26) at solutionWrapper (/tmp/exec_user_vs8nlzs6/exec.js:396:28) at /tmp/exec_user_vs8nlzs6/exec.js:422:24
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(P, Q) {
const combinations = generateCombinations(P, Q, '', 0, 0);
let minDistinctLetters = Infinity;
for (const combination of combinations) {
const distinctLetters = countDistinct(combination);
if (distinctLetters < minDistinctLetters) {
minDistinctLetters = distinctLetters;
}
}
return minDistinctLetters;
}
function generateCombinations(P, Q, combination, pIndex, qIndex) {
if (combination.length === P.length) {
return [combination];
}
const combinations = [];
if (pIndex < P.length) {
const newCombinationP = combination + P[pIndex];
const subCombinationsP = generateCombinations(P, Q, newCombinationP, pIndex + 1, qIndex);
combinations.push(...subCombinationsP);
}
if (qIndex < Q.length) {
const newCombinationQ = combination + Q[qIndex];
const subCombinationsQ = generateCombinations(P, Q, newCombinationQ, pIndex, qIndex + 1);
combinations.push(...subCombinationsQ);
}
return combinations;
}
const set = new Set();
for (let i = 0; i < str.length; i++) {
set.add(str[i]);
}
return set.size;
solution.js:41 for (let i = 0; i < str.length; i++) { ^ ReferenceError: str is not defined at solution.js:41:23 at solution.js:50:2 at solution.js:51:2 at Script.runInContext (vm.js:144:12) at Script.runInNewContext (vm.js:149:17) at Object.runInNewContext (vm.js:303:38) at getSolution (/tmp/exec_user_rfvddps9/exec.js:386:29) at /tmp/exec_user_rfvddps9/exec.js:420:34
solution.js:41 for (let i = 0; i < str.length; i++) { ^ ReferenceError: str is not defined at solution.js:41:23 at solution.js:50:2 at solution.js:51:2 at Script.runInContext (vm.js:144:12) at Script.runInNewContext (vm.js:149:17) at Object.runInNewContext (vm.js:303:38) at getSolution (/tmp/exec_user_rfvddps9/exec.js:386:29) at /tmp/exec_user_rfvddps9/exec.js:420:34
solution.js:41 for (let i = 0; i < str.length; i++) { ^ ReferenceError: str is not defined at solution.js:41:23 at solution.js:50:2 at solution.js:51:2 at Script.runInContext (vm.js:144:12) at Script.runInNewContext (vm.js:149:17) at Object.runInNewContext (vm.js:303:38) at getSolution (/tmp/exec_user_rfvddps9/exec.js:386:29) at /tmp/exec_user_rfvddps9/exec.js:420:34
solution.js:41 for (let i = 0; i < str.length; i++) { ^ ReferenceError: str is not defined at solution.js:41:23 at solution.js:50:2 at solution.js:51:2 at Script.runInContext (vm.js:144:12) at Script.runInNewContext (vm.js:149:17) at Object.runInNewContext (vm.js:303:38) at getSolution (/tmp/exec_user_rfvddps9/exec.js:386:29) at /tmp/exec_user_rfvddps9/exec.js:420:34
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(P, Q) {
const combinations = generateCombinations(P, Q, '', 0, 0);
let minDistinctLetters = Infinity;
for (const combination of combinations) {
const distinctLetters = countDistinct(combination);
if (distinctLetters < minDistinctLetters) {
minDistinctLetters = distinctLetters;
}
}
return minDistinctLetters;
}
function generateCombinations(P, Q, combination, pIndex, qIndex) {
if (combination.length === P.length) {
return [combination];
}
const combinations = [];
if (pIndex < P.length) {
const newCombinationP = combination + P[pIndex];
const subCombinationsP = generateCombinations(P, Q, newCombinationP, pIndex + 1, qIndex);
combinations.push(...subCombinationsP);
}
if (qIndex < Q.length) {
const newCombinationQ = combination + Q[qIndex];
const subCombinationsQ = generateCombinations(P, Q, newCombinationQ, pIndex, qIndex + 1);
combinations.push(...subCombinationsQ);
}
return combinations;
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(P, Q) {
const combinations = generateCombinations(P, Q, '', 0, 0);
let minDistinctLetters = Infinity;
for (const combination of combinations) {
const distinctLetters = countDistinct(combination);
if (distinctLetters < minDistinctLetters) {
minDistinctLetters = distinctLetters;
}
}
return minDistinctLetters;
}
function generateCombinations(P, Q, combination, pIndex, qIndex) {
if (combination.length === P.length) {
return [combination];
}
const combinations = [];
if (pIndex < P.length) {
const newCombinationP = combination + P[pIndex];
const subCombinationsP = generateCombinations(P, Q, newCombinationP, pIndex + 1, qIndex);
combinations.push(...subCombinationsP);
}
if (qIndex < Q.length) {
const newCombinationQ = combination + Q[qIndex];
const subCombinationsQ = generateCombinations(P, Q, newCombinationQ, pIndex, qIndex + 1);
combinations.push(...subCombinationsQ);
}
return combinations;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(P, Q) {
const combinations = generateCombinations(P, Q, '', 0, 0);
let minDistinctLetters = Infinity;
for (const combination of combinations) {
const distinctLetters = countDistinct(combination);
if (distinctLetters < minDistinctLetters) {
minDistinctLetters = distinctLetters;
}
}
return minDistinctLetters;
}
function generateCombinations(P, Q, combination, pIndex, qIndex) {
if (combination.length === P.length) {
return [combination];
}
const combinations = [];
if (pIndex < P.length) {
const newCombinationP = combination + P[pIndex];
const subCombinationsP = generateCombinations(P, Q, newCombinationP, pIndex + 1, qIndex);
combinations.push(...subCombinationsP);
}
if (qIndex < Q.length) {
const newCombinationQ = combination + Q[qIndex];
const subCombinationsQ = generateCombinations(P, Q, newCombinationQ, pIndex, qIndex + 1);
combinations.push(...subCombinationsQ);
}
return combinations;
}
function countDistinct(str) {
let distinctCount = 0;
const charCount = {};
for (let i = 0; i < str.length; i++) {
const char = str[i];
if (!charCount[char]) {
charCount[char] = true;
distinctCount++;
}
}
return distinctCount;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(P, Q) {
const combinations = generateCombinations(P, Q, '', 0, 0);
let minDistinctLetters = Infinity;
for (const combination of combinations) {
const distinctLetters = countDistinct(combination);
if (distinctLetters < minDistinctLetters) {
minDistinctLetters = distinctLetters;
}
}
return minDistinctLetters;
}
function generateCombinations(P, Q, combination, pIndex, qIndex) {
if (combination.length === P.length) {
return [combination];
}
const combinations = [];
if (pIndex < P.length) {
const newCombinationP = combination + P[pIndex];
const subCombinationsP = generateCombinations(P, Q, newCombinationP, pIndex + 1, qIndex);
combinations.push(...subCombinationsP);
}
if (qIndex < Q.length) {
const newCombinationQ = combination + Q[qIndex];
const subCombinationsQ = generateCombinations(P, Q, newCombinationQ, pIndex, qIndex + 1);
combinations.push(...subCombinationsQ);
}
return combinations;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(P, Q) {
const combinations = generateCombinations(P, Q, '', 0, 0);
let minDistinctLetters = Infinity;
function countDistinct(str) {
let distinctCount = 0;
const charCount = {};
for (let i = 0; i < str.length; i++) {
const char = str[i];
if (!charCount[char]) {
charCount[char] = true;
distinctCount++;
}
}
return distinctCount;
}
for (const combination of combinations) {
const distinctLetters = countDistinct(combination);
if (distinctLetters < minDistinctLetters) {
minDistinctLetters = distinctLetters;
}
}
return minDistinctLetters;
}
function generateCombinations(P, Q, combination, pIndex, qIndex) {
if (combination.length === P.length) {
return [combination];
}
const combinations = [];
if (pIndex < P.length) {
const newCombinationP = combination + P[pIndex];
const subCombinationsP = generateCombinations(P, Q, newCombinationP, pIndex + 1, qIndex);
combinations.push(...subCombinationsP);
}
if (qIndex < Q.length) {
const newCombinationQ = combination + Q[qIndex];
const subCombinationsQ = generateCombinations(P, Q, newCombinationQ, pIndex, qIndex + 1);
combinations.push(...subCombinationsQ);
}
return combinations;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(P, Q) {
const combinations = generateCombinations(P, Q, '', 0, 0);
let minDistinctLetters = Infinity;
function countDistinct(str) {
let distinctCount = 0;
const charCount = {};
for (let i = 0; i < str.length; i++) {
const char = str[i];
if (!charCount[char]) {
charCount[char] = true;
distinctCount++;
}
}
return distinctCount;
}
for (const combination of combinations) {
const distinctLetters = countDistinct(combination);
if (distinctLetters < minDistinctLetters) {
minDistinctLetters = distinctLetters;
}
}
return minDistinctLetters;
}
function generateCombinations(P, Q, combination, pIndex, qIndex) {
if (combination.length === P.length) {
return [combination];
}
const combinations = [];
if (pIndex < P.length) {
const newCombinationP = combination + P[pIndex];
const subCombinationsP = generateCombinations(P, Q, newCombinationP, pIndex + 1, qIndex);
combinations.push(...subCombinationsP);
}
if (qIndex < Q.length) {
const newCombinationQ = combination + Q[qIndex];
const subCombinationsQ = generateCombinations(P, Q, newCombinationQ, pIndex, qIndex + 1);
combinations.push(...subCombinationsQ);
}
return combinations;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(P, Q) {
const combinations = generateCombinations(P, Q, '', 0, 0);
let minDistinctLetters = Infinity;
function countDistinct(str) {
let distinctCount = 0;
const charCount = {};
for (let i = 0; i < str.length; i++) {
const char = str[i];
if (!charCount[char]) {
charCount[char] = true;
distinctCount++;
}
}
return distinctCount;
}
for (const combination of combinations) {
const distinctLetters = countDistinct(combination);
if (distinctLetters < minDistinctLetters) {
minDistinctLetters = distinctLetters;
}
}
return minDistinctLetters;
}
function generateCombinations(P, Q, combination, pIndex, qIndex) {
if (combination.length === P.length) {
return [combination];
}
const combinations = [];
if (pIndex < P.length) {
const newCombinationP = combination + P[pIndex];
const subCombinationsP = generateCombinations(P, Q, newCombinationP, pIndex + 1, qIndex);
combinations.push(...subCombinationsP);
}
if (qIndex < Q.length) {
const newCombinationQ = combination + Q[qIndex];
const subCombinationsQ = generateCombinations(P, Q, newCombinationQ, pIndex, qIndex + 1);
combinations.push(...subCombinationsQ);
}
return combinations;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(P, Q) {
const combinations = generateCombinations(P, Q, '', 0, 0);
let minDistinctLetters = Infinity;
function countDistinct(str) {
let distinctCount = 0;
const charCount = {};
for (let i = 0; i < str.length; i++) {
const char = str[i];
if (!charCount[char]) {
charCount[char] = true;
distinctCount++;
}
}
console.log("Count Distinct: ", distinctCount)
return distinctCount;
}
for (const combination of combinations) {
const distinctLetters = countDistinct(combination);
if (distinctLetters < minDistinctLetters) {
minDistinctLetters = distinctLetters;
}
}
return minDistinctLetters;
}
function generateCombinations(P, Q, combination, pIndex, qIndex) {
if (combination.length === P.length) {
return [combination];
}
const combinations = [];
if (pIndex < P.length) {
const newCombinationP = combination + P[pIndex];
const subCombinationsP = generateCombinations(P, Q, newCombinationP, pIndex + 1, qIndex);
combinations.push(...subCombinationsP);
}
if (qIndex < Q.length) {
const newCombinationQ = combination + Q[qIndex];
const subCombinationsQ = generateCombinations(P, Q, newCombinationQ, pIndex, qIndex + 1);
combinations.push(...subCombinationsQ);
}
return combinations;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(P, Q) {
const combinations = generateCombinations(P, Q, '', 0, 0);
let minDistinctLetters = Infinity;
function countDistinct(str) {
let distinctCount = 0;
const charCount = {};
for (let i = 0; i < str.length; i++) {
const char = str[i];
if (!charCount[char]) {
charCount[char] = true;
distinctCount++;
}
}
console.log("Count Distinct: ", distinctCount);
return distinctCount;
}
for (const combination of combinations) {
const distinctLetters = countDistinct(combination);
if (distinctLetters < minDistinctLetters) {
minDistinctLetters = distinctLetters;
}
}
return minDistinctLetters;
}
function generateCombinations(P, Q, combination, pIndex, qIndex) {
if (combination.length === P.length) {
return [combination];
}
const combinations = [];
if (pIndex < P.length) {
const newCombinationP = combination + P[pIndex];
const subCombinationsP = generateCombinations(P, Q, newCombinationP, pIndex + 1, qIndex);
combinations.push(...subCombinationsP);
}
if (qIndex < Q.length) {
const newCombinationQ = combination + Q[qIndex];
const subCombinationsQ = generateCombinations(P, Q, newCombinationQ, pIndex, qIndex + 1);
combinations.push(...subCombinationsQ);
}
return combinations;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(P, Q) {
const combinations = generateCombinations(P, Q, '', 0, 0);
let minDistinctLetters = Infinity;
function countDistinct(str) {
let distinctCount = 0;
const charCount = {};
for (let i = 0; i < str.length; i++) {
const char = str[i];
if (!charCount[char]) {
charCount[char] = true;
distinctCount++;
}
}
console.log("Count Distinct: ", distinctCount);
return distinctCount;
}
for (const combination of combinations) {
const distinctLetters = countDistinct(combination);
if (distinctLetters < minDistinctLetters) {
minDistinctLetters = distinctLetters;
}
}
console.log("");
return minDistinctLetters;
}
function generateCombinations(P, Q, combination, pIndex, qIndex) {
if (combination.length === P.length) {
return [combination];
}
const combinations = [];
if (pIndex < P.length) {
const newCombinationP = combination + P[pIndex];
const subCombinationsP = generateCombinations(P, Q, newCombinationP, pIndex + 1, qIndex);
combinations.push(...subCombinationsP);
}
if (qIndex < Q.length) {
const newCombinationQ = combination + Q[qIndex];
const subCombinationsQ = generateCombinations(P, Q, newCombinationQ, pIndex, qIndex + 1);
combinations.push(...subCombinationsQ);
}
return combinations;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(P, Q) {
const combinations = generateCombinations(P, Q, '', 0, 0);
let minDistinctLetters = Infinity;
function countDistinct(str) {
let distinctCount = 0;
const charCount = {};
for (let i = 0; i < str.length; i++) {
const char = str[i];
if (!charCount[char]) {
charCount[char] = true;
distinctCount++;
}
}
console.log("Count Distinct: ", distinctCount);
return distinctCount;
}
for (const combination of combinations) {
const distinctLetters = countDistinct(combination);
if (distinctLetters < minDistinctLetters) {
minDistinctLetters = distinctLetters;
}
}
console.log("Min Distinct Letters: ", minDistinctLetters);
return minDistinctLetters;
}
function generateCombinations(P, Q, combination, pIndex, qIndex) {
if (combination.length === P.length) {
return [combination];
}
const combinations = [];
if (pIndex < P.length) {
const newCombinationP = combination + P[pIndex];
const subCombinationsP = generateCombinations(P, Q, newCombinationP, pIndex + 1, qIndex);
combinations.push(...subCombinationsP);
}
if (qIndex < Q.length) {
const newCombinationQ = combination + Q[qIndex];
const subCombinationsQ = generateCombinations(P, Q, newCombinationQ, pIndex, qIndex + 1);
combinations.push(...subCombinationsQ);
}
return combinations;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(P, Q) {
const combinations = generateCombinations(P, Q, '', 0, 0);
let minDistinctLetters = Infinity;
function countDistinct(str) {
let distinctCount = 0;
const charCount = {};
for (let i = 0; i < str.length; i++) {
const char = str[i];
if (!charCount[char]) {
charCount[char] = true;
distinctCount++;
}
}
console.log("Count Distinct: ", distinctCount);
return distinctCount;
}
for (const combination of combinations) {
const distinctLetters = countDistinct(combination);
if (distinctLetters < minDistinctLetters) {
minDistinctLetters = distinctLetters;
}
}
console.log("Min Distinct Letters: ", minDistinctLetters);
return minDistinctLetters;
}
function generateCombinations(P, Q, combination, pIndex, qIndex) {
if (combination.length === P.length) {
return [combination];
}
const combinations = [];
if (pIndex < P.length) {
const newCombinationP = combination + P[pIndex];
const subCombinationsP = generateCombinations(P, Q, newCombinationP, pIndex + 1, qIndex);
combinations.push(...subCombinationsP);
}
if (qIndex < Q.length) {
const newCombinationQ = combination + Q[qIndex];
const subCombinationsQ = generateCombinations(P, Q, newCombinationQ, pIndex, qIndex + 1);
combinations.push(...subCombinationsQ);
}
return combinations;
}
Count Distinct: 3 Count Distinct: 2 Count Distinct: 2 Count Distinct: 3 Count Distinct: 2 Count Distinct: 3 Count Distinct: 3 Count Distinct: 3 Min Distinct Letters: 2
Count Distinct: 3 Count Distinct: 3 Count Distinct: 3 Count Distinct: 4 Count Distinct: 3 Count Distinct: 4 Count Distinct: 4 Count Distinct: 4 Count Distinct: 3 Count Distinct: 4 Count Distinct: 4 Count Distinct: 4 Count Distinct: 4 Count Distinct: 4 Count Distinct: 4 Count Distinct: 3 Min Distinct Letters: 3
Count Distinct: 4 Count Distinct: 3 Count Distinct: 3 Count Distinct: 3 Count Distinct: 3 Count Distinct: 3 Count Distinct: 3 Count Distinct: 2 Count Distinct: 3 Count Distinct: 3 Count Distinct: 3 Count Distinct: 2 Count Distinct: 3 Count Distinct: 2 Count Distinct: 2 Count Distinct: 3 Count Distinct: 3 Count Distinct: 3 Count Distinct: 3 Count Distinct: 2 Count Distinct: 3 Count Distinct: 2 Count Distinct: 2 Count Distinct: 3 Count Distinct: 3 Count Distinct: 2 Count Distinct: 2 Count Distinct: 3 Count Distinct: 2 Count Distinct: 3 Count Distinct: 3 Count Distinct: 3 Min Distinct Letters: 2
Count Distinct: 3 Count Distinct: 2 Count Distinct: 2 Count Distinct: 2 Count Distinct: 2 Count Distinct: 2 Count Distinct: 2 Count Distinct: 3 Min Distinct Letters: 2
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(P, Q) {
let strings = [P , Q], combination = '', index = 0, result = [];
if (combination.length === 3) {
result.push(combination);
return;
}
const currentString = strings.join('');
for (let i = index; i < currentString.length; i++) {
const newCombination = combination + currentString[i];
generateCombinations(strings, newCombination, i + 1, result);
}
return result;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(P, Q) {
let strings = [P , Q], combination = '', index = 0, result = [];
if (combination.length === 3) {
result.push(combination);
return;
}
const currentString = strings.join('');
for (let i = index; i < currentString.length; i++) {
const newCombination = combination + currentString[i];
generateCombinations(strings, newCombination, i + 1, result);
}
console.log(result)
return result;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(P, Q) {
let strings = [P , Q], combination = '', index = 0, result = [];
if (combination.length === 3) {
result.push(combination);
return;
}
const currentString = strings.join('');
for (let i = index; i < currentString.length; i++) {
const newCombination = combination + currentString[i];
generateCombinations(strings, newCombination, i + 1, result);
}
console.log(result)
return result;
}
ReferenceError: generateCombinations is not defined at solution (solution.js:16:5) at solutionWrapper (/tmp/exec_user_pz95m2ko/exec.js:396:28) at /tmp/exec_user_pz95m2ko/exec.js:422:24
ReferenceError: generateCombinations is not defined at solution (solution.js:16:5) at solutionWrapper (/tmp/exec_user_pz95m2ko/exec.js:396:28) at /tmp/exec_user_pz95m2ko/exec.js:422:24
ReferenceError: generateCombinations is not defined at solution (solution.js:16:5) at solutionWrapper (/tmp/exec_user_pz95m2ko/exec.js:396:28) at /tmp/exec_user_pz95m2ko/exec.js:422:24
ReferenceError: generateCombinations is not defined at solution (solution.js:16:5) at solutionWrapper (/tmp/exec_user_pz95m2ko/exec.js:396:28) at /tmp/exec_user_pz95m2ko/exec.js:422:24
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(P, Q) {
let strings = [P , Q], combination = '', index = 0, result = [];
if (combination.length === 3) {
result.push(combination);
return;
}
const currentString = strings.join('');
for (let i = index; i < currentString.length; i++) {
const newCombination = combination + currentString[i];
generateCombinations(strings, newCombination, i + 1, result);
}
console.log(result);
return result;
}
ReferenceError: generateCombinations is not defined at solution (solution.js:16:5) at solutionWrapper (/tmp/exec_user_fkfy0omw/exec.js:396:28) at /tmp/exec_user_fkfy0omw/exec.js:422:24
ReferenceError: generateCombinations is not defined at solution (solution.js:16:5) at solutionWrapper (/tmp/exec_user_fkfy0omw/exec.js:396:28) at /tmp/exec_user_fkfy0omw/exec.js:422:24
ReferenceError: generateCombinations is not defined at solution (solution.js:16:5) at solutionWrapper (/tmp/exec_user_fkfy0omw/exec.js:396:28) at /tmp/exec_user_fkfy0omw/exec.js:422:24
ReferenceError: generateCombinations is not defined at solution (solution.js:16:5) at solutionWrapper (/tmp/exec_user_fkfy0omw/exec.js:396:28) at /tmp/exec_user_fkfy0omw/exec.js:422:24
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(P, Q) {
let strings = [P , Q], combination = '', index = 0, result = [];
if (combination.length === 3) {
result.push(combination);
return;
}
const currentString = strings.join('');
for (let i = index; i < currentString.length; i++) {
const newCombination = combination + currentString[i];
solution(strings, newCombination, i + 1, result);
}
console.log(result);
return result;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(P, Q) {
let strings = [P , Q], combination = '', index = 0, result = [];
if (combination.length === 3) {
result.push(combination);
return;
}
const currentString = strings.join('');
for (let i = index; i < currentString.length; i++) {
const newCombination = combination + currentString[i];
solution(strings, newCombination, i + 1, result);
}
console.log(result);
return result;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(P, Q) {
let strings = [P , Q], combination = '', index = 0, result = [];
if (combination.length === 3) {
result.push(combination);
return;
}
const currentString = strings.join('');
for (let i = index; i < currentString.length; i++) {
const newCombination = combination + currentString[i];
generateCombinations(strings, newCombination, i + 1, result);
}
console.log(result);
return result;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(P, Q) {
let strings = [P , Q], combination = '', index = 0, result = [];
function generateCombinations(strings, combination = '', index = 0, result = []) {
if (combination.length === 3) {
result.push(combination);
return;
}
const currentString = strings.join('');
for (let i = index; i < currentString.length; i++) {
const newCombination = combination + currentString[i];
generateCombinations(strings, newCombination, i + 1, result);
}
return result;
}
return result;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(P, Q) {
let strings = [P , Q], combination = '', index = 0, result = [];
function generateCombinations(strings, combination = '', index = 0, result = []) {
if (combination.length === 3) {
result.push(combination);
return;
}
const currentString = strings.join('');
for (let i = index; i < currentString.length; i++) {
const newCombination = combination + currentString[i];
generateCombinations(strings, newCombination, i + 1, result);
}
return result;
}
return result;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(P, Q) {
let strings = [P , Q], combination = '', index = 0, result = [];
function generateCombinations(strings, combination = '', index = 0, result = []) {
if (combination.length === 3) {
result.push(combination);
return;
}
const currentString = strings.join('');
for (let i = index; i < currentString.length; i++) {
const newCombination = combination + currentString[i];
generateCombinations(strings, newCombination, i + 1, result);
}
return result;
}
return result;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(P, Q) {
let strings = [P , Q], combination = '', index = 0, result = [];
function generateCombinations(strings, combination = '', index = 0, result = []) {
if (combination.length === 3) {
result.push(combination);
return;
}
const currentString = strings.join('');
for (let i = index; i < currentString.length; i++) {
const newCombination = combination + currentString[i];
generateCombinations(strings, newCombination, i + 1, result);
}
return result;
}
return result;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(P, Q) {
let strings = [P , Q], combination = '', index = 0, result = [];
function generateCombinations(strings, combination = '', index = 0, result = []) {
if (combination.length === 3) {
result.push(combination);
return;
}
const currentString = strings.join('');
for (let i = index; i < currentString.length; i++) {
const newCombination = combination + currentString[i];
generateCombinations(strings, newCombination, i + 1, result);
}
return result;
}
return result;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(P, Q) {
let strings = [P , Q], combination = '', index = 0, result = [];
function generateCombinations(strings, combination = '', index = 0, result = []) {
if (combination.length === 3) {
result.push(combination);
return;
}
const currentString = strings.join('');
for (let i = index; i < currentString.length; i++) {
const newCombination = combination + currentString[i];
generateCombinations(strings, newCombination, i + 1, result);
}
return result;
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(P, Q) {
let strings = [P , Q];
function generateCombinations(strings, combination = '', index = 0, result = []) {
if (combination.length === 3) {
result.push(combination);
return;
}
const currentString = strings.join('');
for (let i = index; i < currentString.length; i++) {
const newCombination = combination + currentString[i];
generateCombinations(strings, newCombination, i + 1, result);
}
return result;
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(P, Q) {
let strings = [P , Q];
function generateCombinations(strings, combination = '', index = 0, result = []) {
if (combination.length === 3) {
result.push(combination);
return;
}
const currentString = strings.join('');
for (let i = index; i < currentString.length; i++) {
const newCombination = combination + currentString[i];
generateCombinations(strings, newCombination, i + 1, result);
}
return result;
}
}
Invalid result type, integer expected, 'undefined' found Perhaps you are missing a 'return'?
Invalid result type, integer expected, 'undefined' found Perhaps you are missing a 'return'?
Invalid result type, integer expected, 'undefined' found Perhaps you are missing a 'return'?
Invalid result type, integer expected, 'undefined' found Perhaps you are missing a 'return'?
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(P, Q) {
let strings = [P , Q];
function generateCombinations(strings) {
const combinations = [];
const str1 = strings[0];
const str2 = strings[1];
for (let i = 0; i < str1.length; i++) {
for (let j = 0; j < str2.length; j++) {
for (let k = 0; k < str1.length; k++) {
const combination = str1[i] + str2[j] + str1[k];
combinations.push(combination);
}
}
}
return combinations;
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(P, Q) {
function generateCombinations(strings) {
let strings = [P , Q];
const combinations = [];
const str1 = strings[0];
const str2 = strings[1];
for (let i = 0; i < str1.length; i++) {
for (let j = 0; j < str2.length; j++) {
for (let k = 0; k < str1.length; k++) {
const combination = str1[i] + str2[j] + str1[k];
combinations.push(combination);
}
}
}
return combinations;
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(P, Q) {
function generateCombinations(strings) {
strings = [P , Q];
const combinations = [];
const str1 = strings[0];
const str2 = strings[1];
for (let i = 0; i < str1.length; i++) {
for (let j = 0; j < str2.length; j++) {
for (let k = 0; k < str1.length; k++) {
const combination = str1[i] + str2[j] + str1[k];
combinations.push(combination);
}
}
}
console.log(combinations);
return combinations;
}
}
Invalid result type, integer expected, 'undefined' found Perhaps you are missing a 'return'?
Invalid result type, integer expected, 'undefined' found Perhaps you are missing a 'return'?
Invalid result type, integer expected, 'undefined' found Perhaps you are missing a 'return'?
Invalid result type, integer expected, 'undefined' found Perhaps you are missing a 'return'?
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(P, Q) {
function generateCombinations(strings) {
strings = [P , Q];
const combinations = [];
const str1 = strings[0];
const str2 = strings[1];
for (let i = 0; i < str1.length; i++) {
for (let j = 0; j < str2.length; j++) {
for (let k = 0; k < str1.length; k++) {
const combination = str1[i] + str2[j] + str1[k];
combinations.push(combination);
}
}
}
console.log(combinations);
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(P, Q) {
function generateCombinations(strings) {
strings = [P , Q];
const combinations = [];
const str1 = strings[0];
const str2 = strings[1];
for (let i = 0; i < str1.length; i++) {
for (let j = 0; j < str2.length; j++) {
for (let k = 0; k < str1.length; k++) {
const combination = str1[i] + str2[j] + str1[k];
combinations.push(combination);
}
}
}
console.log(combinations);
}return combinations;
}
ReferenceError: combinations is not defined at solution (solution.js:23:2) at solutionWrapper (/tmp/exec_user_dfyz_3v2/exec.js:396:28) at /tmp/exec_user_dfyz_3v2/exec.js:422:24
ReferenceError: combinations is not defined at solution (solution.js:23:2) at solutionWrapper (/tmp/exec_user_dfyz_3v2/exec.js:396:28) at /tmp/exec_user_dfyz_3v2/exec.js:422:24
ReferenceError: combinations is not defined at solution (solution.js:23:2) at solutionWrapper (/tmp/exec_user_dfyz_3v2/exec.js:396:28) at /tmp/exec_user_dfyz_3v2/exec.js:422:24
ReferenceError: combinations is not defined at solution (solution.js:23:2) at solutionWrapper (/tmp/exec_user_dfyz_3v2/exec.js:396:28) at /tmp/exec_user_dfyz_3v2/exec.js:422:24
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(P, Q) {
function generateCombinations(strings) {
const combinations = [];
const str1 = strings[0];
const str2 = strings[1];
for (let i = 0; i < str1.length; i++) {
for (let j = 0; j < str2.length; j++) {
for (let k = 0; k < str1.length; k++) {
const combination = str1[i] + str2[j] + str1[k];
combinations.push(combination);
}
}
}
return combinations;
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(P, Q) {
function generateCombinations(strings) {
const combinations = [];
const str1 = strings[0];
const str2 = strings[1];
for (let i = 0; i < str1.length; i++) {
for (let j = 0; j < str2.length; j++) {
for (let k = 0; k < str1.length; k++) {
const combination = str1[i] + str2[j] + str1[k];
combinations.push(combination);
}
}
}
return combinations;
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(P, Q) {
function generateCombinations(strings) {
const combinations = [];
const str1 = strings[0];
const str2 = strings[1];
for (let i = 0; i < str1.length; i++) {
for (let j = 0; j < str2.length; j++) {
for (let k = 0; k < str1.length; k++) {
const combination = str1[i] + str2[j] + str1[k];
combinations.push(combination);
}
}
}
return combinations;
}
const
generateCombinations()
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(P, Q) {
function generateCombinations(strings) {
const combinations = [];
const str1 = strings[0];
const str2 = strings[1];
for (let i = 0; i < str1.length; i++) {
for (let j = 0; j < str2.length; j++) {
for (let k = 0; k < str1.length; k++) {
const combination = str1[i] + str2[j] + str1[k];
combinations.push(combination);
}
}
}
return combinations;
}
const array = [P,Q];
generateCombinations()
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(P, Q) {
function generateCombinations(strings) {
const combinations = [];
const str1 = strings[0];
const str2 = strings[1];
for (let i = 0; i < str1.length; i++) {
for (let j = 0; j < str2.length; j++) {
for (let k = 0; k < str1.length; k++) {
const combination = str1[i] + str2[j] + str1[k];
combinations.push(combination);
}
}
}
return combinations;
}
const array = [P,Q];
generateCombinations(array)
}
Invalid result type, integer expected, 'undefined' found Perhaps you are missing a 'return'?
Invalid result type, integer expected, 'undefined' found Perhaps you are missing a 'return'?
Invalid result type, integer expected, 'undefined' found Perhaps you are missing a 'return'?
Invalid result type, integer expected, 'undefined' found Perhaps you are missing a 'return'?
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(P, Q) {
function generateCombinations(strings) {
const combinations = [];
const str1 = strings[0];
const str2 = strings[1];
for (let i = 0; i < str1.length; i++) {
for (let j = 0; j < str2.length; j++) {
for (let k = 0; k < str1.length; k++) {
const combination = str1[i] + str2[j] + str1[k];
combinations.push(combination);
}
}
}
return combinations;
}
generateCombinations(array)
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(P, Q) {
const array = [P,Q];
function generateCombinations(strings) {
const combinations = [];
const str1 = strings[0];
const str2 = strings[1];
for (let i = 0; i < str1.length; i++) {
for (let j = 0; j < str2.length; j++) {
for (let k = 0; k < str1.length; k++) {
const combination = str1[i] + str2[j] + str1[k];
combinations.push(combination);
}
}
}
return combinations;
}
generateCombinations(array)
}
Invalid result type, integer expected, 'undefined' found Perhaps you are missing a 'return'?
Invalid result type, integer expected, 'undefined' found Perhaps you are missing a 'return'?
Invalid result type, integer expected, 'undefined' found Perhaps you are missing a 'return'?
Invalid result type, integer expected, 'undefined' found Perhaps you are missing a 'return'?
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(P, Q) {
const array = [P,Q];
function generateCombinations(strings) {
const combinations = [];
const str1 = strings[0];
const str2 = strings[1];
for (let i = 0; i < str1.length; i++) {
for (let j = 0; j < str2.length; j++) {
for (let k = 0; k < str1.length; k++) {
const combination = str1[i] + str2[j] + str1[k];
combinations.push(combination);
}
}
}
return combinations;
}
return generateCombinations(array)
}
Invalid result type, integer expected, 'object' found
Invalid result type, integer expected, 'object' found
Invalid result type, integer expected, 'object' found
Invalid result type, integer expected, 'object' found
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(P, Q) {
const array = [P,Q];
function generateCombinations(strings) {
const combinations = [];
const str1 = strings[0];
const str2 = strings[1];
for (let i = 0; i < str1.length; i++) {
for (let j = 0; j < str2.length; j++) {
for (let k = 0; k < str1.length; k++) {
const combination = str1[i] + str2[j] + str1[k];
combinations.push(combination);
}
}
}
}
return generateCombinations(array)
}
Invalid result type, integer expected, 'undefined' found Perhaps you are missing a 'return'?
Invalid result type, integer expected, 'undefined' found Perhaps you are missing a 'return'?
Invalid result type, integer expected, 'undefined' found Perhaps you are missing a 'return'?
Invalid result type, integer expected, 'undefined' found Perhaps you are missing a 'return'?
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(P, Q) {
const array = [P,Q];
function generateCombinations(strings) {
const combinations = [];
const str1 = strings[0];
const str2 = strings[1];
for (let i = 0; i < str1.length; i++) {
for (let j = 0; j < str2.length; j++) {
for (let k = 0; k < str1.length; k++) {
const combination = str1[i] + str2[j] + str1[k];
combinations.push(combination);
}
}
}
}
return generateCombinations(array);
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(P, Q) {
const array = [P,Q];
function generateCombinations(strings) {
const combinations = [];
const str1 = strings[0];
const str2 = strings[1];
for (let i = 0; i < str1.length; i++) {
for (let j = 0; j < str2.length; j++) {
for (let k = 0; k < str1.length; k++) {
const combination = str1[i] + str2[j] + str1[k];
combinations.push(combination);
}
}
}
}
generateCombinations(array);
return combinations;
}
ReferenceError: combinations is not defined at solution (solution.js:25:1) at solutionWrapper (/tmp/exec_user_80x94sqh/exec.js:396:28) at /tmp/exec_user_80x94sqh/exec.js:422:24
ReferenceError: combinations is not defined at solution (solution.js:25:1) at solutionWrapper (/tmp/exec_user_80x94sqh/exec.js:396:28) at /tmp/exec_user_80x94sqh/exec.js:422:24
ReferenceError: combinations is not defined at solution (solution.js:25:1) at solutionWrapper (/tmp/exec_user_80x94sqh/exec.js:396:28) at /tmp/exec_user_80x94sqh/exec.js:422:24
ReferenceError: combinations is not defined at solution (solution.js:25:1) at solutionWrapper (/tmp/exec_user_80x94sqh/exec.js:396:28) at /tmp/exec_user_80x94sqh/exec.js:422:24
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(P, Q) {
const array = [P,Q];
function generateCombinations(strings) {
const combinations = [];
const str1 = strings[0];
const str2 = strings[1];
for (let i = 0; i < str1.length; i++) {
for (let j = 0; j < str2.length; j++) {
for (let k = 0; k < str1.length; k++) {
const combination = str1[i] + str2[j] + str1[k];
combinations.push(combination);
}
}
}
}
generateCombinations(array);
return combinations;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(P, Q) {
const array = [P,Q];
function generateCombinations(strings) {
const combinations = [];
const str1 = strings[0];
const str2 = strings[1];
for (let i = 0; i < str1.length; i++) {
for (let j = 0; j < str2.length; j++) {
for (let k = 0; k < str1.length; k++) {
const combination = str1[i] + str2[j] + str1[k];
combinations.push(combination);
}
}
}
}
generateCombinations(array);
return combinations;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(P, Q) {
const array = [P,Q];
function generateCombinations(strings) {
const combinations = [];
const str1 = strings[0];
const str2 = strings[1];
for (let i = 0; i < str1.length; i++) {
for (let j = 0; j < str2.length; j++) {
for (let k = 0; k < str1.length; k++) {
const combination = str1[i] + str2[j] + str1[k];
combinations.push(combination);
}
}
}
}
generateCombinations(array);
return combinations;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(P, Q) {
const array = [P,Q];
function generateCombinations(strings) {
const combinations = [];
const str1 = strings[0];
const str2 = strings[1];
for (let i = 0; i < str1.length; i++) {
for (let j = 0; j < str2.length; j++) {
for (let k = 0; k < str1.length; k++) {
const combination = str1[i] + str2[j] + str1[k];
combinations.push(combination);
}
}
}
}
generateCombinations(array);
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(P, Q) {
const array = [P,Q];
function generateCombinations(strings) {
const combinations = [];
const str1 = strings[0];
const str2 = strings[1];
for (let i = 0; i < str1.length; i++) {
for (let j = 0; j < str2.length; j++) {
for (let k = 0; k < str1.length; k++) {
const combination = str1[i] + str2[j] + str1[k];
combinations.push(combination);
}
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(P, Q) {
const array = [P,Q];
const combinations = [];
const str1 = strings[0];
const str2 = strings[1];
for (let i = 0; i < str1.length; i++) {
for (let j = 0; j < str2.length; j++) {
for (let k = 0; k < str1.length; k++) {
const combination = str1[i] + str2[j] + str1[k];
combinations.push(combination);
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(P, Q) {
const strings = [P,Q];
const combinations = [];
const str1 = strings[0];
const str2 = strings[1];
for (let i = 0; i < str1.length; i++) {
for (let j = 0; j < str2.length; j++) {
for (let k = 0; k < str1.length; k++) {
const combination = str1[i] + str2[j] + str1[k];
combinations.push(combination);
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(P, Q) {
const strings = [P,Q];
const combinations = [];
const str1 = strings[0];
const str2 = strings[1];
for (let i = 0; i < str1.length; i++) {
for (let j = 0; j < str2.length; j++) {
for (let k = 0; k < str1.length; k++) {
const combination = str1[i] + str2[j] + str1[k];
combinations.push(combination);
}
}
}
console.log();
return combinations;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(P, Q) {
const strings = [P,Q];
const combinations = [];
const str1 = strings[0];
const str2 = strings[1];
for (let i = 0; i < str1.length; i++) {
for (let j = 0; j < str2.length; j++) {
for (let k = 0; k < str1.length; k++) {
const combination = str1[i] + str2[j] + str1[k];
combinations.push(combination);
}
}
}
console.log(combinations);
return combinations;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(P, Q) {
const strings = [P,Q];
const combinations = [];
const str1 = strings[0];
const str2 = strings[1];
for (let i = 0; i < str1.length; i++) {
for (let j = 0; j < str2.length; j++) {
for (let k = 0; k < str1.length; k++) {
const combination = str1[i] + str2[j] + str1[k];
combinations.push(combination);
}
}
}
console.log(combinations);
return combinations;
}
Invalid result type, integer expected, 'object' foundstdout:
[ 'aba', 'abb', 'abc', 'aca', 'acb', 'acc', 'ada', 'adb', 'adc', 'bba', 'bbb', 'bbc', 'bca', 'bcb', 'bcc', 'bda', 'bdb', 'bdc', 'cba', 'cbb', 'cbc', 'cca', 'ccb', 'ccc', 'cda', 'cdb', 'cdc' ]
Invalid result type, integer expected, 'object' foundstdout:
[ 'aya', 'ayx', 'ayx', 'ayz', 'aza', 'azx', 'azx', 'azz', 'awa', 'awx', 'awx', 'awz', 'aya', 'ayx', 'ayx', 'ayz', 'xya', 'xyx', 'xyx', 'xyz', 'xza', 'xzx', 'xzx', 'xzz', 'xwa', 'xwx', 'xwx', 'xwz', 'xya', 'xyx', 'xyx', 'xyz', 'xya', 'xyx', 'xyx', 'xyz', 'xza', 'xzx', 'xzx', 'xzz', 'xwa', 'xwx', 'xwx', 'xwz', 'xya', 'xyx', 'xyx', 'xyz', 'zya', 'zyx', 'zyx', 'zyz', 'zza', 'zzx', 'zzx', 'zzz', 'zwa', 'zwx', 'zwx', 'zwz', 'zya', 'zyx', 'zyx', 'zyz' ]
Invalid result type, integer expected, 'object' foundstdout:
[ 'bab', 'baa', 'bac', 'baa', 'bad', 'bbb', 'bba', 'bbc', 'bba', 'bbd', 'bab', 'baa', 'bac', 'baa', 'bad', 'bdb', 'bda', 'bdc', 'bda', 'bdd', 'bab', 'baa', 'bac', 'baa', 'bad', 'aab', 'aaa', 'aac', 'aaa', 'aad', 'abb', 'aba', 'abc', 'aba', 'abd', 'aab', 'aaa', 'aac', 'aaa', 'aad', 'adb', 'ada', 'adc', 'ada', 'add', 'aab', 'aaa', 'aac', 'aaa', 'aad', 'cab', 'caa', 'cac', 'caa', 'cad', 'cbb', 'cba', 'cbc', 'cba', 'cbd', 'cab', 'caa', 'cac', 'caa', 'cad', 'cdb', 'cda', 'cdc', 'cda', 'cdd', 'cab', 'caa', 'cac', 'caa', 'cad', 'aab', 'aaa', 'aac', 'aaa', 'aad', 'abb', 'aba', 'abc', 'aba', 'abd', 'aab', 'aaa', 'aac', 'aaa', 'aad', 'adb', 'ada', 'adc', 'ada', 'add', 'aab', 'aaa', 'aac', 'aaa', 'aad', ... 25 more items ]
Invalid result type, integer expected, 'object' foundstdout:
[ 'aaa', 'aam', 'aaz', 'ama', 'amm', 'amz', 'aza', 'azm', 'azz', 'maa', 'mam', 'maz', 'mma', 'mmm', 'mmz', 'mza', 'mzm', 'mzz', 'zaa', 'zam', 'zaz', 'zma', 'zmm', 'zmz', 'zza', 'zzm', 'zzz' ]
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function dfs(have, now, state, mark, num, ans) {
if (num >= ans) {
return;
}
const mask = 1 << now;
if (mask > have) {
ans[0] = num;
return;
}
if ((mask & have) === 0) {
dfs(have, now + 1, state, mark, num, ans);
} else {
let temp = 0, d = 0;
for (let i = now + 1; i < 26; ++i) {
if (mark[i][now] && (have & (1 << i)) > 0) {
temp |= 1 << i;
++d;
}
}
dfs(have ^ temp, now + 1, state | temp, mark, num + d, ans);
dfs(have, now + 1, state | mask, mark, num + 1, ans);
}
}
function solution(P, Q) {
const mark = Array.from({ length: 26 }, () => Array(26).fill(false));
const n = P.length;
for (let i = 0; i < n; ++i) {
const p = P.charCodeAt(i) - 'a'.charCodeAt(0);
const q = Q.charCodeAt(i) - 'a'.charCodeAt(0);
mark[p][q] = mark[q][p] = true;
}
let temp = 0;
for (let i = 0; i < 26; ++i) {
if (mark[i][i]) {
++temp;
for (let j = 0; j < 26; ++j) {
mark[i][j] = mark[j][i] = false;
}
}
}
let have = 0;
for (let i = 0; i < 26; ++i) {
for (let j = 0; j < 26; ++j) {
if (mark[i][j]) {
have |= 1 << i;
break;
}
}
}
const ans = [P.length];
dfs(have, 0, 0, mark, temp, ans);
return ans[0];
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function dfs(have, now, state, mark, num, ans) {
if (num >= ans) {
return;
}
const mask = 1 << now;
if (mask > have) {
ans[0] = num;
return;
}
if ((mask & have) === 0) {
dfs(have, now + 1, state, mark, num, ans);
} else {
let temp = 0, d = 0;
for (let i = now + 1; i < 26; ++i) {
if (mark[i][now] && (have & (1 << i)) > 0) {
temp |= 1 << i;
++d;
}
}
dfs(have ^ temp, now + 1, state | temp, mark, num + d, ans);
dfs(have, now + 1, state | mask, mark, num + 1, ans);
}
}
function solution(P, Q) {
const mark = Array.from({ length: 26 }, () => Array(26).fill(false));
const n = P.length;
for (let i = 0; i < n; ++i) {
const p = P.charCodeAt(i) - 'a'.charCodeAt(0);
const q = Q.charCodeAt(i) - 'a'.charCodeAt(0);
mark[p][q] = mark[q][p] = true;
}
let temp = 0;
for (let i = 0; i < 26; ++i) {
if (mark[i][i]) {
++temp;
for (let j = 0; j < 26; ++j) {
mark[i][j] = mark[j][i] = false;
}
}
}
let have = 0;
for (let i = 0; i < 26; ++i) {
for (let j = 0; j < 26; ++j) {
if (mark[i][j]) {
have |= 1 << i;
break;
}
}
}
const ans = [P.length];
dfs(have, 0, 0, mark, temp, ans);
return ans[0];
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function dfs(have, now, state, mark, num, ans) {
if (num >= ans) {
return;
}
const mask = 1 << now;
if (mask > have) {
ans[0] = num;
return;
}
if ((mask & have) === 0) {
dfs(have, now + 1, state, mark, num, ans);
} else {
let temp = 0, d = 0;
for (let i = now + 1; i < 26; ++i) {
if (mark[i][now] && (have & (1 << i)) > 0) {
temp |= 1 << i;
++d;
}
}
dfs(have ^ temp, now + 1, state | temp, mark, num + d, ans);
dfs(have, now + 1, state | mask, mark, num + 1, ans);
}
}
function solution(P, Q) {
const mark = Array.from({ length: 26 }, () => Array(26).fill(false));
const n = P.length;
for (let i = 0; i < n; ++i) {
const p = P.charCodeAt(i) - 'a'.charCodeAt(0);
const q = Q.charCodeAt(i) - 'a'.charCodeAt(0);
mark[p][q] = mark[q][p] = true;
}
let temp = 0;
for (let i = 0; i < 26; ++i) {
if (mark[i][i]) {
++temp;
for (let j = 0; j < 26; ++j) {
mark[i][j] = mark[j][i] = false;
}
}
}
let have = 0;
for (let i = 0; i < 26; ++i) {
for (let j = 0; j < 26; ++j) {
if (mark[i][j]) {
have |= 1 << i;
break;
}
}
}
const ans = [P.length];
dfs(have, 0, 0, mark, temp, ans);
return ans[0];
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
//In his code we are creating
function dfs(have, now, state, mark, num, ans) {
if (num >= ans) {
return;
}
const mask = 1 << now;
if (mask > have) {
ans[0] = num;
return;
}
if ((mask & have) === 0) {
dfs(have, now + 1, state, mark, num, ans);
} else {
let temp = 0, d = 0;
for (let i = now + 1; i < 26; ++i) {
if (mark[i][now] && (have & (1 << i)) > 0) {
temp |= 1 << i;
++d;
}
}
dfs(have ^ temp, now + 1, state | temp, mark, num + d, ans);
dfs(have, now + 1, state | mask, mark, num + 1, ans);
}
}
function solution(P, Q) {
const mark = Array.from({ length: 26 }, () => Array(26).fill(false));
const n = P.length;
for (let i = 0; i < n; ++i) {
const p = P.charCodeAt(i) - 'a'.charCodeAt(0);
const q = Q.charCodeAt(i) - 'a'.charCodeAt(0);
mark[p][q] = mark[q][p] = true;
}
let temp = 0;
for (let i = 0; i < 26; ++i) {
if (mark[i][i]) {
++temp;
for (let j = 0; j < 26; ++j) {
mark[i][j] = mark[j][i] = false;
}
}
}
let have = 0;
for (let i = 0; i < 26; ++i) {
for (let j = 0; j < 26; ++j) {
if (mark[i][j]) {
have |= 1 << i;
break;
}
}
}
const ans = [P.length];
dfs(have, 0, 0, mark, temp, ans);
return ans[0];
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
//In his code we are creating
function firstSearch(have, now, state, mark, num, ans) {
if (num >= ans) {
return;
}
const mask = 1 << now;
if (mask > have) {
ans[0] = num;
return;
}
if ((mask & have) === 0) {
firstSearch(have, now + 1, state, mark, num, ans);
} else {
let temp = 0, d = 0;
for (let i = now + 1; i < 26; ++i) {
if (mark[i][now] && (have & (1 << i)) > 0) {
temp |= 1 << i;
++d;
}
}
firstSearch(have ^ temp, now + 1, state | temp, mark, num + d, ans);
firstSearch(have, now + 1, state | mask, mark, num + 1, ans);
}
}
function solution(P, Q) {
const mark = Array.from({ length: 26 }, () => Array(26).fill(false));
const n = P.length;
for (let i = 0; i < n; ++i) {
const p = P.charCodeAt(i) - 'a'.charCodeAt(0);
const q = Q.charCodeAt(i) - 'a'.charCodeAt(0);
mark[p][q] = mark[q][p] = true;
}
let temp = 0;
for (let i = 0; i < 26; ++i) {
if (mark[i][i]) {
++temp;
for (let j = 0; j < 26; ++j) {
mark[i][j] = mark[j][i] = false;
}
}
}
let have = 0;
for (let i = 0; i < 26; ++i) {
for (let j = 0; j < 26; ++j) {
if (mark[i][j]) {
have |= 1 << i;
break;
}
}
}
const ans = [P.length];
firstSearch(have, 0, 0, mark, temp, ans);
return ans[0];
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
//In his code we are creating
function firstSearch(letters, now, state, mark, num, ans) {
if (num >= ans) {
return;
}
const mask = 1 << now;
if (mask > letters) {
ans[0] = num;
return;
}
if ((mask & letters) === 0) {
firstSearch(letters, now + 1, state, mark, num, ans);
} else {
let temp = 0, d = 0;
for (let i = now + 1; i < 26; ++i) {
if (mark[i][now] && (letters & (1 << i)) > 0) {
temp |= 1 << i;
++d;
}
}
firstSearch(letters ^ temp, now + 1, state | temp, mark, num + d, ans);
firstSearch(letters, now + 1, state | mask, mark, num + 1, ans);
}
}
function solution(P, Q) {
const mark = Array.from({ length: 26 }, () => Array(26).fill(false));
const n = P.length;
for (let i = 0; i < n; ++i) {
const p = P.charCodeAt(i) - 'a'.charCodeAt(0);
const q = Q.charCodeAt(i) - 'a'.charCodeAt(0);
mark[p][q] = mark[q][p] = true;
}
let temp = 0;
for (let i = 0; i < 26; ++i) {
if (mark[i][i]) {
++temp;
for (let j = 0; j < 26; ++j) {
mark[i][j] = mark[j][i] = false;
}
}
}
let have = 0;
for (let i = 0; i < 26; ++i) {
for (let j = 0; j < 26; ++j) {
if (mark[i][j]) {
have |= 1 << i;
break;
}
}
}
const ans = [P.length];
firstSearch(have, 0, 0, mark, temp, ans);
return ans[0];
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
//In his code we are creating
function firstSearch(letters, current, state, mark, num, ans) {
if (num >= ans) {
return;
}
const mask = 1 << current;
if (mask > letters) {
ans[0] = num;
return;
}
if ((mask & letters) === 0) {
firstSearch(letters, current + 1, state, mark, num, ans);
} else {
let temp = 0, d = 0;
for (let i = current + 1; i < 26; ++i) {
if (mark[i][current] && (letters & (1 << i)) > 0) {
temp |= 1 << i;
++d;
}
}
firstSearch(letters ^ temp, current + 1, state | temp, mark, num + d, ans);
firstSearch(letters, current + 1, state | mask, mark, num + 1, ans);
}
}
function solution(P, Q) {
const mark = Array.from({ length: 26 }, () => Array(26).fill(false));
const n = P.length;
for (let i = 0; i < n; ++i) {
const p = P.charCodeAt(i) - 'a'.charCodeAt(0);
const q = Q.charCodeAt(i) - 'a'.charCodeAt(0);
mark[p][q] = mark[q][p] = true;
}
let temp = 0;
for (let i = 0; i < 26; ++i) {
if (mark[i][i]) {
++temp;
for (let j = 0; j < 26; ++j) {
mark[i][j] = mark[j][i] = false;
}
}
}
let have = 0;
for (let i = 0; i < 26; ++i) {
for (let j = 0; j < 26; ++j) {
if (mark[i][j]) {
have |= 1 << i;
break;
}
}
}
const ans = [P.length];
firstSearch(have, 0, 0, mark, temp, ans);
return ans[0];
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
//In his code we are creating
function firstSearch(letters, current, selectedLetter, mark, num, ans) {
if (num >= ans) {
return;
}
const mask = 1 << current;
if (mask > letters) {
ans[0] = num;
return;
}
if ((mask & letters) === 0) {
firstSearch(letters, current + 1, selectedLetter, mark, num, ans);
} else {
let temp = 0, d = 0;
for (let i = current + 1; i < 26; ++i) {
if (mark[i][current] && (letters & (1 << i)) > 0) {
temp |= 1 << i;
++d;
}
}
firstSearch(letters ^ temp, current + 1, selectedLetter | temp, mark, num + d, ans);
firstSearch(letters, current + 1, selectedLetter | mask, mark, num + 1, ans);
}
}
function solution(P, Q) {
const mark = Array.from({ length: 26 }, () => Array(26).fill(false));
const n = P.length;
for (let i = 0; i < n; ++i) {
const p = P.charCodeAt(i) - 'a'.charCodeAt(0);
const q = Q.charCodeAt(i) - 'a'.charCodeAt(0);
mark[p][q] = mark[q][p] = true;
}
let temp = 0;
for (let i = 0; i < 26; ++i) {
if (mark[i][i]) {
++temp;
for (let j = 0; j < 26; ++j) {
mark[i][j] = mark[j][i] = false;
}
}
}
let have = 0;
for (let i = 0; i < 26; ++i) {
for (let j = 0; j < 26; ++j) {
if (mark[i][j]) {
have |= 1 << i;
break;
}
}
}
const ans = [P.length];
firstSearch(have, 0, 0, mark, temp, ans);
return ans[0];
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
//In his code we are creating
function firstSearch(letters, current, selectedLetter, flag, num, ans) {
if (num >= ans) {
return;
}
const mask = 1 << current;
if (mask > letters) {
ans[0] = num;
return;
}
if ((mask & letters) === 0) {
firstSearch(letters, current + 1, selectedLetter, flag, num, ans);
} else {
let temp = 0, d = 0;
for (let i = current + 1; i < 26; ++i) {
if (flag[i][current] && (letters & (1 << i)) > 0) {
temp |= 1 << i;
++d;
}
}
firstSearch(letters ^ temp, current + 1, selectedLetter | temp, flag, num + d, ans);
firstSearch(letters, current + 1, selectedLetter | mask, flag, num + 1, ans);
}
}
function solution(P, Q) {
const mark = Array.from({ length: 26 }, () => Array(26).fill(false));
const n = P.length;
for (let i = 0; i < n; ++i) {
const p = P.charCodeAt(i) - 'a'.charCodeAt(0);
const q = Q.charCodeAt(i) - 'a'.charCodeAt(0);
mark[p][q] = mark[q][p] = true;
}
let temp = 0;
for (let i = 0; i < 26; ++i) {
if (mark[i][i]) {
++temp;
for (let j = 0; j < 26; ++j) {
mark[i][j] = mark[j][i] = false;
}
}
}
let have = 0;
for (let i = 0; i < 26; ++i) {
for (let j = 0; j < 26; ++j) {
if (mark[i][j]) {
have |= 1 << i;
break;
}
}
}
const ans = [P.length];
firstSearch(have, 0, 0, mark, temp, ans);
return ans[0];
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
//In his code we are creating
function firstSearch(letters, current, selectedLetter, flag, currentLettersSize, ans) {
if (currentLettersSize >= ans) {
return;
}
const mask = 1 << current;
if (mask > letters) {
ans[0] = currentLettersSize;
return;
}
if ((mask & letters) === 0) {
firstSearch(letters, current + 1, selectedLetter, flag, currentLettersSize, ans);
} else {
let temp = 0, d = 0;
for (let i = current + 1; i < 26; ++i) {
if (flag[i][current] && (letters & (1 << i)) > 0) {
temp |= 1 << i;
++d;
}
}
firstSearch(letters ^ temp, current + 1, selectedLetter | temp, flag, currentLettersSize + d, ans);
firstSearch(letters, current + 1, selectedLetter | mask, flag, currentLettersSize + 1, ans);
}
}
function solution(P, Q) {
const mark = Array.from({ length: 26 }, () => Array(26).fill(false));
const n = P.length;
for (let i = 0; i < n; ++i) {
const p = P.charCodeAt(i) - 'a'.charCodeAt(0);
const q = Q.charCodeAt(i) - 'a'.charCodeAt(0);
mark[p][q] = mark[q][p] = true;
}
let temp = 0;
for (let i = 0; i < 26; ++i) {
if (mark[i][i]) {
++temp;
for (let j = 0; j < 26; ++j) {
mark[i][j] = mark[j][i] = false;
}
}
}
let have = 0;
for (let i = 0; i < 26; ++i) {
for (let j = 0; j < 26; ++j) {
if (mark[i][j]) {
have |= 1 << i;
break;
}
}
}
const ans = [P.length];
firstSearch(have, 0, 0, mark, temp, ans);
return ans[0];
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
//In his code we are creating
function firstSearch(letters, current, selectedLetter, flag, currentLettersSize, minOperationsNeeded) {
if (currentLettersSize >= minOperationsNeeded) {
return;
}
const mask = 1 << current;
if (mask > letters) {
minOperationsNeeded[0] = currentLettersSize;
return;
}
if ((mask & letters) === 0) {
firstSearch(letters, current + 1, selectedLetter, flag, currentLettersSize, minOperationsNeeded);
} else {
let temp = 0, d = 0;
for (let i = current + 1; i < 26; ++i) {
if (flag[i][current] && (letters & (1 << i)) > 0) {
temp |= 1 << i;
++d;
}
}
firstSearch(letters ^ temp, current + 1, selectedLetter | temp, flag, currentLettersSize + d, minOperationsNeeded);
firstSearch(letters, current + 1, selectedLetter | mask, flag, currentLettersSize + 1, minOperationsNeeded);
}
}
function solution(P, Q) {
const mark = Array.from({ length: 26 }, () => Array(26).fill(false));
const n = P.length;
for (let i = 0; i < n; ++i) {
const p = P.charCodeAt(i) - 'a'.charCodeAt(0);
const q = Q.charCodeAt(i) - 'a'.charCodeAt(0);
mark[p][q] = mark[q][p] = true;
}
let temp = 0;
for (let i = 0; i < 26; ++i) {
if (mark[i][i]) {
++temp;
for (let j = 0; j < 26; ++j) {
mark[i][j] = mark[j][i] = false;
}
}
}
let have = 0;
for (let i = 0; i < 26; ++i) {
for (let j = 0; j < 26; ++j) {
if (mark[i][j]) {
have |= 1 << i;
break;
}
}
}
const ans = [P.length];
firstSearch(have, 0, 0, mark, temp, ans);
return ans[0];
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
//In his code we are creating
function firstSearch(letters, current, selectedLetter, flag, currentLettersSize, minOperationsNeeded) {
if (currentLettersSize >= minOperationsNeeded) {
return;
}
const lettersSize = 1 << current;
if (lettersSize > letters) {
minOperationsNeeded[0] = currentLettersSize;
return;
}
if ((lettersSize & letters) === 0) {
firstSearch(letters, current + 1, selectedLetter, flag, currentLettersSize, minOperationsNeeded);
} else {
let temp = 0, d = 0;
for (let i = current + 1; i < 26; ++i) {
if (flag[i][current] && (letters & (1 << i)) > 0) {
temp |= 1 << i;
++d;
}
}
firstSearch(letters ^ temp, current + 1, selectedLetter | temp, flag, currentLettersSize + d, minOperationsNeeded);
firstSearch(letters, current + 1, selectedLetter | lettersSize, flag, currentLettersSize + 1, minOperationsNeeded);
}
}
function solution(P, Q) {
const mark = Array.from({ length: 26 }, () => Array(26).fill(false));
const n = P.length;
for (let i = 0; i < n; ++i) {
const p = P.charCodeAt(i) - 'a'.charCodeAt(0);
const q = Q.charCodeAt(i) - 'a'.charCodeAt(0);
mark[p][q] = mark[q][p] = true;
}
let temp = 0;
for (let i = 0; i < 26; ++i) {
if (mark[i][i]) {
++temp;
for (let j = 0; j < 26; ++j) {
mark[i][j] = mark[j][i] = false;
}
}
}
let have = 0;
for (let i = 0; i < 26; ++i) {
for (let j = 0; j < 26; ++j) {
if (mark[i][j]) {
have |= 1 << i;
break;
}
}
}
const ans = [P.length];
firstSearch(have, 0, 0, mark, temp, ans);
return ans[0];
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
//In his code we are creating
function firstSearch(letters, current, selectedLetter, flag, currentLettersSize, minOperationsNeeded) {
if (currentLettersSize >= minOperationsNeeded) {
return;
}
const lettersSize = 1 << current;
if (lettersSize > letters) {
minOperationsNeeded[0] = currentLettersSize;
return;
}
if ((lettersSize & letters) === 0) {
firstSearch(letters, current + 1, selectedLetter, flag, currentLettersSize, minOperationsNeeded);
} else {
let temp = 0, d = 0;
for (let i = current + 1; i < 26; ++i) {
if (flag[i][current] && (letters & (1 << i)) > 0) {
temp |= 1 << i;
++d;
}
}
firstSearch(letters ^ temp, current + 1, selectedLetter | temp, flag, currentLettersSize + d, minOperationsNeeded);
firstSearch(letters, current + 1, selectedLetter | lettersSize, flag, currentLettersSize + 1, minOperationsNeeded);
}
}
function solution(P, Q) {
const mark = Array.from({ length: 26 }, () => Array(26).fill(false));
const n = P.length;
for (let i = 0; i < n; ++i) {
const p = P.charCodeAt(i) - 'a'.charCodeAt(0);
const q = Q.charCodeAt(i) - 'a'.charCodeAt(0);
mark[p][q] = mark[q][p] = true;
}
let temp = 0;
for (let i = 0; i < 26; ++i) {
if (mark[i][i]) {
++temp;
for (let j = 0; j < 26; ++j) {
mark[i][j] = mark[j][i] = false;
}
}
}
let have = 0;
for (let i = 0; i < 26; ++i) {
for (let j = 0; j < 26; ++j) {
if (mark[i][j]) {
have |= 1 << i;
break;
}
}
}
const ans = [P.length];
firstSearch(have, 0, 0, mark, temp, ans);
return ans[0];
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
//In his code we are creating
function firstSearch(letters, current, selectedLetter, flag, currentLettersSize, minOperationsNeeded) {
if (currentLettersSize >= minOperationsNeeded) {
return;
}
const lettersSize = 1 << current;
if (lettersSize > letters) {
minOperationsNeeded[0] = currentLettersSize;
return;
}
if ((lettersSize & letters) === 0) {
firstSearch(letters, current + 1, selectedLetter, flag, currentLettersSize, minOperationsNeeded);
} else {
let temp = 0, d = 0;
for (let i = current + 1; i < 26; ++i) {
if (flag[i][current] && (letters & (1 << i)) > 0) {
temp |= 1 << i;
++d;
}
}
firstSearch(letters ^ temp, current + 1, selectedLetter | temp, flag, currentLettersSize + d, minOperationsNeeded);
firstSearch(letters, current + 1, selectedLetter | lettersSize, flag, currentLettersSize + 1, minOperationsNeeded);
}
}
function solution(P, Q) {
const mark = Array.from({ length: 26 }, () => Array(26).fill(false));
const n = P.length;
for (let i = 0; i < n; ++i) {
const p = P.charCodeAt(i) - 'a'.charCodeAt(0);
const q = Q.charCodeAt(i) - 'a'.charCodeAt(0);
mark[p][q] = mark[q][p] = true;
}
let temp = 0;
for (let i = 0; i < 26; ++i) {
if (mark[i][i]) {
++temp;
for (let j = 0; j < 26; ++j) {
mark[i][j] = mark[j][i] = false;
}
}
}
let have = 0;
for (let i = 0; i < 26; ++i) {
for (let j = 0; j < 26; ++j) {
if (mark[i][j]) {
have |= 1 << i;
break;
}
}
}
const ans = [P.length];
firstSearch(have, 0, 0, mark, temp, ans);
return ans[0];
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
//In his code we are creating
function firstSearch(letters, current, selectedLetter, flag, currentLettersSize, minOperationsNeeded) {
if (currentLettersSize >= minOperationsNeeded) {
return;
}
const lettersSize = 1 << current;
if (lettersSize > letters) {
minOperationsNeeded[0] = currentLettersSize;
return;
}
if ((lettersSize & letters) === 0) {
firstSearch(letters, current + 1, selectedLetter, flag, currentLettersSize, minOperationsNeeded);
} else {
let temp = 0, d = 0;
for (let i = current + 1; i < 26; ++i) {
if (flag[i][current] && (letters & (1 << i)) > 0) {
temp |= 1 << i;
++d;
}
}
firstSearch(letters ^ temp, current + 1, selectedLetter | temp, flag, currentLettersSize + d, minOperationsNeeded);
firstSearch(letters, current + 1, selectedLetter | lettersSize, flag, currentLettersSize + 1, minOperationsNeeded);
}
}
function solution(P, Q) {
const mark = Array.from({ length: 26 }, () => Array(26).fill(false));
const n = P.length;
for (let i = 0; i < n; ++i) {
const p = P.charCodeAt(i) - 'a'.charCodeAt(0);
const q = Q.charCodeAt(i) - 'a'.charCodeAt(0);
mark[p][q] = mark[q][p] = true;
}
let temp = 0;
for (let i = 0; i < 26; ++i) {
if (mark[i][i]) {
++temp;
for (let j = 0; j < 26; ++j) {
mark[i][j] = mark[j][i] = false;
}
}
}
let have = 0;
for (let i = 0; i < 26; ++i) {
for (let j = 0; j < 26; ++j) {
if (mark[i][j]) {
have |= 1 << i;
break;
}
}
}
const ans = [P.length];
firstSearch(have, 0, 0, mark, temp, ans);
return ans[0];
}
The solution obtained perfect score.
A - size of the alphabet
Small tests where some letters have big but similar frequencies, N <= 17, A <= 12.