All Posts

Leetcode 2364: Count Number of Bad Pairs

You are given a 0-indexed integer array, nums. A pair of indices (i, j) is considered a ‘bad pair’ if i < j and j - i is not equal to nums[j] - nums[i]. Your task is to determine the total number of bad pairs in the array.

Leetcode 2365: Task Scheduler II

You are given an array of integers, tasks, representing tasks that need to be completed in order. Each element in tasks[i] represents the type of the i-th task. Additionally, a positive integer space is provided, representing the minimum number of days that must pass after completing a task before another task of the same type can be performed. Each day, you either complete the next task or take a break. Your goal is to determine the minimum number of days needed to complete all tasks.

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 2370: Longest Ideal Subsequence

You are given a string s consisting of lowercase letters and an integer k. A string t is considered ideal if it is a subsequence of s and the absolute difference in the alphabet order of every two adjacent letters in t is less than or equal to k. Your task is to return the length of the longest ideal string.

Leetcode 2374: Node With Highest Edge Score

You are given a directed graph where each node has exactly one outgoing edge, and the graph is represented by an integer array edges of size n. The value at edges[i] indicates that there is a directed edge from node i to node edges[i]. The edge score of a node i is the sum of all the node labels that have an edge pointing to i. Your task is to find the node with the highest edge score. If multiple nodes have the same edge score, return the node with the smallest index.