[LeetCode] Extract Kth Character From The Rope Tree

2689. Extract Kth Character From The Rope Tree

You are given the root of a binary tree and an integer k. Besides the left and right children, every node of this tree has two other properties, a string node.val containing only lowercase English letters (possibly empty) and a non-negative integer node.len. There are two types of nodes in this tree:

  • Leaf: These nodes have no children, node.len = 0, and node.val is some non-empty string.
  • Internal: These nodes have at least one child (also at most two children), node.len > 0, and node.val is an empty string.

The tree described above is called a Rope binary tree. Now we define S[node] recursively as follows:

  • If node is some leaf node, S[node] = node.val,
  • Otherwise if node is some internal node, S[node] = concat(S[node.left], S[node.right]) and S[node].length = node.len.

Return k-th character of the string S[root].

Note: If s and p are two strings, concat(s, p) is a string obtained by concatenating p to s. For example, concat("ab", "zz") = "abzz".

Read more
[LeetCode] Count Houses in a Circular Street

2728. Count Houses in a Circular Street

You are given an object street of class Street that represents a circular street and a positive integer k which represents a maximum bound for the number of houses in that street (in other words, the number of houses is less than or equal to k). Houses’ doors could be open or closed initially.

Initially, you are standing in front of a door to a house on this street. Your task is to count the number of houses in the street.

The class Street contains the following functions which may help you:

  • void openDoor(): Open the door of the house you are in front of.
  • void closeDoor(): Close the door of the house you are in front of.
  • boolean isDoorOpen(): Returns true if the door of the current house is open and false otherwise.
  • void moveRight(): Move to the right house.
  • void moveLeft(): Move to the left house.

Return ans which represents the number of houses on this street.

Read more
[LeetCode] Count Numbers With Unique Digits II

3032. Count Numbers With Unique Digits II

Given two positive integers a and b, return the count of numbers having unique digits in the range [a, b] (inclusive).

Read more
[System Design] Design Distributed Counter

Design Distributed Counter

Read more
[Codeforces] Helvetic Coding Contest 2024 online mirror (teams allowed, unrated) C3. Game on Tree (Hard)Read more
[Codeforces] Helvetic Coding Contest 2024 online mirror (teams allowed, unrated) C2. Game on Tree (Medium)Read more
[Codeforces] Educational Round 165 (Rated for Div. 2) C. Minimizing the SumRead more
[Codeforces] Round 943 (Div. 3) F. Equal XOR SegmentsRead more
[Codeforces] Round 943 (Div. 3) E. Cells ArrangementRead more
[LeetCode] Find the Minimum Cost Array Permutation

3149. Find the Minimum Cost Array Permutation

You are given an array nums which is a permutation of [0, 1, 2, ..., n - 1]. The score of any permutation of [0, 1, 2, ..., n - 1] named perm is defined as:

1
>score(perm) = |perm[0] - nums[perm[1]]| + |perm[1] - nums[perm[2]]| + ... + |perm[n - 1] - nums[perm[0]]|

Return the permutation perm which has the minimum possible score. If multiple permutations exist with this score, return the one that is lexicographically smallest among them.

Read more