<p>Design and implement a data structure for a <ahref="https://en.wikipedia.org/wiki/Least_frequently_used"target="_blank">Least Frequently Used (LFU)</a> cache.</p>
<p>Implement the <code>LFUCache</code> class:</p>
<ul>
<li><code>LFUCache(int capacity)</code> Initializes the object with the <code>capacity</code> of the data structure.</li>
<li><code>int get(int key)</code> Gets the value of the <code>key</code> if the <code>key</code> exists in the cache. Otherwise, returns <code>-1</code>.</li>
<li><code>void put(int key, int value)</code> Update the value of the <code>key</code> if present, or inserts the <code>key</code> if not already present. When the cache reaches its <code>capacity</code>, it should invalidate and remove the <strong>least frequently used</strong> key before inserting a new item. For this problem, when there is a <strong>tie</strong> (i.e., two or more keys with the same frequency), the <strong>least recently used</strong><code>key</code> would be invalidated.</li>
</ul>
<p>To determine the least frequently used key, a <strong>use counter</strong> is maintained for each key in the cache. The key with the smallest <strong>use counter</strong> is the least frequently used key.</p>
<p>When a key is first inserted into the cache, its <strong>use counter</strong> is set to <code>1</code> (due to the <code>put</code> operation). The <strong>use counter</strong> for a key in the cache is incremented either a <code>get</code> or <code>put</code> operation is called on it.</p>
<p>The functions <codedata-stringify-type="code">get</code> and <codedata-stringify-type="code">put</code> must each run in <code>O(1)</code> average time complexity.</p>