Randomly partition array into k segments
RobloxSoftware Engineer · Technical ScreenLast updated
This question evaluates algorithm design, randomization techniques, and time/space complexity analysis within the Coding & Algorithms domain, focusing on partitioning an array into random non-empty segments.
Question
Given a list of integers and an integer k representing the number of segments, write a function that randomly partitions the list into k non-empty segments and returns them as a list of lists. Explain your approach, discuss its time and space complexity, and describe how you would test the randomness of your solution.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.