All Posts

Leetcode 1418: Display Table of Food Orders in a Restaurant

Given a list of customer orders in a restaurant, return a table where each row represents a table number and the columns represent the number of food items ordered at that table, sorted in lexicographical order.

Leetcode 1438: Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit

Given an array of integers nums and a positive integer limit, determine the length of the longest subarray where the absolute difference between the minimum and maximum elements is less than or equal to limit.

Leetcode 1818: Minimum Absolute Sum Difference

You are given two positive integer arrays nums1 and nums2 of the same length n. You are allowed to change at most one element of nums1 to any other value from nums1 to minimize the total absolute sum difference between nums1 and nums2. Return the minimum absolute sum difference after making the replacement. Since the answer may be large, return it modulo 10^9 + 7.

Leetcode 2034: Stock Price Fluctuation

You are given a stream of stock price records, where each record contains a timestamp and the corresponding price of the stock. The records may not be in order, and some records may contain errors that need to be corrected. Your task is to design an algorithm that updates the stock price at a given timestamp, finds the current price at the latest timestamp, and also finds the maximum and minimum prices the stock has been based on the current records.

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.