FastPrepCount Palindromic Base Representations

Count Palindromic Base Representations

SEDEMAC logoSEDEMAC● EasyNEW GRADOA

Updated

Problem statement

For each integer base from 2 through 16, convert the positive integer value to that base. Return how many of those digit sequences read the same from left to right and right to left. Digits are compared by numeric value, so bases above ten need no special text encoding.

Function

countPalindromicBases(value: int) → int

Examples

Example 1

value = 9return = 9

The binary and base-eight forms are palindromes, and every base above nine uses one digit.

Example 2

value = 5return = 13

Each base is checked independently using its digit sequence.

Constraints

  • 1 <= value <= 1000000000
  • bases 2 through 16 are inclusive

More SEDEMAC interview questions

Similar questions at other companies

See SEDEMAC hiring insights
Saved
class Solution {
    public int countPalindromicBases(int value) {
        // Write your code here.
    }

}
Checking account…