Need help for solving a Question asked in google .

Revision en1, by SauravSingh3296, 2024-10-28 21:35:30

first of all let me clear the constraints 1 <= T <= 10 , 1 <= N <= 1e5 and 1 <= K <= 26 ; where 'T' is the number of test cases and 'N' is the size of the string .

Q => A string is called beautiful if each character of the string is one of the first K letters of the English lowercase alphabet and that string does not contain any substring of length 2 or more which is a palindrome.

You are given the following: * Two non-negative integers N and K * A beautiful string S of length N

Task:- Determine the lexicographically smallest string of length N which is the beautiful and is lexicographically larger than string S. If no such string exists output will be -1. If multiple answer exist print any of them .

Input : Number of testcase => T Length of string => N The number of alphabets from starting which can be taken => K string => S

example : 2 4 5 eace 3 8 hgf

answers:

eadb -1

Note : I do not remember the time constraint ;

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English SauravSingh3296 2024-10-28 21:35:30 1030 Initial revision (published)