Microsoft SDE2 Interview Experience

Difficulty: MEDIUMCategory: InterviewExperienceFrequency: 1Asked On 2025-01-19Added By Anonymous
Source: Link

Applied through career portal. Interview asked 2 DSA Questions. (Interview Date 18th Jan 2025)


1.You are given a string s = "31415926535 8979323846264338327" and a list of words:
2.["314", "15926535 89", "79323846264", "338327", "7932", "3846264", "338327"]. Your task is to partition the string s into substrings such that:
3.Each substring is present in the given list of words. The number of partitions (substrings) is minimized.


Provided recursive approach, but interviewer asked to optimize it but I was not able to do it. (He was expecting Trie Solution)


1.https://leetcode.com/problems/time-based-key-value-store/

Second question was easy, able to solve it, but interviewer not liked my approach. Below mentioned is my approach


1class TimeMap { 2public: 3 unordered_map<string,vector<pair<string,int>>> umap; 4 TimeMap() { 5 6 } 7 8 void set(string key, string value, int timestamp) { 9 if(umap.find(key)!=umap.end()){ //already exist in map 10 umap[key].push_back({value,timestamp}); 11 return; 12 } 13 umap[key].push_back({value,timestamp}); 14 return; 15 } 16 17 string search_val(vector<pair<string,int>> &v, int timestamp){ 18 int n=v.size(); 19 int i=0; 20 int j=n-1; 21 22 if(timestamp<v[0].second) return ""; 23 string ans=""; 24 while(i<=j){ 25 int mid=i+(j-i)/2; 26 if(v[mid].second==timestamp) return v[mid].first; 27 else if(v[mid].second<timestamp){ 28 ans=v[mid].first; 29 i=mid+1; 30 } 31 else{ 32 j=mid-1; 33 } 34 } 35 36 return ans; 37 } 38 39 string get(string key, int timestamp) { 40 if(umap.find(key)==umap.end()) return ""; 41 return search_val(umap[key],timestamp); 42 } 43}; 44 45/** 46 * Your TimeMap object will be instantiated and called as such: 47 * TimeMap* obj = new TimeMap(); 48 * obj->set(key,value,timestamp); 49 * string param_2 = obj->get(key,timestamp); 50 */

Microsoft is the first company for which I gave interview for SDE2 level and failed badly in 1st chance, though I have been practising DSA from past 10 months coninously. But I will keep fighting until the very last nail is in the coffin.

Comments