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 of value in the subarray from left to right.

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.

Leetcode 2349: Design a Number Container System

Design a number container system that allows inserting or replacing a number at a specific index and finding the smallest index for a given number.

Leetcode 2353: Design a Food Rating System

Design a food rating system that allows modification of food ratings and can return the highest-rated food item for a given cuisine. In case of a tie, the lexicographically smallest food item should be returned.