From cb726c62b1895a23135caf8c79ca53649663865b Mon Sep 17 00:00:00 2001 From: prabakaran19931593858554573 Date: Wed, 22 Jul 2020 22:47:42 +0530 Subject: [PATCH 01/23] master --- Mock Test/1.md | 61 -------------------------------- Mock Test/2.md | 32 ----------------- adhoc/incre-decre-sqaure-sort.js | 22 ------------ 3 files changed, 115 deletions(-) delete mode 100644 Mock Test/1.md delete mode 100644 Mock Test/2.md delete mode 100644 adhoc/incre-decre-sqaure-sort.js diff --git a/Mock Test/1.md b/Mock Test/1.md deleted file mode 100644 index dd48114..0000000 --- a/Mock Test/1.md +++ /dev/null @@ -1,61 +0,0 @@ -// IMPORT LIBRARY PACKAGES NEEDED BY YOUR PROGRAM -// SOME FUNCTIONALITY WITHIN A PACKAGE MAY BE RESTRICTED -// DEFINE ANY FUNCTION NEEDED -// FUNCTION SIGNATURE BEGINS, THIS FUNCTION IS REQUIRED -``` -function cellCompete(states, days) -{ - let ar = [] - while(days--){ - for(var i=0;iTestcase 1:
Input:
[1, 0, 0, 0, 0, 1, 0, 0], 1

Expected Return Value:
0 1 0 0 1 0 1 0


Testcase 2:
Input:
[1, 1, 1, 0, 1, 1, 1, 1], 2

Expected Return Value:
0 0 0 0 0 1 1 0
\ No newline at end of file diff --git a/Mock Test/2.md b/Mock Test/2.md deleted file mode 100644 index 2cd3dbf..0000000 --- a/Mock Test/2.md +++ /dev/null @@ -1,32 +0,0 @@ - -// IMPORT LIBRARY PACKAGES NEEDED BY YOUR PROGRAM -// SOME FUNCTIONALITY WITHIN A PACKAGE MAY BE RESTRICTED -// DEFINE ANY FUNCTION NEEDED -// FUNCTION SIGNATURE BEGINS, THIS FUNCTION IS REQUIRED -``` -function gcd(a,b) { - if(b === 0) { - return a; - } - return gcd(b, a%b) - } - function generalizedGCD(num, arr) - { - let f = arr[num-1]; - - for(let i=num-2;i>=0;i--) { - f = gcd(f,arr[i]); - } - return f; - } - // FUNCTION SIGNATURE ENDS -``` -
-

The current selected programming language is JavaScript. We emphasize the submission of a fully working code over partially correct but efficient code. Once Test is submitted, you cannot review this problem again. You can use console.log to debug your code. We use NodeJS 10.13 to evaluate your code.

-

-

The greatest common divisor (GCD), also called highest common factor (HCF) of N numbers is the largest positive integer that divides all numbers without giving a remainder.

Write an algorithm to determine the GCD of N positive integers.

Input
The input to the function/method consists of two arguments - 
num, an integer representing the number of positive integers (N). 
arr, a list of positive integers.

-

Output
Return an integer representing the GCD of the given positive integers.

Example
Input:
num = 5 
arr = [2, 4, 6, 8, 10]

-

Output:
2

-

Explanation:
The largest positive integer that divides all the positive integers 2, 4, 6, 8, 10 without a remainder is 2.
So, the output is 2.

