AshnuB's blog

By AshnuB, 4 months ago, In English

Q1) You are given four integer arrays task1, task2, task3, and task4, each of length n.

task1[i], task2[i], task3[i], task4[i] represent the points gained if you choose task type 1, 2, 3, or 4 respectively at index i.

Each index i represents a task bundle.

From each index i, you must choose exactly one task type:

task1, task2, task3, or task4

Each index is used exactly once (no skipping).

Your selection must satisfy the following global constraints:

At least k tasks are chosen from task1 At most k tasks are chosen from task2 The number of tasks chosen from task3 is not equal to k Exactly k tasks are chosen from task4 Maximize the total points, defined as the sum of the selected task values across all indices.

Example 1:

Input:

task1 = [5, 4, 6, 3, 7, 2], task2 = [2, 3, 1, 4, 2, 1], task3 = [4, 2, 5, 1, 3, 4], task4 = [3, 4, 2, 5, 1, 2] , k = 2

Output: 31

Explaination:

One valid assignment is:

Choose task1 at indices 0, 2, 4 Choose task3 at index 5 Choose task4 at indices 1, 3 Counts:

task1 = 3 >= 2 task2 = 0 <= 2 task3 = 1 != 2 task4 = 2 == 2 Total points = 5 + 6 + 7 + 4 + 4 + 5 = 31

Example 2:

Input:

task1 = [1, 1, 1, 1, 1, 1], task2 = [2, 2, 2, 2, 2, 2], task3 = [0, 0, 0, 0, 0, 0], task4 = [1, 1, 1, 1, 1, 1], k = 2

Output: 8

Explanation:

One valid assignment is:

task1 at indices 4, 5 task2 at indices 0, 1 task4 at indices 2, 3 Counts:

task1 = 2 >= 2 task2 = 2 <= 2 task3 = 0 != 2 task4 = 2 == 2 Total Points = 1 + 1 + 2 + 2 + 1 + 1 = 8

Constraints:

1 <= task1.length == task2.length == task3.length == task4.length <= 10^5 1 <= task1[i] , task2[i] , task3[i] , task4[i] <= 10^9 0 <= k <= n

Q2)You are given a string s, Return the number of super substrings.

Substring is said to be super if number of 'A' is strictly greater than number of 'B' is strictly greater than number if 'C' ('A'>'B'>'C') or number of 'A' is strictly lesser than number of 'B'is strictly lesser than number of 'C' ('A'<'B'<'C')

Example 1:

Input: s = "AAAABBC"

Output: 7

Explaination:

Valid Super Substrings follows count('A') > count('B') > count('C'):

s[0..4] => 'A' = 4, 'B' = 1, 'C' = 0 s[0..5] => 'A' = 4, 'B' = 2, 'C' = 0 s[0..6] => 'A' = 4, 'B' = 2, 'C' = 1 s[1..4] => 'A' = 3, 'B' = 1, 'C' = 0 s[1..5] => 'A' = 3, 'B' = 2, 'C' = 0 s[1..6] => 'A' = 3, 'B' = 2, 'C' = 1 s[2..4] => 'A' = 2, 'B' = 1, 'C' = 0

Example 2:

Input: s = "ACBACBA"

Output: 0

Explaination:

Since there is no substrings follows the condition return 0

Example 3:

Input: s = "CCCCBBA"

Output: 7

Explaination:

Valid Super Substrings follows count('A') < count('B') < count('C'):

s[0..4] => 'A' = 0, 'B' = 1, 'C' = 4 s[0..5] => 'A' = 0, 'B' = 2, 'C' = 4 s[0..6] => 'A' = 1, 'B' = 2, 'C' = 4 s[1..4] => 'A' = 0, 'B' = 1, 'C' = 3 s[1..5] => 'A' = 0, 'B' = 2, 'C' = 3 s[1..6] => 'A' = 1, 'B' = 2, 'C' = 3 s[2..4] => 'A' = 0, 'B' = 1, 'C' = 2

Example 4:

Input: s = "AAAABBCCCCBBA"

Output: 27

Explaination:

There are 27 Possible Super Substrings and follows both count('A') < count('B') < count('C') andcount('A') > count('B') > count('C').

Constraints:

1 <= s.length <= 8 * 10^4 s consists only of characters 'A' ,'B' and 'C'.

  • Vote: I like it
  • +1
  • Vote: I do not like it