Woodstock Blog

a tech blog for general algorithmic interview questions

[Google] Maximum Count Array in a Queue

Question

link1

给一个数组a[n],令s[i]为a[i+1..n-1]中比a[i]大的数的数量。

求最大的s[i]。要求O(nlogn)

Solution

This is very similar question to [Google] Form a Queue Given Heights. The idea is to insert elements into BST and count number of larger elements.

Naitive solution can be reached with a list.