Your question is Build Palindrome Generator. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Swiggy QA systems sometimes generate deterministic synthetic strings for validating input handling. Implement a function that constructs the lexicographically smallest palindrome under length and character-category constraints.
The function supports two modes:
length lowercase a characters.length containing exactly letter_count lowercase letters, digit_count digits, and special_count characters. The allowed categories are lowercase English letters, decimal digits, and the special-character set !@#$%^&*.Within each category, use the smallest possible character: a for letters, 0 for digits, and ! for special characters. Compare complete results using ASCII lexicographic order. Return an empty string if the requested construction is impossible. A palindrome is possible only when at most one category count is odd, and the three category counts must sum to length in category-count mode.
Given integers length, letter_count, digit_count, and special_count, return a string of type str. The result must be a palindrome, have exactly length characters, and satisfy the requested category counts.
def generate_palindrome(length, letter_count, digit_count, special_count):