Showing:
Handle Score
@Ibrahim Nash 5761
@akhayrutdinov 5111
@mb1973 4989
@Quandray 4944
@saiujwal13083 4506
@sanjay05 3762
@marius_valentin_dragoi 3516
@sushant_a 3459
@verma_ji 3341
@KshamaGupta 3318
Number of palindromic strings
Medium Accuracy: 0.0% Submissions: 0 Points: 4

Given two integers N and K, the task is to find the count of palindromic strings of length lesser than or equal to N, with first K characters of lowercase English language, such that each character in a string doesn’t appear more than twice.

Note: Anwer can be very large, so, output answer modulo 109+7

Example 1:

Input: N = 3, K = 2
Output: 6
Explanation: The possible strings are:
"a", "b", "aa", "bb", "aba", "bab".

Example 2:

Input: N = 4, K = 3
Output: 6
Explanation: The possible strings are:
"a", "b", "c", "aa", "bb", "cc", "aba",
"aca", "bab", "bcb", "cac", "cbc",
"abba", "acca", "baab", "bccb", "caac",
"cbbc". 

You do not need to read any input or print anything. The task is to complete the function palindromicStrings(), which takes two integers as input and returns the count.

Expected Time Complexity: O(K2)
Expected Auxiliary Space: O(K2)

Constraints:
1 ≤ K ≤ 26
1 ≤ N ≤ 52
N ≤ 2*K