PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

This multi-part question evaluates algorithmic problem-solving across array manipulation, exact fraction comparison, scheduling and simulation with ordered event lists, matrix transformation operations, and string concatenation/counting, exercising skills in data structures, searching, and combinatorial counting.

  • medium
  • Meta
  • Coding & Algorithms
  • Software Engineer

Solve Four Online Assessment Problems

Company: Meta

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

Complete the following four independent coding tasks. For each task, write a function that returns the requested result. 1. **Find the best value index** You are given two equal-length integer arrays, `ratings` and `prices`, where `prices[i] > 0`. For each index `i`, define its value as `ratings[i] / prices[i]`. Return the index with the largest value. If multiple indices have the same value, return the smallest such index. Avoid relying on floating-point division for comparisons; compare fractions exactly. 2. **Schedule round trips** You need to complete `missions` round trips between two locations, `A` and `B`. A round trip consists of one trip from `A` to `B`, followed by one trip from `B` to `A`. You are given two sorted arrays: - `aToB`: times at which you can travel from `A` to `B` - `bToA`: times at which you can travel from `B` to `A` You start at location `A` at time `0`. For each leg, you must choose the earliest available time in the corresponding array that is greater than or equal to your current time. After taking that trip, your current time becomes the chosen time. Return the earliest time after completing all `missions` round trips. If it is impossible to complete all trips, return `-1`. 3. **Execute matrix transformation commands** You are given a 2D matrix and a list of commands. Execute the commands in order and return the final matrix. The command types are: - `swapRows r1 r2`: swap rows `r1` and `r2` - `swapCols c1 c2`: swap columns `c1` and `c2` - `reverseRow r`: reverse the elements in row `r` - `reverseCol c`: reverse the elements in column `c` - `rotate90`: rotate the entire matrix 90 degrees clockwise Use zero-based indices. After a rotation, the matrix dimensions may change. 4. **Count concatenation pairs matching an access code** You are given an array of strings `fragments` and a target string `accessCode`. Count the number of ordered pairs of indices `(i, j)` such that: `fragments[i] + fragments[j] == accessCode` Duplicate strings in `fragments` count separately. An index may be used for both `i` and `j` if it satisfies the condition. Return the total count.

Quick Answer: This multi-part question evaluates algorithmic problem-solving across array manipulation, exact fraction comparison, scheduling and simulation with ordered event lists, matrix transformation operations, and string concatenation/counting, exercising skills in data structures, searching, and combinatorial counting.

Part 1: Find the Best Value Index

You are given two integer arrays, ratings and prices, of equal length. For each index i, define its value as ratings[i] / prices[i], where prices[i] is always positive. Return the index with the largest value. If multiple indices have the same value, return the smallest such index. To avoid precision problems, compare fractions exactly using integer arithmetic instead of floating-point division. If the arrays are empty, return -1.

Constraints

  • 0 <= len(ratings) == len(prices) <= 200000
  • -10^9 <= ratings[i] <= 10^9
  • 1 <= prices[i] <= 10^9
  • If two indices have equal value, return the smaller index

Examples

Input: ([10, 8, 9], [2, 4, 3])

Expected Output: 0

Explanation: The values are 5, 2, and 3, so index 0 is best.

Input: ([1, 2, 3], [2, 4, 6])

Expected Output: 0

Explanation: All ratios are exactly 1/2, so return the smallest index.

Input: ([-1, 2, -3], [1, 2, 1])

Expected Output: 1

Explanation: The values are -1, 1, and -3, so index 1 has the largest value.

Input: ([], [])

Expected Output: -1

Explanation: Empty input has no valid index, so return -1.

Hints

  1. To compare a/b and c/d exactly, compare a*d and c*b instead of dividing.
  2. If you only update the answer when you find a strictly larger ratio, ties automatically keep the smallest index.

Part 2: Schedule Round Trips

You need to complete a given number of round trips between locations A and B. One round trip consists of one trip from A to B, followed by one trip from B to A. You are given two sorted arrays: aToB and bToA. Each element represents one available trip time and can be used at most once. You start at location A at time 0. For each leg, you must take the earliest unused trip in the correct array whose time is greater than or equal to your current time. After taking a trip, your current time becomes that trip's time. Return the earliest possible time after finishing all round trips, or -1 if it is impossible.

Constraints

  • 0 <= missions <= 200000
  • 0 <= len(aToB), len(bToA) <= 200000
  • 0 <= trip time <= 10^9
  • aToB and bToA are sorted in nondecreasing order
  • Each array element represents one trip that can be used at most once

