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 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 2576: Find the Maximum Number of Marked Indices

You are given a 0-indexed integer array nums. Initially, all indices are unmarked. You are allowed to perform the following operation any number of times: Pick two different unmarked indices i and j such that 2 * nums[i] <= nums[j], then mark both indices i and j. Return the maximum possible number of marked indices after performing this operation multiple times.

Leetcode 2594: Minimum Time to Repair Cars

You are given an array ranks representing the ranks of some mechanics, where ranks[i] is the rank of the i-th mechanic. A mechanic with rank r can repair n cars in r * n^2 minutes. You are also given an integer cars representing the total number of cars waiting to be repaired. Return the minimum time required to repair all the cars when all mechanics can work simultaneously.

Leetcode 2601: Prime Subtraction Operation

You are given a 0-indexed integer array nums of length n. You can perform the following operation as many times as needed: pick an index i that has not been previously selected, and choose a prime number p such that p < nums[i]. Then, subtract p from nums[i]. Your task is to determine if it is possible to make the array strictly increasing by performing the operation described.