[LeetCode] Integers With Multiple Sum of Two Cubes

3890. Integers With Multiple Sum of Two Cubes

You are given an integer n.

An integer x is considered good if there exist at least two distinct pairs (a, b) such that:

  • a and b are positive integers.
  • a <= b
  • x = a^3 + b^3

Return an array containing all good integers less than or equal to n, sorted in ascending order.

Read more
[LeetCode] Minimum Increase to Maximize Special Indices

3891. Minimum Increase to Maximize Special Indices

You are given an integer array nums of length n.

An index i (0 < i < n - 1) is special if nums[i] > nums[i - 1] and nums[i] > nums[i + 1].

You may perform operations where you choose any index i and increase nums[i] by 1.

Your goal is to:

  • Maximize the number of special indices.
  • Minimize the total number of operations required to achieve that maximum.

Return an integer denoting the minimum total number of operations required.

Read more
[LeetCode] Minimum Operations to Achieve At Least K Peaks

3892. Minimum Operations to Achieve At Least K Peaks

You are given a ​​​​​​​circular integer array​​​​​​​ nums of length n.

An index i is a peak if its value is strictly greater than its neighbors:

  • The previous neighbor of i is nums[i - 1] if i > 0, otherwise nums[n - 1].
  • The next neighbor of i is nums[i + 1] if i < n - 1, otherwise nums[0].

You are allowed to perform the following operation any number of times:

  • Choose any index i and increase nums[i] by 1.

Return an integer denoting the minimum number of operations required to make the array contain at least k peaks. If it is impossible, return -1.

Read more
[LeetCode] Traffic Signal Color

3894. Traffic Signal Color

You are given an integer timer representing the remaining time (in seconds) on a traffic signal.

The signal follows these rules:

  • If timer == 0, the signal is "Green"
  • If timer == 30, the signal is "Orange"
  • If 30 < timer <= 90, the signal is "Red"

Return the current state of the signal. If none of the above conditions are met, return "Invalid".

Read more
[LeetCode] Count Digit Appearances

3895. Count Digit Appearances

You are given an integer array nums and an integer digit.

Return the total number of times digit appears in the decimal representation of all elements in nums.

Read more
[LeetCode] Count Good Integers on a Grid Path

3906. Count Good Integers on a Grid Path

You are given two integers l and r, and a string directions consisting of exactly three 'D' characters and three 'R' characters.

For each integer x in the range [l, r] (inclusive), perform the following steps:

  • If x has fewer than 16 digits, pad it on the left with leading zeros to obtain a 16-digit string.
  • Place the 16 digits into a 4 × 4 grid in row-major order (the first 4 digits form the first row from left to right, the next 4 digits form the second row, and so on).
  • Starting at the top-left cell (row = 0, column = 0), apply the 6 characters of directions in order:
    • 'D' increments the row by 1.
    • 'R' increments the column by 1.
  • Record the sequence of digits visited along the path (including the starting cell), producing a sequence of length 7.

The integer x is considered good if the recorded sequence is non-decreasing.

Return an integer representing the number of good integers in the range [l, r].

Read more
[LeetCode] Find the Degree of Each Vertex

3898. Find the Degree of Each Vertex

You are given a 2D integer array matrix of size n x n representing the adjacency matrix of an undirected graph with n vertices labeled from 0 to n - 1.

  • matrix[i][j] = 1 indicates that there is an edge between vertices i and j.
  • matrix[i][j] = 0 indicates that there is no edge between vertices i and j.

The degree of a vertex is the number of edges connected to it.

Return an integer array ans of size n where ans[i] represents the degree of vertex i.

Read more
[LeetCode] Maximum Value of Concatenated Binary Segments

3897. Maximum Value of Concatenated Binary Segments

You are given two integer arrays nums1 and nums0, each of size n.

  • nums1[i] represents the number of '1's in the i^th segment.
  • nums0[i] represents the number of '0's in the i^th segment.

For each index i, construct a binary segment consisting of:

  • nums1[i] occurrences of '1' followed by
  • nums0[i] occurrences of '0'.

You may rearrange the order of these segments in any way. After rearranging, concatenate all segments to form a single binary string.

Return the maximum possible integer value of the concatenated binary string.

Since the result can be very large, return the answer modulo 10^9 + 7.

Read more
[LeetCode] Minimum Operations to Transform Array into Alternating Prime

3896. Minimum Operations to Transform Array into Alternating Prime

You are given an integer array nums.

An array is considered alternating prime if:

  • Elements at even indices (0-based) are prime numbers.
  • Elements at odd indices are non-prime numbers.

In one operation, you may increment any element by 1.

Return the minimum number of operations required to transform nums into an alternating prime array.

A prime number is a natural number greater than 1 with only two factors, 1 and itself.

Read more
[LeetCode] Multi Source Flood Fill

3905. Multi Source Flood Fill

You are given two integers n and m representing the number of rows and columns of a grid, respectively.

You are also given a 2D integer array sources, where sources[i] = [r_i, c_i, color_​​​​​​​i] indicates that the cell (r_i, c_i) is initially colored with color_i. All other cells are initially uncolored and represented as 0.

At each time step, every currently colored cell spreads its color to all adjacent uncolored cells in the four directions: up, down, left, and right. All spreads happen simultaneously.

If multiple colors reach the same uncolored cell at the same time step, the cell takes the color with the maximum value.

The process continues until no more cells can be colored.

Return a 2D integer array representing the final state of the grid, where each cell contains its final color.

Read more