Tap here to switch tabs
Problem
Submissions

Problem: Reorder Data in Log Files

Try to solve the Reorder Data in Log Files problem.

Statement

You are given an array of strings logs. Each log is a space delimited string of words, where the first word is an alphanumeric identifier.

There are two categories of logs:

  • Letter logs: All words after the identifier consist exclusively of lowercase English letters.

  • Digit logs: All words after the identifier consist exclusively of digits.

Reorder the logs according to the following rules:

  • All letter logs must appear before any digit logs.

  • Letter logs are sorted lexicographically primarily by their contents. If two letter logs have identical contents, sort them lexicographically by their identifiers.

  • Digit logs must preserve their original relative order.

Return the array of logs after applying the reordering.

Constraints:

  • 1≤1 \leq logs.length ≤100\leq 100

  • 3≤3 \leq logs[i].length ≤100\leq 100

  • All the tokens of logs[i] are separated by a single space.

  • logs[i] is guaranteed to have an identifier and at least 11 word after the identifier.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Reorder Data in Log Files

Try to solve the Reorder Data in Log Files problem.

Statement

You are given an array of strings logs. Each log is a space delimited string of words, where the first word is an alphanumeric identifier.

There are two categories of logs:

  • Letter logs: All words after the identifier consist exclusively of lowercase English letters.

  • Digit logs: All words after the identifier consist exclusively of digits.

Reorder the logs according to the following rules:

  • All letter logs must appear before any digit logs.

  • Letter logs are sorted lexicographically primarily by their contents. If two letter logs have identical contents, sort them lexicographically by their identifiers.

  • Digit logs must preserve their original relative order.

Return the array of logs after applying the reordering.

Constraints:

  • 1≤1 \leq logs.length ≤100\leq 100

  • 3≤3 \leq logs[i].length ≤100\leq 100

  • All the tokens of logs[i] are separated by a single space.

  • logs[i] is guaranteed to have an identifier and at least 11 word after the identifier.