Round 1 : DSA round
Round was easy to medium level. Interviewer asked two leetcode questions.
Expections :
- Tell the approach
- Code the solution on leetcode itself
- Explain TC and SC
Problem 1 : Destination City
Link : https://leetcode.com/problems/destination-city/description/
My solution :
class Solution {
public:
string destCity(vector<vector<string>>& paths)
{
unordered_map<string,int> outgoing_edges;
for(auto &vec : paths)
{
outgoing_edges[vec[0]]++;
}
for(auto &vec : paths)
{
if(outgoing_edges[vec[1]] == 0)
{
return vec[1];
}
}
return "";
}
};Problem 2 : Rabbits in Forest
Link : https://leetcode.com/problems/rabbits-in-forest/description/
My solution :
class Solution {
public:
int numRabbits(vector<int>& answers)
{
unordered_map<int,int> mp;
for(auto x : answers)
{
mp[x]++;
}
int cnt,val,extra=0,bucket,cur;
for(auto p : mp)
{
cnt = p.second;
val = p.first;
bucket = 1 + val;
cur = cnt % bucket;
extra += (bucket - cur) % bucket;
}
return answers.size() + extra;
}
};Was able to solve both problem and explained approaches as well as TC and SC.
Verdict : Selected for Round 2
Comments (5)