- -
\ No newline at end of file diff --git a/adhoc/incre-decre-sqaure-sort.js b/adhoc/incre-decre-sqaure-sort.js deleted file mode 100644 index d5ef0f8..0000000 --- a/adhoc/incre-decre-sqaure-sort.js +++ /dev/null @@ -1,22 +0,0 @@ -const fun = (n, val) => { - if (val >= 10 && parseInt((val + "").split("").sort((x, y) => x < y).join("")) === n) - return 1; - if ((val - 1) === n) { - return 1; - } - if (val > n) { - return 9999; - } - if (val === n) { - return 0; - } - let a = 1 + fun(n, val + 1); - let b = 1 + fun(n, Math.pow(val, 2)); - return Math.min(a, b); -} - -console.log(fun(3, 2) + 2); -console.log(fun(5, 2) + 2); -console.log(fun(15, 2) + 2); -console.log(fun(61, 2) + 2); -console.log(fun(18, 2) + 2); \ No newline at end of file From fcd9b184b2f4dde8b32aeea0aba5b7a4b9a44009 Mon Sep 17 00:00:00 2001 From: prabakaran19931593858554573 Date: Thu, 23 Jul 2020 18:27:58 +0530 Subject: [PATCH 02/23] encryption --- encryption.js | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 encryption.js diff --git a/encryption.js b/encryption.js new file mode 100644 index 0000000..80da723 --- /dev/null +++ b/encryption.js @@ -0,0 +1,69 @@ +'use strict'; + +const fs = require('fs'); + +process.stdin.resume(); +process.stdin.setEncoding('utf-8'); + +let inputString = ''; +let currentLine = 0; + +process.stdin.on('data', inputStdin => { + inputString += inputStdin; +}); + +process.stdin.on('end', _ => { + inputString = inputString.replace(/\s*$/, '') + .split('\n') + .map(str => str.replace(/\s*$/, '')); + + main(); +}); + +function readLine() { + return inputString[currentLine++]; +} +function getMatrixDimension(s) { + let len = Math.floor(Math.sqrt(s.length)); + let m = len; + let n = len + 1; + if ((m * n) < s.length) { + m = n = len + 1; + } + else if (Math.sqrt(s.length) % 1 === 0) { + m = n = Math.sqrt(s.length); + } + return [m, n]; +} +// Complete the encryption function below. +function encryption(s) { + let [m, n] = getMatrixDimension(s); + let strindex = 0; + let grid = []; + for (let i = 0; i < m; i++) { + grid[i] = []; + for (let j = 0; j < n; j++) { + grid[i][j] = s[strindex] || ''; + strindex++; + } + } + let out = ""; + for (let i = 0; i < n; i++) { + for (let j = 0; j < m; j++) { + out += grid[j][i]; + } out += " "; + } + return out; +} + +function main() { + const ws = fs.createWriteStream(process.env.OUTPUT_PATH); + + const s = readLine(); + + let result = encryption(s); + + ws.write(result + "\n"); + + ws.end(); +} From 1dc96776e03219d504d5765e6cfc22e277f01a9d Mon Sep 17 00:00:00 2001 From: prabakaran19931593858554573 Date: Fri, 24 Jul 2020 21:45:07 +0530 Subject: [PATCH 03/23] #organizing containers of balls --- organizing-containers-of-balls.js | 69 +++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 organizing-containers-of-balls.js diff --git a/organizing-containers-of-balls.js b/organizing-containers-of-balls.js new file mode 100644 index 0000000..2cc9dbe --- /dev/null +++ b/organizing-containers-of-balls.js @@ -0,0 +1,69 @@ +'use strict'; + +const fs = require('fs'); + +process.stdin.resume(); +process.stdin.setEncoding('utf-8'); + +let inputString = ''; +let currentLine = 0; + +process.stdin.on('data', inputStdin => { + inputString += inputStdin; +}); + +process.stdin.on('end', _ => { + inputString = inputString.replace(/\s*$/, '') + .split('\n') + .map(str => str.replace(/\s*$/, '')); + + main(); +}); + +function readLine() { + return inputString[currentLine++]; +} + +// Complete the organizingContainers function below. +function organizingContainers(container) { + let containerCount = new Array(container.length).fill(0); + let typeCount = new Array(container.length).fill(0) + container.forEach((type, i_index) => { + type.forEach((val, j_index) => { + containerCount[i_index] += val; + typeCount[j_index] += val; + }); + }); + let pts = "Possible"; + containerCount = containerCount.sort(); + typeCount = typeCount.sort(); + for (let i = 0; i < containerCount.length; i++) { + if (containerCount[i] !== typeCount[i]) { + pts = "Impossible"; + break; + } + } + return pts; +} + +function main() { + const ws = fs.createWriteStream(process.env.OUTPUT_PATH); + + const q = parseInt(readLine(), 10); + + for (let qItr = 0; qItr < q; qItr++) { + const n = parseInt(readLine(), 10); + + let container = Array(n); + + for (let i = 0; i < n; i++) { + container[i] = readLine().split(' ').map(containerTemp => parseInt(containerTemp, 10)); + } + + let result = organizingContainers(container); + + ws.write(result + "\n"); + } + + ws.end(); +} From da99bb87cc394f873927b356df3829c15ff3ad82 Mon Sep 17 00:00:00 2001 From: prabakaran19931593858554573 Date: Sat, 25 Jul 2020 20:19:12 +0530 Subject: [PATCH 04/23] the-grid-search --- the-grid-search.js | 104 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 the-grid-search.js diff --git a/the-grid-search.js b/the-grid-search.js new file mode 100644 index 0000000..1a401f8 --- /dev/null +++ b/the-grid-search.js @@ -0,0 +1,104 @@ +'use strict'; + +const fs = require('fs'); + +process.stdin.resume(); +process.stdin.setEncoding('utf-8'); + +let inputString = ''; +let currentLine = 0; + +process.stdin.on('data', inputStdin => { + inputString += inputStdin; +}); + +process.stdin.on('end', _ => { + inputString = inputString.replace(/\s*$/, '') + .split('\n') + .map(str => str.replace(/\s*$/, '')); + + main(); +}); + +function readLine() { + return inputString[currentLine++]; +} + +const getIndexes = (pattern, match) =>{ + let indexes = []; + let i=0; + let index = pattern.indexOf(match, i); + while(index >= 0){ + indexes.push(index); + i++; + index = pattern.indexOf(match, i); + } + return Array.from(new Set(indexes)); +} +function gridSearch(G, P) { + let G_length = G.length; + let P_length = P.length; + // console.log('G_length :', G_length, ' P_length:', P_length); + for (let i = 0; i < G.length; i++) { + let j = i, p = 0;; + let currentGrid = G[i + p]; + let currentPattern = P[p]; + let indexes = getIndexes(currentGrid, currentPattern); + // console.log(indexes); + for (let k = 0; k < indexes.length; k++) { + let pos = indexes[k]; + if (pos !== -1) { + for (p = 1; p < P.length; p++) { + currentGrid = G[i + p]; + currentPattern = P[p]; + if (getIndexes(currentGrid, currentPattern).indexOf(pos) === -1) { + break; + } + } + } + if (p === P_length) + return "YES"; + } + } + return "NO"; +} + +function main() { + const ws = fs.createWriteStream(process.env.OUTPUT_PATH); + + const t = parseInt(readLine(), 10); + + for (let tItr = 0; tItr < t; tItr++) { + const RC = readLine().split(' '); + + const R = parseInt(RC[0], 10); + + const C = parseInt(RC[1], 10); + + let G = []; + + for (let i = 0; i < R; i++) { + const GItem = readLine(); + G.push(GItem); + } + + const rc = readLine().split(' '); + + const r = parseInt(rc[0], 10); + + const c = parseInt(rc[1], 10); + + let P = []; + + for (let i = 0; i < r; i++) { + const PItem = readLine(); + P.push(PItem); + } + + let result = gridSearch(G, P); + + ws.write(result + "\n"); + } + + ws.end(); +} From 3dacafffd4d9ea1c426176d4b04490bbbca3cf2b Mon Sep 17 00:00:00 2001 From: prabakaran19931593858554573 Date: Sat, 25 Jul 2020 20:29:28 +0530 Subject: [PATCH 05/23] refractored the code --- the-grid-search.js | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/the-grid-search.js b/the-grid-search.js index 1a401f8..f36560c 100644 --- a/the-grid-search.js +++ b/the-grid-search.js @@ -24,11 +24,11 @@ function readLine() { return inputString[currentLine++]; } -const getIndexes = (pattern, match) =>{ +const getIndexes = (pattern, match) => { let indexes = []; - let i=0; + let i = 0; let index = pattern.indexOf(match, i); - while(index >= 0){ + while (index >= 0) { indexes.push(index); i++; index = pattern.indexOf(match, i); @@ -36,27 +36,25 @@ const getIndexes = (pattern, match) =>{ return Array.from(new Set(indexes)); } function gridSearch(G, P) { - let G_length = G.length; - let P_length = P.length; + let gridLength = G.length; + let patternLength = P.length; // console.log('G_length :', G_length, ' P_length:', P_length); - for (let i = 0; i < G.length; i++) { - let j = i, p = 0;; - let currentGrid = G[i + p]; - let currentPattern = P[p]; + for (let gridIndex = 0; gridIndex < gridLength; gridIndex++) { + let patternIndex = 0; + let currentGrid = G[gridIndex + patternIndex]; + let currentPattern = P[patternIndex]; let indexes = getIndexes(currentGrid, currentPattern); // console.log(indexes); for (let k = 0; k < indexes.length; k++) { let pos = indexes[k]; - if (pos !== -1) { - for (p = 1; p < P.length; p++) { - currentGrid = G[i + p]; - currentPattern = P[p]; - if (getIndexes(currentGrid, currentPattern).indexOf(pos) === -1) { - break; - } + for (patternIndex = 1; patternIndex < patternLength; patternIndex++) { + currentGrid = G[gridIndex + patternIndex]; + currentPattern = P[patternIndex]; + if (getIndexes(currentGrid, currentPattern).indexOf(pos) === -1) { + break; } } - if (p === P_length) + if (patternIndex === patternLength) return "YES"; } } From 78a4997ba889cce5f8a0146000d93aff1d6b4053 Mon Sep 17 00:00:00 2001 From: prabakaran19931593858554573 Date: Sat, 25 Jul 2020 20:31:33 +0530 Subject: [PATCH 06/23] the-grid-search --- the-grid-search.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/the-grid-search.js b/the-grid-search.js index f36560c..412190f 100644 --- a/the-grid-search.js +++ b/the-grid-search.js @@ -38,13 +38,11 @@ const getIndexes = (pattern, match) => { function gridSearch(G, P) { let gridLength = G.length; let patternLength = P.length; - // console.log('G_length :', G_length, ' P_length:', P_length); for (let gridIndex = 0; gridIndex < gridLength; gridIndex++) { let patternIndex = 0; let currentGrid = G[gridIndex + patternIndex]; let currentPattern = P[patternIndex]; let indexes = getIndexes(currentGrid, currentPattern); - // console.log(indexes); for (let k = 0; k < indexes.length; k++) { let pos = indexes[k]; for (patternIndex = 1; patternIndex < patternLength; patternIndex++) { From 4102670cf77bab8502a645a308ac2c1d260d36f1 Mon Sep 17 00:00:00 2001 From: prabakaran19931593858554573 Date: Sat, 25 Jul 2020 20:47:44 +0530 Subject: [PATCH 07/23] grid search code refractoring --- the-grid-search.js | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/the-grid-search.js b/the-grid-search.js index 412190f..da47592 100644 --- a/the-grid-search.js +++ b/the-grid-search.js @@ -24,31 +24,32 @@ function readLine() { return inputString[currentLine++]; } -const getIndexes = (pattern, match) => { - let indexes = []; +const getIndices = (word, pattern) => { + let indices = []; let i = 0; - let index = pattern.indexOf(match, i); + let index = word.indexOf(pattern, i); while (index >= 0) { - indexes.push(index); + indices.push(index); i++; - index = pattern.indexOf(match, i); + index = word.indexOf(pattern, i); } - return Array.from(new Set(indexes)); + return Array.from(new Set(indices)); } function gridSearch(G, P) { let gridLength = G.length; let patternLength = P.length; for (let gridIndex = 0; gridIndex < gridLength; gridIndex++) { let patternIndex = 0; - let currentGrid = G[gridIndex + patternIndex]; - let currentPattern = P[patternIndex]; - let indexes = getIndexes(currentGrid, currentPattern); - for (let k = 0; k < indexes.length; k++) { - let pos = indexes[k]; + let gridRow = G[gridIndex + patternIndex]; + let patternRow = P[patternIndex]; + let indices = getIndices(gridRow, patternRow); + for (let index in indices) { + let pos = indices[index]; for (patternIndex = 1; patternIndex < patternLength; patternIndex++) { - currentGrid = G[gridIndex + patternIndex]; - currentPattern = P[patternIndex]; - if (getIndexes(currentGrid, currentPattern).indexOf(pos) === -1) { + gridRow = G[gridIndex + patternIndex]; + patternRow = P[patternIndex]; + let patternRowIndices = getIndices(gridRow, patternRow); + if (patternRowIndices.indexOf(pos) === -1) { break; } } From 51d3d7edf1450b9a03f165ba46829e30376015a3 Mon Sep 17 00:00:00 2001 From: prabakaran19931593858554573 Date: Tue, 28 Jul 2020 20:16:31 +0530 Subject: [PATCH 08/23] absolute-permutation --- absolute-permutation.js | 99 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 absolute-permutation.js diff --git a/absolute-permutation.js b/absolute-permutation.js new file mode 100644 index 0000000..9ef3c3d --- /dev/null +++ b/absolute-permutation.js @@ -0,0 +1,99 @@ + +// let permutation = []; +// const permutate = (arr) => { +// for (let i = 0; i < arr.length - 1; i++) { +// let current = arr[i]; + +// let next = arr[i + 1] +// arr[i] = next; +// arr[i + 1] = current; +// permutation.push(arr.map(x=>x)); +// arr[i + 1] = next; +// arr[i] = current; + +// } +// } + +// let arr = [1, 2, 3] +// permutate(arr) +// console.log(permutation); + + +let permArr = [], + usedChars = []; +function permute(input, diff) { + var i, ch; + for (i = 0; i < input.length; i++) { + // fixed 1, then process [2,3] + ch = input.splice(i, 1)[0]; + // usedchars [1] + usedChars.push(ch); + if (input.length == 0) { + let bool = true; + for (let k = 0; k < usedChars.length; k++) { + if (Math.abs((usedChars[k] - (k + 1))) !== diff) { + bool = false; + break; + } + } + // console.log(usedChars); + if (bool) { + return usedChars; + } + } + // processing [2,3] + let res = permute(input, diff) + if (res.length > 0) { + return res; + } + + input.splice(i, 0, ch); + usedChars.pop(); + } + return []; +}; + +function validate(arr, diff) { + for (let k = 0; k < arr.length; k++) { + let index = k + 1; + let ithElement = arr[k]; + if (Math.abs(index - ithElement) !== diff) { + return []; + } + } + return arr; +} + +function permute2(permutation, diff) { + let length = permutation.length, + c = new Array(length).fill(0), + i = 1, k, p; + let arr = permutation.slice(); + if (validate(arr, diff).length > 0) + return arr; + + while (i < length) { + if (c[i] < i) { + k = i % 2 && c[i]; + p = permutation[i]; + permutation[i] = permutation[k]; + permutation[k] = p; + ++c[i]; + i = 1; + arr = permutation.slice(); + if (validate(arr, diff).length > 0) + return arr; + + } else { + c[i] = 0; + ++i; + } + } + return []; +} +n = 10; +k = 5; + +let numbers = Array.from(Array(n), (_, i) => i + 1); + +console.log((permute2(numbers, k))); \ No newline at end of file From 93587e9eb16a53bc7fb43d666b485a046851d52c Mon Sep 17 00:00:00 2001 From: prabakaran19931593858554573 Date: Tue, 28 Jul 2020 20:18:13 +0530 Subject: [PATCH 09/23] absolute-permutation --- absolute-permutation.js | 146 +++++++++++++++------------------------- 1 file changed, 56 insertions(+), 90 deletions(-) diff --git a/absolute-permutation.js b/absolute-permutation.js index 9ef3c3d..5f7e4f1 100644 --- a/absolute-permutation.js +++ b/absolute-permutation.js @@ -1,99 +1,65 @@ +'use strict'; -// let permutation = []; -// const permutate = (arr) => { -// for (let i = 0; i < arr.length - 1; i++) { -// let current = arr[i]; - -// let next = arr[i + 1] -// arr[i] = next; -// arr[i + 1] = current; -// permutation.push(arr.map(x=>x)); -// arr[i + 1] = next; -// arr[i] = current; - -// } -// } - -// let arr = [1, 2, 3] -// permutate(arr) -// console.log(permutation); - - -let permArr = [], - usedChars = []; -function permute(input, diff) { - var i, ch; - for (i = 0; i < input.length; i++) { - // fixed 1, then process [2,3] - ch = input.splice(i, 1)[0]; - // usedchars [1] - usedChars.push(ch); - if (input.length == 0) { - let bool = true; - for (let k = 0; k < usedChars.length; k++) { - if (Math.abs((usedChars[k] - (k + 1))) !== diff) { - bool = false; - break; - } - } - // console.log(usedChars); - if (bool) { - return usedChars; - } - } - // processing [2,3] - let res = permute(input, diff) - if (res.length > 0) { - return res; - } +const fs = require('fs'); - input.splice(i, 0, ch); - usedChars.pop(); - } - return []; -}; - -function validate(arr, diff) { - for (let k = 0; k < arr.length; k++) { - let index = k + 1; - let ithElement = arr[k]; - if (Math.abs(index - ithElement) !== diff) { - return []; - } - } - return arr; +process.stdin.resume(); +process.stdin.setEncoding('utf-8'); + +let inputString = ''; +let currentLine = 0; + +process.stdin.on('data', inputStdin => { + inputString += inputStdin; +}); + +process.stdin.on('end', _ => { + inputString = inputString.replace(/\s*$/, '') + .split('\n') + .map(str => str.replace(/\s*$/, '')); + + main(); +}); + +function readLine() { + return inputString[currentLine++]; } -function permute2(permutation, diff) { - let length = permutation.length, - c = new Array(length).fill(0), - i = 1, k, p; - let arr = permutation.slice(); - if (validate(arr, diff).length > 0) - return arr; - - while (i < length) { - if (c[i] < i) { - k = i % 2 && c[i]; - p = permutation[i]; - permutation[i] = permutation[k]; - permutation[k] = p; - ++c[i]; - i = 1; - arr = permutation.slice(); - if (validate(arr, diff).length > 0) - return arr; - - } else { - c[i] = 0; - ++i; +// Complete the absolutePermutation function below. +const absolutePermutation = (n, k) => { + if (k === 0) { + return Array.from(Array(n), (_, i) => i + 1) + } + else if ((n / k) % 2 !== 0) { + return [-1]; + } + else { + let add = true, perm = []; + for (let i = 1; i < n + 1; i++) { + add ? perm.push(i + k) : perm.push(i - k); + if (i % k === 0) { + add = add ? false : true; + } } + return perm; } - return []; } -n = 10; -k = 5; -let numbers = Array.from(Array(n), (_, i) => i + 1); +function main() { + const ws = fs.createWriteStream(process.env.OUTPUT_PATH); + + const t = parseInt(readLine(), 10); + + for (let tItr = 0; tItr < t; tItr++) { + const nk = readLine().split(' '); + + const n = parseInt(nk[0], 10); -console.log((permute2(numbers, k))); \ No newline at end of file + const k = parseInt(nk[1], 10); + + let result = absolutePermutation(n, k); + + ws.write(result.join(" ") + "\n"); + } + + ws.end(); +} From 7f65262e6fe647d3eceef88779f5f510286c023a Mon Sep 17 00:00:00 2001 From: prabakaran19931593858554573 Date: Wed, 29 Jul 2020 03:28:22 +0530 Subject: [PATCH 10/23] larrys array --- larrys-array.js | 54 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 larrys-array.js diff --git a/larrys-array.js b/larrys-array.js new file mode 100644 index 0000000..3f782f9 --- /dev/null +++ b/larrys-array.js @@ -0,0 +1,54 @@ +'use strict'; + +const fs = require('fs'); + +process.stdin.resume(); +process.stdin.setEncoding('utf-8'); + +let inputString = ''; +let currentLine = 0; + +process.stdin.on('data', inputStdin => { + inputString += inputStdin; +}); + +process.stdin.on('end', _ => { + inputString = inputString.replace(/\s*$/, '') + .split('\n') + .map(str => str.replace(/\s*$/, '')); + + main(); +}); + +function readLine() { + return inputString[currentLine++]; +} + +// Complete the larrysArray function below. +function larrysArray(A) { + let count = 0; + for (let i = 1; i < A.length; i++) { + for (let k = 0; k < i; k++) { + if (A[k] > A[i]) count++; + } + } + return count % 2 === 0 ? "YES": "NO"; +} + +function main() { + const ws = fs.createWriteStream(process.env.OUTPUT_PATH); + + const t = parseInt(readLine(), 10); + + for (let tItr = 0; tItr < t; tItr++) { + const n = parseInt(readLine(), 10); + + const A = readLine().split(' ').map(ATemp => parseInt(ATemp, 10)); + + let result = larrysArray(A); + + ws.write(result + "\n"); + } + + ws.end(); +} \ No newline at end of file From 8ca9f199493cdfdf614fe16e941d16427bfde4c9 Mon Sep 17 00:00:00 2001 From: "Prabakaran.A" Date: Wed, 29 Jul 2020 03:32:08 +0530 Subject: [PATCH 11/23] Update README.md --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 4f2f53b..000472d 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,5 @@ # Hackerrank-JS-Solutions Solved entire easy problems & few medium problems in data structures category + +# Contributor +Contributors always welcome, need help in algorithm documentations From 83cc09cd0ce8c39e71863755d7cae47278baeea4 Mon Sep 17 00:00:00 2001 From: prabakaran19931593858554573 Date: Wed, 29 Jul 2020 14:25:04 +0530 Subject: [PATCH 12/23] sherlock-and-anagrams --- sherlock-and-anagrams.js | 61 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 sherlock-and-anagrams.js diff --git a/sherlock-and-anagrams.js b/sherlock-and-anagrams.js new file mode 100644 index 0000000..e663eee --- /dev/null +++ b/sherlock-and-anagrams.js @@ -0,0 +1,61 @@ +'use strict'; + +const fs = require('fs'); + +process.stdin.resume(); +process.stdin.setEncoding('utf-8'); + +let inputString = ''; +let currentLine = 0; + +process.stdin.on('data', inputStdin => { + inputString += inputStdin; +}); + +process.stdin.on('end', _ => { + inputString = inputString.replace(/\s*$/, '') + .split('\n') + .map(str => str.replace(/\s*$/, '')); + + main(); +}); + +function readLine() { + return inputString[currentLine++]; +} + +function sherlockAndAnagrams(s) { + let hash = {}; + for (let i = 0; i < s.length; i++) { + for (let j = i + 1; j < s.length + 1; j++) { + let key = s.slice(i, j).split('').sort().join(''); + hash[key] = hash[key] ? hash[key] + 1 : 1; + } + + } + let count = 0; + for (let key in hash) { + if (key !== s) { + // n * n-1 /2 + count += hash[key] * (hash[key] - 1) / 2; + }; + } + return count; + +} + +function main() { + const ws = fs.createWriteStream(process.env.OUTPUT_PATH); + + const q = parseInt(readLine(), 10); + + for (let qItr = 0; qItr < q; qItr++) { + const s = readLine(); + + let result = sherlockAndAnagrams(s); + + ws.write(result + "\n"); + } + + ws.end(); +} From 6dba1fc24d837a1a9dd1345913ab158f9d4305d2 Mon Sep 17 00:00:00 2001 From: "Prabakaran.A" Date: Wed, 29 Jul 2020 14:35:42 +0530 Subject: [PATCH 13/23] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 000472d..c543036 100644 --- a/README.md +++ b/README.md @@ -2,4 +2,4 @@ Solved entire easy problems & few medium problems in data structures category # Contributor -Contributors always welcome, need help in algorithm documentations +Contributors always welcome From 42e763092e28e0668b788ff5f06ed0fb67a8ce6d Mon Sep 17 00:00:00 2001 From: prabakaran19931593858554573 Date: Wed, 29 Jul 2020 23:11:25 +0530 Subject: [PATCH 14/23] interesting problem, lot of code improvement will be need --- almost-sorted.js | 96 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 almost-sorted.js diff --git a/almost-sorted.js b/almost-sorted.js new file mode 100644 index 0000000..10d17fb --- /dev/null +++ b/almost-sorted.js @@ -0,0 +1,96 @@ +'use strict'; + +process.stdin.resume(); +process.stdin.setEncoding('utf-8'); + +let inputString = ''; +let currentLine = 0; + +process.stdin.on('data', inputStdin => { + inputString += inputStdin; +}); + +process.stdin.on('end', _ => { + inputString = inputString.replace(/\s*$/, '') + .split('\n') + .map(str => str.replace(/\s*$/, '')); + + main(); +}); + +function readLine() { + return inputString[currentLine++]; +} + +// Complete the almostSorted function below. +function almostSorted(arr) { + const isSorted = arr => arr.every((v, i, a) => !i || a[i - 1] <= v); + const swap = (arr, i, j) => { + let t = arr[i]; + arr[i] = arr[j]; + arr[j] = t; + }; + const reverse = (arr, i, j) => { + let split = arr.slice(i, j + 1); + split.reverse(); + arr.splice(i, j, ...split); + } + + let peak = [], valley = []; + for (let i = 1; i < arr.length - 1; i++) { + let prev = arr[i - 1], + current = arr[i], + next = arr[i + 1]; + if (current > prev && current > next && next > prev) { + // console.log("peak", i + 1, current) + peak.push(i + 1) + } + else if (prev > current && current < next && next > prev) { + // console.log("valley", i + 1, current) + + valley.push(i + 1) + } + } + // console.log(valley, peak) + if (arr.length === 2) { + if (arr[0] > arr[1]) + console.log(`yes\nswap 1 2`); + } + // case 2 + else if (valley.length === 1 && peak.length === 1) { + swap(arr, peak[0] - 1, valley[0] - 1); + if (isSorted(arr)) { + console.log(`yes\nswap ${peak[0]} ${valley[0]}`); + return; + } + swap(arr, peak[0] - 1, valley[0] - 1); + reverse(arr, peak[0] - 1, valley[0] - 1); + // swap + if (isSorted(arr)) { + console.log(`yes\nreverse ${peak[0]} ${valley[0]}`); + } else { + console.log('no'); + } + } + // case 1 + else if (valley.length === 1) + console.log("no"); + // case 4 + else if (valley.length === 0 && peak.length === 0) { + reverse(arr, 0, arr.length - 1) + if (isSorted(arr)) { + console.log(`yes\nreverse 1 ${arr.length}`) + } else { console.log('no') } + } + else { + console.log("no"); + } +} + +function main() { + const n = parseInt(readLine(), 10); + + const arr = readLine().split(' ').map(arrTemp => parseInt(arrTemp, 10)); + + almostSorted(arr); +} From 9815ea2c43c750ac48d51eef2d1ae42f86a0deaf Mon Sep 17 00:00:00 2001 From: prabakaran19931593858554573 Date: Thu, 30 Jul 2020 14:17:57 +0530 Subject: [PATCH 15/23] fibonacci modified, js big mul and big add implemented, passed 8/10 test case --- fibonacci-modified.js | 89 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 fibonacci-modified.js diff --git a/fibonacci-modified.js b/fibonacci-modified.js new file mode 100644 index 0000000..dc7fe82 --- /dev/null +++ b/fibonacci-modified.js @@ -0,0 +1,89 @@ +'use strict'; + +const fs = require('fs'); + +process.stdin.resume(); +process.stdin.setEncoding('utf-8'); + +let inputString = ''; +let currentLine = 0; + +process.stdin.on('data', inputStdin => { + inputString += inputStdin; +}); + +process.stdin.on('end', _ => { + inputString = inputString.replace(/\s*$/, '') + .split('\n') + .map(str => str.replace(/\s*$/, '')); + + main(); +}); + +function readLine() { + return inputString[currentLine++]; +} + +function add(a, b) { + let carry = 0; + let i = 0; + for (i = 0; i < b.length; i++) { + let n = a[i] + b[i] + carry; + a[i] = n % 10; + carry = Math.floor(n / 10); + } + while (carry > 0) { + a[i] = typeof a[i] !== 'undefined' ? a[i] : 0 + let n = a[i] + carry; + a[i] = n % 10; + carry = Math.floor(n / 10); + i++; + } + return a; +} + +const mul = (b, a) => { + let out = []; + let k = 0, carry = 0; + for (let i = 0; i < a.length; i++) { + for (let j = 0; j < b.length; j++) { + let e = typeof out[k] !== 'undefined' ? out[k] : 0; + let n = (a[i] * b[j]) + carry + e; + out[k] = n % 10; + carry = Math.floor(n / 10); + k++; + } + if (carry > 0) { + out[k] = carry; + carry = 0; + } + k = i + 1; + } + return out; +} +function fibonacciModified(t1, t2, n) { + let hash = {}; + hash[1] = [t1]; + hash[2] = [t2]; + for (let i = 3; i < n + 1; i++) { + hash[i] = add(mul(hash[i - 1].map(x => x), hash[i - 1].map(x => x)), hash[i - 2].map(x => x)) + } + return hash[n].reverse().join(''); +} +function main() { + const ws = fs.createWriteStream(process.env.OUTPUT_PATH); + + const t1T2n = readLine().split(' '); + + const t1 = parseInt(t1T2n[0], 10); + + const t2 = parseInt(t1T2n[1], 10); + + const n = parseInt(t1T2n[2], 10); + + let result = fibonacciModified(t1, t2, n); + + ws.write(result + "\n"); + + ws.end(); +} From 21934a642daf6eabaae2bff8f2022e8404e74970 Mon Sep 17 00:00:00 2001 From: prabakaran19931593858554573 Date: Thu, 30 Jul 2020 16:07:04 +0530 Subject: [PATCH 16/23] fibonacci-modified using big init --- fibonacci-modified.js | 46 +++++-------------------------------------- 1 file changed, 5 insertions(+), 41 deletions(-) diff --git a/fibonacci-modified.js b/fibonacci-modified.js index dc7fe82..411ecd2 100644 --- a/fibonacci-modified.js +++ b/fibonacci-modified.js @@ -24,52 +24,16 @@ function readLine() { return inputString[currentLine++]; } -function add(a, b) { - let carry = 0; - let i = 0; - for (i = 0; i < b.length; i++) { - let n = a[i] + b[i] + carry; - a[i] = n % 10; - carry = Math.floor(n / 10); - } - while (carry > 0) { - a[i] = typeof a[i] !== 'undefined' ? a[i] : 0 - let n = a[i] + carry; - a[i] = n % 10; - carry = Math.floor(n / 10); - i++; - } - return a; -} - -const mul = (b, a) => { - let out = []; - let k = 0, carry = 0; - for (let i = 0; i < a.length; i++) { - for (let j = 0; j < b.length; j++) { - let e = typeof out[k] !== 'undefined' ? out[k] : 0; - let n = (a[i] * b[j]) + carry + e; - out[k] = n % 10; - carry = Math.floor(n / 10); - k++; - } - if (carry > 0) { - out[k] = carry; - carry = 0; - } - k = i + 1; - } - return out; -} function fibonacciModified(t1, t2, n) { let hash = {}; - hash[1] = [t1]; - hash[2] = [t2]; + hash[1] = BigInt(t1); + hash[2] = BigInt(t2); for (let i = 3; i < n + 1; i++) { - hash[i] = add(mul(hash[i - 1].map(x => x), hash[i - 1].map(x => x)), hash[i - 2].map(x => x)) + hash[i] = (hash[i - 1] * hash[i - 1]) + hash[i - 2]; } - return hash[n].reverse().join(''); + return hash[n] } + function main() { const ws = fs.createWriteStream(process.env.OUTPUT_PATH); From 395e008be1624794b99deb67a6cc9458eee986b3 Mon Sep 17 00:00:00 2001 From: "Prabakaran.A" Date: Thu, 30 Jul 2020 16:18:26 +0530 Subject: [PATCH 17/23] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index c543036..5d0d1de 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # Hackerrank-JS-Solutions Solved entire easy problems & few medium problems in data structures category +one step at a time + # Contributor Contributors always welcome From 7f348c2712fd4884b5d30a2d9dee46a46f092f8b Mon Sep 17 00:00:00 2001 From: prabakaran19931593858554573 Date: Thu, 30 Jul 2020 19:12:16 +0530 Subject: [PATCH 18/23] richie-rich algo. algo for highest value palindrome --- richie-rich.js | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 richie-rich.js diff --git a/richie-rich.js b/richie-rich.js new file mode 100644 index 0000000..f404bb8 --- /dev/null +++ b/richie-rich.js @@ -0,0 +1,88 @@ +'use strict'; + +const fs = require('fs'); + +process.stdin.resume(); +process.stdin.setEncoding('utf-8'); + +let inputString = ''; +let currentLine = 0; + +process.stdin.on('data', inputStdin => { + inputString += inputStdin; +}); + +process.stdin.on('end', _ => { + inputString = inputString.replace(/\s*$/, '') + .split('\n') + .map(str => str.replace(/\s*$/, '')); + + main(); +}); + +function readLine() { + return inputString[currentLine++]; +} + +// Complete the highestValuePalindrome function below. +const isValidPalindrome = (s) => { + let m = Math.ceil(s.length / 2); + for (let i = 0, j = s.length - 1; i < m, j >= m; i++ , j--) { + if (s[i] !== s[j]) { return false; } + } + return true; +} +function highestValuePalindrome(s, n, k) { + let lives = k; + let mod = new Array(n).fill(false); + let temp = s.split(''); + for (let i = 0; i < n / 2; i++) { + let j = n - i - 1; + if (temp[i] != temp[j]) { + mod[i] = true; + lives--; + } + if (temp[i] < temp[j]) + temp[i] = temp[j]; + else if (temp[i] > temp[j]) + temp[j] = temp[i]; + if (lives < 0) + return "-1"; + } + let j = 0; + while ((lives > 0) && (j < n / 2)) { + if (temp[j] != '9') { + if (mod[j]) + lives++; + if (lives > 1) { + temp[j] = '9'; + temp[n - j - 1] = '9'; + lives -= 2; + } + } + j++; + } + if (n % 2 == 1) { + if (lives > 0) + temp[Math.floor(n / 2)] = '9'; + } + return temp.join(''); +} + +function main() { + const ws = fs.createWriteStream(process.env.OUTPUT_PATH); + + const nk = readLine().split(' '); + + const n = parseInt(nk[0], 10); + + const k = parseInt(nk[1], 10); + + const s = readLine(); + + let result = highestValuePalindrome(s, n, k); + + ws.write(result + "\n"); + + ws.end(); +} From 62645ddb1e993dc50a7d6da391514bd10504da75 Mon Sep 17 00:00:00 2001 From: prabakaran19931593858554573 Date: Sun, 2 Aug 2020 17:58:25 +0530 Subject: [PATCH 19/23] solving old Contest --- once-in-a-tram.js | 51 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 once-in-a-tram.js diff --git a/once-in-a-tram.js b/once-in-a-tram.js new file mode 100644 index 0000000..67a26e1 --- /dev/null +++ b/once-in-a-tram.js @@ -0,0 +1,51 @@ +process.stdin.resume(); +process.stdin.setEncoding('ascii'); + +var input_stdin = ""; +var input_stdin_array = ""; +var input_currentline = 0; + +process.stdin.on('data', function (data) { + input_stdin += data; +}); + +process.stdin.on('end', function () { + input_stdin_array = input_stdin.split("\n"); + main(); +}); + +function readLine() { + return input_stdin_array[input_currentline++]; +} + +/////////////// ignore above this line //////////////////// + +function pad(num, size) { + var s = num+""; + while (s.length < size) s = "0" + s; + return s; +} +function onceInATram(x) { + while(1) { + let left = parseInt(x[0]) +parseInt(x[1])+parseInt(x[2]); + for(let j=parseInt(x.slice(3,6))+1;j<1000;j++) + { + // console.log(j) + let str = pad(j,3); + let right = parseInt(str[0]) +parseInt(str[1])+parseInt(str[2]); + // console.log(right) + if(left === right) + { + return x.slice(0,3)+str; + } + } + let nest = parseInt(x.slice(0,3))+1 + x = nest+"000"; + } +} + +function main() { + var x = readLine(); + var result = onceInATram(x); + process.stdout.write("" + result + "\n"); +} \ No newline at end of file From 841abfba98fb8934f7326fdac4c0528c83283fd9 Mon Sep 17 00:00:00 2001 From: prabakaran19931593858554573 Date: Sun, 2 Aug 2020 23:17:19 +0530 Subject: [PATCH 20/23] high security strings --- high-security-strings.js | 47 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 high-security-strings.js diff --git a/high-security-strings.js b/high-security-strings.js new file mode 100644 index 0000000..936c163 --- /dev/null +++ b/high-security-strings.js @@ -0,0 +1,47 @@ +'use strict'; + +const fs = require('fs'); + +process.stdin.resume(); +process.stdin.setEncoding('utf-8'); + +let inputString = ''; +let currentLine = 0; + +process.stdin.on('data', function(inputStdin) { + inputString += inputStdin; +}); + +process.stdin.on('end', function() { + inputString = inputString.split('\n'); + + main(); +}); + +function readLine() { + return inputString[currentLine++]; +} + +function getStrength(password, weight_a) { + password = password.toLowerCase(); + let c = 0; + for(let i in password){ + let value = (password[i].charCodeAt() - 97) + weight_a; + c+= (value <=25) ? value : (value - 26); + } + return c; +} + +function main() { + const ws = fs.createWriteStream(process.env.OUTPUT_PATH); + + const password = readLine(); + + const weight_a = parseInt(readLine().trim(), 10); + + const strength = getStrength(password, weight_a); + + ws.write(strength + '\n'); + + ws.end(); +} From e866f1f8d423ed29251b7eeaba5bda865b2c041f Mon Sep 17 00:00:00 2001 From: prabakaran19931593858554573 Date: Mon, 3 Aug 2020 11:59:13 +0530 Subject: [PATCH 21/23] #contests --- maximum-sum-10-1.js | 63 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 maximum-sum-10-1.js diff --git a/maximum-sum-10-1.js b/maximum-sum-10-1.js new file mode 100644 index 0000000..b9501ca --- /dev/null +++ b/maximum-sum-10-1.js @@ -0,0 +1,63 @@ +//https://www.hackerrank.com/contests/hack-the-interview-vi-asia-pacific/challenges/maximum-sum-10-1 +'use strict'; + +const fs = require('fs'); + +process.stdin.resume(); +process.stdin.setEncoding('utf-8'); + +let inputString = ''; +let currentLine = 0; + +process.stdin.on('data', function(inputStdin) { + inputString += inputStdin; +}); + +process.stdin.on('end', function() { + inputString = inputString.split('\n'); + + main(); +}); + +function readLine() { + return inputString[currentLine++]; +} + +/* + * Complete the 'performOperations' function below. + * + * The function is expected to return a LONG_INTEGER_ARRAY. + * The function accepts following parameters: + * 1. INTEGER N + * 2. INTEGER_ARRAY op + */ +function performOperations(N, op) { + let out = []; + let first = 1, last = N; + let sum = Math.floor( ((N-2) * (N+1)) / 2); + for(let i =0;i Date: Tue, 4 Aug 2020 13:41:24 +0530 Subject: [PATCH 22/23] recursion, power sum --- the-power-sum.js | 76 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 the-power-sum.js diff --git a/the-power-sum.js b/the-power-sum.js new file mode 100644 index 0000000..aeb281a --- /dev/null +++ b/the-power-sum.js @@ -0,0 +1,76 @@ +'use strict'; + +const fs = require('fs'); + +process.stdin.resume(); +process.stdin.setEncoding('utf-8'); + +let inputString = ''; +let currentLine = 0; + +process.stdin.on('data', inputStdin => { + inputString += inputStdin; +}); + +process.stdin.on('end', _ => { + inputString = inputString.replace(/\s*$/, '') + .split('\n') + .map(str => str.replace(/\s*$/, '')); + + main(); +}); + +function readLine() { + return inputString[currentLine++]; +} + +function count(S, m, n, power) { + // If n is 0 then there is 1 solution + // (do not include any coin) + if (n === 0) + return 1; + + // If n is less than 0 then no + // solution exists + if (n < 0) + return 0; + + // If there are no coins and n + // is greater than 0, then no + // solution exist + if (m <= 0 && n >= 1) + return 0; + + // count is sum of solutions (i) + // including S[m-1] (ii) excluding S[m-1] + return count(S, m - 1, n, power) + count(S, m - 1, n - Math.pow(S[m - 1], power), power); +} + +// Complete the powerSum function below. +function powerSum(X, N) { + let m = 1; + let sums = [] + for (let i = 1; i < X; i++) { + if (Math.pow(i, N) > X) { + break; + } else { + sums.push(i); + } + } + console.log(sums) + return count(sums, sums.length, X, N); +} + +function main() { + const ws = fs.createWriteStream(process.env.OUTPUT_PATH); + + const X = parseInt(readLine(), 10); + + const N = parseInt(readLine(), 10); + + let result = powerSum(X, N); + + ws.write(result + "\n"); + + ws.end(); +} From d349491d77c1ef104ee062cde55bd659e45b782a Mon Sep 17 00:00:00 2001 From: prabakaran19931593858554573 Date: Tue, 4 Aug 2020 15:09:58 +0530 Subject: [PATCH 23/23] Into the Dynamic Programming --- coin-change.js | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 coin-change.js diff --git a/coin-change.js b/coin-change.js new file mode 100644 index 0000000..84c5d33 --- /dev/null +++ b/coin-change.js @@ -0,0 +1,93 @@ +'use strict'; + +const fs = require('fs'); + +process.stdin.resume(); +process.stdin.setEncoding('utf-8'); + +let inputString = ''; +let currentLine = 0; + +process.stdin.on('data', function (inputStdin) { + inputString += inputStdin; +}); + +process.stdin.on('end', function () { + inputString = inputString.split('\n'); + + main(); +}); + +function readLine() { + return inputString[currentLine++]; +} + +/* + * Complete the 'getWays' function below. + * + * The function is expected to return a LONG_INTEGER. + * The function accepts following parameters: + * 1. INTEGER n + * 2. LONG_INTEGER_ARRAY c + */ + +function getWays(n, c) { + // Write your code here + return count(c, c.length, n); +} +function readLine() { + return inputString[currentLine++]; +} +let memory = {} +function count(S, m, n) { + // If n is 0 then there is 1 solution + // (do not include any coin) + if (n === 0) + return 1; + + // If n is less than 0 then no + // solution exists + if (n < 0) + return 0; + + // If there are no coins and n + // is greater than 0, then no + // solution exist + if (m <= 0 && n >= 1) + return 0; + + // count is sum of solutions (i) + // including S[m-1] (ii) excluding S[m-1] + // return count(S, m - 1, n) + count(S, m, n - S[m - 1]); + + let leftsubtree = m - 1 + '-' + n; + let rightsubtree = m + '-' + (n - S[m - 1]); + + if (typeof memory[leftsubtree] === 'undefined') + memory[leftsubtree] = count(S, m - 1, n); + + if (typeof memory[rightsubtree] === 'undefined') + memory[rightsubtree] = count(S, m, n - S[m - 1]); + + return memory[leftsubtree] + memory[rightsubtree]; +} + +function main() { + const ws = fs.createWriteStream(process.env.OUTPUT_PATH); + + const firstMultipleInput = readLine().replace(/\s+$/g, '').split(' '); + + const n = parseInt(firstMultipleInput[0], 10); + + const m = parseInt(firstMultipleInput[1], 10); + + const c = readLine().replace(/\s+$/g, '').split(' ').map(cTemp => parseInt(cTemp, 10)); + + // Print the number of ways of making change for 'n' units using coins having the values given by 'c' + + const ways = getWays(n, c); + + ws.write(ways + '\n'); + + ws.end(); +}