diff --git a/.github/workflows/auto-merge.yml b/.github/workflows/auto-merge.yml index 93e9d30..041a130 100644 --- a/.github/workflows/auto-merge.yml +++ b/.github/workflows/auto-merge.yml @@ -29,4 +29,5 @@ jobs: - name: Merge daily-leetcode to main run: | git merge --no-ff daily-leetcode - git push origin main \ No newline at end of file + git push origin main + diff --git a/README.md b/README.md index 1448e7f..68ab4f9 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,6 @@ - [Goal](#-goal) - [Create Exercise File Script](#-create-exercise-file-script) - [Folder Structure](#-folder-structure) -- [Português](#-práticas-de-código) --- diff --git a/leetcode/daily/2025-04-21-count-the-hidden-sequences.js b/leetcode/daily/2025-04-21-count-the-hidden-sequences.js new file mode 100644 index 0000000..22e06f0 --- /dev/null +++ b/leetcode/daily/2025-04-21-count-the-hidden-sequences.js @@ -0,0 +1,22 @@ +// Count the Hidden Sequences +// Created on 2025-04-21 + +function solution(differences, lower, upper) { + let minPrefix = 0; + let maxPrefix = 0; + let prefixSum = 0; + + for (let diff of differences) { + prefixSum += diff; + minPrefix = Math.min(minPrefix, prefixSum); + maxPrefix = Math.max(maxPrefix, prefixSum); + } + + const minStart = lower - minPrefix; + const maxStart = upper - maxPrefix; + + const result = maxStart - minStart + 1; + return result > 0 ? result : 0; +} + +console.log(solution([2,2,3], 1, 8))