[LeetCode] Maximum Profitable Triplets With Increasing Prices I

2907. Maximum Profitable Triplets With Increasing Prices I

Given the 0-indexed arrays prices and profits of length n. There are n items in an store where the ith item has a price of prices[i] and a profit of profits[i].

We have to pick three items with the following condition:

  • prices[i] < prices[j] < prices[k] where i < j < k.

If we pick items with indices i, j and k satisfying the above condition, the profit would be profits[i] + profits[j] + profits[k].

Return the maximum profit we can get, and -1 if it’s not possible to pick three items with the given condition.

Read more
[LeetCode] Maximum Linear Stock Score

2898. Maximum Linear Stock Score

1
>prices`, where `prices[i]` is the price of a particular stock on the `ith` day, your task is to select some of the elements of `prices

A selection indexes, where indexes``k which is a subsequence of the array [1, 2, ..., n]

  • For every 1 < j <= k, prices[indexes[j]] - prices[indexes[j - 1]] == indexes[j] - indexes[j - 1].

A subsequence is an array that can be derived from another array by deleting some or no elements without changing the order of the remaining elements.

indexes, is equal to the sum of the following array: [prices[indexes[1]], prices[indexes[2]], ..., prices[indexes[k]].

Return the maximum score that a linear selection can have.

Read more
[LeetCode] Element Appearing More Than 25% In Sorted Array

1287. Element Appearing More Than 25% In Sorted Array

Given an integer array sorted in non-decreasing order, there is exactly one integer in the array that occurs more than 25% of the time, return that integer.

Read more
[LeetCode] Count the Number of Good Partitions

10034. Count the Number of Good Partitions

You are given a 0-indexed array nums consisting of positive integers.

A partition of an array into one or more contiguous subarrays is called good if no two subarrays contain the same number.

Return the total number of good partitions of nums.

Since the answer may be large, return it modulo 109 + 7.

Read more
[LeetCode] Count Subarrays Where Max Element Appears at Least K Times

10033. Count Subarrays Where Max Element Appears at Least K Times

You are given an integer array nums and a positive integer k.

Return the number of subarrays where the maximum element of nums appears at least k times in that subarray.

A subarray is a contiguous sequence of elements within an array.

Read more
[LeetCode] Double Modular Exponentiation

10032. Double Modular Exponentiation

You are given a 0-indexed 2D array variables where variables[i] = [ai, bi, ci, mi], and an integer target.

An index i is good if the following formula holds:

  • 0 <= i < variables.length
  • ((aibi % 10)ci) % mi == target

Return an array consisting of good indices in any order.

Read more
[LeetCode] Count Tested Devices After Test Operations

10031. Count Tested Devices After Test Operations

You are given a 0-indexed integer array batteryPercentages having length n, denoting the battery percentages of n 0-indexed devices.

Your task is to test each device i in order from 0 to n - 1, by performing the following test operations:

  • If batteryPercentages[i] is greater than 0 :
    • Increment the count of tested devices.
    • Decrease the battery percentage of all devices with indices j in the range [i + 1, n - 1] by 1, ensuring their battery percentage never goes below 0, i.e, batteryPercentages[j] = max(0, batteryPercentages[j] - 1).
    • Move to the next device.
  • Otherwise, move to the next device without performing any test.

Return an integer denoting the number of devices that will be tested after performing the test operations in order.

Read more
[Codeforces] Round 154 (Div. 2) D. Table with Letters - 2Read more
[Codeforces] Round 157 (Div. 1) C. Little Elephant and LCMRead more
[Codeforces] Round 160 (Div. 1) C. Maxim and MatrixRead more