0% found this document useful (0 votes)
5 views3 pages

Moks

The document describes three different problems from LeetCode. The first problem involves transforming a string into a 'good' string by removing adjacent characters that are the same letter in different cases. The second problem focuses on maximizing the score from a solitaire game with three piles of stones, and the third problem counts the number of substrings composed entirely of '1's in a binary string.

Uploaded by

andriykhr03
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views3 pages

Moks

The document describes three different problems from LeetCode. The first problem involves transforming a string into a 'good' string by removing adjacent characters that are the same letter in different cases. The second problem focuses on maximizing the score from a solitaire game with three piles of stones, and the third problem counts the number of substrings composed entirely of '1's in a binary string.

Uploaded by

andriykhr03
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
You are on page 1/ 3

https://leetcode.

com/problems/make-the-string-great/
Given a string s of lower and upper case English letters.

A good string is a string which doesn't have two adjacent characters s[i] and s[i + 1]
where:
• 0 <= i <= s.length - 2
• s[i] is a lower-case letter and s[i + 1] is the same letter but in upper-case or vice-
versa.
To make the string good, you can choose two adjacent characters that make the string bad and
remove them. You can keep doing this until the string becomes good.
Return the string after making it good. The answer is guaranteed to be unique under the given
constraints.
Notice that an empty string is also good.

Input: s = "leEeetcode"
Output: "leetcode"
Explanation: In the first step, either you choose i = 1 or i = 2, both will
result "leEeetcode" to be reduced to "leetcode".

Example 2:
Input: s = "abBAcC"
Output: ""
Explanation: We have many possible scenarios, and all lead to the same answer.
For example:
"abBAcC" --> "aAcC" --> "cC" --> ""
"abBAcC" --> "abBA" --> "aA" --> ""

Example 3:
Input: s = "s"
Output: "s"

You are playing a solitaire game with three piles of stones of sizes a, b, and c respectively. Each
turn you choose two different non-empty piles, take one stone from each, and add 1 point to your
score. The game stops when there are fewer than two non-empty piles (meaning there are no more
available moves).
Given three integers a, b, and c, return the maximum score you can get.
https://leetcode.com/problems/maximum-score-from-removing-stones/description/
Example 1:
Input: a = 2, b = 4, c = 6
Output: 6
Explanation: The starting state is (2, 4, 6). One optimal set of moves is:
- Take from 1st and 3rd piles, state is now (1, 4, 5)
- Take from 1st and 3rd piles, state is now (0, 4, 4)
- Take from 2nd and 3rd piles, state is now (0, 3, 3)
- Take from 2nd and 3rd piles, state is now (0, 2, 2)
- Take from 2nd and 3rd piles, state is now (0, 1, 1)
- Take from 2nd and 3rd piles, state is now (0, 0, 0)
There are fewer than two non-empty piles, so the game ends. Total: 6 points.

Example 2:
Input: a = 4, b = 4, c = 6
Output: 7
Explanation: The starting state is (4, 4, 6). One optimal set of moves is:
- Take from 1st and 2nd piles, state is now (3, 3, 6)
- Take from 1st and 3rd piles, state is now (2, 3, 5)
- Take from 1st and 3rd piles, state is now (1, 3, 4)
- Take from 1st and 3rd piles, state is now (0, 3, 3)
- Take from 2nd and 3rd piles, state is now (0, 2, 2)
- Take from 2nd and 3rd piles, state is now (0, 1, 1)
- Take from 2nd and 3rd piles, state is now (0, 0, 0)
There are fewer than two non-empty piles, so the game ends. Total: 7 points.

Example 3:
Input: a = 1, b = 8, c = 8
Output: 8
Explanation: One optimal set of moves is to take from the 2nd and 3rd piles for
8 turns until they are empty.
After that, there are fewer than two non-empty piles, so the game ends.

Constraints:

• 1 <= a, b, c <= 105


Given a binary string s, return the number of substrings with all characters 1's. Since the answer
may be too large, return it modulo 109 + 7.

011
011
01 11

Example 1:
Input: s = "0110111"
Output: 9
Explanation: There are 9 substring in total with only 1's characters.
"1" -> 5 times.
"11" -> 3 times.
"111" -> 1 time.

Example 2:
Input: s = "101"
Output: 2
Explanation: Substring "1" is shown 2 times in s.

Example 3:
Input: s = "111111"
Output: 21
Explanation: Each substring contains only 1's characters.

Constraints:

• 1 <= s.length <= 105


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

You might also like