From ce9b63fafa493676a49c4b1f3d6f560e861e9a87 Mon Sep 17 00:00:00 2001 From: Dennis Date: Sun, 11 Jan 2026 17:51:23 +0100 Subject: [PATCH 1/3] Setup Problem --- Problems/Nom-Nom-Numbers/README.md | 28 +++++++++++++++ .../Nom-Nom-Numbers/nom-nom-numbers.test.ts | 34 +++++++++++++++++++ Problems/Nom-Nom-Numbers/solver.ts | 3 ++ 3 files changed, 65 insertions(+) create mode 100644 Problems/Nom-Nom-Numbers/README.md create mode 100644 Problems/Nom-Nom-Numbers/nom-nom-numbers.test.ts create mode 100644 Problems/Nom-Nom-Numbers/solver.ts diff --git a/Problems/Nom-Nom-Numbers/README.md b/Problems/Nom-Nom-Numbers/README.md new file mode 100644 index 0000000..7b546f8 --- /dev/null +++ b/Problems/Nom-Nom-Numbers/README.md @@ -0,0 +1,28 @@ +# Nom Nom Numbers + +A number can "eat" the number to its right if it’s larger than that number. +When it eats, it becomes the sum of both numbers. +Keep repeating this process from left to right until no more eating can happen. + +## Infos which are maybe needed + +Some Infos. This section can also just get deleted + +## Documentation + +### Solution Idea + +The Idea to solve this problem + +--- + +### [Implementation](./solver.ts) + +The implementation for solving this problem + +--- + +### Information's %Informations where the problem comes from. Most of them came from Sloth Byte% + +This problem comes from the newsletter [Sloth Bytes](https://slothbytes.beehiiv.com). +[Post](https://slothbytes.beehiiv.com/p/the-future-of-software-engineering-interviews) from October 28, 2025. diff --git a/Problems/Nom-Nom-Numbers/nom-nom-numbers.test.ts b/Problems/Nom-Nom-Numbers/nom-nom-numbers.test.ts new file mode 100644 index 0000000..b188f55 --- /dev/null +++ b/Problems/Nom-Nom-Numbers/nom-nom-numbers.test.ts @@ -0,0 +1,34 @@ +import { describe, expect, it } from "vitest"; +import nom_nom from "./solver"; + +describe("Returns the correct remaining numbers", () => { + it("should return [15] for [5, 3, 7] input", () => { + expect(nom_nom([5, 3, 7])).toEqual([15]); + }); + + it("should return [8, 9] for [5, 3, 7] input", () => { + expect(nom_nom([5, 3, 7])).toEqual([15]); + }); + + it("should return [1, 2, 3] for [1, 2, 3] input", () => { + expect(nom_nom([1, 2, 3])).toEqual([1, 2, 3]); + }); + + it("should return [3, 3] for [2, 1, 3] input", () => { + expect(nom_nom([2, 1, 3])).toEqual([3, 3]); + }); + + it("should return [22] for [8, 5, 9] input", () => { + expect(nom_nom([8, 5, 9])).toEqual([22]); + }); + + it("should return [17, 100] for [6, 5, 6, 100] input", () => { + expect(nom_nom([6, 5, 6, 100])).toEqual([17, 100]); + }); +}); + +// describe("Another description for the tests. Maybe those which are throwing errors", () => { +// it("should return something for this input", () => { +// expect(true).toEqual(true); +// }); +// }); diff --git a/Problems/Nom-Nom-Numbers/solver.ts b/Problems/Nom-Nom-Numbers/solver.ts new file mode 100644 index 0000000..bde2853 --- /dev/null +++ b/Problems/Nom-Nom-Numbers/solver.ts @@ -0,0 +1,3 @@ +export default function nom_nom(numbers: number[]): number[] { + throw new Error("No solution implemented"); +} From 9afe819b55101661daf4580d2d03cd95693770ef Mon Sep 17 00:00:00 2001 From: Dennis Date: Mon, 12 Jan 2026 11:01:08 +0100 Subject: [PATCH 2/3] Problem solved --- Problems/Nom-Nom-Numbers/nom-nom-numbers.test.ts | 12 ++++++++++++ Problems/Nom-Nom-Numbers/solver.ts | 13 ++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/Problems/Nom-Nom-Numbers/nom-nom-numbers.test.ts b/Problems/Nom-Nom-Numbers/nom-nom-numbers.test.ts index b188f55..ff1a76a 100644 --- a/Problems/Nom-Nom-Numbers/nom-nom-numbers.test.ts +++ b/Problems/Nom-Nom-Numbers/nom-nom-numbers.test.ts @@ -25,6 +25,18 @@ describe("Returns the correct remaining numbers", () => { it("should return [17, 100] for [6, 5, 6, 100] input", () => { expect(nom_nom([6, 5, 6, 100])).toEqual([17, 100]); }); + + it("should return [84] for [82, 2] input", () => { + expect(nom_nom([82, 2])).toEqual([84]); + }); + + it("should return [] for [] input", () => { + expect(nom_nom([])).toEqual([]); + }); + + it("should return [2] for [2] input", () => { + expect(nom_nom([2])).toEqual([2]); + }); }); // describe("Another description for the tests. Maybe those which are throwing errors", () => { diff --git a/Problems/Nom-Nom-Numbers/solver.ts b/Problems/Nom-Nom-Numbers/solver.ts index bde2853..28d7126 100644 --- a/Problems/Nom-Nom-Numbers/solver.ts +++ b/Problems/Nom-Nom-Numbers/solver.ts @@ -1,3 +1,14 @@ export default function nom_nom(numbers: number[]): number[] { - throw new Error("No solution implemented"); + if (numbers.length <= 1) return numbers; + + const result: (number | undefined)[] = numbers.slice(); + + for (let i = 1; i < result.length; i++) { + if ((result[i - 1] ?? 0) > (result[i] ?? 0)) { + result[i] = (result[i - 1] ?? 0) + (result[i] ?? 0); + result[i - 1] = undefined; + } + } + + return result.filter((r) => r !== undefined); } From bb633180ec73de91efb8abd72e49fbc5a948410d Mon Sep 17 00:00:00 2001 From: Dennis Date: Mon, 12 Jan 2026 11:06:10 +0100 Subject: [PATCH 3/3] Finished Problem --- Problems/Nom-Nom-Numbers/README.md | 6 +++--- Problems/Nom-Nom-Numbers/nom-nom-numbers.test.ts | 4 ++++ README.md | 1 + 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Problems/Nom-Nom-Numbers/README.md b/Problems/Nom-Nom-Numbers/README.md index 7b546f8..0026b15 100644 --- a/Problems/Nom-Nom-Numbers/README.md +++ b/Problems/Nom-Nom-Numbers/README.md @@ -12,14 +12,14 @@ Some Infos. This section can also just get deleted ### Solution Idea -The Idea to solve this problem +This is a really simple approach. +The base idea is to loop over the given array and check the current number with the previous number. If this previous number is bigger than the current number, we set the current number to the sum of current and previous, and also set the previous number to undefined which indicates that this number ate a other number. +We repeat the progress until the last number is reached. Now we return the array without undefined values and this will be the result. --- ### [Implementation](./solver.ts) -The implementation for solving this problem - --- ### Information's %Informations where the problem comes from. Most of them came from Sloth Byte% diff --git a/Problems/Nom-Nom-Numbers/nom-nom-numbers.test.ts b/Problems/Nom-Nom-Numbers/nom-nom-numbers.test.ts index ff1a76a..9d8574e 100644 --- a/Problems/Nom-Nom-Numbers/nom-nom-numbers.test.ts +++ b/Problems/Nom-Nom-Numbers/nom-nom-numbers.test.ts @@ -30,6 +30,10 @@ describe("Returns the correct remaining numbers", () => { expect(nom_nom([82, 2])).toEqual([84]); }); + it("should return [2, 20, 80, 1] for [2, 20, 81] input", () => { + expect(nom_nom([2, 20, 80, 1])).toEqual([2, 20, 81]); + }); + it("should return [] for [] input", () => { expect(nom_nom([])).toEqual([]); }); diff --git a/README.md b/README.md index f0ece2f..1e54b04 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,7 @@ This repository is about solving coding-problems. It contains famous (or not tha - [Phone-Letter-Combinations](./Problems/Phone-Letter-Combinations/README.md) (Easy) - [Itinerary-In-Alphabetical-Order](./Problems/Itinerary-In-Alphabetical-Order/README.md) (Easy) - [Dependable-Jobs-Schedule](./Problems/Dependable-Jobs-Schedule/README.md) (Easy) +- [Nom-Nom-Numbers](./Problems/Nom-Nom-Numbers/README.md) (Easy)