This code passes majority of testcases on CSES.fi except the ones from 6-9 for which I keep getting TLE. Tried many times, but could not fix it. Any hints?
SOLVED! But anyway, I want to know on which part you'd possibly make optimizations.. In case your method differs with mine it might be a pretty useful insight to know ^_^
String concatenation may take a lot of time, as it copies the whole string a, add a char, then write the resulting string to a (This actually depends on some factor, such as the language, compiler, etc, I dont really understand about that too). Instead of building the string ans, you can decide whether an answer exist (the d value in your code) and if it does, print the output as you go through the array cnt[] twice, one for the first half of the answer, and the other for the second half.
SOLVED! But anyway, I want to know on which part you'd possibly make optimizations.. In case your method differs with mine it might be a pretty useful insight to know ^_^
String concatenation may take a lot of time, as it copies the whole string
a, add a char, then write the resulting string toa(This actually depends on some factor, such as the language, compiler, etc, I dont really understand about that too). Instead of building the stringans, you can decide whether an answer exist (thedvalue in your code) and if it does, print the output as you go through the arraycnt[]twice, one for the first half of the answer, and the other for the second half.Relevant blog : https://codeforces.me/blog/entry/94701
Edit : Added a link to relevant blog