PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches

Quick Overview

This multi-part prompt evaluates proficiency in core programming competencies: string parsing and character classification, simulation/greedy processing of linear movement and arrays, matrix manipulation including row/column operations and rotations, and undirected graph path reconstruction.

  • easy
  • Meta
  • Coding & Algorithms
  • Machine Learning Engineer

Solve four OA string/array/matrix/graph tasks

Company: Meta

Role: Machine Learning Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Take-home Project

You have 4 independent coding tasks. ## 1) Uppercase vs lowercase count difference Given a string `s` consisting of ASCII letters (and possibly other characters), count: - `U` = number of uppercase letters `'A'..'Z'` - `L` = number of lowercase letters `'a'..'z'` Return the absolute difference `|U - L|`. **Input:** string `s` **Output:** integer --- ## 2) Scooter-walking trip (total distance ridden) You travel along a 1D line from position `0` to position `target > 0`. There are scooters located at positions given by an array `scooters` (not necessarily sorted). Each scooter can be ridden for **up to 10 distance units** and then becomes unusable. Rules of movement: 1. You start at position `pos = 0`. 2. If there exists a scooter at a position `>= pos` and `<= target`, you **walk** to the closest scooter on your right (i.e., the smallest scooter position `p` such that `p >= pos`). 3. From that scooter position `p`, you **ride** it forward for `min(10, target - p)` distance units, ending at `pos = p + min(10, target - p)`. 4. Repeat steps 2–3 until you reach `target` or there is no scooter at or ahead of your current position before `target`. If no such scooter exists, you walk the remaining distance to `target`. Return the **total distance traveled while riding scooters** (do not include walking distance). **Input:** integer `target`, integer array `scooters` **Output:** integer total ridden distance --- ## 3) Apply operations to a matrix Given an `m x n` matrix `A` and a list of operations, apply them in order and return the final matrix. Supported operations: - `SWAP_ROW r1 r2`: swap row `r1` and row `r2` - `SWAP_COL c1 c2`: swap column `c1` and column `c2` - `REVERSE_ROW r`: reverse the elements within row `r` (e.g., `[1,2,3] -> [3,2,1]`) - `REVERSE_COL c`: reverse the elements within column `c` - `ROTATE_CW`: rotate the entire matrix 90 degrees clockwise (dimensions become `n x m`) Assume indices are 0-based and all operations are valid. **Input:** matrix `A`, list of operations (with parameters) **Output:** final matrix after all operations --- ## 4) Reconstruct travel path from unordered adjacent photos You forgot the exact travel order, but you have `n-1` photos. Each photo records two **consecutive** locations you visited, but **the order within a photo is unknown**. Example: `[[1,2],[3,2],[4,3]]` corresponds to the path `[1,2,3,4]` (or the reverse `[4,3,2,1]`). Given an array `photos` of length `n-1`, where each element is a pair `[a, b]` representing an undirected adjacency between consecutive locations, reconstruct and return the full path as an array of length `n`. You may return the path in either direction. **Input:** array `photos` of pairs **Output:** array `path` listing all locations in order **Assumptions:** The underlying graph formed by the pairs is guaranteed to be a simple path (i.e., exactly two endpoints with degree 1, all others degree 2).

Quick Answer: This multi-part prompt evaluates proficiency in core programming competencies: string parsing and character classification, simulation/greedy processing of linear movement and arrays, matrix manipulation including row/column operations and rotations, and undirected graph path reconstruction.

Part 1: Absolute Difference Between Uppercase and Lowercase Counts

Given a string s that may contain ASCII letters and other characters, count how many characters are uppercase English letters ('A' to 'Z') and how many are lowercase English letters ('a' to 'z'). Return the absolute difference between those two counts. Non-letter characters do not affect the answer.

Constraints

  • 0 <= len(s) <= 10^5
  • s may contain any ASCII characters
  • Only characters in 'A'..'Z' and 'a'..'z' should be counted

Examples

Input: ("",)

Expected Output: 0

Explanation: Empty string: both counts are 0.

Input: ("aA",)

Expected Output: 0

Explanation: One uppercase and one lowercase letter.

Input: ("Hello, WORLD!",)

Expected Output: 2

Explanation: Uppercase = 6 (H, WORLD), lowercase = 4 (ello), so answer is 2.

Input: ("1234!?",)

Expected Output: 0

Explanation: There are no letters.

Input: ("z",)

Expected Output: 1

Explanation: Uppercase = 0, lowercase = 1.

Hints

  1. Scan the string once and maintain two counters.
  2. Compare each character directly against the uppercase and lowercase ASCII ranges.

Part 2: Scooter-Walking Trip Total Ridden Distance

You travel on a 1D line from position 0 to a positive target. Scooters are placed at given positions, possibly unsorted. Starting from your current position pos, if there is at least one scooter at a position p such that p >= pos and p <= target, you must walk to the closest such scooter on your right, meaning the smallest valid p. From that scooter, you can ride forward for at most 10 distance units, or until reaching target, whichever comes first. Then you repeat from your new position. If no scooter exists at or ahead of your current position before target, you walk the rest of the way. Return only the total distance ridden on scooters.

