Blog

Partition a Linked List by Value X (part 2)

To expand on the problem here Partition Linked List Based on value x

I now asked this question.

Partition a Linked List by a value x, so that values less than x come first, values equal to x come next, and values greater than x come last. Note: Retain relative order.

Unlike the previous question, this one has no shortcuts that were obvious to me.

To solve this problem, I need the concept of 3 lists. LessThanList (LTList), EqualToList (EqList), and GreaterThanList (GTList).

Because we are doing this in place and are working with linked list, it’s sufficient to just move around pointers without actually creating new lists.

So the pointers will track the beginning and end of their respective list.

startOfLTList, endOfLTList,

startOfEqList, endOfEqList,

startOfGTList, endOfGtList

 

 

So for an input of 4, 3, 6, 5, 2

We get an output of 3, 2, 4, 6 ,5

Where the partitions are 3, 2,| 4, | 6 ,5

Partition Linked List Based on value x

During my algorithm review I came across this problem.

Write an algorithm to partition a linked list around a value, x, so that all nodes less than x comes before all all nodes greater than or equal to x.

I really like this problem, because it is being very generous and allows you to be very efficient. Here are some tips that will help you with getting  a full solution.

Tip 1 – A complete sort is not necessary. (smile) (more…)

Most Useful Linux Commands

This is a lit of commands that I find found very useful on linux and related technologies.

Command 1

This command can prevent you from having a crisis.

(more…)

Site blocked from McAfee Web Gateway

Have you seen this before?

Warning message about blocked site

You may be trying to access a site from inside of a firewall and you get a scary message like this. What’s even worse is if it’s your own site and makes you wonder what in the world is going on. The message you may see is: (more…)

Compass file not found error in sass cache

Recently, I was working on a sass project and then started to get strange errors about a file not being found. The error referenced a non existent file in the sass cache folder. I wasn’t sure why the file was not being generated, I had never seen this before.

The error came in two forms:

(more…)

Fixing Website Blocked. Category None

Seen this before?

Stop sign with a hand
You shall not pass

You may have received an error that says content blocked with category “none” when you try to access a certain website from within a firewall. I have seen this happen with BlueCoat firewall which is often used by very large companies to limit the sites that their computers can visit. (more…)

Better Organization with Sass Media Queries

Using media queries can get confusing and overlapping especially when structure is lacking. With sass css compiler and mixins we can structure our media queries and use them far more elegantly.

(more…)

Getting Selected Option From PHP Select List

light_bulb_large

Let’s say you have a php select box that is dynamically generated through your php loop. You want to make sure that the selected option is always displayed even after reload.

Here is an example of a basic dynamic list:

However when the page loads, you cannot tell which color was selected and aren’t sure where to put the html ‘selected’ value because the code simply ran through the colors loop.

Solution: (more…)

Deploying WordPress via Bash Script

robots-large

Deploying your site should be easy. There are many ways to accomplish this, and I decided to take a bash script approach for one project. This will appeal to the more hands-on developers, but don’t worry everything has been explained here.

(more…)