Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 5761 |

@blackshadows | 5715 |

@akhayrutdinov | 5111 |

@mb1973 | 4989 |

@Quandray | 4944 |

@saiujwal13083 | 4506 |

@sanjay05 | 3762 |

@marius_valentin_dragoi | 3516 |

@sushant_a | 3459 |

@verma_ji | 3341 |

@KshamaGupta | 3318 |

Complete Leaderboard | |

Handle | Score |

@aroranayan999 | 1115 |

@bt8816103042 | 739 |

@thealchemist627 | 456 |

@dalwainazism125 | 453 |

@akashkale117 | 453 |

@shivanandp12345678910 | 453 |

@codeantik | 448 |

@SherlockHolmes3 | 447 |

@SHOAIBVIJAPURE | 430 |

@shalinibhataniya1097 | 408 |

@ShamaKhan1 | 392 |

Complete Leaderboard |

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 10^{9}+7

**Example 1:**

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

**Example 2:**

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

**Your task:**

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(K^{2})

**Expected Auxiliary Space:** O(K^{2})

**Constraints:**

1 ≤ K ≤ 26

1 ≤ N ≤ 52

N ≤ 2*K

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes
Number of palindromic strings

...