Salesforce | Onsite | Reservoir Sampling

Difficulty: EASYCategory: InterviewExperienceFrequency: 1Asked On 2022-02-18Added By Anonymous
Source: Link

Fill the n*n empty grid with m stars randomly.


Input: 3*3 grid, m =2

//Let 1 represent a star


Output:

000

010

001


According to the interviewer, optimal solution should use a List.


I found a similar problem later on:

https://leetcode.com/discuss/interview-question/algorithms/124759

Comments