diff --git a/Problems/Daily-Temperatures/README.md b/Problems/Daily-Temperatures/README.md new file mode 100644 index 0000000..2e602a9 --- /dev/null +++ b/Problems/Daily-Temperatures/README.md @@ -0,0 +1,30 @@ +# Daily Temperatures + +You are given an array of integers temperatures where temperatures[i] represents the daily temperatures on the ith day. +Return an array where output[i] is the number of days after the ith day before a warmer temperature appears on a future day. If there is no day in the future where a warmer temperature will appear for the ith day, set output[i] to 0 instead. + +## Documentation + +### Solution Idea & [Implementation](./solver.ts) + +The idea is straightforward: + +Loop over each number in the array. +For every number, start a second loop that goes through the remaining elements of the array, beginning at the next index. + +In this inner loop, check each number until you find one that is greater than the current number. +Count how many steps it takes to find such a number. + +- If a larger number is found, return the number of steps taken. +- If the end of the array is reached without finding a larger number, return `0`. + +Repeat this process for every number in the array. + +(Sorry for only one text. But don't want to write two :|) + +--- + +### Information's + +This problem comes from the newsletter [Sloth Bytes](https://slothbytes.beehiiv.com). +[Post](https://slothbytes.beehiiv.com/p/docker-for-dummies) from March 25, 2026. diff --git a/Problems/Daily-Temperatures/daily temperatures.test.ts b/Problems/Daily-Temperatures/daily temperatures.test.ts new file mode 100644 index 0000000..5dcedac --- /dev/null +++ b/Problems/Daily-Temperatures/daily temperatures.test.ts @@ -0,0 +1,16 @@ +import { describe, expect, it } from "vitest"; +import dailyTemperatures from "./solver"; + +describe("Should return the correct days it takes to the next warm day", () => { + it("should return [1, 4, 1, 2, 1, 0, 0] for the first input", () => { + expect(dailyTemperatures([30, 38, 30, 36, 35, 40, 28])).toEqual([1, 4, 1, 2, 1, 0, 0]); + }); + + it("should return [0,0,0] for the second input", () => { + expect(dailyTemperatures([22, 21, 20])).toEqual([0, 0, 0]); + }); + + it("should return [1, 4, 1, 2, 1, 0, 0] for the first input", () => { + expect(dailyTemperatures([30, 38, 30, 37, 35, 40, 28])).toEqual([1, 4, 1, 2, 1, 0, 0]); + }); +}); diff --git a/Problems/Daily-Temperatures/solver.ts b/Problems/Daily-Temperatures/solver.ts new file mode 100644 index 0000000..5353ea2 --- /dev/null +++ b/Problems/Daily-Temperatures/solver.ts @@ -0,0 +1,7 @@ +export default function dailyTemperatures(temps: number[]): number[] { + return temps.map((temp, i) => { + for (let index = i + 1; index < temps.length; index++) if (temp < temps[index]) return index - i; + + return 0; + }); +} diff --git a/Problems/Vertical-List/README.md b/Problems/Vertical-List/README.md index 3171a17..ad88617 100644 --- a/Problems/Vertical-List/README.md +++ b/Problems/Vertical-List/README.md @@ -22,9 +22,11 @@ If it does not exist, we know that the previous word was shorter, so we insert a By doing this for every word and every character, the solution array is built correctly and the final transformed text can be returned. +(Sorry for only one text. But don't want to write two :|) + --- ### Information's This problem comes from the newsletter [Sloth Bytes](https://slothbytes.beehiiv.com). -[Post](https://slothbytes.beehiiv.com/p/why-your-delete-button-is-a-lie) from May 18, 2026. +[Post](https://slothbytes.beehiiv.com/p/why-your-delete-button-is-a-lie) from March 18, 2026. diff --git a/Problems/Vertical-List/vertical-list.test.ts b/Problems/Vertical-List/vertical-list.test.ts index 755d2bf..369c3bb 100644 --- a/Problems/Vertical-List/vertical-list.test.ts +++ b/Problems/Vertical-List/vertical-list.test.ts @@ -1,7 +1,7 @@ import { describe, expect, it } from "vitest"; import verticalTxt from "./solver"; -describe("Description for the tests", () => { +describe("Returns the same Text written from up to down", () => { it("should return a 2x7 Matrix for 'Holy bananas'", () => { expect(verticalTxt("Holy bananas")).toEqual([ ["H", "b"], diff --git a/README.md b/README.md index 04aebcc..7ba56f6 100644 --- a/README.md +++ b/README.md @@ -6,9 +6,9 @@ This repository is about solving coding-problems. It contains famous (or not tha ## Problems -Solved: **27 problems** +Solved: **28 problems** -🟢 Easy: 21 +🟢 Easy: 22 🟠 Medium: 5 🔴 Hard: 1 @@ -41,6 +41,7 @@ Solved: **27 problems** | [Missing Number](./Problems/Missing-Number/README.md) | 🟢 Easy | | [Seven Boom!](./Problems/Seven-Boom/README.md) | 🟢 Easy | | [Vertical List](./Problems/Vertical-List/README.md) | 🟢 Easy | +| [Daily Temperatures](./Problems/Daily-Temperatures/README.md) | 🟢 Easy |