All Posts

Leetcode 2320: Count Number of Ways to Place Houses

Given a street with two rows of plots, each containing n plots, find the number of ways houses can be placed such that no two houses are adjacent on the same side of the street. Return the result modulo 10^9 + 7.

Leetcode 2327: Number of People Aware of a Secret

On day 1, one person discovers a secret. Each person will share the secret after a delay and forget it after a certain number of days. Return the number of people who know the secret at the end of day n, modulo 10^9 + 7.

Leetcode 2369: Check if There is a Valid Partition For The Array

You are given a 0-indexed integer array, and you need to partition it into one or more contiguous subarrays. A partition is valid if each subarray meets one of the following conditions:

  1. The subarray contains exactly 2 equal elements.
  2. The subarray contains exactly 3 equal elements.
  3. The subarray contains exactly 3 consecutive increasing elements, where the difference between adjacent elements is 1. Return true if there is at least one valid partition in the array, otherwise return false.

Leetcode 2370: Longest Ideal Subsequence

You are given a string s consisting of lowercase letters and an integer k. A string t is considered ideal if it is a subsequence of s and the absolute difference in the alphabet order of every two adjacent letters in t is less than or equal to k. Your task is to return the length of the longest ideal string.

Leetcode 2380: Time Needed to Rearrange a Binary String

You are given a binary string s. In one second, all occurrences of the substring ‘01’ are simultaneously replaced with ‘10’. This process repeats until no occurrences of ‘01’ exist in the string. The task is to return the number of seconds required to complete this process.

Leetcode 2400: Number of Ways to Reach a Position After Exactly k Steps

You are standing at a starting position startPos on an infinite number line, and you need to reach a destination endPos in exactly k steps. In each step, you can move either one position to the left or one position to the right. Your task is to find the number of different ways to reach endPos from startPos in exactly k steps. Since the number of ways can be very large, return the result modulo 10^9 + 7.