All Posts

Leetcode 1262: Greatest Sum Divisible by Three

Given an array of integers, find the maximum sum of any subsequence where the sum is divisible by 3.

Leetcode 1277: Count Square Submatrices with All Ones

Given a m x n matrix of ones and zeros, count how many square submatrices are filled with all ones.

Leetcode 1334: Find the City With the Smallest Number of Neighbors at a Threshold Distance

Given a set of cities connected by weighted edges, find the city with the least number of reachable cities under a distance threshold. If multiple cities have the same number of reachable cities, return the one with the greatest index.

Leetcode 1372: Longest ZigZag Path in a Binary Tree

Given the root of a binary tree, find the length of the longest ZigZag path in the tree. A ZigZag path is one where you move left and right alternately, starting from any node.

Leetcode 1387: Sort Integers by The Power Value

The task is to find the kth integer in the range [lo, hi] sorted by the number of steps required to reach 1 using the Collatz conjecture rules. The power of a number is the number of steps needed to reach 1, following the rules: if the number is even, divide it by 2, and if it’s odd, multiply it by 3 and add 1.

Leetcode 1395: Count Number of Teams

You are given a list of soldiers, each with a unique rating. You need to form teams of 3 soldiers from this list. A valid team is one where the soldiers’ ratings are either strictly increasing or strictly decreasing as we move from left to right in the team. The team must satisfy the condition that the indices (i, j, k) follow 0 <= i < j < k < n.