All Posts

Leetcode 2531: Make Number of Distinct Characters Equal

You are given two strings, word1 and word2. In each move, you swap one character from word1 with one from word2. Determine if it is possible to make the number of distinct characters in both strings equal with exactly one swap.

Leetcode 2537: Count the Number of Good Subarrays

Given an integer array nums and an integer k, return the number of “good” subarrays. A subarray is good if it contains at least k pairs of indices (i, j) such that i < j and nums[i] == nums[j]. A subarray is a contiguous non-empty sequence of elements within the array.

Leetcode 2540: Minimum Common Value

Given two integer arrays nums1 and nums2 sorted in non-decreasing order, return the smallest integer that is common to both arrays. If no such integer exists, return -1.

Leetcode 2549: Count Distinct Numbers on Board

You are given a positive integer n, initially placed on a board. For each number x on the board, find all integers i such that 1 <= i <= n and x % i == 1. Add these numbers to the board. Your goal is to determine how many distinct integers will be present on the board after a billion days.

Leetcode 2554: Maximum Number of Integers to Choose From a Range I

You are given an array banned consisting of integers, an integer n, and an integer maxSum. Your task is to return the maximum number of integers you can select from the range [1, n] such that none of them are in the banned list and their sum does not exceed maxSum.

Leetcode 2564: Substring XOR Queries

You are given a binary string s and a 2D array of queries. Each query is represented as [firsti, secondi], where firsti and secondi are integers. For each query, you need to find the shortest substring of s whose decimal value XORed with firsti equals secondi.

In other words, find a substring whose decimal value, when XORed with firsti, results in secondi. If such a substring exists, return its starting and ending indices (0-indexed). If no such substring exists, return [-1, -1].

If there are multiple valid substrings, return the one with the smallest starting index.