Article 43 - More Programming Interview Questions

This is yet another article dedicated to programming interview questions. Hone your skills and make sure you understand these types of problems.

Our Dress Code is (Business) Causal

While this may not be a typical question, it is important to understand the true meaning behind this type of comment. In truth, many candidates do not even know how to respond. Consider some typical responses, "Candidates should dress formally" or "This is how I present my professional self".

Although the second response may sound more sound and professional, there are better ways to distinguish yourself, especially from your other rival candidates.

First, we must understand what the interviewer really wants to know when they say that. Remember, once you meet your interviewers, your interview has already begun. So it is important to perform at all times. Getting back to the point, consider a situation when you pointed out the unique clothing worn by another friend, associate, or stranger. Why did you say that, you wonder? Perhaps, you wanted to point out that the individial stands out, is different from the rest, or is simply weird.

You do want to stand out but not awkwardly. Reply to your interviewer by indicating that this is your professional representation.

Convert an Integer into a String and Back

Just use the Horner's rule. I have seen so many different approaches that it is just pointless to talk about them anymore. Chances are, the interviewer already knows about this rule and is determined to find out if you know it as well. In other words, to gauge your depth of technical awareness.

To convert an integer to a string, simply use an iterative approach and produce the string backwards, that is from the ones digit to the nth digit for an integer with n digits. For each iteration, apply the modulo operation to the current value by 10 and then divide the number of 10. Truncate the decimal points after the division and use this value as the current value for the next iteration. Afterwards, you will have the digits backwards, you can reverse them in the string. Alternatively, in Java, you can use the prepend operation in a StringBuilder or any list structure that can traverse backwards.

Convert integer to string algorithm.

To solve the other side of the problem, we will apply Horner's rule. Without this rule, we need to read the string to determine the number of digits in the integer so we can multiply the digits to the proper placevalues. This, however, requires two passes, one for reading the number of digits, while the second extracts the information out.

Instead of doing that, we can use the algorithm to perform the conversion in just one pass. We ignore the place value determination pass, since we do not really require it.

The algorithm is to iterate over the characters in the string. For each digit we extract from the string (via character), we multiply our existing answer by 10 and then add the new value to it. That is as simple as it gets.

Convert string to integer algorithm.

Memory Aligned Allocation

Tricky question, not really. Just a mimic of the function malloc (in c) with a few twists to make sure the address returned is aligned. Rest assure, almost all questions will give an alignment value that is a power of 2. For a simple case, we will just return the 0x00 address (null address) on errors such as insufficient memory available.

The idea is to allocate enough memory to store the alignment value and an alignment buffer just before the memory location.

Comments (17)

Posted by anonymous - buy discount viagra online at Saturday, March 2, 2013 12:53 PM

zpq4As Hey, thanks for the blog.Really looking forward to read more. Will read on...

Posted by anonymous - buy discount viagra at Saturday, March 2, 2013 3:13 PM

Really informative post.Much thanks again. Great.

Posted by anonymous - buy viagra online at Saturday, March 2, 2013 3:13 PM

Great blog.Much thanks again. Really Great.

Posted by anonymous - Cheap Christian Louboutin Shoes for Sale at Friday, March 8, 2013 2:42 AM

take Cheap Christian Louboutin Shoes for Sale http://clshoes2013888.tumblr.com/ bear-foot is extremely fine

Posted by anonymous - esavsqokeq at Thursday, March 21, 2013 10:02 AM

PBUMdy <a href="http://kmiugrzerady.com/">kmiugrzerady</a>, [url=http://rnuquvcxiewy.com/]rnuquvcxiewy[/url], [link=http://ejgvioxvyopu.com/]ejgvioxvyopu[/link], http://fqrzggnaphzj.com/

Post a comment

  • Name:
  • Post:
  • Challenge:

Register or login to post comments easier.


Vantasy World Copyright 2011 - 2017. Vantasy World is a project developed by Vantasy Online. Privacy Policy.