All Posts
Leetcode 2080: Range Frequency Queries
Design a data structure that allows you to efficiently find the frequency of a given value in a subarray. Implement the class RangeFreqQuery
with the following methods:
RangeFreqQuery(int[] arr)
initializes the data structure.int query(int left, int right, int value)
returns the frequency ofvalue
in the subarray fromleft
toright
.
Leetcode 2166: Design Bitset
You are tasked with implementing a Bitset class that supports operations such as setting bits, clearing bits, flipping all bits, and querying the state of the bits (whether all bits are set to 1, at least one bit is set to 1, etc.).
Leetcode 2241: Design an ATM Machine
Design an ATM machine that can handle deposits and withdrawals of five denominations: $20, $50, $100, $200, and $500. When withdrawing, the machine always tries to use the highest denominations available first. Implement methods to deposit money and withdraw specified amounts.
Leetcode 2336: Smallest Number in Infinite Set
You have a set containing all positive integers starting from 1. You need to implement a class SmallestInfiniteSet that has the following methods:
- SmallestInfiniteSet() Initializes the set to contain all positive integers starting from 1.
- popSmallest() Removes and returns the smallest integer in the set.
- addBack(int num) Adds a positive integer num back into the set, if it’s not already present in the set.