Jobs
Interviews

Solve Sort Log Files using Python Language

Solve Sort Log Files using Python to enhance your skills with python coding practice , master coding concepts, and prepare for interviews with practical exercises and detailed solutions.

Sort Log Files

Difficulty : Easy

Categories :

  • Sorting algorithms

Given an array of strings logs, where each log entry is of the form "id content", sort the logs with the following rules:

  1. Letter logs (content starts with letters) come before digit logs (content starts with digits)
  2. Letter logs are sorted by their content; if contents are same, sort by their IDs
  3. Digit logs maintain their relative ordering

Constraints:

  • 1 ≤ logs.length ≤ 100
  • 3 ≤ logs[i].length ≤ 100
  • All IDs are unique
  • Each log has at least one word after its ID

Examples:

Input: ["dig1 8", "let1 art", "dig2 3", "let2 own"]
Output: ["let1 art", "let2 own", "dig1 8", "dig2 3"]
Explanation: Letter logs come first, sorted by content
Input: ["dig1 1", "let1 cat", "let2 cat"]
Output: ["let1 cat", "let2 cat", "dig1 1"]
Explanation: When contents tie, sort by ID

Coding works best on a laptop or desktop, with a keyboard and a wider editor. You can read the problem here and solve it there.

Problem Solving

Input

What You'll Find Here

Interactive Exercises Practice coding with problems designed for beginners and experts.

Step-by-Step Solutions Understand every step of the solution process.

Real-World Scenarios Apply your skills to real-world problems and boost your confidence.

Choose from the following categories