Problem

Reverse Base36 Number

Learn this problem
ZOZopsmartOA

Problem statement

You are given a non-negative decimal integer n.

Convert n to its uppercase base-36 representation. Reverse that base-36 string, then interpret the reversed string as a base-36 number and return its decimal value.

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

Note: if the reversed string has leading zeros, they are ignored when interpreting the reversed string as a base-36 number (e.g., "01" is interpreted as 1).

Function

reverseBase36Number(n: long) → long

Examples

Example 1

n = 100return = 1010

100 in base 36 is 2S. Reversing gives S2, which is 28 * 36 + 2 = 1010.

Example 2

n = 36return = 1

36 in base 36 is 10. Reversing gives 01, whose decimal value is 1.

Constraints

  • 0 <= n <= 1012
  • The returned value fits in a 64-bit signed integer.

More Zopsmart problems

drafts saved locally
public long reverseBase36Number(long n) {
  // write your code here
}
n100
expected1010
checking account