All Posts

Leetcode 1824: Minimum Sideway Jumps

A frog is traveling on a 3-lane road, starting at point 0 on lane 2. The frog wants to reach point n, but there may be obstacles at various points on the road. The frog can either move forward on the same lane or jump to another lane if the current lane is blocked. The goal is to find the minimum number of side jumps the frog needs to take to reach point n while avoiding obstacles.

Leetcode 1871: Jump Game VII

You are given a binary string s and two integers minJump and maxJump. Initially, you are at index 0 of the string s, which is guaranteed to be ‘0’. You can move from index i to index j if: i + minJump <= j <= min(i + maxJump, s.length - 1), and s[j] == ‘0’. Return true if it’s possible to reach the last index of the string (s.length - 1), or false otherwise.

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 1911: Maximum Alternating Subsequence Sum

You are given an array nums. The alternating sum of a sequence is calculated as the sum of elements at even indices minus the sum of elements at odd indices. Your task is to find the maximum alternating sum of any subsequence formed by deleting some elements from the array without changing the relative order of the remaining elements.

Leetcode 1937: Maximum Number of Points with Cost

You are given a matrix of integers points with dimensions m x n (0-indexed). Initially, you are at score 0, and your goal is to maximize the score by selecting one cell in each row. To gain points, you can select a cell (r, c) from each row. The value at points[r][c] will add to your score. However, if you choose cells from different columns in adjacent rows, the difference between their column indices will subtract from your score. Specifically, if you select a cell at (r, c1) in row r and a cell at (r + 1, c2) in row r + 1, the penalty is abs(c1 - c2). Your task is to return the maximum score you can achieve by choosing cells from each row.

Leetcode 1947: Maximum Compatibility Score Sum

You are given a survey with n questions where each question’s answer is either 0 (no) or 1 (yes). The survey is completed by m students and m mentors. Each student’s answers are represented by a 2D array of size m x n, and similarly, each mentor’s answers are represented by another 2D array. The compatibility score of a student-mentor pair is calculated as the number of answers that are the same for both the student and the mentor. Your task is to find the optimal pairing of students to mentors that maximizes the sum of the compatibility scores.