Best site for GRE, LSAT, SAT, GMAT, TOEFL, CCNA, CCSA and interview sample questions

# Programming Interview Questions

If you are going to appear for the interview for the position of a software analyst, Java, or C++ programmer, then programming interview questions are an integral part of it that you have to be prepared for. These questions tend to come with a lot of challenges and they do cover all the aspects of programming. They are regarding string, array, linked lists, binary tree, searching, sorting, and numbers.

Let us have a look at the list of some top programming interview questions:

Question 1: Give me the code for checking whether a string is a palindrome or not.

String is a fundamental and possibly the most common aspect of programming that you would come across during your interview. You might always get an opening question based on string knowledge. It can be regarding the length or replacement. Palindromes are the strings which have their reverse the same as their original. Demonstrate a technique to explain how to reverse string in Java without using application string interface.

Question 2: In an array, how do you find that 1-100 many numbers are duplicates?

Array is said to be the favorite topic of the interviewers. There are many questions on array and therefore, you need to prepare for this topic very well and note down other questions too that come to your mind. For this particular question, you will have to use a trick. The trick is to use a hashmap or a hashtable. Then you can store the respective numbers as keys and their occurrences as values. If a number is already present in your hashtable, then its value can be incremented or 1 can be inserted as its value. After this, all those numbers which have the values more than one, can be printed later.

Question 3: Find out the number that is absent in second array, if you are given two arrays - 1,2,3,4,5 and 2,3,1,0,5.

There are some tips to solve such type of programming questions. Hashtable can be used to resolve this problem. Put all the elements of the second array in the hashtable and then for every element of the first array, check whether it is present in hash or not. At last, pick out those elements which are not there in the hash table.

Question 4: How to find a middle element of a linked list in single pass?

Answer this question with a simple solution. Traverse across the linked list till you get its tail. It should point to null so that you can know the length of the linked list and reiterate it till the mid point. Most probably, after this question, you will be asked to find out the middle element in single pass. You should be able to explain it by demonstrating your skills in space-time trade off. You can either use two pointers at a time or a single pointer.

Question 5: How would you sort a result set based on two columns?

In this case, you will have to assume two table viz. product and category. Sorting would be done on the basis of category first and product name later.

var sortedProds = _db.Products.Orderby(c => c.Category).ThenBy(n => n.Name)

Question 6: How to use LINQ to query against a DataTable?

You can never query against rows collection of DataTable, since Ienumerable<T> is not implemented by DataRowCollection. Therefore, you will need to use AsEnumerable() extension for DataTable. For more elaboration, you can also provide an example:

var results = from myRow in myDataTable.AsEnumerable()

where myRow.Field<int>("RowNo") = = 1

select myRow;

Question 7: When to use .First and when to use .FirstOrDefault with LINQ?

This question tests your detailed technical knowledge. When you know the sequence or expect it to have at least one element, then it is advisable to use .First. ON the contrary, when you know that you have to check whether the sequence has any element or not, then it is better to use .FirstOrDefault.

Question 8: Write a LINQ expression to concatenate a List in a single string that is separated by a delimiter.

It is better ti use string.Join to handle this type of problem. You can solve it in interview as below:
string delimeter = ",";

List<string> items = new List<string>() { "foo", "boo", "john", "doe" };

Console.WriteLine(items.Aggregate((i, j) => i + delimeter + j));

Question 9: Find all the occurrences of the, The and THE.

To answer this question, you would have to use the notion of groups and alterations. Using alteration notion enables you to get a choice of alternate patterns to choose between. However, the simplest solution of all is - (the|The|THE). This tends to match any one in the group of of three alternatives. One more solution consists of sub patterns and looks like - (tT)(hH)(eE).

Question 10: Ignore all the vowels in given text.

Some text will be given to you and you will have to perform the given task of ignoring all the vowels in it. You will have to use the negation operator ^ and note that the caret i.e. ^ at the beginning of the class signifies that those characters are not needed there. If this much is known, then you will be able to answer easily and confidently:
[^aeiou]

Apart from these top questions, there are some more programming interview questions too. All of them demand that you must be perfect with your technical knowledge. Programming interviews are tougher than most of the other types of interviews. Up-to-date preparation is what helps in excelling in such interviews.

Sample Test Questions
GRE Sample Questions
CAT Sample Questions
GMAT Sample Questions
TOEFL Sample Questions
ACT Sample Questions
SAT Sample Questions
LSAT Sample Questions
PSAT Sample Questions
MCAT Sample Questions
PMP Sample Questions
GED Sample Questions
ECDL Sample Questions
DMV Sample Questions
CCNA Sample Questions
MCSE Sample Questions
Network+ Sample Questions
A+ Sample Questions
Technical Sample Questions
WASL Sample Questions
CISA Sample Questions