LeetCode Question · Feb 2025

Microsoft OA 17-02-2025

337 views 5 replies

Question Details

1.\tgiven N, A[], B[] and H[] \tA[] = from/to district \tB[] = from/to district \tH[] = hospital district \twe have to return time it takes to reach to farthest district from any hospital;...

Full Details

1.\tgiven N, A[], B[] and H[]
\tA[] = from/to district
\tB[] = from/to district
\tH[] = hospital district

\twe have to return time it takes to reach to farthest district from any hospital; it takes 1 minute to cross one district. if district is unreachable then return -1;

\texample 1 : \tN = 6 \tA[] = [1,1,0,1,3] \tB[] = [2,0,5,3,4] \tH[] = [2,4]
\t
\toutput = 3 (since from 2 farthest is 5 which have distance as 3)
\t
\timage

\t
\texample 2 : \tN = 6 \tA[] = [1,1,2,3,3,5] \tB[] = [6,2,3,4,5,6] \tH[] = [1,4]
\t
\toutput = 2 (since from 1 or 4 farthest is 5 which have max distance as 2)
\t
\timage

\texample 3 : \tN = 6 \tA[] = [1,2,3,3] \tB[] = [2,3,4,5] \tH[] = [1,4]
\t
\toutput = -1 (since from any hospital we cannot reach 6)
\t
image

example 4 : N = 3 \tA[] = [1] \tB[] = [2] \tH[] = [1,2,3]
\t
\toutput = 0 (since every district is hospital)
image

  1. given 2 strings
    s1 = ".xxx...x"
    s2 = "..x.xxxx"

string represents a road with "." as smooth and "x" as potholes. we have to fix the potholes so we need to block the some part of road. but road must be open in such a way that pasenger can pass from left to right; we have to return the number of potholes we can fix while keeping the traffic open.

`example 1 :
s1 = "..xx.x."
s2= "x.x.x..."

output = 4 (since if we use shown path then 4 potholes can be fixed"`

image

`example 2 :
s1 = ".xxx...x"
s2 = "..x.xxxx"

output = 6 (since if we use shown path then 6 potholes can be fixed"`
image

`example 3 :
s1 = "xxxxx"
s2 = "..x.."

output = 5 (since if we use shown path then 5 potholes can be fixed"`
image

I m able to solve both but verdict is yet to come

About This Question

This is a reported interview question from a microsoft interview for a swe role during the oa round reported in 2025.

It covers the following topics: Strings .

Topics