Message on Whatsapp 8879355057 for DSA(OA + Interview) + Fullstack Dev Training + 1-1 Personalized Mentoring to get 10+LPA Job
0 like 0 dislike
1,329 views
All tcs nqt codes for all batches available in group @tcs_nqt_ans : https://telegram.im/@tcs_nqt_ans

Link to all the TCS_NQT Coding Questions and Answers of year 2022 : https://www.desiqna.in/tag/tcs_nqt
in Online Assessments by Expert (111,530 points)
edited by | 1,329 views

2 Answers

0 like 0 dislike
Best answer

C++ code : 

#include <bits/stdc++.h>
using namespace std;

int main()
{
    // your code goes here
    int n, k;
    cin >> n >> k;
    vector<int> arr;
    // int temp = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> arr[i];
    }
    // vector<pair<int, int>> queries;
    int temp1, temp2;
    unordered_map<int, int> mp;
    for (int i = 0; i < n; i++)
    {
        mp[arr[i]]++;
    }
    for (int i = 0; i < k; i++)
    {
        cin >> temp1 >> temp2;
        // queries.push_back({temp1, temp2});
        mp[arr[temp1]]--;
        arr[temp1] = temp2;
        mp[arr[temp1]]++;

        int ans = 0;
        for (auto it : mp)
        {
            if (it.second == 1)
                ans++;
        }
        cout << ans << " ";
    }

    return 0;
}
by Expert (111,530 points)
0 like 0 dislike
by Expert (35,210 points)