All Posts

Leetcode 1773: Count Items Matching a Rule

You are given an array items, where each items[i] represents the type, color, and name of the ith item. You are also given a rule consisting of two strings: ruleKey and ruleValue. The task is to count how many items match the rule. An item matches the rule if one of the following conditions is true:

  • ruleKey == 'type' and ruleValue matches the type of the item.
  • ruleKey == 'color' and ruleValue matches the color of the item.
  • ruleKey == 'name' and ruleValue matches the name of the item.

Leetcode 1774: Closest Dessert Cost

You are planning to make a custom dessert by choosing an ice cream base and toppings. The dessert must follow these rules: You must select one ice cream base. You can add one or more types of toppings, or choose to skip toppings. You can add at most two of each topping type. You are given an array representing the base costs and topping costs. The goal is to create a dessert where the total cost is as close as possible to the target price. If there are multiple dessert combinations that meet the target price, return the lower cost.

Leetcode 1775: Equal Sum Arrays With Minimum Number of Operations

You are given two arrays, nums1 and nums2, with integers between 1 and 6. The lengths of the two arrays can differ. In one operation, you can change any element in either array to any value between 1 and 6. The task is to find the minimum number of operations required to make the sums of the two arrays equal. If it is not possible to make the sums equal, return -1.

Leetcode 1785: Minimum Elements to Add to Form a Given Sum

You are given an integer array nums and two integers limit and goal. The elements of the array nums have a property such that abs(nums[i]) <= limit. Your task is to determine the minimum number of elements you need to add to the array in order to make the sum equal to goal. The added elements must also satisfy the condition that their absolute value is less than or equal to limit.

Leetcode 1792: Maximum Average Pass Ratio

A school has several classes, and each class will have students taking a final exam. You are provided with a 2D array where each class is represented by two values: the number of students who will pass and the total number of students in the class. Additionally, a number of brilliant students, ’extraStudents,’ is provided. These brilliant students are guaranteed to pass if assigned to any class. The goal is to assign these extra students to maximize the average pass ratio of all classes. The pass ratio of a class is defined as the number of students passing divided by the total number of students in the class. You need to return the maximum possible average pass ratio after optimally distributing the extra students.

Leetcode 1798: Maximum Number of Consecutive Values You Can Make

You are given an integer array ‘coins’, where each element represents the value of a coin you own. You can use these coins to create sums of values starting from 0. Your task is to find the maximum number of consecutive integer values starting from 0 that you can make with your coins.