vector<int>delete_nth(vector<int>arr,intocc){// stores the numbers and its corresponding count in answer vectorunordered_map<int,int>numCount;// the answer vectorvector<int>ans;// if count of any number is less than occ,// only then add it in ansfor(intnum:arr){if(numCount[num]<occ){ans.push_back(num);numCount[num]++;}}returnans;}
Started with blinking LEDs, ended inside a database query engine. Embedded C++, IoT firmware, and Native Iceberg OTF in Teradata Vantage. Currently automating myself using RAG + AI agents.
ans vector contains each number only up to occ times. So, occ can never be negative. If user passed a negative number as occ, then ans vector will be empty.
If given numbers are negative, still there should not be any problem. Example,
Here is C++ solution,
What if given numbers are not positive ?
ansvector contains each number only up toocctimes. So,occcan never be negative. If user passed a negative number asocc, thenansvector will be empty.If given numbers are negative, still there should not be any problem. Example,