mediumStringsPattern: Mixed

Lexicographical Phrase Reconstructor Solution

Problem Statement

Given a collection of disjoint phrases, arrange them lexicographically to form the lexicographically smallest possible string.

Examples

Example 1:
Input:{"phrases":["apple","banana","cherry"]}
Output:applebananacherry
Example 2:
Input:{"phrases":["dog","cat","bird"]}
Output:birdcatdog

Constraints

  • Each phrase is at most 50 characters long.
  • The total number of phrases does not exceed 200.
Time: O(n log n) Space: O(n)
The optimal approach is to use a sorting algorithm to sort the phrases lexicographically, and then concatenate them in the sorted order. This approach has a time complexity of O(n log n) due to the sorting step.

Run, Test & Submit Code

Ready to practice this challenge? Launch our interactive compilation environment with compiler validation.

Solve on Interactive Workspace

Tested Solutions

No solution code is currently loaded.
Complete this code in the workspace editor.