Microsoft on-site Coding Round

Difficulty: MEDIUMCategory: InterviewExperienceFrequency: 1Asked On 2024-07-22Added By Anonymous
Source: Link

Company: Microsoft
Role: unknown
Interview Stage: Onsite
Location: unknown
Year: unknown

Original Post Content:

Given cities n from 0 to N-1 in a doubly link manner, also given number of amenities m (0 to m-1 for each city). Also, given a matrix amenities of N x M where amenities [i][j] = 1 denotes amenity is present and 0 means amenity is not present. Distance between any two adjacent city is 1.

Find a city which has smallest distance to access all amenities.

Eg:
    int n = 5, m = 3;
    vector<vector<int>> inp = {
        {1, 0, 0},
        {0, 0, 0},
        {1, 1, 0},
        {0, 1, 0},
        {0, 0, 1}
    };

    ans = 3 (city 3 has dist 2 to access all amenities)

Comments