[Codeforces] Avito Code Challenge 2018 C. Useful DecompositionRead more
[Codeforces] Round #485 (Div. 2) C. Three displaysRead more
[Codeforces] Round #486 (Div. 3) C. Equal SumsRead more
[Codeforces] Codeforces #488 by NEAR (Div. 2) B. Knights of a Polygonal TableRead more
[LeetCode] Average Height of Buildings in Each Segment

2015. Average Height of Buildings in Each Segment

A perfectly straight street is represented by a number line. The street has building(s) on it and is represented by a 2D integer array buildings, where buildings[i] = [starti, endi, heighti]. This means that there is a building with heighti in the half-closed segment [starti, endi).

You want to describe the heights of the buildings on the street with the minimum number of non-overlapping segments. The street can be represented by the 2D integer array street where street[j] = [leftj, rightj, averagej] describes a half-closed segment [leftj, rightj) of the road where the average heights of the buildings in the segment is averagej.

  • For example, if buildings = [[1,5,2],[3,10,4]], the street could be represented by street = [[1,3,2],[3,5,3],[5,10,4]] because:
  • From 1 to 3, there is only the first building with an average height of 2 / 1 = 2.
  • From 3 to 5, both the first and the second building are there with an average height of (2+4) / 2 = 3.
  • From 5 to 10, there is only the second building with an average height of 4 / 1 = 4.

Given buildings, return the 2D integer array street as described above (excluding any areas of the street where there are no buldings). You may return the array in any order.

The average of n elements is the sum of the n elements divided (integer division) by n.

A half-closed segment [a, b) is the section of the number line between points a and b including point a and not including point b.

Read more
[LeetCode] Clumsy Factorial

1006. Clumsy Factorial

The factorial of a positive integer n is the product of all positive integers less than or equal to n.

  • For example, factorial(10) = 10 9 8 7 6 5 4 3 2 * 1.

We make a clumsy factorial using the integers in decreasing order by swapping out the multiply operations for a fixed rotation of operations with multiply ‘*’, divide ‘/‘, add ‘+’, and subtract ‘-‘ in this order.

  • For example, clumsy(10) = 10 9 / 8 + 7 - 6 5 / 4 + 3 - 2 * 1.

However, these operations are still applied using the usual order of operations of arithmetic. We do all multiplication and division steps before any addition or subtraction steps, and multiplication and division steps are processed left to right.

Additionally, the division that we use is floor division such that 10 * 9 / 8 = 90 / 8 = 11.

Given an integer n, return the clumsy factorial of n.

Read more
[LeetCode] Number of Unique Flavors After Sharing K Candies

2107. Number of Unique Flavors After Sharing K Candies

You are given a 0-indexed integer array candies, where candies[i] represents the flavor of the ith candy. Your mom wants you to share these candies with your little sister by giving her k consecutive candies, but you want to keep as many flavors of candies as possible.

Return the maximum number of unique flavors of candy you can keep after sharing with your sister.

Read more
[LeetCode] Print Words Vertically

1324. Print Words Vertically

Given a string s. Return all the words vertically in the same order in which they appear in s.

Words are returned as a list of strings, complete with spaces when is necessary. (Trailing spaces are not allowed).
Each word would be put on only one column and that in one column there will be only one word.

Read more
[LeetCode] Widest Pair of Indices With Equal Range Sum

1983. Widest Pair of Indices With Equal Range Sum

You are given two 0-indexed binary arrays nums1 and nums2. Find the widest pair of indices (i, j) such that i <= j and nums1[i] + nums1[i+1] + … + nums1[j] == nums2[i] + nums2[i+1] + … + nums2[j].

The widest pair of indices is the pair with the largest distance between i and j. The distance between a pair of indices is defined as j - i + 1.

Return the distance of the widest pair of indices. If no pair of indices meets the conditions, return 0.

Read more
[AtCoder] E - Unique ColorRead more