All Posts

Leetcode 2605: Form Smallest Number From Two Digit Arrays

You are given two arrays nums1 and nums2, both containing unique digits. Your task is to find the smallest possible number that contains at least one digit from both arrays. If there are common digits between the two arrays, the smallest common digit will be the answer. If no common digit exists, return the smallest number formed by taking the smallest digit from each array.

Leetcode 2606: Find the Substring With Maximum Cost

You are given a string s, a string chars of distinct characters, and an integer array vals of the same length as chars. The value of each character is determined by either its position in the alphabet or a corresponding value in the vals array if it is present in chars. The cost of a substring is the sum of the values of each character in that substring. Your goal is to find the maximum cost of any substring of s.

Leetcode 2607: Make K-Subarray Sums Equal

You are given a circular integer array arr and an integer k. In this circular array, the first element follows after the last one, and the last element precedes the first one. Your task is to determine the minimum number of operations required to make the sum of every subarray of length k equal. In each operation, you can pick any element in the array and either increase or decrease it by 1.

Leetcode 2610: Convert an Array Into a 2D Array With Conditions

Given an integer array, your task is to create a 2D array from the input array satisfying the following conditions:

  1. The 2D array should contain all the elements of the input array.
  2. Each row of the 2D array should contain distinct integers.
  3. The number of rows in the 2D array should be minimal. Return the resulting array. If there are multiple valid answers, return any of them.

Leetcode 2611: Mice and Cheese

You have two mice and a set of n different types of cheese. Each type of cheese has a different point value when eaten by either mouse. The first mouse must eat exactly k types of cheese, while the second mouse eats the remaining cheese types. Your task is to maximize the total points the two mice can achieve by distributing the cheese types between the mice.

Leetcode 2614: Prime In Diagonal

Given a 2D grid of integers, you need to determine the largest prime number present on any of the diagonals of the grid. A number is considered prime if it is greater than 1 and divisible only by 1 and itself. The diagonal elements are those where the row and column indices are the same or sum to the length of the grid minus 1.