Category Archives: Programming Interview

Algorithms, Part I on Coursera

About a week ago I finished Algorithms, Part I course on Coursera. Few thoughts after completing this course:

  • good course by Robert Sedgewick and Kevin Wayne that is focused primarily on algorithms and their analysis
  • great refresher especially for those who worked in the industry for a while
  • course uses Java as programming language, but having very little Java experience wasn’t a problem, being proficient in C++ and especially C# helped a lot
  • the course focuses mostly on application of existing algorithms but does not focus on the algorithm design which is its biggest drawback
  • Dr. Java IDE that comes with the course is terrible. Instead, I used Eclipse and version of Java that the default course setup installs on your machine (see previous post on how to configure Eclipse for this course)
  • the course does not provide a verified certificate which is a bummer especially after all the hard work
  • all of the programming tasks were fun and challenging
  • lecture and slides are helpful but you obviously need to do your own learning in addition to that

In order to be successful in this class, you need to:

  • make sure you keep delivering exercises and programming assignments before the due date or at least hard deadline. For me it was a big challenge in the beginning due to packed schedule but I had supportive environment and overall experience was smooth.
  • do not study if you’re tired after work – instead, get a good night of sleep and study when your brain is fresh – sounds like a no-brainer but it’s not so obvious until you experience double load – both at work and in the class
  • do not use Dr Java – it’s almost impossible to debug your code fast, especially complex data types. Install Eclipse. Enough said.
  • try to have fun and enjoy every moment of it!

Overall, I recommend this class.

Programming Interview Preparation: Whiteboard

In a month you will have programming interview at elite Big Co or rocket-ship startup. You are reading CLRS, Programming Interviews Exposed and even coded 20 problems. You are confident and things are going well. But wait, aren’t you expected to solve programming tasks on a whiteboard?  

In a month in your interview loop not only will you meet sharpest engineers, A+ players who consistently want to raise the bar and have no mercy towards B and C players, but your code will be scrutinized, you need to deliver solution under pressure and on time. On a whiteboard.

Whiteboard coding isn’t programming per se, it’s a sport. Every second counts, every line of code is important and you are required to show your best. Get ready, read on and you will walk on water during your coding session.

Of course, you need to practice. Practice a lot. Not alone, but with a real interviewer.

Stage 1: Get Familiar with Whiteboard. If you are lucky enough to have a competent friend or mentor – ask him or her to interview you at least twice a week. Do a mock interview on a whiteboard as often as possible. You first goal is to get a feel what it is like to have several whiteboard coding sessions a day. At this stage you need to become absolutely comfortable to code on a whiteboard, it should be just as easy as typing on a computer.

Stage 2: Become Fast Whiteboard Coder. I mean really fast whiteboard coder. When an interviewer asks you to solve the task which involves binary tree, you don’t want to ask too many questions. 30 seconds and binary tree node should be on the whiteboard. Not only you saved 10-15 minutes of interviewing time that you will use towards solution, but you also impressed the interviewer since past 5 candidates just started to warm up at this point.

Stage 3: Become a Whiteboard Master. We are not going to talk how to solve your task here – you are a rock star engineer, why do you need any help with that? At this point you are polishing your skills:

  • Buy thin markers and use them during interview. They will help save expensive whiteboard space and your code will be much easier to read. Remember to bring several markers to the interview, you may forget to put it back in your pocket if the interview was very intense!
  • Use whiteboard space wisely. Practice and make sure that your solution is not stretched all over whiteboard.
  • Time yourself. Make sure you really know how long it takes you to implement data structures, loops, error handling and standard solutions such as traversing linked list.

You will be much better off even if you will practice in complete solitude, but best results are achieved with a ruthless interviewer. Practice, don’t rush and you will succeed.

Programming Interview Preparation: Books

I am frequently asked how to prepare for a technical interview at top software companies in the US. Having been on both sides of programming interviews, I can say that one of the keys to successful interview is to start preparation early and have focus.

Maintaining focus during preparation is difficult as there literally thousands of programming problems to solve. However, I will keep the list of must-read books short as they will prepare you for 99% of all programming interviews. Here are the books per area:

Programming Interviews

Algorithms

Computer Architecture

Software Design

Ideally you would read all of them and complete most tasks, but if you are on a really tight schedule, both books from Programming Interviews category will get you started and the rest can be used as a reference.

Good luck and raise the bar!

Task: Swap Subtrees

// In a given binary tree swap right and left node,
// so that the tree will look like:
//	        4		        4
//	       / \             / \
//        2   5	=>        5   2
//       / \		         / \
//      1   3		        3   1

typedef struct _TreeNode
{
	struct _TreeNode* pLeft;
	struct _TreeNode* pRight; //arbitrary
	int data;
} TreeNode, *PTreeNode; 

bool SwapSubtrees(PTreeNode root)
{
	if(!root)
	{
		return false;	
	}

	PTreeNode tmp = root->pRight;
	root->pRight = root->pLeft;
	root->pLeft = tmp;

	if(root->pRight)
	{
		SwapSubtrees(root->pRight);	
	}
	if(root->pLeft)
	{
		SwapSubtrees(root->pLeft);	
	}

	return true;
}