Find the Running Median

  • + 0 comments

    c++ Using unordered map

    unordered_map<string, int> umap;
    vector<int> toReturn;
    for(unsigned i = 0; i < queries.size(); ++i) {
        if(queries.at(i).at(0) == "add") {
            for(unsigned j = 0; j < queries.at(i).at(1).size(); ++j){
                ++umap[queries.at(i).at(1).substr(0,j+1)];
            }
        } else if(queries.at(i).at(0) == "find") {
            toReturn.push_back(umap[queries.at(i).at(1)]);
        }
    }
    return toReturn;