All Posts

Leetcode 1700: Number of Students Unable to Eat Lunch

In a school cafeteria, sandwiches are placed in a stack and students queue up to get one. Each student has a preference for the type of sandwich, and they either take the sandwich from the stack or move to the back of the queue if the sandwich is not to their liking. The goal is to determine how many students are unable to get a sandwich.

Leetcode 1717: Maximum Score From Removing Substrings

You are given a string s and two integers x and y. You can perform two types of operations any number of times:

  1. Remove the substring “ab” and gain x points.
  2. Remove the substring “ba” and gain y points.

Each time a substring is removed, the characters are deleted from the string, and the corresponding points are added to your total score. Your task is to maximize the total score after applying these operations any number of times.

Leetcode 1910: Remove All Occurrences of a Substring

Given two strings s and part, perform the following operation on s until all occurrences of the substring part are removed. Find the leftmost occurrence of the substring part and remove it from s. Return s after removing all occurrences of part.

Leetcode 1963: Minimum Number of Swaps to Make the String Balanced

You are given a string s of even length n. The string contains exactly n/2 opening brackets [ and n/2 closing brackets ]. A string is called balanced if for every opening bracket there exists a corresponding closing bracket, with each closing bracket having a matching opening bracket before it. Your task is to return the minimum number of swaps needed to make the string balanced.

Leetcode 1996: The Number of Weak Characters in the Game

You are given a list of characters’ properties, where each character has two main attributes: attack and defense. A character is weak if another character exists with both greater attack and defense values. Return the number of weak characters in the list.

Leetcode 2000: Reverse Prefix of Word

You are given a string ‘word’ and a character ‘ch’. Reverse the portion of the string starting at index 0 and ending at the index of the first occurrence of ‘ch’. If ‘ch’ is not found, return the original string.