All Posts

Leetcode 2170: Minimum Operations to Make the Array Alternating

You are given a 0-indexed array nums consisting of n positive integers. The array nums is called alternating if nums[i - 2] == nums[i] and nums[i - 1] != nums[i] for all valid i. In one operation, you can choose an index i and change nums[i] into any positive integer. Your task is to return the minimum number of operations required to make the array alternating.

Leetcode 2171: Removing Minimum Number of Magic Beans

You are given an array of positive integers representing the number of magic beans in each bag. Your task is to remove some beans (possibly none) from each bag so that the number of beans in each remaining non-empty bag is equal. You need to find the minimum number of beans to remove.

Leetcode 2176: Count Equal and Divisible Pairs in an Array

You are given a 0-indexed integer array nums of length n and an integer k. You need to count the number of pairs (i, j) where 0 <= i < j < n such that nums[i] == nums[j] and the product i * j is divisible by k. Return the number of such pairs.

Leetcode 2185: Counting Words With a Given Prefix

You are given an array of strings and a target prefix. Your task is to count how many strings in the array start with this target prefix.

Leetcode 2187: Minimum Time to Complete Trips

You are given an array ’time’ where each element ’time[i]’ represents the time taken by the ith bus to complete a trip. Your task is to calculate the minimum amount of time required for all buses to complete at least ’totalTrips’ trips in total. Each bus can complete multiple trips consecutively.

Leetcode 2190: Most Frequent Number Following Key In an Array

You are given an integer array ’nums’ and an integer ‘key’, which is present in ’nums’. Your task is to find the integer that most frequently appears immediately after an occurrence of ‘key’ in the array. In other words, count how many times each integer follows ‘key’ and return the integer that appears the most.