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
30 changes: 30 additions & 0 deletions Problems/Vertical-List/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Vertical-List

Create a function that converts a string into a matrix of characters that can be read vertically. Add spaces when characters are missing.

## Documentation

### Solution Idea & [Implementation](./solver.ts)

The idea is to loop over every word in the text and process each character separately.

For every character, we first check whether an array already exists in the solution array at the index of the character's position in the word.
If not, we create a new array there.

Then we place the character into the solution array at this position:

\[character position\]\[word index\]

This correctly rearranges the characters, but the spaces for shorter words are still missing.

To fix this, whenever the word index is greater than `0`, we check whether the previous character position exists for the previous word.
If it does not exist, we know that the previous word was shorter, so we insert an empty space at that position.

By doing this for every word and every character, the solution array is built correctly and the final transformed text can be returned.

---

### 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.
17 changes: 17 additions & 0 deletions Problems/Vertical-List/solver.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export default function verticalTxt(text: string): string[][] {
const textArray = text.split(" ");
const solution: string[][] = [];

textArray.forEach((word, wordNumber) => {
word.split("").forEach((char, charNumber) => {
if (solution[charNumber] === undefined) solution[charNumber] = [];

if (wordNumber > 0 && solution[charNumber][wordNumber - 1] === undefined)
solution[charNumber][wordNumber - 1] = " ";

solution[charNumber][wordNumber] = char;
});
});

return solution;
}
38 changes: 38 additions & 0 deletions Problems/Vertical-List/vertical-list.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { describe, expect, it } from "vitest";
import verticalTxt from "./solver";

describe("Description for the tests", () => {
it("should return a 2x7 Matrix for 'Holy bananas'", () => {
expect(verticalTxt("Holy bananas")).toEqual([
["H", "b"],
["o", "a"],
["l", "n"],
["y", "a"],
[" ", "n"],
[" ", "a"],
[" ", "s"],
]);
});

it("should return a 2x6 Matrix for 'Hello fellas'", () => {
expect(verticalTxt("Hello fellas")).toEqual([
["H", "f"],
["e", "e"],
["l", "l"],
["l", "l"],
["o", "a"],
[" ", "s"],
]);
});

it("should return a 4x6 Matrix for 'Hello fellas I'm Dennis'", () => {
expect(verticalTxt("Hello fellas I'm Dennis")).toEqual([
["H", "f", "I", "D"],
["e", "e", "'", "e"],
["l", "l", "m", "n"],
["l", "l", " ", "n"],
["o", "a", " ", "i"],
[" ", "s", " ", "s"],
]);
});
});
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@

This repository is about solving coding-problems. It contains famous (or not that famous) problems with my solution (Dennis Bauer). I ranked the problems as 🟢 Easy, 🟠 Medium and 🔴 Hard. These ranks reflect the time I invested in the problem and how difficult it felt to me.

# Problem-list

<!-- PROBLEMS_START -->

## Problems

Solved: **26 problems**
Solved: **27 problems**

🟢 Easy: 20
🟢 Easy: 21
🟠 Medium: 5
🔴 Hard: 1

Expand Down Expand Up @@ -42,10 +40,11 @@ Solved: **26 problems**
| [Bingo Check](./Problems/Bingo-Check/README.md) | 🟢 Easy |
| [Missing Number](./Problems/Missing-Number/README.md) | 🟢 Easy |
| [Seven Boom!](./Problems/Seven-Boom/README.md) | 🟢 Easy |
| [Vertical List](./Problems/Vertical-List/README.md) | 🟢 Easy |

<!-- PROBLEMS_END -->

## npm-Version:
## npm-Version

The version indicates how much problems are implemented (cp -> Coding Problem)

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading