Amazon | Pune Onsite - Written Coding Assesment
Anonymous User
253

Hiring Drive for SDE 1 was held in Pune on 23rd April 2022.
We were given below 2 questions to solve in 1 hour time.


Q1 - Write a logic to get the risk of Covid infection a user might have based on his contacts state. Each user will have a unique clientId. You'll have 2 API's given to you :
1 - bool isCovidInfected(long clientID) - returns true if client is covid infected and false otherwise
2 - List getCloseContacts(clientID) - returns the list of all close contacts of the given user.
Risk for a user will be 100% if anyone of his close contacts is infected, reduce the risk by 20% for each layer an infected person is away from the user.
eg :
1 - C is infected and is a close contact of A, so A's risk is 100%
2 - C is infected and is close contact of A and A is close contact of B but B is not a close contact of C, so B's risk is 80%
3 - image

 here A is infected so G's risk is 40% and F's risk is 80% and Z's risk is 60%.

Q2 - Given an string of numbers, print all valid IP addresses that can be formed from them which follow below conditions :
1 - A valid IP will have 4 octets, each octet can be between 0 - 255
2 - Numbers should be taken in a sequence
3 - You can skip the numbers from start or back but not from the middle.

eg : [2,1,3,4,5,2,1,6,7,8,4,7]
valid ip's are :
2.1.3.4
21.34.52.1
3.4.5.2
4.52.167.84
7.8.4.7
etc.


My Solutions:
A1 - I coded a memoized solution where we'll do a DFS on all close contacts, I was storing the risk for each clientId in a dp array.
A2 - I was not able to come up with a solution for Q2, I was thinking of a pick / not pick strategy but because of the continuos condition was not able to apply it correctly.


Can anyone please help me in trying to understand the approach to both the questions ?

Comments (6)