View on GitHub

advent-of-code-2024

Readable Advent of Code 2024 algorithms and solutions in C language

Day 2: Red-Nosed Reports

Let $L$ be a set of lists where for all $\ell\in L$, for all $e\in\ell$, we have $e\in\mathbb{R}$. Let $n^\ast=\max_{\ell\in L}(\mathrm{len}(\ell))$.

Part A

Algorithm 1:

Algorithm 2 with list $\ell$ as an argument; returns the index of the first “unsafe” index, or $\mathrm{len}(\ell)$ if all indices are “safe”:

Time complexity: $O(\lvert L\rvert\cdot n^\ast)$.

Space complexity: $O(1)$.

Part B

Algorithm 3:

Time complexity: $O(\lvert L\rvert\cdot n^\ast)$.

Space complexity: $O(1)$.