I am a coding monkey, and I am proud of it. I have done lots of work in machine learning area, especially recommendation system and AutoML. This blog summarize my journey to become an expert monkey in distributed system and LLM.
Sunnyvale
[Lintcode] Count of Smaller Number before itself
2 minute read
Give you an integer array (index from 0 to n-1, where n is the size of this array, value from 0 to 10000) . For each element Ai in the array, count the number of element before this element Ai is smaller than it and return count number array.
In this problem, we need to first build an big enough (0 to 10000) segment tree which hold the count of elements in each range. Then as we go along the array, we update the segment tree and query the segment tree. At first, I was trying to adding new tree node into this segment tree, but this method does not work, since it needs to rearrange the segment tree to make it stay in a consistent state. So the better way is to initialize a big enough tree first and then modify on it.
Leave a Comment