Examples

Input: (2, [1, 5, 10], [2, 6, 10])

Expected Output: 6

Explanation: Take 1 (A->B), then 2 (B->A), then 5 (A->B), then 6 (B->A).

Input: (2, [0, 1], [0, 1])

Expected Output: 1

Explanation: Trips at time 0 can be used for the first round trip, and trips at time 1 for the second.

Input: (2, [1], [2, 3])

Expected Output: -1

Explanation: After using 1 and 2 for the first round trip, there is no remaining A->B trip for the second.

Input: (0, [], [])

Expected Output: 0

Explanation: No round trips are required, so you finish immediately at time 0.

Hints

  1. Because the arrays are sorted and time only moves forward, two pointers are enough.
  2. After you use a trip at index i, the next search in that same array should continue from i + 1.

Part 3: Execute Matrix Transformation Commands

You are given a 2D matrix and a list of commands. Apply the commands in order and return the final matrix. Supported commands are: ('swapRows', r1, r2), ('swapCols', c1, c2), ('reverseRow', r), ('reverseCol', c), and ('rotate90',), which rotates the entire matrix 90 degrees clockwise. All indices are zero-based and guaranteed to be valid at the moment each command is executed.

Constraints

  • 0 <= number of rows, columns <= 100
  • 0 <= number of commands <= 1000
  • All rows in the input matrix have the same length
  • All command indices are valid for the matrix state when that command is processed

Examples

Input: ([[1, 2, 3], [4, 5, 6]], [('swapRows', 0, 1), ('reverseRow', 0)])

Expected Output: [[6, 5, 4], [1, 2, 3]]

Explanation: After swapping rows, the first row becomes [4, 5, 6], then reversing it gives [6, 5, 4].

Input: ([[1, 2, 3], [4, 5, 6]], [('rotate90',)])

Expected Output: [[4, 1], [5, 2], [6, 3]]

Explanation: A 2x3 matrix becomes a 3x2 matrix after one clockwise rotation.

Input: ([[1, 2], [3, 4], [5, 6]], [('swapCols', 0, 1), ('reverseCol', 1)])

Expected Output: [[2, 5], [4, 3], [6, 1]]

Explanation: Swapping columns gives [[2, 1], [4, 3], [6, 5]], then reversing column 1 changes it to [5, 3, 1].

Input: ([[7]], [('rotate90',), ('reverseCol', 0), ('reverseRow', 0)])

Expected Output: [[7]]

Explanation: A single-element matrix stays the same under all these operations.

Hints

  1. Most commands affect only one row or one column, but rotate90 rebuilds the whole matrix.
  2. For a clockwise rotation, the new row c comes from old column c read from bottom to top.

Part 4: Count Concatenation Pairs Matching an Access Code

You are given an array of strings fragments and a target string accessCode. Count the number of ordered pairs of indices (i, j) such that fragments[i] + fragments[j] == accessCode. Duplicate strings count separately. The same index may be used for both i and j if it satisfies the condition.

Constraints

  • 0 <= len(fragments) <= 200000
  • 0 <= len(accessCode) <= 200000
  • The total length of all strings in fragments is at most 200000
  • Strings may be empty
  • The same index may be used for both positions in a pair

Examples

Input: (['ab', 'c', 'a', 'bc'], 'abc')

Expected Output: 2

Explanation: The valid ordered pairs are ('ab', 'c') and ('a', 'bc').

Input: (['a', 'a', ''], 'a')

Expected Output: 4

Explanation: Pairs are ('', 'a') using either 'a', and ('a', '') using either 'a', for a total of 4.

Input: (['', 'x', ''], '')

Expected Output: 4

Explanation: There are two empty strings, so every ordered pair of empty-string indices is valid: 2 * 2 = 4.

Input: (['aa'], 'aaaa')

Expected Output: 1

Explanation: The only valid pair is index (0, 0), which is allowed.

Input: (['a', 'b'], 'abx')

Expected Output: 0

Explanation: No ordered pair concatenates to 'abx'.

Hints

  1. If you fix the left fragment, the right fragment is completely determined.
  2. Use a frequency map so duplicate strings contribute multiple pairs automatically.
Last updated: May 18, 2026

Loading coding console...

PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Solve Tree Columns And Maze Variants - Meta (medium)
  • Solve Tree Diameter and Palindromic Counts - Meta (medium)
  • Simulate Monster Team Battles - Meta (hard)
  • Solve a Key-Door Corridor Maze - Meta (medium)
  • Solve Array Merge and Parentheses Cleanup - Meta (medium)