[CS Academy] Virus on a TreeRead more
[LeetCode] Count of Integers

2719. Count of Integers

You are given two numeric strings num1 and num2 and two integers max_sum and min_sum. We denote an integer x to be good if:

  • num1 <= x <= num2
  • min_sum <= digit_sum(x) <= max_sum.

Return the number of good integers. Since the answer may be large, return it modulo 109 + 7.

Note that digit_sum(x) denotes the sum of the digits of x.

Read more
[LeetCode] Sum of Matrix After Queries

2718. Sum of Matrix After Queries

You are given an integer n and a 0-indexed 2D array queries where queries[i] = [typei, indexi, vali].

Initially, there is a 0-indexed n x n matrix filled with 0‘s. For each query, you must apply one of the following changes:

  • if typei == 0, set the values in the row with indexi to vali, overwriting any previous values.
  • if typei == 1, set the values in the column with indexi to vali, overwriting any previous values.

Return the sum of integers in the matrix after all queries are applied.

Read more
[LeetCode] Semi-Ordered Permutation

2717. Semi-Ordered Permutation

You are given a 0-indexed permutation of n integers nums.

A permutation is called semi-ordered if the first number equals 1 and the last number equals n. You can perform the below operation as many times as you want until you make nums a semi-ordered permutation:

  • Pick two adjacent elements in nums, then swap them.

Return the minimum number of operations to make nums a semi-ordered permutation.

A permutation is a sequence of integers from 1 to n of length n containing each number exactly once.

Read more
[LeetCode] Minimize String Length

2716. Minimize String Length

Given a 0-indexed string s, repeatedly perform the following operation any number of times:

  • Choose an index i in the string, and let c be the character in position i. Delete the closest occurrence of c to the left of i (if any) and the closest occurrence of c to the right of i (if any).

Your task is to minimize the length of s by performing the above operation any number of times.

Return an integer denoting the length of the minimized string.

Read more
[Codeforces] Round 269 (Div. 2) D. MUH and Cube WallsRead more
[Codeforces] Round 273 (Div. 2) C. Table DecorationsRead more
[Codeforces] Round 275 (Div. 1) B. Interesting ArrayRead more
[Codeforces] Round 275 (Div. 2) B. Friends and PresentsRead more
[Codeforces] Round 278 (Div. 1) A. Fight the MonsterRead more