All Posts

Leetcode 547: Number of Provinces

You are given a matrix where each element indicates if two cities are directly connected. Your task is to determine the number of provinces formed by the cities. A province is a group of directly or indirectly connected cities.

Leetcode 553: Optimal Division

Given an array of integers, you need to add parentheses in such a way that the division expression evaluates to the maximum possible value. The division must respect the adjacency of integers in the array.

Leetcode 554: Brick Wall

Given a rectangular wall made up of bricks with varying widths, your task is to determine the minimum number of bricks that a vertical line crosses. The line should be drawn such that it does not cross any brick’s edge, and you cannot place the line at the edges of the wall.

Leetcode 556: Next Greater Element III

Given a positive integer n, find the smallest integer which can be formed by rearranging the digits of n and is greater than n. If no such integer exists, return -1.

Leetcode 560: Subarray Sum Equals K

Given an array nums of integers and an integer k, find the total number of contiguous subarrays whose sum equals k.

Leetcode 565: Array Nesting

You are given an array nums, a permutation of numbers from [0, n-1], and for each index k, you need to build a set s[k] by repeatedly selecting elements based on the rule nums[k] -> nums[nums[k]] -> nums[nums[nums[k]]], stopping when a duplicate is found. Return the longest length of any such set s[k].