[Codeforces] Educational Round 10 C. Foe PairsRead more
[Codeforces] Educational Round 10 D. Nested SegmentsRead more
[Codeforces] Round 347 (Div. 1) A. RebusRead more
[Codeforces] Educational Round 12 D. Simple SubsetRead more
[Codeforces] Round 349 (Div. 1) A. Reberland LinguisticsRead more
[LeetCode] Maximum Strictly Increasing Cells in a Matrix

2713. Maximum Strictly Increasing Cells in a Matrix

Given a 1-indexed m x n integer matrix mat, you can select any cell in the matrix as your starting cell.

From the starting cell, you can move to any other cell in the same row or column, but only if the value of the destination cell is strictly greater than the value of the current cell. You can repeat this process as many times as possible, moving from cell to cell until you can no longer make any moves.

Your task is to find the maximum number of cells that you can visit in the matrix by starting from some cell.

Return an integer denoting the maximum number of cells that can be visited.

Read more
[LeetCode] Minimum Cost to Make All Characters Equal

2712. Minimum Cost to Make All Characters Equal

You are given a 0-indexed binary string s of length n on which you can apply two types of operations:

  • Choose an index i and invert all characters from index 0 to index i (both inclusive), with a cost of i + 1
  • Choose an index i and invert all characters from index i to index n - 1 (both inclusive), with a cost of n - i

Return the minimum cost to make all characters of the string equal.

Invert a character means if its value is ‘0’ it becomes ‘1’ and vice-versa.

Read more
[LeetCode] Difference of Number of Distinct Values on Diagonals

2711. Difference of Number of Distinct Values on Diagonals

Given a 0-indexed 2D grid of size m x n, you should find the matrix answer of size m x n.

The value of each cell (r, c) of the matrix answer is calculated in the following way:

  • Let topLeft[r][c] be the number of distinct values in the top-left diagonal of the cell (r, c) in the matrix grid.
  • Let bottomRight[r][c] be the number of distinct values in the bottom-right diagonal of the cell (r, c) in the matrix grid.

Then answer[r][c] = |topLeft[r][c] - bottomRight[r][c]|.

Return the matrix answer.

A matrix diagonal is a diagonal line of cells starting from some cell in either the topmost row or leftmost column and going in the bottom-right direction until reaching the matrix’s end.

A cell (r1, c1) belongs to the top-left diagonal of the cell (r, c), if both belong to the same diagonal and r1 < r. Similarly is defined bottom-right diagonal.

Read more
[LeetCode] Remove Trailing Zeros From a String

2710. Remove Trailing Zeros From a String

Given a positive integer num represented as a string, return the integer num without trailing zeros as a string.

Read more
[Codeforces] Round 352 (Div. 1) A. Recycling BottlesRead more