<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>tyler yang</title><link>https://88mangos.github.io/</link><description>Recent content on tyler yang</description><generator>Hugo -- 0.147.2</generator><language>en</language><lastBuildDate>Sat, 30 May 2026 00:00:00 +0000</lastBuildDate><atom:link href="https://88mangos.github.io/index.xml" rel="self" type="application/rss+xml"/><item><title>LC 2126: Destroying Asteroids</title><link>https://88mangos.github.io/algos/2026-05-30/</link><pubDate>Sat, 30 May 2026 00:00:00 +0000</pubDate><guid>https://88mangos.github.io/algos/2026-05-30/</guid><description>&lt;p>Lowkey trivial. Solved it in 1 minute. It&amp;rsquo;s just a clean heuristic problem, kinda like &lt;a href="./2026-05-12.md">May 22nd&amp;rsquo;s Daily Problem, LC 1665: Minimum Initial Energy to Finish Tasks&lt;/a> except the heuristic is even easier to see.&lt;/p>
&lt;h1 id="my-solution">My Solution:&lt;/h1>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#abb2bf;background-color:#282c34;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-python" data-lang="python">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#c678dd">class&lt;/span> &lt;span style="color:#e5c07b">Solution&lt;/span>:
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#c678dd">def&lt;/span> &lt;span style="color:#61afef;font-weight:bold">asteroidsDestroyed&lt;/span>(&lt;span style="color:#e5c07b">self&lt;/span>, &lt;span style="color:#e06c75">mass&lt;/span>: &lt;span style="color:#e5c07b">int&lt;/span>, &lt;span style="color:#e06c75">asteroids&lt;/span>: &lt;span style="color:#e06c75">List&lt;/span>[&lt;span style="color:#e5c07b">int&lt;/span>]) &lt;span style="color:#56b6c2">-&amp;gt;&lt;/span> &lt;span style="color:#e5c07b">bool&lt;/span>:
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#e06c75">asteroids&lt;/span>&lt;span style="color:#56b6c2">.&lt;/span>&lt;span style="color:#e06c75">sort&lt;/span>() &lt;span style="color:#7f848e"># sort lo to hi&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#7f848e"># heuristic: collide with the smallest asteroids first,&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#7f848e"># accumulate mass, &lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#7f848e"># and just keep goin.&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#e06c75">curr&lt;/span> &lt;span style="color:#56b6c2">=&lt;/span> &lt;span style="color:#e06c75">mass&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#c678dd">for&lt;/span> &lt;span style="color:#e06c75">a&lt;/span> &lt;span style="color:#56b6c2">in&lt;/span> &lt;span style="color:#e06c75">asteroids&lt;/span>:
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#c678dd">if&lt;/span> &lt;span style="color:#e06c75">curr&lt;/span> &lt;span style="color:#56b6c2">&amp;gt;=&lt;/span> &lt;span style="color:#e06c75">a&lt;/span>:
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#e06c75">curr&lt;/span> &lt;span style="color:#56b6c2">+=&lt;/span> &lt;span style="color:#e06c75">a&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#c678dd">continue&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#c678dd">return&lt;/span> &lt;span style="color:#e5c07b">False&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#c678dd">return&lt;/span> &lt;span style="color:#e5c07b">True&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div></description></item><item><title>LC 1752 (and 4)</title><link>https://88mangos.github.io/algos/2026-05-22/</link><pubDate>Fri, 22 May 2026 00:00:00 +0000</pubDate><guid>https://88mangos.github.io/algos/2026-05-22/</guid><description>&lt;h1 id="the-daily-easy-1752-check-if-array-is-sorted-and-rotated">The Daily (Easy): &lt;code>1752. Check if Array Is Sorted and Rotated&lt;/code>&lt;/h1>
&lt;p>Here is my solution:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#abb2bf;background-color:#282c34;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-python" data-lang="python">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#c678dd">class&lt;/span> &lt;span style="color:#e5c07b">Solution&lt;/span>:
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#c678dd">def&lt;/span> &lt;span style="color:#61afef;font-weight:bold">check&lt;/span>(&lt;span style="color:#e5c07b">self&lt;/span>, &lt;span style="color:#e06c75">nums&lt;/span>: &lt;span style="color:#e06c75">List&lt;/span>[&lt;span style="color:#e5c07b">int&lt;/span>]) &lt;span style="color:#56b6c2">-&amp;gt;&lt;/span> &lt;span style="color:#e5c07b">bool&lt;/span>:
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#e06c75">n&lt;/span> &lt;span style="color:#56b6c2">=&lt;/span> &lt;span style="color:#e5c07b">len&lt;/span>(&lt;span style="color:#e06c75">nums&lt;/span>)
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#e06c75">diffs&lt;/span> &lt;span style="color:#56b6c2">=&lt;/span> [(&lt;span style="color:#e06c75">nums&lt;/span>[&lt;span style="color:#e06c75">i&lt;/span>] &lt;span style="color:#56b6c2">-&lt;/span> &lt;span style="color:#e06c75">nums&lt;/span>[&lt;span style="color:#e06c75">i&lt;/span>&lt;span style="color:#56b6c2">-&lt;/span>&lt;span style="color:#d19a66">1&lt;/span>]) &lt;span style="color:#56b6c2">&amp;lt;&lt;/span> &lt;span style="color:#d19a66">0&lt;/span> &lt;span style="color:#c678dd">for&lt;/span> &lt;span style="color:#e06c75">i&lt;/span> &lt;span style="color:#56b6c2">in&lt;/span> &lt;span style="color:#e5c07b">range&lt;/span>(&lt;span style="color:#e06c75">n&lt;/span>)]
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#7f848e"># print(sum(diffs))&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#c678dd">return&lt;/span> &lt;span style="color:#e5c07b">sum&lt;/span>(&lt;span style="color:#e06c75">diffs&lt;/span>) &lt;span style="color:#56b6c2">==&lt;/span> &lt;span style="color:#d19a66">1&lt;/span> &lt;span style="color:#56b6c2">or&lt;/span> &lt;span style="color:#e5c07b">sum&lt;/span>(&lt;span style="color:#e06c75">diffs&lt;/span>) &lt;span style="color:#56b6c2">==&lt;/span> &lt;span style="color:#d19a66">0&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>in essence, you just make sure there&amp;rsquo;s only one inflection point (where the next item is greater than the prev, i.e., breaks monotonically increasing order), or there are no inflection points, i.e., all items are the same.&lt;/p>
&lt;h1 id="a-greater-challenge-4-median-of-two-sorted-arrays">A greater challenge: &lt;code>4. Median of Two Sorted Arrays&lt;/code>&lt;/h1>
&lt;p>At first I thought this was kinda like 210 where we maintain a max heap of all items less than median and min heap of all items greater than current median. But then the TC is $O((m + n) \log (m + n))$ which would just be the same as sorting and then taking the &lt;code>(m + n) // 2&lt;/code>th element.&lt;/p></description></item><item><title>LC 153 and 154: Find Minimum in Rotated Sorted Array (II)</title><link>https://88mangos.github.io/algos/2026-05-15/</link><pubDate>Fri, 15 May 2026 00:00:00 +0000</pubDate><guid>https://88mangos.github.io/algos/2026-05-15/</guid><description>&lt;p>At first, this problem seems trivial. Returning &lt;code>min(nums)&lt;/code> gives you the right answer, but this is $O(n)$ TC. Some people in the solutions were talking about the solution being $\Omega(n)$ runtime, arguing you must check every single element to find the minimum. But that doesn&amp;rsquo;t quite use the sorted rotation part of the question&amp;hellip; so that&amp;rsquo;s fishy!&lt;/p>
&lt;h1 id="my-initial-solution-before-i-read-the-comments">My Initial Solution, Before I read the Comments&lt;/h1>
&lt;p>Linear search for the pivot point of the rotation. Break early, but still worst case $O(n)$.&lt;/p></description></item><item><title>LC 2784: Check if Array is Good</title><link>https://88mangos.github.io/algos/2026-05-13/</link><pubDate>Wed, 13 May 2026 00:00:00 +0000</pubDate><guid>https://88mangos.github.io/algos/2026-05-13/</guid><description>&lt;p>This was lwk easy asf I lwk misread at first and thought it was just a permutation of 1 to n but turns out there&amp;rsquo;s two &lt;code>n&lt;/code>s required so it was a little more complicated.&lt;/p></description></item><item><title>Phone Shortcuts and Automations</title><link>https://88mangos.github.io/other/habits/</link><pubDate>Wed, 13 May 2026 00:00:00 +0000</pubDate><guid>https://88mangos.github.io/other/habits/</guid><description>&lt;p>I&amp;rsquo;ve recently deleted YouTube and Instagram, and now only use them on my computer. As a result I have been picking up my phone and then doing nothing a lot more, so I figure I&amp;rsquo;d try to automate away as many things as I can to reduce the number of things I need to do on my phone.&lt;/p>
&lt;p>I categorize these automations and shortcuts into three types:&lt;/p>
&lt;ol>
&lt;li>Settings, i.e., things you can do in the Settings app in iOS 26&lt;/li>
&lt;li>App Automatic Notifications, i.e., things that apps let you do&lt;/li>
&lt;li>Shortcuts/Automations, i.e., things in the Shortcuts app.&lt;/li>
&lt;/ol>
&lt;p>The productivity apps that I use (and follow) are:&lt;/p></description></item><item><title>Initial Brainstorm</title><link>https://88mangos.github.io/projects/zilk/initial-brainstorm/</link><pubDate>Tue, 12 May 2026 00:00:00 +0000</pubDate><guid>https://88mangos.github.io/projects/zilk/initial-brainstorm/</guid><description>Using Google Gemini to feel out the scope of the project</description></item><item><title>LC 1665: Minimum Initial Energy to Finish Tasks</title><link>https://88mangos.github.io/algos/2026-05-12/</link><pubDate>Tue, 12 May 2026 00:00:00 +0000</pubDate><guid>https://88mangos.github.io/algos/2026-05-12/</guid><description>&lt;p>Daily Problem for May 11th, 2026&lt;/p>
&lt;h1 id="my-notes-unedited">My Notes (Unedited)&lt;/h1>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#abb2bf;background-color:#282c34;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-python" data-lang="python">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#c678dd">class&lt;/span> &lt;span style="color:#e5c07b">Solution&lt;/span>:
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#7f848e"># initial thoughts: this seems like DP....&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#7f848e"># probably bottom-up though right? Idk let&amp;#39;s see&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#7f848e">#&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#7f848e"># base case is if there&amp;#39;s one task, the min amount of energy is the minimum&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#7f848e">#&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#7f848e"># so let&amp;#39;s define the subproblem in terms of index i,&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#7f848e"># where the value is the minimum amount of energy to finish up to and including task i&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#7f848e">#&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#7f848e"># i = 0: then it&amp;#39;s just minimum[i]&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#7f848e"># i = 1: it&amp;#39;s min of&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#7f848e"># do 0 then 1, so we start with minimum[0], use up actual[0]&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#7f848e"># and now we need minimum[1], so it&amp;#39;s minimum[1] - (minimum[0] - actual[0])&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#7f848e"># or we could do 1 and then 0, minimum[0] - (minimum[1] - actual[1])&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#7f848e"># i = 2: we have the results of the first two, so it&amp;#39;s analogous?&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#7f848e"># do 2, then 0 and 1, or,&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#7f848e"># do 0 and 1, then 2.&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#7f848e"># the subproblem result is the minimum for [0,1], the actual is just the sum of actual[0] and actual[1].&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#7f848e"># there are n! permutations of tasks, need to reduce this search space&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#7f848e"># dp = [float(&amp;#39;inf&amp;#39;) for i in range(n)]&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#7f848e"># for i in range(n):&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#7f848e"># if i == 0:&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#7f848e"># dp[i] = minimum[0]&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#7f848e"># else:&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#7f848e"># # do [0...i-1], then i&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#7f848e"># # do i, then [0...i-1]&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#7f848e"># # issue, what if i is somewhere in the middle? This doesn&amp;#39;t cover all possibilities.&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#7f848e"># # okay so what if we do graph search?&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#7f848e"># # we consider all possible nodes&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#7f848e"># # each node contains task index i and amount of energy&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#7f848e"># # cost to travel an edge is actual[i]&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#7f848e"># # edges only exist based on minimum[i]&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#7f848e"># # yeah this will do it surely.&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#7f848e"># ok so graph search idea&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#7f848e"># task i can go to all other tasks j if&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#7f848e"># the node has enough energy&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#7f848e"># the max amount of energy necessary is bounded by the sum of all minimum[i]&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#7f848e"># let&amp;#39;s say we start there&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#7f848e"># we do a APSP using Floyd Warshall&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#7f848e"># find the min weight SP? but this is more like a spanning tree since we must hit every task&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#7f848e">#&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#7f848e"># I think it&amp;#39;s MST but the edges are weighted by the additional energy necessary.&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#7f848e"># it&amp;#39;s a directed graph, the logic above (pasted here)&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#7f848e"># do 0 then 1, so we start with minimum[0], use up actual[0]&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#7f848e"># and now we need minimum[1], so it&amp;#39;s minimum[1] - (minimum[0] - actual[0])&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#7f848e"># or we could do 1 and then 0, minimum[0] - (minimum[1] - actual[1])&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#7f848e"># is sorta repeatable - we can travel from 0 to 1, or 1 to 0. The cost from 0 to 1 is&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#7f848e"># minimum[1] - (minimum[0] - actual[0]), and it&amp;#39;s assumed you have minimum[0] to start.&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#7f848e"># Then we just do a minimum spanning tree? But the issue is the edges are directed so it&amp;#39;s a little more annoying.&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#7f848e"># the edges being directed and having to hit all vertices implies some sort of priority first search maybe?&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#7f848e">#&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#7f848e"># it&amp;#39;s so hard to figure out what the graph should be, maybe it is DP after all?&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#7f848e"># and my subproblems just suck?&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#7f848e"># I guess technically there are 0 to i-1 solved before,&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#7f848e"># so there are i places to insert task[i],&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#7f848e"># but the number of subproblems blow up in terms of subsets.&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#7f848e">#&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#7f848e"># i guess it might be sort of resembling coin change?&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#7f848e"># it could be a binary search DP. We know the maximum answer is the sum of the minimums[0...n]&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#7f848e"># so we can start at halfway, if that&amp;#39;s possible we guess down, otherwise we guess up?&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#7f848e"># but that&amp;#39;s log n DPs... that probably sucks ass.&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#7f848e">#&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#c678dd">def&lt;/span> &lt;span style="color:#61afef;font-weight:bold">minimumEffort&lt;/span>(&lt;span style="color:#e5c07b">self&lt;/span>, &lt;span style="color:#e06c75">tasks&lt;/span>: &lt;span style="color:#e06c75">List&lt;/span>[&lt;span style="color:#e06c75">List&lt;/span>[&lt;span style="color:#e5c07b">int&lt;/span>]]) &lt;span style="color:#56b6c2">-&amp;gt;&lt;/span> &lt;span style="color:#e5c07b">int&lt;/span>:
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#e06c75">n&lt;/span> &lt;span style="color:#56b6c2">=&lt;/span> &lt;span style="color:#e5c07b">len&lt;/span>(&lt;span style="color:#e06c75">tasks&lt;/span>)
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#e06c75">actual&lt;/span> &lt;span style="color:#56b6c2">=&lt;/span> []
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#e06c75">minimum&lt;/span> &lt;span style="color:#56b6c2">=&lt;/span> []
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#c678dd">for&lt;/span> &lt;span style="color:#e06c75">i&lt;/span> &lt;span style="color:#56b6c2">in&lt;/span> &lt;span style="color:#e5c07b">range&lt;/span>(&lt;span style="color:#e06c75">n&lt;/span>):
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#e06c75">actual&lt;/span>&lt;span style="color:#56b6c2">.&lt;/span>&lt;span style="color:#e06c75">append&lt;/span>(&lt;span style="color:#e06c75">tasks&lt;/span>[&lt;span style="color:#e06c75">i&lt;/span>][&lt;span style="color:#d19a66">0&lt;/span>])
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#e06c75">minimum&lt;/span>&lt;span style="color:#56b6c2">.&lt;/span>&lt;span style="color:#e06c75">append&lt;/span>(&lt;span style="color:#e06c75">tasks&lt;/span>[&lt;span style="color:#e06c75">i&lt;/span>][&lt;span style="color:#d19a66">1&lt;/span>])
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;div class="highlight">&lt;pre tabindex="0" style="color:#abb2bf;background-color:#282c34;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-fallback" data-lang="fallback">&lt;span style="display:flex;">&lt;span>It could be doable to store states where the states contain the ones completed thus far, but then just this bitset is 2^n possible outcomes, which is surely not in time bounds (so this type of DP is infeasible)
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>oh shit you can&amp;#39;t refill energy, you only start with a bunch. That drastically changes the problem.
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>Then the answer is lower bounded by the maximum value in the minimum array
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>and upper bounded by the sum of the actuals
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> # bound_1 = sum(actual), need to be able complete all the tasks
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> # bound_2 = max(minimum), need to be able to start all the tasks
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> # answer lies somewhere in between
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>take the MST idea from earlier. since we assume taht minimum[i] &amp;gt;= actual[i],
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>the true cost of a node is (minimum[0] - actual[0]) for the zeroth node,
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>so the costs are all minimum[i] - actual[i].
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>oh wait do we just want to do the highest cost nodes first...
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>is it provable that this attains the minimum solution?
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>because a [1, 5] node costs more than a [13, 14] node,
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>but the 14 imposes a stricter requirement?
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>But anyways we&amp;#39;ll need a lot more down the line...
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>oh shit THAT&amp;#39;s where the DP subproblems are?
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>So the min cost of achieving all the previous is the sum of their minimum[i] - actual[i]?
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>no because that doesn&amp;#39;t tell us where to insert the thing.
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>if we sum the costs that&amp;#39;s naively wrong because in the case of
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> [1, 5] and [13, 14] the sum of costs is 4 + 1 = 5, but ig if we added the max actual[i] = 13
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> then we&amp;#39;d get 18 which is correct.
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>so ideally we get the highest cost nodes out of the way earlier,
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>but we also want to get the highest barrier to entry nodes out of the way earlier too (while we have energy to use)
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>also patently untrue, because it sometimes may be better to do a higher cost node if its actual[i] is low,
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>that way we preserve energy. So this somehow still feels like DP...
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>what if it&amp;#39;s sort by cost, tiebreak by putting higher minimums last? but that makes no intuitive sense, you&amp;#39;d want higher minimums to come early on?
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>continuing the old DP logic
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> # i = 0: then it&amp;#39;s just minimum[i]
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> # i = 1: it&amp;#39;s min of
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> # do 0 then 1, so we start with minimum[0], use up actual[0]
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> # and now we need minimum[1], so it&amp;#39;s minimum[1] - (minimum[0] - actual[0])
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> # or we could do 1 and then 0, minimum[0] - (minimum[1] - actual[1])
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> # i = 2: min of
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> # do [0, 1], then 2
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> # do 2, then [0, 1]
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> # do 0, 2, 1
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> # do 1, 2, 0
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> #
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> # So we reuse the i=1 for the subproblems
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> # but then we have to compute new permutations,
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> # the number of which is proportional to the number of tasks we&amp;#39;ve already done.
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> #
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> #
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> # this goes back to the subproblem states being a bitset of length n which gives 2^n states,
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> # but maybe the reuse is OK?
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> # I mean the issue is there aren&amp;#39;t THAT many states right... fib(n) requires n states,
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> # it&amp;#39;s just that they&amp;#39;re reused a lot.
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> # but this already has an exponential number of states, and DP work is poly in # of states, so this can&amp;#39;t be
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> #
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> #
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> #
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> #
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>For some reason I keep going back to MSTs in my mind.
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>if we used Kruskal&amp;#39;s, we&amp;#39;d sort the edge weights and then try adding one by one
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>but what would the edges be for this graph so that I can find the MST?
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>If the n vertices are the n tasks,
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>the cost of an undirected edge is kinda nonsense...
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>I&amp;#39;m still thinking about the minimum[0] - actual[0] thing
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>the cost of a task is that we need to muster up the minimum energy to do it, and then expend the actual energy.
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>We&amp;#39;d want the high effort tasks first I guess. So we&amp;#39;ll sort by cost then by high to low min energy.
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h1 id="reflection">Reflection&lt;/h1>
&lt;p>Yeah I way overthought this problem at first. I guess I was a little traumatized from &lt;a href="./2026-05-07.md">LC3629&lt;/a>, since I missed the quite obvious graph search solution.&lt;/p></description></item><item><title>Throwing in the Towel</title><link>https://88mangos.github.io/projects/jstarb/the-end/</link><pubDate>Tue, 12 May 2026 00:00:00 +0000</pubDate><guid>https://88mangos.github.io/projects/jstarb/the-end/</guid><description>Ran into a very familiar wall</description></item><item><title>Second Attempt</title><link>https://88mangos.github.io/projects/jstarb/second-attempt/</link><pubDate>Mon, 11 May 2026 00:00:00 +0000</pubDate><guid>https://88mangos.github.io/projects/jstarb/second-attempt/</guid><description>Running into a wall, again</description></item><item><title>First Attempt</title><link>https://88mangos.github.io/projects/jstarb/first-attempt/</link><pubDate>Sat, 09 May 2026 00:00:00 +0000</pubDate><guid>https://88mangos.github.io/projects/jstarb/first-attempt/</guid><description>Running into a wall</description></item><item><title>Initial Implementation</title><link>https://88mangos.github.io/projects/jstarb/initial-design/</link><pubDate>Fri, 08 May 2026 00:00:00 +0000</pubDate><guid>https://88mangos.github.io/projects/jstarb/initial-design/</guid><description>Getting Started with the Project</description></item><item><title>Learning Zig via Ziglings</title><link>https://88mangos.github.io/projects/zig/</link><pubDate>Fri, 08 May 2026 00:00:00 +0000</pubDate><guid>https://88mangos.github.io/projects/zig/</guid><description>Learning a cool programming language</description></item><item><title>Exigence</title><link>https://88mangos.github.io/projects/jstarb/exigence/</link><pubDate>Thu, 07 May 2026 00:00:00 +0000</pubDate><guid>https://88mangos.github.io/projects/jstarb/exigence/</guid><description>Why did I even want to write this</description></item><item><title>LC 3629: Minimum Jumps to Reach End via Prime Teleportation</title><link>https://88mangos.github.io/algos/2026-05-07/</link><pubDate>Thu, 07 May 2026 00:00:00 +0000</pubDate><guid>https://88mangos.github.io/algos/2026-05-07/</guid><description>&lt;p>Daily Problem for May 7th, 2026&lt;/p>
&lt;h1 id="problem-statement">Problem Statement&lt;/h1>
&lt;p>You are given an integer array nums of length n.&lt;/p>
&lt;p>You start at index 0, and your goal is to reach index n - 1.&lt;/p>
&lt;p>From any index i, you may perform one of the following operations:&lt;/p>
&lt;ul>
&lt;li>Adjacent Step: Jump to index i + 1 or i - 1, if the index is within bounds.&lt;/li>
&lt;li>Prime Teleportation: If nums[i] is a prime number p, you may instantly jump to any index j != i such that nums[j] % p == 0.&lt;/li>
&lt;/ul>
&lt;p>Return the minimum number of jumps required to reach index n - 1&lt;/p></description></item></channel></rss>