[Codeforces] Educational Round 75 (Rated for Div. 2) D. Salary ChangingRead more
[Codeforces] Educational Round 77 (Rated for Div. 2) D. A Game with TrapsRead more
[LeetCode] Count Paths That Can Form a Palindrome in a Tree

2791. Count Paths That Can Form a Palindrome in a Tree

You are given a tree (i.e. a connected, undirected graph that has no cycles) rooted at node 0 consisting of n nodes numbered from 0 to n - 1. The tree is represented by a 0-indexed array parent of size n, where parent[i] is the parent of node i. Since node 0 is the root, parent[0] == -1.

You are also given a string s of length n, where s[i] is the character assigned to the edge between i and parent[i]. s[0] can be ignored.

Return the number of pairs of nodes (u, v) such that u < v and the characters assigned to edges on the path from u to v can be rearranged to form a palindrome.

A string is a palindrome when it reads the same backwards as forwards.

Read more
[LeetCode] Maximum Number of Groups With Increasing Length

2790. Maximum Number of Groups With Increasing Length

You are given a 0-indexed array usageLimits of length n.

Your task is to create groups using numbers from 0 to n - 1, ensuring that each number, i, is used no more than usageLimits[i] times in total across all groups. You must also satisfy the following conditions:

  • Each group must consist of distinct numbers, meaning that no duplicate numbers are allowed within a single group.
  • Each group (except the first one) must have a length strictly greater than the previous group.

Return an integer denoting the maximum number of groups you can create while satisfying these conditions.

Read more
[LeetCode] Largest Element in an Array after Merge Operations

2789. Largest Element in an Array after Merge Operations

You are given a 0-indexed array nums consisting of positive integers.

You can do the following operation on the array any number of times:

  • Choose an integer i such that 0 <= i < nums.length - 1 and nums[i] <= nums[i + 1]. Replace the element nums[i + 1] with nums[i] + nums[i + 1] and delete the element nums[i] from the array.

Return the value of the largest element that you can possibly obtain in the final array.

Read more
[LeetCode] Split Strings by Separator

2788. Split Strings by Separator

Given an array of strings words and a character separator, split each string in words by separator.

Return an array of strings containing the new strings formed after the splits, excluding empty strings.

Notes

  • separator is used to determine where the split should occur, but it is not included as part of the resulting strings.
  • A split may result in more than two strings.
  • The resulting strings must maintain the same order as they were initially given.
Read more
[Codeforces] Round 604 (Div. 1) B. Beautiful SequenceRead more
[Codeforces] Good Bye 2019 D. Strange DeviceRead more
[Codeforces] Round 605 (Div. 3) E. Nearest Opposite ParityRead more
[LeetCode] Ways to Express an Integer as Sum of Powers

2787. Ways to Express an Integer as Sum of Powers

Given two positive integers n and x.

Return the number of ways n can be expressed as the sum of the xth power of unique positive integers, in other words, the number of sets of unique integers [n1, n2, ..., nk] where n = n1x + n2x + ... + nkx.

Since the result can be very large, return it modulo 109 + 7.

For example, if n = 160 and x = 3, one way to express n is n = 23 + 33 + 53.

Read more