← Meta Interview Insights

Meta·Software Engineer·Online Assessment (OA)·Intermediate

Intermediate
Apr 2026

Summary

Ran into this string counting problem on a Meta SWE online assessment. Pretty straightforward on the surface but worth knowing what they're actually looking for.

Questions Asked (1)

Q1

Given a string of uppercase and lowercase English letters, return the difference between the count of uppercase letters and the count of lowercase letters.

Algorithms & Data Structures
Author's notes

Linear scan, count as you go, done.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the problem and edge cases, then propose a single-pass solution that counts uppercase and lowercase letters using character code ranges. Discuss time and space complexity, and consider potential optimizations or alternative approaches.

Pro tip: Mention that you can compute the difference in one pass without storing separate counts, and discuss how this scales for very large strings or streaming input.

1. Clarify requirements and edge cases

Ask about input constraints (e.g., string length, character set) and edge cases like empty string or strings with only one case. Confirm that the difference is uppercase count minus lowercase count.

2. Outline a straightforward solution

Propose iterating through each character, checking if it's uppercase or lowercase, and maintaining a running difference. This is O(n) time and O(1) space.

3. Discuss implementation details

Explain how to check case: e.g., using ASCII ranges (65-90 for uppercase, 97-122 for lowercase) or built-in methods like isupper()/islower(). Mention that incrementing for uppercase and decrementing for lowercase yields the difference directly.

4. Analyze complexity and trade-offs

State time complexity O(n) and space O(1). Discuss if multiple passes or additional data structures would be needed for variations (e.g., if the string is a stream).

5. Test with examples

Walk through a small example like 'Hello World' to verify the logic: uppercase count 2, lowercase count 8, difference -6. Also test edge cases like empty string (0) and all uppercase (positive difference).

Key Points to Mention

  • Time complexity O(n) and space complexity O(1)
  • Character encoding (ASCII) and case checking methods
  • Handling edge cases: empty string, no letters, mixed cases
  • Single-pass solution with running difference
  • Potential follow-up: handling Unicode or non-English letters
  • Scalability for large inputs or streaming data

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