2217. Find Palindrome With Fixed Length Medium
1/**
2 * [2217] Find Palindrome With Fixed Length
3 *
4 * 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.
5 * A palindrome is a number that reads the same backwards and forwards. Palindromes cannot have leading zeros.
6 *
7 * Example 1:
8 *
9 * Input: queries = [1,2,3,4,5,90], intLength = 3
10 * Output: [101,111,121,131,141,999]
11 * Explanation:
12 * The first few palindromes of length 3 are:
13 * 101, 111, 121, 131, 141, 151, 161, 171, 181, 191, 202, ...
14 * The 90^th palindrome of length 3 is 999.
15 *
16 * Example 2:
17 *
18 * Input: queries = [2,4,6], intLength = 4
19 * Output: [1111,1331,1551]
20 * Explanation:
21 * The first six palindromes of length 4 are:
22 * 1001, 1111, 1221, 1331, 1441, and 1551.
23 *
24 *
25 * Constraints:
26 *
27 * 1 <= queries.length <= 5 * 10^4
28 * 1 <= queries[i] <= 10^9
29 * 1 <= intLength <= 15
30 *
31 */
32pub struct Solution {}
33
34// problem: https://leetcode.com/problems/find-palindrome-with-fixed-length/
35// discuss: https://leetcode.com/problems/find-palindrome-with-fixed-length/discuss/?currentPage=1&orderBy=most_votes&query=
36
37// submission codes start here
38
39impl Solution {
40 pub fn kth_palindrome(queries: Vec<i32>, int_length: i32) -> Vec<i64> {
41
42 }
43}
44
45// submission codes end
46
47#[cfg(test)]
48mod tests {
49 use super::*;
50
51 #[test]
52 fn test_2217() {
53 }
54}
55
Back
© 2025 bowen.ge All Rights Reserved.