← Visa Interview Insights

Visa·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jul 2026

Summary

Visa SWE interview, coding round with a string problem. Pretty standard stuff but the substring angle made me second-guess my approach midway through.

Questions Asked (1)

Q1

Given a string, how would you count the number of palindromic substrings it contains?

Algorithms & Data Structures
Author's notes

Started with the brute force and they let me run with it for a bit before nudging me toward something better.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the problem: count all substrings that are palindromes, including duplicates. Then present an efficient solution using expand-around-center, which checks each possible center in O(n^2) time and O(1) space, and discuss trade-offs with other approaches like dynamic programming or Manacher's algorithm.

Pro tip: Mention that you would handle both odd and even length palindromes by expanding around each character and each gap between characters, and note that this approach avoids the O(n^2) space of DP while being simpler than Manacher's.

1. Clarify the problem

Confirm that we need to count all palindromic substrings, including single characters and duplicates, and discuss input constraints (e.g., string length, character set).

2. Choose an approach

Select expand-around-center for its O(n^2) time and O(1) space, or mention dynamic programming (O(n^2) time and space) and Manacher's algorithm (O(n) time) as alternatives.

3. Explain the algorithm

For each index i, expand around center i for odd-length palindromes and around center i and i+1 for even-length palindromes, incrementing a counter for each valid expansion.

4. Analyze complexity

State that the time complexity is O(n^2) because each center can expand up to O(n) times, and space complexity is O(1) as only a few variables are used.

5. Test with examples

Walk through a small example like 'aaa' to show the count (6) and verify the logic, and mention edge cases like empty string or single character.

Key Points to Mention

  • Expand-around-center technique for odd and even length palindromes
  • Time complexity O(n^2) and space complexity O(1) for the optimal simple approach
  • Comparison with dynamic programming (O(n^2) time and space) and Manacher's algorithm (O(n) time)
  • Handling of edge cases: empty string, single character, all same characters
  • Counting duplicates as separate substrings (e.g., 'aaa' has 6 palindromic substrings)
  • Potential follow-up: optimizing to O(n) with Manacher's algorithm if needed

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.