All Posts

Leetcode 2555: Maximize Win From Two Segments

You are given a sorted array prizePositions containing positions of prizes along a line and an integer k. Your task is to select two segments of length k such that you can maximize the number of prizes collected. The two segments may overlap, and you can collect all prizes within either of the segments.

Leetcode 2556: Disconnect Path in a Binary Matrix by at Most One Flip

You are given a binary matrix grid where you can move from any cell (row, col) to adjacent cells (row + 1, col) or (row, col + 1) only if they have the value 1. The grid is disconnected if there is no path from the top-left corner (0, 0) to the bottom-right corner (m - 1, n - 1). You are allowed to flip at most one cell (changing a 1 to 0 or vice versa), but you cannot flip the cells (0, 0) or (m - 1, n - 1). Return true if it is possible to disconnect the grid by flipping at most one cell, otherwise return false.

Leetcode 2559: Count Vowel Strings in Ranges

Given an array of strings words and a list of queries, each query asks to count the number of strings in the specified range that start and end with a vowel. The vowels are ‘a’, ’e’, ‘i’, ‘o’, and ‘u’.

Leetcode 2560: House Robber IV

A robber is tasked with stealing money from houses lined along a street. Each house has a certain amount of money, but the robber refuses to rob adjacent houses. The robber must steal from at least ‘k’ houses. Your goal is to determine the minimum amount of money the robber will steal from any house, out of all the possible ways of selecting at least ‘k’ houses, given the constraints.

Leetcode 2563: Count the Number of Fair Pairs

Given an integer array nums of size n and two integers lower and upper, find the number of fair pairs. A pair (i, j) is considered fair if it satisfies the following conditions:

  • 0 <= i < j < n
  • lower <= nums[i] + nums[j] <= upper

Return the number of such pairs.

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.