All Posts

Leetcode 2385: Amount of Time for Binary Tree to Be Infected

You are given the root of a binary tree where each node has a unique value, and an integer start representing the initial infected node. At minute 0, the infection begins at the node with value start. Each minute, an adjacent uninfected node becomes infected. Your task is to return the total number of minutes it takes for the entire tree to become infected.

Leetcode 2395: Find Subarrays With Equal Sum

You are given a 0-indexed integer array nums. Your task is to determine if there are two subarrays of length 2 that have the same sum, but these subarrays must begin at different indices in the array. A subarray is defined as a contiguous sequence of elements within the array.

Leetcode 2399: Check Distances Between Same Letters

You are given a string s consisting of lowercase English letters where each letter appears exactly twice. You are also given an array distance of length 26, where each element represents the number of characters between the two occurrences of the corresponding letter (0-indexed, ‘a’ corresponds to index 0, ‘b’ to index 1, etc.). Your task is to determine if the string s is a ‘well-spaced’ string. A string is well-spaced if, for each letter in s, the number of characters between its two occurrences matches the corresponding value in the distance array.

Leetcode 2404: Most Frequent Even Element

You are given an integer array nums. Your task is to return the most frequent even element in the array. If there is a tie (i.e., multiple even elements appear the most number of times), return the smallest one. If there is no even element, return -1.

Leetcode 2405: Optimal Partition of String

You are given a string s. Your task is to partition this string into the fewest number of substrings such that no character appears more than once in each substring. Each character must belong to exactly one substring in the partition.

Leetcode 2418: Sort the People

Given two arrays, one containing the names and the other containing the corresponding heights of people, return the names sorted in descending order by their heights.