All Posts

Leetcode 2207: Maximize Number of Subsequences in a String

You are given a string text and another string pattern of length 2, consisting of lowercase English letters. Your task is to insert one of the characters from pattern into text exactly once, and then return the maximum number of times pattern appears as a subsequence in the modified text.

Leetcode 2222: Number of Ways to Select Buildings

You are given a binary string s that represents the types of buildings along a street. Each building is either an office (‘0’) or a restaurant (‘1’). You are tasked with selecting 3 buildings for inspection, with the constraint that no two consecutive buildings in the selection can be of the same type. Return the number of valid ways to select 3 buildings where no two consecutive buildings are of the same type.

Leetcode 2245: Maximum Trailing Zeros in a Cornered Path

You are given a 2D integer array called grid of size m x n, where each cell contains a positive integer. A cornered path is a specific path in the grid with at most one directional change. The path must move either horizontally or vertically up to a single turn and then continue in the alternate direction. The product of a path is the product of all integers in that path. The task is to find the maximum number of trailing zeros in the product of a cornered path.

Leetcode 2256: Minimum Average Difference

You are given a 0-indexed integer array nums of length n. For each index i, calculate the absolute difference between the average of the first i + 1 elements and the average of the last n - i - 1 elements. Both averages should be rounded down to the nearest integer. Your task is to find the index i with the minimum average difference. If there are multiple indices with the same difference, return the smallest index.

Leetcode 2270: Number of Ways to Split Array

You are given an integer array nums of length n. The task is to find how many valid splits exist in nums. A valid split is defined as an index i such that the sum of the first i + 1 elements is greater than or equal to the sum of the remaining elements from index i + 1 to the end. The split must be at an index where at least one element exists on the right side of i.

Leetcode 2271: Maximum White Tiles Covered by a Carpet

You are given a 2D integer array tiles, where each element tiles[i] = [li, ri] represents that all integers from li to ri are painted white on a number line. Additionally, you are given an integer carpetLen, which represents the length of a carpet that can be placed anywhere on the number line. Your task is to return the maximum number of white tiles that can be covered by placing the carpet in a way that it maximizes the number of white tiles covered.