๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
9.55K subscribers
5.57K photos
3 videos
95 files
9.8K links
๐ŸšฉMain Group - @SuperExams
๐Ÿ“Job Updates - @FresherEarth

๐Ÿ”ฐAuthentic Coding Solutions(with Outputs)
โš ๏ธDaily Job Updates
โš ๏ธHackathon Updates & Solutions

Buy ads: https://telega.io/c/cs_algo
Download Telegram
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Photo
#include<bits/stdc++.h>
using namespace std;

vector<vector<int>> textQueries(vector<string> sentences, vector<string> queries){
    int n = sentences.size(), m = queries.size();
    map<string, multiset<int>> mp;
    for(int i=0; i<n;i++){
        string temp = sentences[i];
        string tt = "";
        for(int j=0; j<sentences[i].length(); j++){
            if(temp[j]==' '){
                mp[tt].insert(i);
                tt = "";
            }else{
                tt += temp[j];
            }
        }
        mp[tt].insert(i);
    }

    vector<vector<int>> ans;

    for(int i=0; i<m; i++){
        string tt = "";
        string temp = queries[i];
        multiset<int> st, st2;
        for(int j=0; j<temp.length(); j++){
            if(temp[j]==' '){
                st = mp[tt];
                tt = "";
                break;
            }else{
                tt += temp[j];
            }
        }
        if(tt!="") {st = mp[tt]; tt="";}

        for(int j=0; j<temp.length(); j++){
            if(temp[j]==' '){
                for(auto it: mp[tt]){
                    if(st.find(it)!=st.end()){
                        st2.insert(it);
                    }
                }
                st = st2;
                tt = "";
                st2.clear();
            }else{
                tt += temp[j];
            }
        }
        if(tt!=""){
            for(auto it: mp[tt]){
                if(st.find(it)!=st.end()){
                    st2.insert(it);
                }
            }
            st = st2;
            st2.clear();
        }

        if(st.size()==0) ans.push_back({-1});
        else{
            vector<int> temp;
            for(auto it: st){
                temp.push_back(it);
            }
            ans.push_back(temp);
        }

    }

    return ans;
}

int main()
{
    vector<string> sentences = {"how it was done", "are you how", "it goes to", "goes done are it"};
    vector<string> queries = {"done it", "it"};

    vector<vector<int>> ans = textQueries(sentences, queries);
    for(auto i: ans){
        for(auto j: i){
            cout << j << " ";
        }cout << endl;
    }

}

Simple Text Queries โœ…
ServiceNow
๐Ÿ‘1