← Meta Interview Insights

Meta·Software Engineer·Onsite - Coding / Algorithms·Intermediate

Intermediate
May 2026

Summary

Meta SWE coding round with two questions back to back. Nothing too brutal but the pairing felt deliberate, like they wanted to see if you could shift gears quickly.

Questions Asked (2)

Q1

Given two strings where one defines a custom character ordering, rearrange the second string so its characters appear in that custom order. Characters not present in the ordering string can go anywhere.

Algorithms & Data Structures
Author's notes

Pretty approachable once you see it as a counting problem.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the problem constraints and edge cases, then propose a solution using a hash map to store the custom order indices. Iterate through the custom order string, appending matching characters from the second string, then append any remaining characters. Discuss time and space complexity and potential optimizations.

Pro tip: Demonstrate awareness of Unicode and case sensitivity by asking whether the strings are ASCII or Unicode and if case matters. Also, mention that if the custom order is not a permutation of all characters, you can use a frequency map to handle duplicates efficiently.

1. Clarify requirements and edge cases

Ask about character set (ASCII/Unicode), case sensitivity, and whether the custom order string contains all characters from the second string. Confirm that characters not in the order can be placed anywhere.

2. Choose data structures

Use a hash map to map each character in the custom order to its index. Optionally, use a frequency map (or counting sort) for the second string to handle duplicates efficiently.

3. Outline algorithm

Iterate through the custom order string; for each character, append it to the result as many times as it appears in the second string (using the frequency map). Then append any remaining characters not in the custom order.

4. Analyze complexity

State that the time complexity is O(n + m) where n and m are the lengths of the strings, and space complexity is O(k) where k is the number of unique characters. Mention that this is optimal.

5. Discuss optimizations and trade-offs

If the custom order is a permutation of all characters, you can sort using a custom comparator. For large alphabets, consider using an array if the character set is small (e.g., ASCII).

Key Points to Mention

  • Hash map for O(1) lookup of custom order indices
  • Frequency map or counting sort to handle duplicates efficiently
  • Time complexity O(n + m) and space complexity O(k)
  • Edge cases: empty strings, characters not in custom order, case sensitivity
  • Alternative approach: custom comparator sort (O(n log n)) and when it's preferable
  • Stability: preserving relative order of characters not in custom order (if required)

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

Q2

Given a word and an abbreviation string where digits represent the count of skipped characters, determine if the abbreviation is a valid representation of the word. No leading zeros allowed, and non-digit characters must match exactly.

Algorithms & Data Structures
Author's notes

This one tripped me up more than I expected for a follow-up.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use a two-pointer technique to traverse the word and abbreviation simultaneously, handling digits by parsing the full number and skipping that many characters in the word. Validate that digits don't have leading zeros and that non-digit characters match exactly, ensuring the entire word is consumed.

Pro tip: Clarify edge cases upfront, such as empty strings, abbreviations with only digits, and numbers exceeding word length, to demonstrate thoroughness. Also, discuss time and space complexity (O(n) time, O(1) space) to show efficiency awareness.

1. Clarify requirements and edge cases

Confirm with the interviewer the rules: no leading zeros, digits represent skipped characters, and non-digits must match. Discuss edge cases like empty strings, consecutive digits, and numbers larger than the word length.

2. Choose two-pointer approach

Use two pointers, one for the word and one for the abbreviation, to traverse both strings. This allows efficient comparison and skipping without extra space.

3. Parse digits and skip characters

When encountering a digit, parse the entire number (checking for leading zeros) and advance the word pointer by that count. Ensure the count doesn't exceed the remaining word length.

4. Compare non-digit characters

For non-digit characters, check if they match the current character in the word. If not, return false. Advance both pointers.

5. Validate full consumption

After traversal, ensure both pointers have reached the end of their respective strings. If not, the abbreviation is invalid.

Key Points to Mention

  • Two-pointer technique for O(n) time and O(1) space complexity.
  • Handling of leading zeros: if a digit is '0' and it's the start of a number, return false.
  • Parsing multi-digit numbers correctly (e.g., '12' means skip 12 characters).
  • Edge cases: empty word, abbreviation with only digits, number exceeding word length.
  • Ensuring the entire word is consumed by the abbreviation.
  • Character matching for non-digit characters.

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