From 1214dcadfea02092ef739bacfc8a79bd81ffb160 Mon Sep 17 00:00:00 2001 From: Boxfriend Date: Wed, 3 Dec 2025 23:04:27 -0500 Subject: [PATCH] improved time complexity from exponential to linear time --- AdventOfCode2025/Lobby.cs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/AdventOfCode2025/Lobby.cs b/AdventOfCode2025/Lobby.cs index de0287d..dcc426b 100644 --- a/AdventOfCode2025/Lobby.cs +++ b/AdventOfCode2025/Lobby.cs @@ -11,17 +11,23 @@ public class Lobby : IAdventSolution var total = 0; foreach (var line in lines) { - var max = 0; + var first = '0'; + var second = '0'; for (var i = 0; i < line.Length; i++) { - for (var j = i + 1; j < line.Length; j++) + if (i != line.Length - 1 && line[i] > first) { - var num = int.Parse(line[i].ToString() + line[j].ToString()); - if (num > max) max = num; - + first = line[i]; + second = line[i + 1]; + } + else if (line[i] > second) + { + second = line[i]; } } - total += max; + + + total += int.Parse($"{first}{second}"); } return new AdventSolution(total.ToString(), null);