Smartest and cleanest solution I have seen for this question. Amazing job!
@JohnIdlewood Жыл бұрын
The salt is inserting into the middle of the array. Inserting into the middle of the array is O(n) because you have to copy it. So the result complexity is still O(n^2)
@crackfaang Жыл бұрын
Yea it’s not possible to optimal solve it without a sorted array data structure that can maintain the sorted order and also insert in O(1) time. Other languages have it but Python unfortunately doesn’t out of the box
@dojoPojo Жыл бұрын
@@crackfaang Thanks a lot ! for this c++ code it is giving TLE for 3 test cases but that's okay public: vector countSmaller(vector& nums) { multiset sorted; vector ans(nums.size()); for (int i = nums.size() - 1; i >= 0; i--) { int curr = nums[i]; auto it = sorted.lower_bound(curr); ans[i] = distance(sorted.begin(), it); sorted.insert(it, curr); } return ans; } };
@meylyssa36664 ай бұрын
it's so simple as you explained it! Clean and ah so smart, thank you a lot!
@kalyanvejallaАй бұрын
such a fantastic video!
@vivek.tiwaryАй бұрын
We can avoid reversing operation & directly assign to result[r] = index;
@mohammadfaizanazim88659 ай бұрын
loved the haha at 1:05 :XD
@Aryan-ku6ji2 ай бұрын
the only issue here is that we are using sorted containers which is not a part of default python package. OA might not accept this. Also its not available in languages like C++ where these are just AVL ..so the indexing takes O(n) time. Here its a chunk like data structure which not only inserts, deletes in log n time but indexes in O(1) time... interviewer might ask you to implement this and you get caught in rabbithole🤣..Better to use merge sort here
@andriidanylov945311 ай бұрын
Wow.Shortest solution
@billy98082 жыл бұрын
Bro, I just want to say thank you for the help, I watch your videos every day. I got demotivated since most companies were laying off or hiring freeze, but your consistent uploads kept me on my feet. My first FAANG paycheque is coming your way
@crackfaang2 жыл бұрын
Thanks for the kind words my friend. I know it’s tough given the current job market but this is actually the best time to Leetcode because there’s really zero time pressure on you and you can take your time to learn everything properly without worrying about a deadline. Make the most of the time since most people will just stop entirely. When hiring resumes you’ll be ready to go while everyone else starting up again
@johnj1714 ай бұрын
Hiii Now hey You i have subscribes and I am loving you content and your little intimidation too don't so stop now!
@ziqinwu23377 ай бұрын
Thank you!
@billy98082 жыл бұрын
10K+ Subscribers by next year Feb💯
@crackfaang2 жыл бұрын
That’s the goal. I have some big plans for the channel next year… hoping for 100k by the end of next December!