Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions Problems/Nom-Nom-Numbers/README.md
Original file line number Diff line number Diff line change
@@ -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

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)

---

### 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.
50 changes: 50 additions & 0 deletions Problems/Nom-Nom-Numbers/nom-nom-numbers.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
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]);
});

it("should return [84] for [82, 2] input", () => {
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([]);
});

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", () => {
// it("should return something for this input", () => {
// expect(true).toEqual(true);
// });
// });
14 changes: 14 additions & 0 deletions Problems/Nom-Nom-Numbers/solver.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export default function nom_nom(numbers: number[]): number[] {
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);
}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) (<span style="color:green">Easy</span>)
- [Itinerary-In-Alphabetical-Order](./Problems/Itinerary-In-Alphabetical-Order/README.md) (<span style="color:green">Easy</span>)
- [Dependable-Jobs-Schedule](./Problems/Dependable-Jobs-Schedule/README.md) (<span style="color:green">Easy</span>)
- [Nom-Nom-Numbers](./Problems/Nom-Nom-Numbers/README.md) (<span style="color:green">Easy</span>)

<!-- PROBLEMS_END -->

Expand Down