Binary Palindromic Subsequences of Length 5
Updated
Problem statement
Given a binary string s, return how many of its subsequences of length 5 are palindromes. The answer can be very large, so return it modulo 10^9 + 7.
- A binary string contains only the characters
'0'and'1'. - A palindrome reads the same from left to right and from right to left.
- A subsequence keeps some of the characters of
s, possibly all of them, in their original order. - Two subsequences are counted separately when they use different positions of
s, even if they spell the same string.
Function
getPalindromesCount(s: String) → intExamples
Example 1
s = "0100110"return = 5Numbering positions from 1, four choices spell 01010: positions (1, 2, 3, 6, 7), (1, 2, 3, 5, 7), (1, 2, 4, 6, 7) and (1, 2, 4, 5, 7). One more, (1, 2, 5, 6, 7), spells 01110. The total is 5.
Example 2
s = "010110"return = 3Numbering positions from 1, positions (1, 2, 3, 4, 6) and (1, 2, 3, 5, 6) spell 01010, and (1, 2, 4, 5, 6) spells 01110. The total is 3.
Example 3
s = "01111"return = 0The only subsequence of length 5 is the whole string 01111, which is not a palindrome.
Constraints
5 <= s.length <= 105s[i] is either '0' or '1'
More Citadel Online Assessment questions
- Speed Up a Slow FunctionOA · PHONE SCREEN · Seen Nov 2026
- Possible MEX Values After One Optional IncrementOA · Seen Oct 2026
- Busy IntersectionOA · Seen Sep 2026
- Shortest Path in an Unweighted GraphOA · Seen Sep 2026
- Maximize Workday EarningsOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Minimum Changes for Palindromic BlocksOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Minimum Image Processing CostOA · Seen Jul 2026
- Coprime Pick with Change CostOA · Seen Jul 2026
- Process SchedulingOA · Seen Mar 2026
- Employee With the Most OverlapsOA · Seen Feb 2026
Similar questions at other companies
- Count Digit Replacements with No Equal Adjacent DigitsMicrosoft · OAMicrosoft interview questions
- Maximum Redundancy After One Segment FlipBloomberg LP · OABloomberg LP interview questions
- Replace '?' to Avoid Adjacent DuplicatesSalesforce · OASalesforce interview questions
- Count Equal-Frequency SubsequencesExpedia · OAExpedia interview questions
- Maximum Positive FeedbackTikTok · OATikTok interview questions
- Generate One-Two Strings with Sum NGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
- Count Vowel PermutationsZscaler · ONSITE INTERVIEWZscaler interview questions
- Maximum Game Score with Fixed Forward JumpsStripe · OAStripe interview questions
- Maximum Equal-Bit Pairs in a SubsequenceAmazon · OA
- Frog Paths Without Long RunsSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
Citadel interview experiences
- Citadel Securities Quant Researcher Intern Loop: 1 Experience
- Citadel Securities Research Engineer Interview: 1 Experience
- Citadel Securities SWE Intern First Round: 2 Experiences
- Citadel Securities Experienced SWE Interviews: 1 Experience
- Citadel SWE Intern Later Rounds and Superday: 13 Experiences
- Citadel SWE Intern First-Round Questions: 20 Experiences