PracHub
QuestionsPremiumLearningGuidesInterview PrepNEWCoaches
|Home/Coding & Algorithms/Meta

Sort a string by custom order

Last updated: Mar 29, 2026

Quick Overview

This question evaluates string manipulation, custom ordering, stable reordering, and algorithmic complexity analysis with attention to space usage, placed in the Coding & Algorithms domain and focusing on practical algorithm design and implementation.

  • Medium
  • Meta
  • Coding & Algorithms
  • Software Engineer

Sort a string by custom order

Company: Meta

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: Medium

Interview Round: Technical Screen

Given a priority string P of distinct characters and a text string S, reorder S so that all characters appearing in P come first and are grouped in the exact order specified by P, followed by all characters not in P while preserving their original relative order. Return the reordered string. Design an O(|P| + |S|) algorithm and discuss space usage. How would you adapt the solution for Unicode and for case-insensitive ordering?

Quick Answer: This question evaluates string manipulation, custom ordering, stable reordering, and algorithmic complexity analysis with attention to space usage, placed in the Coding & Algorithms domain and focusing on practical algorithm design and implementation.

Related Interview Questions

  • Solve Tree Columns And Maze Variants - Meta (medium)
  • Solve a Key-Door Corridor Maze - Meta (medium)
  • Solve Array Merge and Parentheses Cleanup - Meta (medium)
  • Solve Two Backtracking Array Problems - Meta (hard)
  • Solve Maze and Suffix Problems - Meta (medium)
Meta logo
Meta
Aug 7, 2025, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
1
0

Given a priority string P of distinct characters and a text string S, reorder S so that all characters appearing in P come first and are grouped in the exact order specified by P, followed by all characters not in P while preserving their original relative order. Return the reordered string. Design an O(|P| + |S|) algorithm and discuss space usage. How would you adapt the solution for Unicode and for case-insensitive ordering?

Comments (0)

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