Microsoft SDE2 Interview Experience

Anonymous User
2324
Jan 19, 2025
Jan 29, 2025

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:
    ["314", "15926535 89", "79323846264", "338327", "7932", "3846264", "338327"]. Your task is to partition the string s into substrings such that:
    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
class TimeMap {
public:
    unordered_map<string,vector<pair<string,int>>> umap;
    TimeMap() {
        
    }
    
    void set(string key, string value, int timestamp) {
        if(umap.find(key)!=umap.end()){ //already exist in map
            umap[key].push_back({value,timestamp});
            return;
        }
        umap[key].push_back({value,timestamp});
        return;
    }
    
    string search_val(vector<pair<string,int>> &v, int timestamp){
        int n=v.size();
        int i=0;
        int j=n-1;

        if(timestamp<v[0].second) return "";
        string ans="";
        while(i<=j){
            int mid=i+(j-i)/2;
            if(v[mid].second==timestamp) return v[mid].first;
            else if(v[mid].second<timestamp){
                ans=v[mid].first;
                i=mid+1;
            }
            else{
                j=mid-1;
            }
        }

        return ans;
    }

    string get(string key, int timestamp) {
        if(umap.find(key)==umap.end()) return "";
        return search_val(umap[key],timestamp);
    }
};

/**
 * Your TimeMap object will be instantiated and called as such:
 * TimeMap* obj = new TimeMap();
 * obj->set(key,value,timestamp);
 * string param_2 = obj->get(key,timestamp);
 */

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 (7)