Saitama_theGoat's blog

By Saitama_theGoat, history, 14 months ago, In English

Find the middle element when the numbers in an n \times n multiplication table are sorted in increasing order. It is assumed that n is odd. For example, the 3 \times 3 multiplication table is as follows:

$$$ \begin{matrix} 1 & 2 & 3 \\ 2 & 4 & 6 \\ 3 & 6 & 9 \\ \end{matrix} $$$

The numbers in increasing order are [1,2,2,3,3,4,6,6,9], so the answer is 3. Input The only input line has an integer n. Output Print one integer: the answer to the task. Constraints

1 \le n < 10^6

Example Input: 3

Output: 3

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it

By Saitama_theGoat, history, 14 months ago, In English

You are given a binary string s and a positive integer k.

Return the length of the longest subsequence of s that makes up a binary number less than or equal to k.

Note:

The subsequence can contain leading zeroes. The empty string is considered to be equal to 0. A subsequence is a string that can be derived from another string by deleting some or no characters without changing the order of the remaining characters.

Example 1:

Input: s = "1001010", k = 5 Output: 5 Explanation: The longest subsequence of s that makes up a binary number less than or equal to 5 is "00010", as this number is equal to 2 in decimal. Note that "00100" and "00101" are also possible, which are equal to 4 and 5 in decimal, respectively. The length of this subsequence is 5, so 5 is returned

any ideas or hints on how to solve it.

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it