Palindrome Match Percentage
Reported by candidates from Apple's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The edge case that breaks a naive solution in this Apple OA, reported September 2026, is the empty string and the single character. Pairs is zero, so you divide by zero unless you guard it. The task itself is simple two-pointers work: compare mirrored characters, count matches, return a percentage string. Apple's version adds a formatting twist, because the output needs exactly two decimals with half values rounded up. Most people nail the loop and lose points on the last line. If you blank on the rounding, StealthCoder can run invisibly during the live assessment as a safety net. Read the rules below first, though.
The problem
Given a string text, measure how closely it matches a palindrome by comparing mirrored character pairs. Let pairs = floor(text.length / 2). Count a pair when text[i] == text[text.length - 1 - i] for 0 <= i < pairs. The middle character of an odd-length string does not form a pair. Return 100 × matchingPairs / pairs as a string with exactly two digits after the decimal point, rounded to the nearest hundredth with half values rounded up. Strings of length zero or one return "100.00". Comparison is case-sensitive and literal: spaces and punctuation are not removed. Function palindromeMatchPercentage(text: String) → String Examples Example 1 text = "racecar" return = "100.00" All three mirrored pairs match. The middle e is excluded. Example 2 text = "abca" return = "50.00" The outer a pair matches, while b and c do not. Example 3 text = "abcdefa" return = "33.33" One of the three mirrored pairs matches, so the exact fraction is rounded to 33.33. Constraints 0 <= text.length <= 20000. text contains printable ASCII characters, including spaces and punctuation. The returned value always contains exactly two digits after the decimal point.
Reported by candidates. Source: FastPrep
Pattern and pitfall
Walk two pointers inward from both ends, or just loop i from 0 to pairs-1 and compare text[i] with text[n-1-i]. Count matches. If n is 0 or 1, return "100.00" before anything else. The real pitfall is rounding. Floating point can turn 0.125 into 0.12499999 and give you the wrong hundredth. Use integers instead: compute (matches * 10000 * 2 + pairs) / (2 * pairs) with integer division to get the percentage in hundredths, rounded half up. Then format it as whole part, a dot, and two zero-padded digits. Don't strip spaces or punctuation and don't lowercase anything, since the comparison is literal and case-sensitive. The length cap of 20000 means O(n) is trivially fine. If the integer rounding trick slips your mind mid-assessment, StealthCoder is the hedge that surfaces it while you keep typing.
StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.
You can drill Palindrome Match Percentage cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. If you're reading this with an OA window open, you're who this was built for.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Apple's OA.
Apple reuses patterns across OAs. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Palindrome Match Percentage FAQ
How hard is Palindrome Match Percentage really?+
Easy on the algorithm, annoying on the details. The loop is a few lines. The points get lost on the zero-pair guard and on exact two-decimal rounding with half up. If you handle those two, you're done in minutes.
What's the trick to the rounding?+
Avoid floats. Compute hundredths as an integer: (matches * 20000 + pairs) / (2 * pairs) using integer division. That's round-half-up on 100 * matches / pairs scaled by 100. Then print the quotient divided by 100, a dot, and the remainder padded to two digits.
What edge cases should I test before submitting?+
Empty string, a single character, length two, and an odd-length string where the middle is excluded. Also test strings with spaces, punctuation, and mixed case, since comparison is literal. Check that 33.33 and 50.00 from the examples come out exactly.
Is the two-pointers pattern still asked in Apple OAs?+
It was reported for Apple in September 2026, so yes, it's live. Mirrored comparison and palindrome checks are a common warmup shape. Expect a small twist like formatting or counting instead of a pure boolean check.
How do I prepare for this in 48 hours?+
Write this one from scratch twice. Once with two index pointers, once with a single loop over pairs. Practice the integer rounding and zero-padded formatting in your language of choice. Those are the parts you can't afford to fumble.