feat(leetcode-daily): today

This commit is contained in:
Barrett Ruth 2025-04-08 09:58:22 -04:00
parent 98d99a017d
commit 0ea685e154
2 changed files with 48 additions and 0 deletions

View file

@ -35,6 +35,41 @@
<h1 class="post-title">Leetcode Daily</h1>
</header>
<article class="post-article">
<h2>
<a
target="blank"
href="https://leetcode.com/problems/minimum-number-of-operations-to-make-elements-in-array-distinc"
>minimum number of operations to make array distinct</a
>
&mdash; 9/13/24
</h2>
<div class="problem-content">
<h3>understanding the problem</h3>
<p>
You can remove elements in groups of 3 <i>solely</i> from the
beginning of the array. Perform this operation until there are no
more duplicates left, returning the number of times you had to
perform the operation.
</p>
<h3>solution: rephrase the question</h3>
<p>
Definitionally, you remove the <i>last</i> duplicate. If such
duplicate is at 0-indexed <code>i</code>, it belongs to the \(\lceil
\frac{i + 1}{3}\rceil\)th chunk of 3 (i.e. operation). Find the last
duplicate by leveraging a frequency map and iterating backwards
through the input.
</p>
<div class="code" data-file="mnootmad.cpp"></div>
<h3>asymptotic complexity</h3>
<p>
The solution is optimal, considering the least amount of elements
possible in:
</p>
<ul>
<li><u>Time Complexity</u>: \(\O(n)\)</li>
<li><u>Space Complexity</u>: \(\Theta(1)\)</li>
</ul>
</div>
<h2>
<a
target="blank"