All Posts

Leetcode 1046: Last Stone Weight

In this problem, we have an array of integers representing stones. Each stone has a weight, and on each turn, we choose the two heaviest stones, smash them together, and apply the following rules: If the two stones have the same weight, both are destroyed. If they have different weights, the stone with the smaller weight is destroyed, and the stone with the larger weight gets reduced by the smaller stone’s weight. The process continues until at most one stone remains. Your task is to return the weight of the last remaining stone. If no stones are left, return 0.

Leetcode 1048: Longest String Chain

You are given an array of words, where each word consists of lowercase English letters. A wordA is considered a predecessor of wordB if you can insert exactly one letter anywhere in wordA without changing the order of the other characters to make it equal to wordB. A word chain is a sequence of words such that each word is a predecessor of the next one. Your task is to find the length of the longest word chain that can be formed from the given list of words.

Leetcode 1049: Last Stone Weight II

You are given an array of integers representing the weights of stones. In each turn, you can select two stones, x and y, with x <= y, and smash them together. The result of the smash is as follows: if x equals y, both stones are destroyed, otherwise, the stone with weight x is destroyed, and the stone with weight y becomes y - x. The process continues until there is at most one stone left. Your task is to return the smallest possible weight of the remaining stone, or return 0 if no stones are left.

Leetcode 1051: Height Checker

A school is arranging students in a line for an annual photograph. The students are required to stand in a non-decreasing order of height. The expected order is represented by an array, where each element corresponds to the expected height of the student at that position. Given the current arrangement of the students’ heights, determine the number of positions where the height of the student does not match the expected height.

Leetcode 1052: Grumpy Bookstore Owner

A bookstore owner has a store open for ’n’ minutes. During each minute, a certain number of customers enter the store, but the owner may be grumpy and fail to satisfy some customers. The grumpy behavior of the owner is given as a binary array, where 1 means the owner is grumpy and 0 means they are not. The owner has a special technique to remain calm for a specified number of consecutive minutes, but it can only be used once. The goal is to find the maximum number of customers who can be satisfied throughout the day by using this technique.

Leetcode 1053: Previous Permutation With One Swap

Given an array of positive integers, return the lexicographically largest permutation that is smaller than the given array. This can be done by swapping exactly two elements. If no such swap is possible (i.e., the array is already the smallest permutation), return the same array.