Sort and merge string lists by length
Company: Apple
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: Medium
Interview Round: Technical Screen
Quick Answer: This question evaluates understanding of sorting algorithms, stability, merging strategies, and time/space complexity analysis when ordering strings by length, and is categorized under Coding & Algorithms.
Constraints
- Input strings may have equal lengths
- When already_sorted=True both lists are individually sorted by length
Examples
Input: (['pear', 'a', 'plum'], ['bb', 'apple'], False)
Expected Output: ['a', 'bb', 'pear', 'plum', 'apple']
Input: (['a', 'bb', 'cccc'], ['d', 'eee'], True)
Expected Output: ['a', 'd', 'bb', 'eee', 'cccc']
Input: ([], ['zz', 'q'], False)
Expected Output: ['q', 'zz']
Hints
- Stable sorting solves the unsorted case.
- The follow-up is the merge step from merge sort.