Meta Coding Interview / OA Questions: Palindrome Check and Continuous Subsequence Sum

18 Views
No Comments

Question Statement

Write a function that returns true if a given string is a palindrome (a palindrome is a string that is the same when reversed, if you ignore punctuation and capitalization). Some examples of palindromes are:

  • Race car!
  • A man, a plan, a canal, Panama!

Question

Given a sequence of positive integers and a positive integer total target, return whether a continuous sequence of integers sums up to target.

Example

  • [1, 3, 1, 4, 23], 8 : True (because 3 + 1 + 4 = 8)
  • [1, 3, 1, 4, 23], 7 : False

This problem combines two classic interview tasks. The palindrome check requires normalizing the string by ignoring punctuation and capitalization, then comparing characters with a two-pointer approach. The continuous subsequence sum problem can be solved efficiently with a sliding window because the array contains positive integers: expand the window while the sum is too small, and shrink it from the left when the sum exceeds the target. This gives an O(n) solution.

END
 0