[LeetCode] Prime In Diagonal

2614. Prime In Diagonal

You are given a 0-indexed two-dimensional integer array nums.

Return the largest prime number that lies on at least one of the diagonals of nums. In case, no prime is present on any of the diagonals, return 0.

Note that:

  • An integer is prime if it is greater than 1 and has no positive integer divisors other than 1 and itself.
  • An integer val is on one of thediagonals of nums if there exists an integer i for which nums[i][i] = val or an i for which nums[i][nums.length - i - 1]= val.

img

In the above diagram, one diagonal is [1,5,9] and another diagonal is [3,5,7].

Read more
[LeetCode] Sum of Distances

2615. Sum of Distances

You are given a 0-indexed integer array nums. There exists an array arr of length nums.length, where arr[i] is the sum of |i - j| over all j such that nums[j] == nums[i] and j != i. If there is no such j, set arr[i] to be 0.

Return the array arr.

Read more
[LeetCode] Minimize the Maximum Difference of Pairs

2616. Minimize the Maximum Difference of Pairs

You are given a 0-indexed integer array nums and an integer p. Find p pairs of indices of nums such that the maximum difference amongst all the pairs is minimized. Also, ensure no index appears more than once amongst the p pairs.

Note that for a pair of elements at the index i and j, the difference of this pair is |nums[i] - nums[j]|, where |x| represents the absolute value of x.

Return the minimum maximum difference among all p pairs.

Read more
[LeetCode] Minimum Number of Visited Cells in a Grid

2617. Minimum Number of Visited Cells in a Grid

You are given a 0-indexed m x n integer matrix grid. Your initial position is at the top-left cell (0, 0).

Starting from the cell (i, j), you can move to one of the following cells:

  • Cells (i, k) with j < k <= grid[i][j] + j (rightward movement), or
  • Cells (k, j) with i < k <= grid[i][j] + i (downward movement).

Return the minimum number of cells you need to visit to reach the bottom-right cell (m - 1, n - 1). If there is no valid path, return -1.

Read more
[Codeforces] Round 789 (Div. 2) B2. Tokitsukaze and Good 01-String (hard version)Read more
[Codeforces] CodeCraft-22 and Codeforces Round 795 (Div. 2) D. Max GEQ SumRead more
[Codeforces] Round 807 (Div. 2) D. Mark and LightbulbsRead more
[Codeforces] Educational Round 132 (Rated for Div. 2) C. Recover an RBSRead more
[Codeforces] Round 812 (Div. 2) D. Tournament CountdownRead more
[Hacker Rank] Larry`s ArrayRead more