← Meta Interview Insights

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

Intermediate
Apr 2026

Summary

Meta SWE coding round, four back-to-back problems covering a pretty wide range of topics. Nothing felt impossible but the matrix transformation one slowed me down more than I expected.

Questions Asked (4)

Q1

Given two equal-length arrays of ratings and prices, find the index with the highest ratings-to-price ratio. Ties go to the smaller index, and you must compare fractions exactly without floating-point division.

Algorithms & Data Structures
Author's notes

The no-floating-point constraint is the whole point of this problem and I almost missed it.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, clarify that the goal is to find the index maximizing ratings[i]/prices[i] without floating-point division. Then, iterate through the arrays, maintaining the best index and comparing each candidate fraction to the current best using cross-multiplication (ratings[i] * prices[best] > ratings[best] * prices[i]). Handle ties by keeping the smaller index (i.e., only update if strictly greater).

Pro tip: Mention that cross-multiplication avoids precision issues and works for positive integers; also note that if prices can be zero, you must handle that edge case separately (e.g., treat as infinite ratio or skip).

1. Clarify assumptions and edge cases

Confirm that arrays are equal length, ratings and prices are positive integers (or handle zeros), and that ties go to the smaller index. Ask about input size to discuss time complexity.

2. Initialize best index

Start with best = 0 as the initial candidate, assuming the first element is valid (or handle empty arrays if allowed).

3. Iterate and compare fractions exactly

For each i from 1 to n-1, compare ratings[i]/prices[i] with ratings[best]/prices[best] using cross-multiplication: if ratings[i] * prices[best] > ratings[best] * prices[i], update best = i. If equal, do not update to preserve smaller index.

4. Return the best index

After the loop, return best as the index with the highest ratings-to-price ratio.

5. Analyze complexity and discuss optimizations

State that the solution runs in O(n) time and O(1) extra space. Mention that no better asymptotic complexity is possible since all elements must be examined at least once.

Key Points to Mention

  • Avoid floating-point division to prevent precision errors; use cross-multiplication for exact comparison.
  • Tie-breaking rule: only update the best index when the new ratio is strictly greater, ensuring the smaller index is kept.
  • Time complexity: O(n) single pass; space complexity: O(1).
  • Edge cases: empty arrays (if allowed), zero prices (handle division by zero), negative numbers (if applicable).
  • Potential overflow: cross-multiplication may exceed integer limits; consider using 64-bit integers or arbitrary precision if needed.
  • Alternative approaches: using rational numbers or comparing via floating-point with epsilon (not recommended due to precision).

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

Q2

You need to complete a given number of round trips between two locations using sorted departure time arrays. Each leg requires picking the earliest available time at or after your current time. Return the finish time or -1 if it's impossible.

Algorithms & Data Structures
Author's notes

Binary search on each leg to find the earliest valid departure.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the problem as a sequence of binary searches: for each leg, find the earliest departure time in the sorted array that is >= current time, update current time to that departure plus travel time, and repeat for all required round trips. If at any point no valid departure exists, return -1. This yields O(k log n) time where k is the number of legs and n is the array length.

Pro tip: Clarify the exact semantics of 'round trip' and whether travel time is symmetric; also mention that using binary search (e.g., bisect) is optimal, but if the arrays are small, a linear scan might be simpler and equally acceptable.

1. Clarify the problem

Confirm the number of round trips, whether each round trip consists of two legs (outbound and return), and whether travel time is the same in both directions. Also verify the input format: two sorted arrays of departure times.

2. Define the state

Maintain a variable for the current time, initially set to the earliest possible start time (e.g., 0 or the first departure time). For each leg, you will update this time based on the chosen departure.

3. Choose the algorithm

For each leg, perform a binary search on the relevant sorted array to find the smallest departure time >= current time. If found, update current time to that departure plus the travel time; otherwise, return -1.

4. Iterate over all legs

Repeat the binary search for each required leg (2 * number of round trips). Alternate between the two arrays for outbound and return legs.

5. Return the result

After processing all legs, return the final current time. If any leg fails, return -1 immediately.

Key Points to Mention

  • Binary search (or bisect) to efficiently find the earliest valid departure time in a sorted array.
  • Time complexity: O(k log n) where k is the total number of legs and n is the size of the departure arrays.
  • Edge cases: empty arrays, no valid departure, zero round trips, and large numbers of trips.
  • Handling of travel time: whether it's added to the departure time to get arrival, and if it's the same for both directions.
  • Alternating between the two arrays for outbound and return legs.
  • Early termination: return -1 as soon as a leg cannot be completed.

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

