## First missing positive with only primitives

As soon as I saw the First missing positive question, I decided to write my own method for this before writing my review on the question. Judge me by the same standards as bazang wants to be judged, i.e. As if this was written for a big company such as Google for an interview. I … Read more

## Two Rectangles intersection

I have two rectangles characterized by 4 values each : Left position X, top position Y, width W and height H: X1, Y1, H1, W1 X2, Y2, H2, W2 Rectangles are not rotated, like so: +——————–> X axis | | (X,Y) (X+W, Y) | +————–+ | | | | | | | | | | … Read more

## How does a sentinel node offer benefits over NULL?

On the Sentinel Node wikipedia page it says that the benefits of a sentinel node over NULL are : Increased speed of operations Reduced algorithmic code size Increased data structure robustness (arguably). I don’t really understand how the checks against a sentinel node would be faster (or how to properly implement them in a linked … Read more

## Is there an O(n) integer sorting algorithm?

The last week I stumbled over this paper where the authors mention on the second page: Note that this yields a linear running time for integer edge weights. The same on the third page: This yields a linear running time for integer edge weights and O(m log n) for comparison-based sorting. And on the 8th … Read more

## How do I convert an Int to a String in C# without using ToString()?

Convert the following int argument into a string without using any native toString functionality. public string integerToString(int integerPassedIn){ //Your code here } Since everything inherits from Object and Object has a ToString() method how would you convert an int to a string without using the native ToString() method? The problem with string concatenation is that … Read more

## Check if a binary tree is a mirror image or symmetric

What is the basic algorithm for testing if a tree is symmetrical? Because it is a binary tree, I would assume that it would be a recursive definition of sorts The formal question is below: A binary tree is a mirror image of itself if its left and right subtrees are identical mirror images i.e., … Read more

## How much do two rectangles overlap?

I have two rectangles a and b with their sides parallel to the axes of the coordinate system. I have their co-ordinates as x1,y1,x2,y2. I’m trying to determine, not only do they overlap, but HOW MUCH do they overlap? I’m trying to figure out if they’re really the same rectangle give or take a bit … Read more

## Good algorithm and data structure for looking up words with missing letters?

I need to write an efficient algorithm for looking up words with missing letters in a dictionary and I want the set of possible words. For example, if I have th??e, I might get back “these”, “those”, “theme:, “there”, etc. There will be up to TWO question marks and when two question marks do occur, … Read more

## Java, Shifting Elements in an Array

I have an array of objects in Java, and I am trying to pull one element to the top and shift the rest down by one. Assume I have an array of size 10, and I am trying to pull the fifth element. The fifth element goes into position 0 and all elements from 0 … Read more