Ctrl K

Text Entries First

Medium
A server journal is an array of strings entries. Each string is a sequence of words separated by single spaces. The first word is the entry's tag (lowercase English letters and digits), followed by at least one word of content. There are two kinds of entries: - **text** entries, where every content word consists of lowercase English letters; - **numeric** entries, where every content word consists of digits. Reorder the journal as follows: 1. All text entries come before all numeric ones. 2. Text entries are sorted lexicographically by content (everything after the tag, taken as one string). When two entries have the same content, the one with the lexicographically smaller tag goes first. 3. Numeric entries keep their original relative order. Return the reordered journal.
Example 1
entries=["srv2 404 17", "db1 disk full", "srv1 200", "web3 cache miss", "db2 disk full"] → ['web3 cache miss', 'db1 disk full', 'db2 disk full', 'srv2 404 17', 'srv1 200']

The text entries are disk full (twice) and cache miss. cache miss comes first, and the two disk full entries are ordered by tag: db1 before db2. The numeric entries srv2 and srv1 keep their original order at the end.

Example 2
entries=["a9 7 7", "b1 3"] → ['a9 7 7', 'b1 3']

There are no text entries, so the order does not change.

Example 3
entries=["x1 zoo", "y1 zoo keeper", "z1 7"] → ['x1 zoo', 'y1 zoo keeper', 'z1 7']
Constraints
  • 1 ≤ len(entries) ≤ 100
  • 3 ≤ len(entries[i]) ≤ 100
  • Words are separated by exactly one space; every entry has a tag and at least one content word
  • A tag consists of lowercase English letters and digits; the content is either all lowercase-letter words or all digit words
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsAnagram Buckets MediumBiggest Number From Pieces MediumA Subsequence of One Word Only MediumLongest Word by Crossing Out MediumClosest Clock Readings Medium
loading Python…
Input
entries=["srv2 404 17", "db1 disk full", "srv1 200", "web3 cache miss", "db2 disk full"]
Expected
['web3 cache miss', 'db1 disk full', 'db2 disk full', 'srv2 404 17', 'srv1 200']

Run checks the first 3 tests in your browser. Submit checks all 51 tests on the server, hidden ones included.