FastPrepPalindrome Match Percentage
Problems/Palindrome Match Percentage

Palindrome Match Percentage

Apple logoApple● EasyFULLTIMEONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Source note: The interview report asks for a palindrome check followed by a percentage measuring closeness to a palindrome. The mirrored-pair formula, literal character handling, exact rounding rule, and callable interface make the reported follow-up deterministic; the core task matches the visible report at about 85%.

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.

More Apple problems

  • Evaluate DivisionPHONE SCREEN · Seen Nov 2026
  • Reverse a Linked ListPHONE SCREEN · Seen Nov 2026
  • Validate a BST with a Custom ComparisonPHONE SCREEN · Seen Nov 2026
All Apple interview questionsSee Apple hiring insights
Saved
class Solution {
    public String palindromeMatchPercentage(String text) {
        // Write your solution here.
    }
}
Checking account…