[AtCoder] C - Write and EraseRead more
[AtCoder] D - Restoring Road NetworkRead more
[AtCoder] C - Sugar WaterRead more
[Codeforces] COMPFEST 13 - Finals Online Mirror (Unrated, ICPC Rules, Teams Preferred) J. Jeopardy of Dropped BallsRead more
[Codeforces] Round #744 (Div. 3) C. TicksRead more
[Codeforces] Round #756 (Div. 3) D. Weights Assignment For Tree EdgesRead more
[Codeforces] Round #757 (Div. 2) C. Divan and bitwise operationsRead more
[Codeforces] Good Bye 2021: 2022 is NEAR C. Representative EdgesRead more
[LeetCode] Sum Game

1927. Sum Game

Alice and Bob take turns playing a game, with Alice starting first.

You are given a string num of even length consisting of digits and ‘?’ characters. On each turn, a player will do the following if there is still at least one ‘?’ in num:

  1. Choose an index i where num[i] == ‘?’.
  2. Replace num[i] with any digit between ‘0’ and ‘9’.

The game ends when there are no more ‘?’ characters in num.

For Bob to win, the sum of the digits in the first half of num must be equal to the sum of the digits in the second half. For Alice to win, the sums must not be equal.

  • For example, if the game ended with num = “243801”, then Bob wins because 2+4+3 = 8+0+1. If the game ended with num = “243803”, then Alice wins because 2+4+3 != 8+0+3.

Assuming Alice and Bob play optimally, return true if Alice will win and false if Bob will win.

Read more
[LeetCode] Unique Length-3 Palindromic Subsequences

1930. Unique Length-3 Palindromic Subsequences

Given a string s, return the number of unique palindromes of length three that are a subsequence of s.

Note that even if there are multiple ways to obtain the same subsequence, it is still only counted once.

A palindrome is a string that reads the same forwards and backwards.

A subsequence of a string is a new string generated from the original string with some characters (can be none) deleted without changing the relative order of the remaining characters.

  • For example, “ace” is a subsequence of “abcde”.
Read more