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.
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.
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.
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.
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].