From 413b1d25aefc3aa82cd48993c812cdd73db4e5cb Mon Sep 17 00:00:00 2001 From: Abhinandan <93651229+AE-Hertz@users.noreply.github.com> Date: Fri, 16 Aug 2024 16:21:23 +0530 Subject: [PATCH 1/4] feat: lc soluton,js for no. 0624 --- .../Solution.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 solution/0600-0699/0624.Maximum Distance in Arrays/Solution.js diff --git a/solution/0600-0699/0624.Maximum Distance in Arrays/Solution.js b/solution/0600-0699/0624.Maximum Distance in Arrays/Solution.js new file mode 100644 index 0000000000000..9031c8ce5988b --- /dev/null +++ b/solution/0600-0699/0624.Maximum Distance in Arrays/Solution.js @@ -0,0 +1,19 @@ +/** + * @param {number[][]} arrays + * @return {number} + */ +var maxDistance = function(arrays) { + let minVal = arrays[0][0]; + let maxVal = arrays[0][arrays[0].length - 1]; + let maxDist = 0; + + for (let i = 1; i < arrays.length; i++) { + const currentMin = arrays[i][0]; + const currentMax = arrays[i][arrays[i].length - 1]; + maxDist = Math.max(maxDist, Math.abs(currentMax - minVal), Math.abs(maxVal - currentMin)); + minVal = Math.min(minVal, currentMin); + maxVal = Math.max(maxVal, currentMax); + } + + return maxDist; +}; From ba248ed5a7fff724685a7b261dc788e0fdf2515b Mon Sep 17 00:00:00 2001 From: AE-Hertz Date: Fri, 16 Aug 2024 11:15:18 +0000 Subject: [PATCH 2/4] style: format code and docs with prettier --- solution/0600-0699/0624.Maximum Distance in Arrays/Solution.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/solution/0600-0699/0624.Maximum Distance in Arrays/Solution.js b/solution/0600-0699/0624.Maximum Distance in Arrays/Solution.js index 9031c8ce5988b..1aad3bc59ea44 100644 --- a/solution/0600-0699/0624.Maximum Distance in Arrays/Solution.js +++ b/solution/0600-0699/0624.Maximum Distance in Arrays/Solution.js @@ -2,7 +2,7 @@ * @param {number[][]} arrays * @return {number} */ -var maxDistance = function(arrays) { +var maxDistance = function (arrays) { let minVal = arrays[0][0]; let maxVal = arrays[0][arrays[0].length - 1]; let maxDist = 0; From 1db91b565327fc57b3432213ff6ceb604acc80ee Mon Sep 17 00:00:00 2001 From: AE-Hertz Date: Tue, 20 Aug 2024 06:42:49 +0000 Subject: [PATCH 3/4] style: format code and docs with prettier --- .../0600-0699/0624.Maximum Distance in Arrays/Solution.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/solution/0600-0699/0624.Maximum Distance in Arrays/Solution.js b/solution/0600-0699/0624.Maximum Distance in Arrays/Solution.js index 2ce1cdd97b1f0..1aad3bc59ea44 100644 --- a/solution/0600-0699/0624.Maximum Distance in Arrays/Solution.js +++ b/solution/0600-0699/0624.Maximum Distance in Arrays/Solution.js @@ -2,7 +2,7 @@ * @param {number[][]} arrays * @return {number} */ -var maxDistance = function(arrays) { +var maxDistance = function (arrays) { let minVal = arrays[0][0]; let maxVal = arrays[0][arrays[0].length - 1]; let maxDist = 0; @@ -16,4 +16,4 @@ var maxDistance = function(arrays) { } return maxDist; -}; \ No newline at end of file +}; From 41f2c251293392d5916b0933dabc9f57e9d0a05b Mon Sep 17 00:00:00 2001 From: Abhinandan <93651229+AE-Hertz@users.noreply.github.com> Date: Wed, 21 Aug 2024 10:05:34 +0530 Subject: [PATCH 4/4] feat: add js solution lc 0664 --- .../0664.Strange Printer/Solution.js | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 solution/0600-0699/0664.Strange Printer/Solution.js diff --git a/solution/0600-0699/0664.Strange Printer/Solution.js b/solution/0600-0699/0664.Strange Printer/Solution.js new file mode 100644 index 0000000000000..1e41a60420d0e --- /dev/null +++ b/solution/0600-0699/0664.Strange Printer/Solution.js @@ -0,0 +1,21 @@ +/** + * @param {string} s + * @return {number} + */ +var strangePrinter = function(s) { + const n = s.length; + const f = new Array(n).fill(0).map(() => new Array(n).fill(1 << 30)); + for (let i = n - 1; i >= 0; --i) { + f[i][i] = 1; + for (let j = i + 1; j < n; ++j) { + if (s[i] === s[j]) { + f[i][j] = f[i][j - 1]; + } else { + for (let k = i; k < j; ++k) { + f[i][j] = Math.min(f[i][j], f[i][k] + f[k + 1][j]); + } + } + } + } + return f[0][n - 1]; +};