[Codeforces] Educational Round 18 D. Paths in a Complete Binary TreeRead more
[Codeforces] Round 408 (Div. 2) C. Bank HackingRead more
[Codeforces] Educational Round 20 C. Maximal GCDRead more
[Codeforces] Educational Round 20 D. Magazine AdRead more
[Codeforces] Educational Round 21 D. Array DivisionRead more
[Codeforces] Educational Round 24 E. Card Game AgainRead more
[Codeforces] Round 416 (Div. 2) C. Vladik and Memorable TripRead more
[LeetCode] Apply Operations to Maximize Score

2818. Apply Operations to Maximize Score

You are given an array nums of n positive integers and an integer k.

Initially, you start with a score of 1. You have to maximize your score by applying the following operation at most k times:

  • Choose any non-empty subarray nums[l, ..., r] that you haven’t chosen previously.
  • Choose an element x of nums[l, ..., r] with the highest prime score. If multiple such elements exist, choose the one with the smallest index.
  • Multiply your score by x.

Here, nums[l, ..., r] denotes the subarray of nums starting at index l and ending at the index r, both ends being inclusive.

The prime score of an integer x is equal to the number of distinct prime factors of x. For example, the prime score of 300 is 3 since 300 = 2 * 2 * 3 * 5 * 5.

Return the maximum possible score after applying at most k operations.

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

Read more
[LeetCode] Minimum Absolute Difference Between Elements With Constraint

2817. Minimum Absolute Difference Between Elements With Constraint

You are given a 0-indexed integer array nums and an integer x.

Find the minimum absolute difference between two elements in the array that are at least x indices apart.

In other words, find two indices i and j such that abs(i - j) >= x and abs(nums[i] - nums[j]) is minimized.

Return an integer denoting the minimum absolute difference between two elements that are at least x indices apart.

Read more
[LeetCode] Double a Number Represented as a Linked List

2816. Double a Number Represented as a Linked List

You are given the head of a non-empty linked list representing a non-negative integer without leading zeroes.

Return the head of the linked list after doubling it.

Read more