Skip to content
We areTOP 1%

Palindrome Degree

HardRating 2200CodeforcesString Algorithms (KMP, Z, Hashing)
Solve on Codeforces(opens in a new tab)
Track your progress
First attempt
Re-solve after a few days
Final pass before interviews
Approach hintTry it first, then reveal

A palindromic prefix of length i has degree deg[i / 2] + 1, and any other prefix has degree 0. Test whether each prefix is a palindrome in O(1) by maintaining forward and backward hashes incrementally.

More in String Algorithms (KMP, Z, Hashing)

String Algorithms (KMP, Z, Hashing) questions
#ProblemPlatformDifficultyOpen1st1st Visit2nd2nd VisitRevRevise
1Longest Happy PrefixLeetCodeHard Solve Longest Happy Prefix on LeetCode (opens in a new tab)
2PasswordCodeforcesMedium 1700Solve Password on Codeforces (opens in a new tab)
3Shortest PalindromeLeetCodeHard Solve Shortest Palindrome on LeetCode (opens in a new tab)
4Prefix-Suffix Palindrome (Hard version)CodeforcesHard 1800Solve Prefix-Suffix Palindrome (Hard version) on Codeforces (opens in a new tab)
5Sum of Scores of Built StringsLeetCodeHard Solve Sum of Scores of Built Strings on LeetCode (opens in a new tab)
6Tavas and MalekasCodeforcesHard 1900Solve Tavas and Malekas on Codeforces (opens in a new tab)
7Longest Duplicate SubstringLeetCodeHard Solve Longest Duplicate Substring on LeetCode (opens in a new tab)
8Prefixes and SuffixesCodeforcesHard 2000Solve Prefixes and Suffixes on Codeforces (opens in a new tab)
9Watto and MechanismCodeforcesHard 2000Solve Watto and Mechanism on Codeforces (opens in a new tab)
10Palindrome DegreeCodeforcesHard 2200Solve Palindrome Degree on Codeforces (opens in a new tab)
11Anthem of BerlandCodeforcesHard 2300Solve Anthem of Berland on Codeforces (opens in a new tab)

Sign in to track your progress

Your checkboxes, streak and activity heatmap are saved to your account and sync across devices. It is free.
Sign in with email

New here? Create an account