Tap here to switch tabs
Problem
Submissions

Problem: Maximum Score After Binary Swaps

Try to solve the Maximum Score After Binary Swaps problem.

Statement

You are given an integer array nums of length n and a binary string s of the same length.

In one operation, you can select an index i such that 0≤i<n−10 \le i < n - 1, s[i] is $'0'$, and s[i + 1] is $'1'$, and swap s[i] with s[i + 1].

You may apply this operation any number of times.

The total score is the sum of nums[i] for all indices i where s[i] is equal to $'1'$.

Return the maximum score achievable.

Constraints:

  • n == nums.length == s.length

  • 1≤1 \le n ≤105\le 10^5

  • 1≤1 \le nums[i] ≤109\le 10^9

  • s[i] is either $'0'$ or $'1'$

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Maximum Score After Binary Swaps

Try to solve the Maximum Score After Binary Swaps problem.

Statement

You are given an integer array nums of length n and a binary string s of the same length.

In one operation, you can select an index i such that 0≤i<n−10 \le i < n - 1, s[i] is $'0'$, and s[i + 1] is $'1'$, and swap s[i] with s[i + 1].

You may apply this operation any number of times.

The total score is the sum of nums[i] for all indices i where s[i] is equal to $'1'$.

Return the maximum score achievable.

Constraints:

  • n == nums.length == s.length

  • 1≤1 \le n ≤105\le 10^5

  • 1≤1 \le nums[i] ≤109\le 10^9

  • s[i] is either $'0'$ or $'1'$