I read other posts saying Duolingo asks the encrypt question, but I didn't get that one.
The question I got was very similar to LeetCode 128. The input is a list of timestamps (unsorted, in the format yyyy-mm-dd-hh-mm), and the output is a list of intervals (in the format yyyy-mm-dd). I wasn't allowed to sort, and the solution approach is the same as LeetCode 128, in O(n).
You need to convert the data type from LocalDateTime to LocalDate (the interviewer allowed me to google the library), and then you just go through it with a set.
The question isn't hard, but in the end I didn't solve it with the optimal O(n) solution, and I got rejected.
- How do you determine an interval's start and end dates from the timestamps? (Just yyyy-mm-dd. The answer doesn't need to be sorted, a Set is enough.)
- How do you merge intervals in O(n) with a set, without sorting? (Look at the LeetCode 128 solution.)
Discussion
Loading comments…