Solve top-K and string rotation match
Company: TikTok
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: Medium
Interview Round: Technical Screen
1) Given an unsorted array of integers and an integer k, return the k largest elements in descending order. Implement at least two approaches (e.g., a size-k min-heap and a quickselect-based method), discuss time/space complexities, and explain how you would handle duplicates and very large inputs (streaming or external memory).
2) Given two strings s and goal, you may repeatedly move the first character of s to the end of s. Determine whether s can be transformed into goal by any number of such operations. If yes, return the minimum number of moves needed; otherwise, return -1. Specify the algorithm, edge cases, and complexity.
Quick Answer: This question evaluates proficiency in selection and string algorithms—top-K selection (heap and selection algorithms), handling duplicates and large-scale inputs via streaming or external memory, and cyclic string rotation detection with minimal-move computation in the Coding & Algorithms domain.