Katkat

Solve Four Online Assessment Problems

MetaSoftware Engineer · Technical Screen

Last updated

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.

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.

  1. 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.

  1. 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.

  1. 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.