All Posts

Leetcode 2367: Number of Arithmetic Triplets

You are given a strictly increasing array of integers, nums, and a positive integer diff. A triplet (i, j, k) is an arithmetic triplet if the following conditions hold: i < j < k, nums[j] - nums[i] == diff, and nums[k] - nums[j] == diff. Your task is to return the number of unique arithmetic triplets that can be formed from the given array.

Leetcode 2368: Reachable Nodes With Restrictions

You are given a tree with n nodes and n - 1 edges, where nodes are labeled from 0 to n - 1. Additionally, a list of restricted nodes is provided. Your goal is to determine the maximum number of nodes that can be visited starting from node 0, without passing through any restricted node. Node 0 itself is not restricted.

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 2373: Largest Local Values in a Matrix

You are given a square matrix grid of size n x n. Your task is to generate a new matrix maxLocal of size (n - 2) x (n - 2) where each element maxLocal[i][j] represents the largest value from a 3 x 3 submatrix in grid centered at (i + 1, j + 1). In other words, for each element of the new matrix, find the maximum value from its surrounding 3 x 3 region in the original grid.

Leetcode 2381: Shifting Letters II

You are given a string s consisting of lowercase English letters and a 2D array shifts. Each entry in the array represents a shift operation, where a segment of the string from starti to endi (inclusive) is shifted forward if directioni is 1, or backward if directioni is 0. A forward shift means replacing a character with the next letter in the alphabet (wrapping around from ‘z’ to ‘a’), and a backward shift means replacing a character with the previous letter (wrapping around from ‘a’ to ‘z’). You need to return the final string after all shifts are applied.

Leetcode 2383: Minimum Hours of Training to Win a Competition

You are preparing for a competition where you will face a series of opponents. Each opponent has a specified energy and experience. To defeat an opponent, your energy and experience must both exceed theirs. Before entering the competition, you are allowed to train to improve your energy or experience. For every hour of training, you can either increase your energy or your experience by one. You need to determine the minimum number of training hours required to defeat all the opponents in order.