← Capital One Interview Insights

Capital One·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jul 2026

Summary

Capital One coding screen for a software engineer role. One algorithmic question, pretty focused, nothing too wild.

Questions Asked (1)

Q1

Given a string, count how many length-3 substrings have the same first and last character (case-insensitive). The middle character can be anything.

Algorithms & Data Structures
Author's notes

Not a hard problem once you see it.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the problem: we need to count all length-3 substrings where the first and last characters match case-insensitively. Then, walk through a simple O(n) solution that iterates through the string once, comparing characters at positions i and i+2 after normalizing case, and incrementing a counter when they match.

Pro tip: Mention that you can avoid creating substrings or using extra space by comparing characters directly, which shows attention to efficiency and clean coding. Also, explicitly handle edge cases like strings shorter than 3 characters.

1. Clarify the problem

Confirm that substrings are contiguous, length exactly 3, and that case-insensitivity means 'A' and 'a' are considered equal. Ask if the input can be empty or have non-alphabetic characters.

2. Outline a brute-force approach

Describe generating all length-3 substrings and checking each one, noting it would be O(n) time and O(1) extra space if done without creating new strings, but O(n) substrings if created.

3. Optimize to a single pass

Explain that you can iterate from index 0 to n-3, and for each i, compare the characters at i and i+2 after converting both to lowercase (or using a case-insensitive comparison). Increment a counter if they match.

4. Analyze complexity

State that the optimized solution runs in O(n) time and O(1) extra space, since it only uses a counter and a few variables.

5. Test with examples

Walk through a sample string like 'AbcA' to verify the count, and mention edge cases such as strings of length less than 3 (return 0) and strings with all matching characters.

Key Points to Mention

  • Case-insensitive comparison: convert characters to the same case (e.g., lowercase) before comparing.
  • Single-pass iteration: loop i from 0 to n-3, comparing s[i] and s[i+2].
  • Time complexity: O(n) where n is the length of the string.
  • Space complexity: O(1) extra space, as no additional data structures are needed.
  • Edge cases: strings shorter than 3 characters return 0; handle empty string.
  • Avoid unnecessary substring creation to keep memory usage low.

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