Easy Brute force and Optimized Solution(Map) in c++
Intuition\n Describe your first thoughts on how to solve this problem. \nBrute Force is pretty staright forward, Optimal solution can be solved using variation 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nBrute Force is pretty staright forward, Optimal solution can be solved using variation of sliding Window\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nThis is the implementation of the function `distinctDifferenceArray`, which takes a vector of integers `v` as input and returns another vector `ans`. The purpose of this function is to calculate the distinct difference array of the input vector.\n\nThe distinct difference array of a vector `v` is another vector `ans` such that `ans[i]` is the number of distinct values in the subvector `v[0:i]` of `v` after taking the differences of adjacent elements.\n\nThe function first initializes two maps `m1` and `m2` to keep track of the frequency of each element in the subvector `v[0:i]` and `v[i+1:n-1]` respectively. It then loops through the input vector `v` and updates the maps `m1` and `m2` accordingly.\n\nFor each element `v[i]`, the function increments the frequency of `v[i]` in `m1` and removes it from `m2` if its frequency becomes zero. It then calculates the difference in size between `m1` and `m2`, which represents the number of distinct values in the subvector `v[0:i]` after taking the differences of adjacent elements. This value is appended to the `ans` vector.\n\nFinally, the function returns the `ans` vector.\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Brute Force Code\n```\nclass Solution {\npublic:\n    vector<int> distinctDifferenceArray(vector<int>& v) {\n        int n=v.size();\n        vector<int>ans;\n        for(int i=0;i<n;i++)\n        {\n            set<int>s1,s2;\n            for(int j=0;j<=i;j++)\n                s1.insert(v[j]);\n            for(int j=i+1;j<n;j++)\n                s2.insert(v[j]);\n            ans.push_back(s1.size()-s2.size());\n        }\n        return ans;\n    }\n};\n```\n\n#Optimal Code using MAP\n```\nclass Solution {\npublic:\n    vector<int> distinctDifferenceArray(vector<int>& v) {\n        int n=v.size();\n        map<int,int>m1,m2;\n        for(auto i:v)\n            m2[i]++;\n        vector<int>ans;\n        for(int i=0;i<n;i++)\n        {\n            m2[v[i]]--;\n            if(m2[v[i]]==0)\n                m2.erase(v[i]);\n            m1[v[i]]++;\n            ans.push_back(m1.size()-m2.size());\n        }\n        return ans;\n    }\n};\n```
['Ordered Map', 'Sliding Window', 'C++']