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 2073: Time Needed to Buy Tickets

You are given a queue of n people, where each person wants to buy a specific number of tickets. The task is to determine the time taken for the person at index k to finish buying all their tickets.

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 2105: Watering Plants II

Alice and Bob are tasked with watering a garden of n plants. The plants are arranged in a row and need varying amounts of water. Alice waters the plants from left to right, while Bob waters them from right to left. They both begin with full watering cans. If they don’t have enough water for the next plant, they refill their cans. In case they both reach the same plant, the one with more water in their can should water the plant, or Alice waters it in case of a tie. The goal is to determine how many times Alice and Bob have to refill their cans to water all the plants.

Leetcode 2109: Adding Spaces to a String

You are given a string s and an array spaces. The array contains indices where spaces need to be inserted into the string. Each space should be added before the character at the respective index. Return the modified string with the spaces inserted.