Mid/SeniorArrayMath

Find Palindrome With Fixed Length

Given an integer array queries and a positive integer intLength, return an array answer where answer[i] is either the queries[i]^th smallest positive palindrome of length intLength or -1 if no such palindrome exists.

A palindrome is a number that reads the same backwards and forwards. Palindromes cannot have leading zeros.

Example 1
Inputqueries = [1,2,3,4,5,90], intLength = 3
Output[101,111,121,131,141,999]
The first few palindromes of length 3 are 101, 111, 121, 131, 141, ..., and the 90th palindrome of length 3 is 999.
Example 2
Inputqueries = [2,4,6], intLength = 4
Output[1111,1331,1551]
The first six palindromes of length 4 are 1001, 1111, 1221, 1331, 1441, and 1551.

Constraints

  • 1 <= queries.length <= 5 * 10^4
  • 1 <= queries[i] <= 10^9
  • 1 <= intLength <= 15

Asked at 1 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate