[AtCoder] E - Complete Binary TreeRead more
[AtCoder] C - Social Distance on GraphRead more
[AtCoder] F - #(subset sum = K) with Add and EraseRead more
[AtCoder] C - LU / RD MarkingRead more
[AtCoder] F - Vacation QueryRead more
[LeetCode] Minimize OR of Remaining Elements Using Operations

3022. Minimize OR of Remaining Elements Using Operations

You are given a 0-indexed integer array nums and an integer k.

In one operation, you can pick any index i of nums such that 0 <= i < nums.length - 1 and replace nums[i] and nums[i + 1] with a single occurrence of nums[i] & nums[i + 1], where & represents the bitwise AND operator.

Return the minimum possible value of the bitwise OR of the remaining elements of nums after applying at most k operations.

Read more
[LeetCode] Alice and Bob Playing Flower Game

3021. Alice and Bob Playing Flower Game

Alice and Bob are playing a turn-based game on a circular field surrounded by flowers. The circle represents the field, and there are x flowers in the clockwise direction between Alice and Bob, and y flowers in the anti-clockwise direction between them.

The game proceeds as follows:

  1. Alice takes the first turn.
  2. In each turn, a player must choose either the clockwise or anti-clockwise direction and pick one flower from that side.
  3. At the end of the turn, if there are no flowers left at all, the current player captures their opponent and wins the game.

Given two integers, n and m, the task is to compute the number of possible pairs (x, y) that satisfy the conditions:

  • Alice must win the game according to the described rules.
  • The number of flowers x in the clockwise direction must be in the range [1,n].
  • The number of flowers y in the anti-clockwise direction must be in the range [1,m].

Return the number of possible pairs (x, y) that satisfy the conditions mentioned in the statement.

Read more
[LeetCode] Find the Maximum Number of Elements in Subset

3020. Find the Maximum Number of Elements in Subset

You are given an array of positive integers nums.

You need to select a subset of nums which satisfies the following condition:

  • You can place the selected elements in a 0-indexed array such that it follows the pattern: [x, x2, x4, ..., xk/2, xk, xk/2, ..., x4, x2, x] (Note that k can be be any non-negative power of 2). For example, [2, 4, 16, 4, 2] and [3, 9, 3] follow the pattern while [2, 4, 8, 4, 2] does not.

Return the maximum number of elements in a subset that satisfies these conditions.

Read more
[LeetCode] Number of Changing Keys

3019. Number of Changing Keys

You are given a 0-indexed string s typed by a user. Changing a key is defined as using a key different from the last used key. For example, s = "ab" has a change of a key while s = "bBBb" does not have any.

Return the number of times the user had to change the key.

Note: Modifiers like shift or caps lock won’t be counted in changing the key that is if a user typed the letter 'a' and then the letter 'A' then it will not be considered as a changing of key.

Read more
[Codeforces] Round 662 (Div. 2) D. Rarity and New DressRead more