Constraints

  • 1 <= target <= 10^9
  • 0 <= len(scooters) <= 2 * 10^5
  • 0 <= scooters[i] <= 10^9
  • Scooter positions may be unsorted and may contain duplicates

Examples

Input: (25, [5, 15])

Expected Output: 20

Explanation: Ride from 5 to 15 (10 units), then from 15 to 25 (10 units).

Input: (23, [12, 2, 20])

Expected Output: 20

Explanation: Walk to 2, ride to 12; ride from 12 to 22; then walk the last 1 unit.

Input: (8, [0, 3, 20])

Expected Output: 8

Explanation: A scooter is available at position 0, so you can ride directly to target.

Input: (10, [])

Expected Output: 0

Explanation: No scooters exist, so the whole trip is walking.

Input: (10, [10])

Expected Output: 0

Explanation: You walk to position 10 and have already reached target, so the ridden distance is 0.

Hints

  1. Since your position only moves forward, sorting the scooter positions is very helpful.
  2. After sorting, use a pointer to find the first scooter that is not behind your current position.

Part 3: Apply Sequential Operations to a Matrix

Given a matrix A and a list of operations, apply the operations in order and return the final matrix. Each operation is represented as a list or tuple whose first element is the operation name. Supported operations are: ['SWAP_ROW', r1, r2], ['SWAP_COL', c1, c2], ['REVERSE_ROW', r], ['REVERSE_COL', c], and ['ROTATE_CW']. Indices are 0-based, and every operation is guaranteed to be valid for the current matrix shape when it is applied.

Constraints

  • 1 <= number of rows, number of columns <= 200
  • 0 <= len(operations) <= 1000
  • All indices in operations are valid at the moment the operation is applied
  • Matrix values are integers

Examples

Input: ([[1, 2], [3, 4]], [['SWAP_ROW', 0, 1], ['SWAP_COL', 0, 1]])

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

Explanation: First swap the rows, then swap the two columns.

Input: ([[1, 2, 3], [4, 5, 6]], [['REVERSE_ROW', 1], ['REVERSE_COL', 0]])

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

Explanation: Row 1 becomes [6,5,4], then column 0 is reversed.

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

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

Explanation: The 2x3 matrix becomes a 3x2 matrix after rotation.

Input: ([[1, 2], [3, 4], [5, 6]], [['ROTATE_CW'], ['SWAP_ROW', 0, 1], ['SWAP_COL', 0, 1]])

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

Explanation: This checks that later row and column indices are interpreted after rotation.

Input: ([[7]], [['ROTATE_CW'], ['REVERSE_ROW', 0], ['REVERSE_COL', 0]])

Expected Output: [[7]]

Explanation: A 1x1 matrix stays unchanged under all valid operations.

Hints

  1. Most operations can be simulated directly on the matrix.
  2. A 90-degree clockwise rotation can be built by reversing the row order and then transposing.

Part 4: Reconstruct a Travel Path from Unordered Adjacent Photos

You are given photos, where each photo contains two locations that were visited consecutively, but the order inside each photo is unknown. Each pair [a, b] therefore represents an undirected edge between consecutive locations. The full set of pairs is guaranteed to form one simple path. Reconstruct the entire path. To make the output deterministic, if both directions are valid, return the one whose first location is smaller. Location IDs are integers.

Constraints

  • 2 <= n <= 2 * 10^5, where n is the number of locations in the path
  • len(photos) = n - 1
  • Each photo is a pair of integers [a, b]
  • The graph formed by the pairs is guaranteed to be a simple path

Examples

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

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

Explanation: The path is 1-2-3-4, and 1 is the smaller endpoint.

Input: ([[5, 4], [2, 3], [4, 3]],)

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

Explanation: The same path can be read in reverse, but we start from the smaller endpoint 2.

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

Expected Output: [-1, 0, 1, 2]

Explanation: The path uses negative and positive labels.

Input: ([[10, 20]],)

Expected Output: [10, 20]

Explanation: With one photo, the path contains exactly two locations.

Input: ([[7, 8], [5, 6], [6, 7]],)

Expected Output: [5, 6, 7, 8]

Explanation: The photos are unordered, but the underlying graph is still a simple path.

Hints

  1. In a path graph, the two endpoints are exactly the nodes with degree 1.
  2. Once you start from an endpoint, keep moving to the neighbor that is not the previous node.
Last updated: May 6, 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 Two Backtracking Array Problems - Meta (hard)
  • Solve Array, Matrix, and Recommendation Problems - Meta (medium)
  • Find a String Containing Another - Meta (medium)
  • Solve Subarray Sum and Local Minimum - Meta (hard)
  • Validate abbreviations and brackets - Meta (medium)