[LeetCode] Visit Array Positions to Maximize Score

2786. Visit Array Positions to Maximize Score

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

You are initially at position 0 in the array and you can visit other positions according to the following rules:

  • If you are currently in position i, then you can move to any position j such that i < j.
  • For each position i that you visit, you get a score of nums[i].
  • If you move from a position i to a position j and the parities of nums[i] and nums[j] differ, then you lose a score of x.

Return the maximum total score you can get.

Note that initially you have nums[0] points.

Read more
[LeetCode] Sort Vowels in a String

2785. Sort Vowels in a String

Given a 0-indexed string s, permute s to get a new string t such that:

  • All consonants remain in their original places. More formally, if there is an index i with 0 <= i < s.length such that s[i] is a consonant, then t[i] = s[i].
  • The vowels must be sorted in the nondecreasing order of their ASCII values. More formally, for pairs of indices i, j with 0 <= i < j < s.length such that s[i] and s[j] are vowels, then t[i] must not have a higher ASCII value than t[j].

Return the resulting string.

The vowels are 'a', 'e', 'i', 'o', and 'u', and they can appear in lowercase or uppercase. Consonants comprise all letters that are not vowels.

Read more
[LeetCode] Check if Array is Good

2784. Check if Array is Good

You are given an integer array nums. We consider an array good if it is a permutation of an array base[n].

base[n] = [1, 2, ..., n - 1, n, n](in other words, it is an array of length n + 1 which contains 1 to n - 1exactly once, plus two occurrences of n). For example, base[1] = [1, 1] andbase[3] = [1, 2, 3, 3].

Return true if the given array is good, otherwise return false.

Note: A permutation of integers represents an arrangement of these numbers.

Read more
[Codeforces] Round 881 (Div. 3) F1. Omsk Metro (simple version)Read more
[Codeforces] Round 874 (Div. 3) F. Ira and FlamencoRead more
[Codeforces] Round 880 (Div. 1) A. k-th equalityRead more
[Codeforces] Round 871 (Div. 4) H. Don`t Blame MeRead more
[Codeforces] Round 870 (Div. 2) D. Running MilesRead more
[CS Academy] Epic Marble BattlesRead more
[CS Academy] Sugarel and SubstringsRead more