All Posts

Leetcode 1888: Minimum Number of Flips to Make the Binary String Alternating

You are given a binary string s consisting of ‘0’s and ‘1’s. You can perform two operations on the string:

  1. Type-1: Move the first character of the string to the end.
  2. Type-2: Flip the value of any character in the string (‘0’ becomes ‘1’ and ‘1’ becomes ‘0’). The goal is to make the string alternating, i.e., no two adjacent characters should be the same. You need to find the minimum number of type-2 operations required to make the string alternating.

Leetcode 1984: Minimum Difference Between Highest and Lowest of K Scores

You are given a 0-indexed array nums where each element represents the score of a student. You need to select the scores of exactly k students such that the difference between the highest and the lowest score of the selected students is minimized. Your task is to return the minimum possible difference.

Leetcode 2024: Maximize the Confusion of an Exam

You are given a string answerKey where each character represents a question’s answer (either ‘T’ for True or ‘F’ for False), and an integer k. You are allowed to change at most k answers. Your task is to find the maximum number of consecutive ‘T’s or ‘F’s in the string after performing at most k changes.

Leetcode 2090: K Radius Subarray Averages

Given an array of integers, you need to compute the k-radius average for each element in the array. The k-radius average for an element at index i is the average of the elements from index i - k to i + k (inclusive). If there are fewer than k elements before or after the index i, the result for that index will be -1.

Leetcode 2134: Minimum Swaps to Group All 1's Together II

You are given a binary circular array, where each element is either 0 or 1. The goal is to group all the 1’s together in the array using the minimum number of swaps. A swap consists of exchanging the values at two distinct positions in the array. The array is circular, meaning the first and last elements are adjacent. Your task is to find the minimum number of swaps required to group all the 1’s together.

Leetcode 2260: Minimum Consecutive Cards to Pick Up

You are given an array cards where each element represents a card’s value. A matching pair of cards occurs when two cards have the same value. Your task is to find the minimum number of consecutive cards you need to pick to guarantee that you have a pair of matching cards. If it’s impossible to find a matching pair, return -1.