Leetcode 315(Hard) Count of Smaller Numbers After Self: Simple C++ Solution (Using Merge Sort)

preview_player
Показать описание
In this video, I provide a simple solution with an explanation to the Leetcode 315: Count of Smaller Numbers After Self in the hard category. The problem is trivial to solve with time complexity of O(N^2). This solution is based on merge sort, is supplemented with explanation and visualizations, bringing the complexity down to O(Nlog(N)).
Рекомендации по теме
Комментарии
Автор

This is amazing. So glad to have stumbled across your video.
You can make this slightly faster by making your temp a vector of pairs, instead of a vector of vectors.
For those that do not know, traversing through a vector is slower than it is traversing through an array and in turn a pair.

satyakiranmayibhamidimarri
Автор

Best video for this question!! Keep making more videos. You will definity get more subscribers and views

ujjvalsharma
Автор

You can change the mouse settings for left handed too... world is made for both handed people.. 😀

PankajKumarThapa
Автор

Thanks for the well explained video man.

papayasprout
Автор

Thank you for the excellent video!! By the way, what is the drawing tool you are using?

hshinver
Автор

Good video 🤩. Don't give up, Please make more videos your subscribers will 📈

logicalhuman
Автор

I don't know c++ so I couldn't catch syntax errors. But I was able to find the l-r when you were coding.

a.yashwanth
Автор

For the exact same code, why i am getting TLE?

Prashantkumar-pnqq
Автор

Here is 8 line code with O(n.log(n)) complexity

Vector<int> countSmaller(vector<int>& nums) {
vector<int>v;
int n=nums.size();
vector<int>res(n);
if(n==0)
return res;
res[n-1]=0;
v.push_back(nums[n-1]);
for(int i=n-2;i>=0;i--)
{
v.insert(lower_bound(v.begin(), v.end(), nums[i]), nums[i]);
res[i]=lower_bound(v.begin(), v.end(), nums[i])-v.begin();
}

return res;
}

ayushgarg
Автор

the world is made up for right handed people.. hahaa.

SreekantShenoy
welcome to shbcf.ru