All Posts

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 789: Escape The Ghosts

You are playing a simplified game on an infinite 2-D grid where you start at position [0, 0], and your goal is to reach a destination point target = [xtarget, ytarget]. There are several ghosts on the map, each with its starting position. You and the ghosts can all independently move one unit in any of the four cardinal directions (north, east, south, or west), or stay still. If you can reach the destination before any ghost catches up with you, you escape. You cannot escape if you reach any square at the same time as a ghost. Your task is to return true if it is possible to escape, otherwise return false.

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.

Leetcode 836: Rectangle Overlap

You are given two axis-aligned rectangles represented by two lists, rec1 and rec2. Each list contains four integers: [x1, y1, x2, y2], where (x1, y1) represents the bottom-left corner and (x2, y2) represents the top-right corner of the rectangle. You need to determine if the two rectangles overlap. Two rectangles overlap if their intersection area is positive. Rectangles that only touch at the edges or corners do not count as overlapping.

Leetcode 837: New 21 Game

Alice is playing a game where she starts with 0 points and randomly draws a number from the range [1, maxPts] each time. Alice continues drawing until her points reach or exceed a target value k. After each draw, she may stop if her total points reach or exceed k. The goal is to determine the probability that Alice has at most n points before reaching k points.

Leetcode 840: Magic Squares In Grid

Given a grid of integers, the task is to find how many 3x3 magic square subgrids are present in the given grid. A 3x3 magic square is a grid that contains distinct numbers from 1 to 9, such that each row, each column, and both diagonals have the same sum. The input grid can contain numbers ranging from 0 to 15, but only numbers between 1 and 9 are valid for forming a magic square.