All Posts

Leetcode 1116: Print Zero Even Odd

You are given an instance of the class ZeroEvenOdd, which contains three functions: zero, even, and odd. The same instance of ZeroEvenOdd is passed to three different threads. Thread A calls zero() to print zeros, thread B calls even() to print even numbers, and thread C calls odd() to print odd numbers. The goal is to output a sequence of numbers in the order: 0, 1, 2, 3, …, 2n, where n is the given number, and the length of the sequence is 2n. The threads should execute asynchronously, ensuring that the sequence is printed correctly.

Leetcode 1123: Lowest Common Ancestor of Deepest Leaves

Given the root of a binary tree, your task is to return the lowest common ancestor (LCA) of its deepest leaf nodes. The LCA of a set of nodes is the deepest node that is an ancestor of all the nodes in the set. A leaf node is one that does not have any children.

Leetcode 1124: Longest Well-Performing Interval

You are given a list of integers representing the number of hours worked each day. A day is considered tiring if the number of hours worked is strictly greater than 8. A well-performing interval is an interval of days where the number of tiring days is strictly larger than the number of non-tiring days. Your task is to return the length of the longest well-performing interval.

Leetcode 1129: Shortest Path with Alternating Colors

You are given a directed graph with n nodes, where each node is labeled from 0 to n-1. The graph contains edges that can be either red or blue. You are provided with two lists of edges: redEdges and blueEdges, where redEdges[i] = [ai, bi] indicates a directed red edge from node ai to node bi, and blueEdges[j] = [uj, vj] indicates a directed blue edge from node uj to node vj. Your goal is to find the shortest alternating path from node 0 to each node x. Return an array answer where each answer[x] is the length of the shortest alternating path from node 0 to node x, or -1 if no such path exists.

Leetcode 1130: Minimum Cost Tree From Leaf Values

You are given an array arr of positive integers. Consider all binary trees such that each node has either 0 or 2 children, the values of arr correspond to the values of each leaf in an in-order traversal of the tree, and the value of each non-leaf node is equal to the product of the largest leaf values in its left and right subtrees. Return the smallest possible sum of the values of the non-leaf nodes among all possible binary trees.

Leetcode 1131: Maximum of Absolute Value Expression

You are given two arrays arr1 and arr2 of integers, both having equal lengths. Calculate the maximum value of the expression: |arr1[i] - arr1[j]| + |arr2[i] - arr2[j]| + |i - j| for all pairs of indices i and j, where 0 <= i, j < arr1.length.