All Posts

Leetcode 2069: Walking Robot Simulation II

A robot is placed on a grid and initially faces East. It is instructed to move forward by a specified number of steps. If the robot attempts to move out of bounds, it turns 90 degrees counterclockwise and tries again. The task is to implement a class for the robot that can handle these movements and return its current position and direction.

Leetcode 2070: Most Beautiful Item for Each Query

You are given a list of items, where each item has a price and a beauty score. You are also given a list of price queries. For each query, find the maximum beauty of an item with a price less than or equal to the query price. If no such item exists, return 0.

Leetcode 2075: Decode the Slanted Ciphertext

Given an encoded string and the number of rows used to encode the original text, recover the original string. The encoded text is produced by filling a matrix in a slanted transposition cipher and reading it row by row.

Leetcode 2079: Watering Plants

You need to water n plants arranged in a row. Starting at the river, you water the plants in order, refilling your watering can when it runs out. The goal is to determine the total number of steps to water all the plants.

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 2086: Minimum Number of Food Buckets to Feed the Hamsters

You are given a string representing hamster positions. The string consists of ‘H’ for a hamster and ‘.’ for an empty space. You must place food buckets in empty positions such that all hamsters are fed. A hamster is fed if a food bucket is placed at one of its adjacent positions. Your task is to return the minimum number of food buckets required to feed all the hamsters. If it is impossible, return -1.