Microsoft | Senior Software Engineer | Bangalore | 12/12/2020[Reject]
Anonymous User
1567

I have 9+ years of experience in software development.

Prior to the interview i got information that there willl be 4 rounds of the interview. Out of 4 first two rounds are mandatory and next 1 are based on the performance.

Round 1 : Technical coding round:
The question was how much time it will take to infect all people, a matrix of 0 and 1 is provided, where 0 denotes non-infected people and 1 denotes infected people. At one time(suppose seconds) infection can spread in all the directons except diagonals.

Sample Input :

0,0,0,0
0,1,0,0
0,0,0,0
0,0,1,0

So, here the output would be 3 seconds

Explaination:
At 1st sec the matrix becomes
0,1,0,0
1,1,1,0
0,1,1,0
0,1,1,1

At time 2nd second the matrix becomes,
1,1,1,0
1,1,1,1
1,1,1,1
1,1,1,1

At 3rd second matrix will be completely filled of 1.

This problem is simillar to the problem,
https://leetcode.com/problems/number-of-islands/

I solved it using BFS. After that qualified for 2nd round.

Round 2 : It was LLD round as per ealier communication.
Question 1 : Problem which you encountered recently and you have solved by yourself.
Answer : Answered it about a migration.

Question 2 :
Date RollDate(Date d, int n) --> To add n number of days to date provided.

Constraint
1. Functional
2. Compact Code
3. Bug Free

Answer : I have written the code. I was not able to explain completely due to time constraint. In this round some settings of codility was changed and i was not able to use mouse to reach a particular place of the editor.

Code :
'''
static int dArr[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };

public static Date nextDate (Date d, int days)
{

    // int yearI = (days>365)? days/365: 0;
    // days = days%365;//TODO: for 366

    if (days == 0)
        return d;

    int dDate = d.getDate(); //12
    int mDate = d.getMonth(); //12
    int yDate = d.getYear(); // 2020

    int cDate = dArr[mDate - 1]; //dDate= 31

    int finalDate = 0;
    int finalMonth = mDate;
    int finalYear = yDate;

    if (cDate < dDate) {
        days = cDate - dDate;
    }
    else {
        finalDate = dDate + days;
        Date lessD = new Date();
        lessD.setDate(finalDate);
        lessD.setMonth(finalMonth);
        lessD.setYear(finalYear);
        return lessD;
    }

    int monthConsidered = mDate + 1;

    if (mDate == dArr.length) {
        monthConsidered = 0;
        finalYear += 1;
    }

    while (days > 0) {
        for (int i = monthConsidered; i < dArr.length; i++) {
            if (days == 0) {
                finalMonth = i;
                finalDate = 1;
            }
            if (days > dArr[i]) {
                days -= dArr[i];
            }
            else {
                finalDate = dArr[i] - days;
                finalMonth = i;
            }
        }
    }

    Date x = new Date();
    x.setDate(finalDate);
    x.setMonth(finalMonth);
    x.setYear(finalYear);

    return x;

}

'''

Might be my code was not compact. So, rejected.
If i would have written something like Calendar.addDays(), it would have not be right actually with 1 line it could have achieved.
Actually, i am in a state not able to get what interviewer was expecting.

Comments (2)