How to efficiently build a tree from a flat structure?
I have a bunch of objects in a flat structure. These objects have an ID and a ParentID property so they can be … Read more
I have a bunch of objects in a flat structure. These objects have an ID and a ParentID property so they can be … Read more
The Binary Tree here is may not necessarily be a Binary Search Tree. The structure could be taken as – struct node { … Read more
A common task in programming interviews (not from my experience of interviews though) is to take a string or an integer and list … Read more
I need a quick algorithm to select 5 random elements from a generic list. For example, I’d like to get 5 random elements … Read more
Let’s say you wanted to implement a breadth-first search of a binary tree recursively. How would you go about it? Is it possible … Read more
I need a rolling window (aka sliding window) iterable over a sequence/iterator/generator. Default Python iteration can be considered a special case, where the … Read more
What is the best approach to calculating the largest prime factor of a number? I’m thinking the most efficient would be the following: … Read more
OK, so I don’t sound like an idiot I’m going to state the problem/requirements more explicitly: Needle (pattern) and haystack (text to search) … Read more
OK – I’m almost embarrassed posting this here (and I will delete if anyone votes to close) as it seems like a basic … Read more
I understand that Tortoise and Hare’s meeting concludes the existence of a loop, but how does moving tortoise to the beginning of linked … Read more