Given an array of numbers, return array of products of all other numbers (no division)

I was asked this question in a job interview, and I’d like to know how others would solve it. I’m most comfortable with Java, but solutions in other languages are welcome. Given an array of numbers, nums, return an array of numbers products, where products[i] is the product of all nums[j], j != i. Input … Read more

What is the best way to compute trending topics or tags?

Many sites offer some statistics like “The hottest topics in the last 24h”. For example, Topix.com shows this in its section “News Trends”. There, you can see the topics which have the fastest growing number of mentions. I want to compute such a “buzz” for a topic, too. How could I do this? The algorithm … Read more

Efficient way to apply multiple filters to pandas DataFrame or Series

I have a scenario where a user wants to apply several filters to a Pandas DataFrame or Series object. Essentially, I want to efficiently chain a bunch of filtering (comparison operations) together that are specified at run-time by the user. The filters should be additive (aka each one applied should narrow results). I’m currently using … Read more

Fastest way to sort 10 numbers? (numbers are 32 bit)

I’m solving a problem and it involves sorting 10 numbers (int32) very quickly. My application needs to sort 10 numbers millions of times as fast as possible. I’m sampling a data set of billions of elements and every time I need to pick 10 numbers out of it (simplified) and sort them (and make conclusions … Read more