Problem

Base36 Square Root

ZopsmartOA

You are given a non-negative decimal integer n.

First, convert n to its uppercase hexadecimal representation without any prefix. Then treat that hexadecimal string as a base-36 number and convert it back to decimal. Return the floor of the square root of that decimal value.

In base 36, digits 0 through 9 have values 0 through 9, and letters A through Z have values 10 through 35.

Examples
01 · Example 1
n = 100
return = 14

100 in hexadecimal is 64. Interpreting 64 as base 36 gives 6 * 36 + 4 = 220. The floor square root of 220 is 14.

02 · Example 2
n = 31
return = 7

31 in hexadecimal is 1F. Interpreting 1F as base 36 gives 51, whose floor square root is 7.

Constraints
  • n is a non-negative decimal integer.
  • The converted base-36 value fits in a 64-bit signed integer.
More Zopsmart problems
drafts saved locally
public long base36SquareRoot(long n) {
  // write your code here
}
n100
expected14
sign in to submit