Algorithms

3K

Solutions

10

Articles & Videos

4K

Contributors

An algorithm is a self-contained step-by-step set of operations to be performed. Algorithms exist that perform calculation, data processing, and automated reasoning. Starting from an initial state and initial input (perhaps empty), the instructions describe a computation that, when executed, proceeds through a finite number of well-defined successive states, eventually producing "output" and terminating at a final ending state. The transition from one state to the next is not necessarily deterministic; some algorithms, known as randomized algorithms, incorporate random input.

Share tech news, updates, or what's on your mind.

Sign up to Post

Here's an interesting coding puzzle:

A trader can perform two buys and two sells in a day of a given stock. An array of positive integers represents the share price of this stock at different times of the day (index i = 0 represents hour 1, i=1 represents hour 2, etc). The trader must always sell any current shares he has before he buys more shares. Write a function that determines the maximum profit the trader can make by buying and selling stock for a given day.

int maximizeProfit(int[] prices) {
   // Your code here
}

ex:
[10, 22, 5, 75, 65, 80]
The maximum profit is 87: buy at 10 sell at 22, buy at 5, sell at 80.

Open in new window


The solution should have time complexity O(n).
2
Free Tool: Port Scanner
LVL 9
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

If you're interested in block chains (as used in bit coin and now for many other purposes) I found this to be a very good primer.
6
I've been really interested in recommendation systems lately which has lead my down a few rabbit holes. One of these landed on a similarity measurement called Jaccard similarity which is a fairly straightforward metric for communicating how many elements two sets have in common.

This turns out to be very difficult to compute without some tricks but can be estimated with a certain degree of confidence using minHashing. If this sort of thing interests you I would check out this blog post by Chris McCormick - its one of the best explanations I came across (even though its in the context of document similarity). There is even some python code provided.

I would summarize the technique in one sentence as: by randomly shuffling the union of two sets and looking at the first element in the new, shuffled set, the probability that it is an item belonging to their intersection is equal to the Jaccard Similarity.

http://mccormickml.com/2015/06/12/minhash-tutorial-with-python-code/
5

Algorithms

3K

Solutions

10

Articles & Videos

4K

Contributors

An algorithm is a self-contained step-by-step set of operations to be performed. Algorithms exist that perform calculation, data processing, and automated reasoning. Starting from an initial state and initial input (perhaps empty), the instructions describe a computation that, when executed, proceeds through a finite number of well-defined successive states, eventually producing "output" and terminating at a final ending state. The transition from one state to the next is not necessarily deterministic; some algorithms, known as randomized algorithms, incorporate random input.