All Posts

Leetcode 787: Cheapest Flights Within K Stops

You are given a number of cities and a list of flights between them. Each flight has a price and connects two cities. You need to find the cheapest route from a given source city to a destination city with at most a certain number of stops. If no such route exists, return -1.

Leetcode 788: Rotated Digits

Given an integer n, find how many integers in the range [1, n] are ‘good’ integers. A number is considered ‘good’ if after rotating each of its digits by 180 degrees, it becomes a valid different number. The rotation rules for digits are as follows: 0, 1, and 8 stay the same, 2 and 5 swap places, 6 and 9 swap places, and other digits are not valid when rotated.

Leetcode 790: Domino and Tromino Tiling

You are given a 2 x n grid and two types of tiles: a 2 x 1 domino and a tromino (which can be rotated). You must cover the grid entirely with these tiles. The task is to find the number of possible ways to tile the 2 x n board, modulo 10^9 + 7. Each tile must cover exactly two adjacent squares, and every square must be covered by a tile.

Leetcode 792: Number of Matching Subsequences

You are given a string s and an array of strings words. Your task is to determine how many words from the array are subsequences of the string s. A subsequence of a string is derived by deleting some or no characters from the original string without altering the order of the remaining characters.

Leetcode 799: Champagne Tower

You are given a champagne tower in the shape of a pyramid. The topmost glass is filled with a specified amount of champagne. When a glass is full, the excess champagne spills equally into the two glasses directly beneath it. Given the total amount of champagne poured, determine how full a particular glass at row query_row and glass query_glass will be after the champagne has spilled.

Leetcode 808: Soup Servings

You have two types of soup: A and B, with an initial volume of n ml of each. You can serve soup using four possible operations, each with a 25% chance of being chosen randomly. When serving, the amounts of soups A and B used are specified by each operation. If there is insufficient soup for a full operation, serve as much as possible. The process stops when one of the soups runs out. Return the probability that soup A will be exhausted first, plus half the probability that both soups will be exhausted at the same time.