Katkat

Solve top-K and string rotation match

TikTokSoftware Engineer · Technical Screen

Last updated

Solve top-K and string rotation match evaluates algorithm design, data structures, correctness, complexity, edge cases, and implementation details in a realistic interview setting. A strong answer states assumptions, handles edge cases, explains trade-offs, and shows how to validate the result clearly.

  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.