All Posts

Leetcode 2104: Sum of Subarray Ranges

You are given an integer array nums. A subarray of nums is a contiguous sequence of elements. The range of a subarray is defined as the difference between the maximum and minimum elements within that subarray.

Your task is to calculate the sum of the ranges for all possible subarrays in the given array nums.

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 2108: Find First Palindromic String in the Array

Given a list of words, return the first word that is a palindrome. A palindrome is a word that reads the same forwards and backwards. If no palindromic word is found, return an empty string.

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.

Leetcode 2110: Number of Smooth Descent Periods of a Stock

You are given an integer array prices representing the daily price history of a stock, where prices[i] is the stock price on the ith day. A smooth descent period of a stock consists of contiguous days such that the price on each day decreases by exactly 1 from the previous day. The first day of the period can be a single-day smooth descent. Return the total number of smooth descent periods.

Leetcode 2121: Intervals Between Identical Elements

You are given an array of integers. Your task is to calculate the sum of absolute differences between the index of each element and the indices of all other occurrences of the same element. For each element in the array, return the sum of intervals to all its identical elements in the array.