All Posts

Leetcode 1529: Minimum Suffix Flips

You are given a binary string target and another string s initialized to all zeros. In one operation, you can flip all bits in the inclusive range starting from index i to n-1. The task is to determine the minimum number of operations needed to make s equal to target.

Leetcode 1536: Minimum Swaps to Arrange a Binary Grid

You are given an n x n binary grid, and in one move, you can swap any two adjacent rows. The grid is valid if all the cells above the main diagonal are zeros. Your task is to return the minimum number of swaps needed to make the grid valid, or -1 if it’s not possible.

Leetcode 1541: Minimum Insertions to Balance a Parentheses String

You are given a string s containing only the characters '(' and ')'. A string is considered balanced if each '(' has a matching pair of consecutive '))' and if they appear in the correct order. Your task is to return the minimum number of insertions needed to make the string balanced.

Leetcode 1546: Maximum Number of Non-Overlapping Subarrays With Sum Equals Target

Given an integer array nums and an integer target, return the maximum number of non-empty, non-overlapping subarrays that sum up to the target.

Leetcode 1561: Maximum Number of Coins You Can Get

You and two friends are given 3n piles of coins, and in each step, three piles are chosen. Alice always picks the pile with the most coins, you pick the second largest pile, and your friend Bob picks the remaining pile. Repeat this process until all piles are picked. Your goal is to maximize the total number of coins you can collect.

Leetcode 1567: Maximum Length of Subarray With Positive Product

Given an array of integers, your task is to find the maximum length of a contiguous subarray where the product of all its elements is positive. The product of a subarray is considered positive if the result of multiplying all elements of the subarray results in a positive number.