Solve these string, subset, and date problems
Company: ByteDance
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
You are asked to solve multiple coding tasks.
1) **Reverse word order in a string**
- Input: a string `s` containing words separated by spaces (may contain leading/trailing spaces and multiple spaces between words).
- Output: a string where the **order of words is reversed**, with **exactly one space** between words, and **no leading/trailing spaces**.
- Example: `" the sky is blue " -> "blue is sky the"`
**Follow-up:** If the input is a **mutable character array** (e.g., `char[]`), modify it **in place** (O(1) extra space) to achieve the same result.
2) **All subsets (no duplicates in input)**
- Input: an integer array `nums` where all elements are distinct.
- Output: return all possible subsets (the power set). Order does not matter.
3) **All unique subsets (duplicates allowed in input)**
- Input: an integer array `nums` that may contain duplicates.
- Output: return all **unique** subsets (no duplicate subsets in the output).
4) **Days between two dates**
- Input: two dates `date1` and `date2` in the format `YYYY-MM-DD`.
- Output: return the absolute number of days between the two dates.
- Assume valid Gregorian calendar dates.
Overview: This multi-part question evaluates string and array manipulation, in-place algorithm implementation, combinatorial subset generation with and without duplicate handling, and calendar date arithmetic, testing competencies in algorithm design, complexity analysis, and edge-case handling within the Coding & Algorithms domain and requiring both conceptual understanding and practical implementation skills. Such problems are commonly asked in technical interviews to gauge a candidate's ability to implement efficient algorithms, reason about permutations and deduplication, manage memory constraints for in-place operations, and correctly handle date calculations and input edge cases.
Read the full ByteDance Software Engineer interview experience this question came from