[LeetCode] Build Array Where You Can Find The Maximum Exactly K Comparisons

1420. Build Array Where You Can Find The Maximum Exactly K Comparisons

You are given three integers n, m and k. Consider the following algorithm to find the maximum element of an array of positive integers:

You should build the array arr which has the following properties:

  • arr has exactly n integers.
  • 1 <= arr[i] <= m where (0 <= i < n).
  • After applying the mentioned algorithm to arr, the value search_cost is equal to k.

Return the number of ways to build the array arr under the mentioned conditions. As the answer may grow large, the answer must be computed modulo 109 + 7.

Read more
[Codeforces] Round #738 (Div. 2) D1. Mocha and Diana (Easy Version)Read more
[LeetCode] UTF-8 Validation

393. UTF-8 Validation

Given an integer array data representing the data, return whether it is a valid UTF-8 encoding.

A character in UTF8 can be from 1 to 4 bytes long, subjected to the following rules:

  1. For a 1-byte character, the first bit is a 0, followed by its Unicode code.
  2. For an n-bytes character, the first n bits are all one’s, the n + 1 bit is 0, followed by n - 1 bytes with the most significant 2 bits being 10.

This is how the UTF-8 encoding would work:


Char. number range | UTF-8 octet sequence
(hexadecimal) | (binary)
——————————+——————————————————————-
0000 0000-0000 007F | 0xxxxxxx
0000 0080-0000 07FF | 110xxxxx 10xxxxxx
0000 0800-0000 FFFF | 1110xxxx 10xxxxxx 10xxxxxx
0001 0000-0010 FFFF | 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx

</code></pre>
Note: The input is an array of integers. Only the least significant 8 bits of each integer is > used to store the data. This means each integer represents only 1 byte of data.

Read more
[Codeforces] Round #723 (Div. 2) B. I Hate 1111Read more
[Codeforces] Round #743 (Div. 2) B. SwapsRead more
[Codeforces] Round #744 (Div. 3) D. Productive MeetingRead more
[Codeforces] Bubble Cup 14 - Finals Online Mirror (Unrated, ICPC Rules, Teams Preferred, Div. 2) J. Robot FactoryRead more
[LeetCode] Delete Operation for Two Strings

583. Delete Operation for Two Strings

Given two strings word1 and word2, return the minimum number of steps required to make word1 and word2 the same.

In one step, you can delete exactly one character in either string.

Read more
[LeetCode] Edit Distance

72. Edit Distance

Given two strings word1 and word2, return the minimum number of operations required to convert word1 to word2.

You have the following three operations permitted on a word:

  • Insert a character
  • Delete a character
  • Replace a character
Read more
[LeetCode] Sliding Puzzle

773. Sliding Puzzle

On an 2 x 3 board, there are five tiles labeled from 1 to 5, and an empty square represented by 0. A move consists of choosing 0 and a 4-directionally adjacent number and swapping it.

The state of the board is solved if and only if the board is [[1,2,3],[4,5,0]].

Given the puzzle board board, return the least number of moves required so that the state of the board is solved. If it is impossible for the state of the board to be solved, return -1.

Read more