Solve Three Algorithmic Problems
Company: Meta
Role: Machine Learning Engineer
Category: Coding & Algorithms
Difficulty: hard
Interview Round: Onsite
Three coding questions were mentioned:
1. **Second-largest distinct permutation**
Given an array of integers that may contain duplicates, consider all distinct permutations of the array ordered from largest to smallest in lexicographic order. Return the second-largest distinct permutation.
Examples:
- `[1, 2, 3, 4, 5] -> [5, 4, 3, 1, 2]`
- `[1, 1, 5] -> [1, 5, 1]`
You may assume there are at least two distinct permutations.
2. **Merge m sorted arrays and return first k values**
You are given `m` integer arrays, each already sorted in non-decreasing order. Return the first `k` values in globally sorted order across all arrays. Preserve duplicates.
3. **Choose a subset of words with no repeated characters**
Given a list of words, choose a subset whose concatenation contains no repeated characters. Maximize the total number of unique characters in the concatenated result. A word that contains duplicate characters internally cannot be part of any valid solution unless those duplicates are allowed by the rules; assume the final concatenation must contain each character at most once. Discuss an algorithm that still works when the input contains thousands of words.
Quick Answer: This set of problems evaluates algorithmic problem-solving skills such as reasoning about permutations and duplicate handling, efficiently merging multiple sorted arrays, and combinatorial selection under character-uniqueness constraints.