PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Meta

Solve string transform and min-move sorting

Last updated: Mar 29, 2026

Quick Overview

This two-part problem evaluates string manipulation and algorithmic problem-solving competencies, specifically rule-based text transformation and computation of minimal movement cost for sorting via adjacent swaps.

  • medium
  • Meta
  • Coding & Algorithms
  • Software Engineer

Solve string transform and min-move sorting

Company: Meta

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

## Problem 1: "Goat Latin"-style string transformation You are given a sentence `s` consisting of words separated by single spaces. Transform it into a new sentence using these rules: 1. For each word: - If it begins with a vowel (`a,e,i,o,u` or `A,E,I,O,U`), keep the word as-is. - Otherwise, move its first character to the end of the word. 2. Append the string `"ma"` to the end of the word. 3. Append the letter `'a'` repeated `i` times, where `i` is the 1-based index of the word in the sentence. 4. Join the transformed words with single spaces. **Input:** a string `s` **Output:** the transformed string --- ## Problem 2: Minimum total moving distance to sort an array You are given an integer array `arr` (may contain duplicates), e.g. `[5, 2, 2, 4, 3]`. You want to reorder the array into **nondecreasing** order. - An element can be moved by swapping with adjacent elements. - The **cost** of moving an element is the number of adjacent positions it shifts (equivalently, each adjacent swap costs 1). Return the **minimum total cost** required to transform `arr` into sorted order. **Input:** integer array `arr` **Output:** minimum total moving distance (an integer) **Notes/constraints (typical interview scale):** - Aim for better than `O(n^2)` time for large `n`. - Be careful with duplicates (multiple valid sorted arrangements exist).

Quick Answer: This two-part problem evaluates string manipulation and algorithmic problem-solving competencies, specifically rule-based text transformation and computation of minimal movement cost for sorting via adjacent swaps.

Related Interview Questions

  • Find Shortest Unique Prefixes - Meta (medium)
  • Compute Exclusive Execution Times - Meta (medium)
  • Solve Tree Columns And Maze Variants - Meta (medium)
  • Solve Tree Diameter and Palindromic Counts - Meta (medium)
  • Simulate Monster Team Battles - Meta (hard)
Meta logo
Meta
Jan 22, 2026, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
5
0
Loading...

Problem 1: "Goat Latin"-style string transformation

You are given a sentence s consisting of words separated by single spaces.

Transform it into a new sentence using these rules:

  1. For each word:
    • If it begins with a vowel ( a,e,i,o,u or A,E,I,O,U ), keep the word as-is.
    • Otherwise, move its first character to the end of the word.
  2. Append the string "ma" to the end of the word.
  3. Append the letter 'a' repeated i times, where i is the 1-based index of the word in the sentence.
  4. Join the transformed words with single spaces.

Input: a string s

Output: the transformed string

Problem 2: Minimum total moving distance to sort an array

You are given an integer array arr (may contain duplicates), e.g. [5, 2, 2, 4, 3].

You want to reorder the array into nondecreasing order.

  • An element can be moved by swapping with adjacent elements.
  • The cost of moving an element is the number of adjacent positions it shifts (equivalently, each adjacent swap costs 1).

Return the minimum total cost required to transform arr into sorted order.

Input: integer array arr

Output: minimum total moving distance (an integer)

Notes/constraints (typical interview scale):

  • Aim for better than O(n^2) time for large n .
  • Be careful with duplicates (multiple valid sorted arrangements exist).

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Meta•More Software Engineer•Meta Software Engineer•Meta Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,000+ 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.