Count Distinct Palindromic Substrings
Updated
Problem statement
Count the different nonempty palindromic substrings of s. A substring uses consecutive characters, and a palindrome reads the same forward and backward.
For this exercise, assume equal substring text is counted once, even when it occurs at different or overlapping positions. Return the number of different palindromes. The empty string contains none and returns 0.
Function
countDistinctPalindromes(s: String) → intExamples
Example 1
s = "ababa"return = 5The distinct values are a, b, aba, bab and ababa.
Example 2
s = "aaaa"return = 4The four distinct values are a, aa, aaa and aaaa, regardless of repeated occurrences.
Example 3
s = ""return = 0The empty substring is not counted.
Constraints
0 <= s.length <= 5000.- Every character is a lowercase English letter.
More Roblox Online Assessment questions
- Centered Block Placement QueriesOA · Seen Oct 2026
- Robot Navigation Around LasersOA · Seen Oct 2026
- Factory Batch Profit (Game Adaptation)OA · Seen Sep 2026
- Nested Recipe Blocks (Game Adaptation)OA · Seen Sep 2026
- Vehicle Builds for Required Terrain (Game Adaptation)OA · Seen Sep 2026
- Track Received Byte RangesOA · Seen Sep 2026
- Inventory Discount TrackerOA · Seen Sep 2026
- Break a PalindromeOA · Seen Jun 2026
- Count Pairs Differing in One DigitOA · Seen Oct 2025
- Find Zero Cells in a 2×2 GridOA · Seen Oct 2025
Similar questions at other companies
- Minimum Merge ConflictsAmazon · OA
- Lexicographically Smallest Grid Path with One Letter ChangeInfosys · OAInfosys interview questions
- Incident MonitorStripe · OAStripe interview questions
- Balance a Chemical EquationMicrosoft · OAMicrosoft interview questions
- Longest Repeated Letter Block with Adjacent SwapsIntuit · OAIntuit interview questions
- Count Substrings Matching with One Adjacent SwapInMobi · OAInMobi interview questions
- Binary CircuitAkuna Capital · OAAkuna Capital interview questions
- String Formation (Also for AI/ML Software Engineer Intern :)Snowflake · OASnowflake interview questions
- Binary Sorting Rounds After FlipsVisa · OAVisa interview questions
- Minimum Numeric Code TransformationAdobe · OAAdobe interview questions