Q3

Execute a sequence of matrix transformation commands in order: swap rows, swap columns, reverse a row, reverse a column, or rotate the whole matrix 90 degrees clockwise. Return the final matrix state.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

This one took the most time.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the input format and constraints, then choose an efficient representation (e.g., 2D array) and apply each command sequentially. For rotation, consider using a coordinate transformation or in-place rotation to avoid unnecessary copying, and discuss trade-offs between simplicity and performance.

Pro tip: Mention that you can handle rotation by adjusting indices or using a transpose-reverse approach, and highlight that in-place operations can save memory but may complicate code—show awareness of these trade-offs.

1. Clarify requirements and constraints

Ask about matrix dimensions, command frequency, and whether operations should be in-place or can return a new matrix. Confirm if rotation is always 90 degrees clockwise and if commands are given as strings or enums.

2. Choose data structure and representation

Decide between a 2D array, list of lists, or a flat array with index math. Consider if a coordinate mapping approach (e.g., tracking row/col transformations) could simplify repeated operations.

3. Implement each operation

Write helper functions for swap rows, swap columns, reverse row, reverse column, and rotate. For rotation, use either a new matrix or in-place transpose and reverse to achieve O(1) extra space.

4. Process commands sequentially

Iterate through the command list, applying each operation to the current matrix state. Ensure operations mutate the matrix correctly and handle edge cases like empty matrix or invalid indices.

5. Analyze complexity and optimize

Discuss time and space complexity: each operation is O(n) or O(n^2) for rotation. Suggest optimizations like lazy evaluation or composing transformations if many commands are given.

Key Points to Mention

  • Time and space complexity of each operation, especially rotation (O(n^2) time, O(1) space if in-place).
  • In-place rotation using transpose and reverse for 90-degree clockwise rotation.
  • Handling edge cases: empty matrix, 1x1 matrix, non-square matrices (if allowed).
  • Trade-offs between simplicity (creating new matrices) and efficiency (in-place operations).
  • Potential for composing transformations to avoid repeated O(n^2) rotations.
  • Testing strategy: unit tests for each operation and integration tests for command sequences.

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

Q4

Count the number of ordered index pairs (i, j) in an array of strings where concatenating fragments[i] and fragments[j] equals a target string. Duplicates count separately, and i can equal j.

Algorithms & Data Structures
Author's notes

Felt like the easiest of the four.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use a hash map to store the frequency of each fragment. For each fragment, compute the required complement (target minus prefix or suffix) and look it up in the map, summing frequencies. Handle the case where the fragment itself is the complement by ensuring correct counting (e.g., using frequency before or after adding).

Pro tip: Clarify edge cases upfront: empty strings, fragments longer than target, and duplicates. Also, discuss time/space complexity trade-offs and potential optimizations like using a trie for prefix matching if needed.

1. Understand the problem

Restate the problem: count ordered pairs (i, j) where fragments[i] + fragments[j] == target. Note that i can equal j and duplicates count separately.

2. Choose data structure

Use a hash map to store the frequency of each fragment. This allows O(1) lookups for complements.

3. Iterate and count

For each fragment, check if it is a prefix of target. If so, compute the needed suffix and add its frequency from the map. Similarly, check if it is a suffix and add the frequency of the needed prefix. Be careful to avoid double-counting when the fragment itself is the complement.

4. Handle self-pairing

For each fragment, check if it is a prefix of the target. If it is, compute the remainder and add its frequency from the map to the total count. This naturally handles i=j and duplicates.

5. Analyze complexity

Time complexity: O(n * L) where n is number of fragments and L is average length for prefix check, or O(n * len(target)) worst case. Space complexity: O(n) for the hash map.

Key Points to Mention

  • Use a hash map to store fragment frequencies for O(1) complement lookups.
  • Only fragments that are prefixes of the target can be the first part of a valid concatenation.
  • Handle duplicates by counting frequencies, and i=j is naturally included when iterating over all indices.
  • Edge cases: empty strings, fragments longer than target, and target itself as a fragment.
  • Time complexity: O(n * L) where L is the length of the target for prefix checks, space O(n).
  • Potential optimization: use a trie to quickly find all prefixes of the target among fragments, but hash map is sufficient for most cases.

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