[LeetCode] Permutations IV

3470. Permutations IV

Given two integers, n and k, an alternating permutation is a permutation of the first n positive integers such that no two adjacent elements are both odd or both even.

Return the k-th alternating permutation sorted in lexicographical order. If there are fewer than k valid alternating permutations, return an empty list.

Read more
[LeetCode] Find Minimum Cost to Remove Array Elements

3469. Find Minimum Cost to Remove Array Elements

You are given an integer array nums. Your task is to remove all elements from the array by performing one of the following operations at each step until nums is empty:

  • Choose any two elements from the first three elements of nums and remove them. The cost of this operation is the maximum of the two elements removed.
  • If fewer than three elements remain in nums, remove all the remaining elements in a single operation. The cost of this operation is the maximum of the remaining elements.

Return the minimum cost required to remove all the elements.

Read more
[LeetCode] Find the Number of Copy Arrays

3468. Find the Number of Copy Arrays

You are given an array original of length n and a 2D array bounds of length n x 2, where bounds[i] = [ui, vi].

You need to find the number of possible arrays copy of length n such that:

  1. (copy[i] - copy[i - 1]) == (original[i] - original[i - 1]) for 1 <= i <= n - 1.
  2. ui <= copy[i] <= vi for 0 <= i <= n - 1.

Return the number of such arrays.

Read more
[LeetCode] Transform Array by Parity

3467. Transform Array by Parity

You are given an integer array nums. Transform nums by performing the following operations in the exact order specified:

  1. Replace each even number with 0.
  2. Replace each odd numbers with 1.
  3. Sort the modified array in non-decreasing order.

Return the resulting array after performing these operations.

Read more
[AtCoder] G - offenceRead more
[AtCoder] C - MST on Line++Read more
[AtCoder] D - Good PermutationRead more
[AtCoder] D - Interval CountsRead more
[AtCoder] F - Fuel Round TripRead more
[AtCoder] G - Counting Shortest PathsRead more