Programming Interview Questions
So you want to know what they are going to ask? Or maybe you are looking for questions to ask?
Here are some programming questions or puzzles often asked in programming interviews. There are usually more than one answer to these questions. Some of them are open ended questions to test how you think
and communicate a technical point.
Popular topics are:
4. Other data structures are Linked List, Tree, Stack, Que.
5. Object Oriented Programming
6. Multi Threading
7. SQL and Databases
8. Miscellaneous Programming Topics
10. Soft Questions
Algorithms Interview Questions
- Can you discuss the characteristics of different sort algorithms such as bubble sort, heap sort, merge sort, quick sort, hash sort? When would you prefer one of them over the other?
- What does it mean for a sort algorithm to be stable?
- What kind of search algorithms are available to search sorted data?
- How does a hashtable work?
- Which one do you think will perform faster?
There is a tree structure. The leaf nodes of the tree contain letters like A, B...Z.
- Sorting 1 million Strings using Collections API in Java, or C++ using STL?
- A binary search over 1 million Strings in Java? Or a binary search of 1 million strings in C++? (STL)
- A lookup of a String key in a Java HashMap, or a lookup of a string key in an STL HashMap? Does STL have a HashMap implementation in the first place? What Map implementations are available in
STL? (We are not just talking Visual C++)
- To tackle above problems (storing, sorting 1 million strings), what kind of classes (or frameworks) would you use in Java and in C++? What are their cons and pros? How does Java and it’s
libraries compare with C++ with regard to these frameworks?
- Write code to print the letters that the leaf nodes contain, from left to right.
- Write code to compare two trees to see if their leaf nodes contain the same letters in the same order or not.
Given a tree where each node contains a letter like A...Z, print each letter in breadth-first order. What data structure would you use to do this? (Hint: It’s a queue)
There are 8 bins, each with capacity C. We have a constant stream of goodies each with different size that we need to place into these bins. We start filling the bins from left to right. Whenever an
input fits in a bin, we put it there, we do not look any further.
- A. You can put everything in a StringBuilder and compare two strings at the end.
- B. If the trees are big and you want to end comparison as soon as there is a difference found, you can start two threads, each traversing 1 tree, and instead of writing to a StringBuilder,
they will be writing to a Pipe. Their parent thread will read from this pipe and will stop the threads as soon as a difference is found.
- A. What is the complexity of our algorithm? O(n)? O(n*n) ? or O(nlogn)?
- B. How can we make it faster without changing the final outcome (without changing the content of the bins)? and when we do that what would the complexity be?
- Hint: O(nlogn) is possible.
Speed up your job search. E-mail your resume to thousands of employers:
C Style Strings:
- Find a substring inside a string.
- Find a 4 byte substring inside a string. (Instead of comparing bytes or characters, can you now compare as 32 bit integers? What would you do to make your function to be portable across 16,32, 64 bit
- Find and replace a substring inside a string with another string.
Reverse the contents of the string.
- Using secondary storage.
- Not using any other storage, assuming existing char* has space to hold the final string. (Or it does not and you need to guard for that.)
- What happens when string to find is shorter than string to replace with. What happens if it is longer.
Reverse the words of the string.
- Using extra storage.
- Without using extra storage (in place).
How do you go about solving above problems in Java? What are the differences in handling strings in C, C++ and Java. What options are available? What are the cons and pros?
- Using extra storage.
- Not using extra storage.
- How do you declare and allocate 2-D and 3-D arrays in C? What are possible options?
- How do you declare and allocate 2-D and 3-D arrays in Java? (Or, is there such thing as 2-D, 3-D arrays in Java in the first place?) What are possible options?
Data Structures Interview Questions
- What is Linked List (single, double), tree, que, stack, map, hashtable? In Java, if you want to map string keys to string values, which implementation classes are well known to fit this purpose? What
would you use, if you wanted to access the keys in sorted order?
- How do you detect that a linked list is circular?
- How do you traverse a tree in depth first order?
- There is the following tree: Root is 1, under it, left node is 2, right node is 3. Under 2, there is 4 and 5. Under 3, there is 6 and 7. What is the algorithm to be able to print them in the order
Object Oriented Programming Interview Questions
- What is Inheritance, Encapsulation, Polymorphism? Give examples to illustrate how they are useful. In C++ and/or Java what language syntax and constructs help implement these concepts?
Why is the java.lang.String final?
When would you override equals() method?
When would you override hashCode() method? What else would you do if you override hashCode()?
What are auto pointers? What are smart pointers? Have you seen them in action? Where are they used?
Is Windows API object oriented? In what way it is, what way it is not?
- What is a constructor? What is a destructor in C++?
- Does Java have a destructor?
- Why do we declare destructors to be virtual in C++?
- What are private, protected, public modifiers for class members? In Java, what is the default? (no modifiers specified? What is the impact?)
- What is “final” used for as in final class MyClass in Java?
- Why does C# have a overrides keyword to override virtual functions where as Java does not have it?
Multi-Threading Interview Questions
- How is multi-threading beneficial? What do we gain out of it? What are the pitfalls and dangers we are faced with when we build multi-threaded systems?
- In Java, what basic language elements are available to aid multi-threading?
- What is synchronized, wait, notify?
- How is notifyAll() different than notify()?
- What is a Semaphore?
- What is a Critical Section?
- What is a Mutex?
- What is InterlockedIncrement?
- Can you please implement a Semaphore in Java?
- There are 2 threads. You want these 2 threads to do some work and then reach a certain point but not proceed until the other thread also reaches a certain point. How do you implement this in Java?
How do the 2 threads wait for each other? Once they reach that certain point, how will they know when they both can proceed?
- There is an array of sorted elements. Assuming that the cost of inter-thread communication is insignificant compared to the cost of accessing these elements, how can we design a multi-threaded
algorithm to search for a value within this sorted data set?
In a multi-threaded system, assume that there is 1 writer that modifies the contents of an integer array. There are multiple readers who take consistent snapshots of this array for their use. If the
writer definition is as below, what is the reader implementation going to be like?
Writer: declare int c = 0; global variable at the beginning (reader threads can see this variable).
Assume that c++; is an atomic operation.
SQL and Databases Interview Questions
- What is a Primary Key?
- What is a Candidate Key?
- What is a Unique Key?
- What is Index?
- What is Unique Index?
- What is Cluster Index?
- What are ACID properties?
- What is a transaction?
- How do you start a transaction, how do you end it?
- What is 2 phase commit? When is it needed?
- What is DDL, what is DML?
- What are commonly used isolation levels? Their names? Their purpose?
- How does READ_UNCOMMITED differ compared to READ_COMMITED? Are there differences between major databases with regard to isolation levels? Can you compare READ_COMMITTED isolation level of Oracle
versus DB2 or SQL Server?
- When would you use READ_UNCOMMITED? READ_COMMITTED? REPEATABLE_READ? SERIALIZEABLE_READ? What are the cons and pros?
- What is a shared lock? What is an exclusive lock? When would a database acquire these locks?
- There is an EMPLOYEES(ID, NAME, MANAGER_ID) table. MANAGER_ID points to the ID column of the same table. Given a manager name (assuming ID is unique and NAME is unique), what kind of SQL query would
you write to retrieve all employees directly managed by this manager? What is the query to get employees 2 levels down? Is there a way to write a query to get employees N levels down? Is there
another way of organising this table (different columns?) to hold these kinds of tree structures?
- What is a View? How is a View useful?
- What is a Trigger? How is a Trigger useful?
- What is a Stored Procedure? How is a Stored Procedure useful?
- What is a sub select query?
- What is a correlated sub select?
- What is a calling convention such as cdecl or stdcall? What are the differences between cdecl, stdcall and pascal calling conventions? Why do we care about them? What is the calling convention
used in Windows API?
- In cdecl calling convention, who maintains the stack when a function is called? The caller, or the called function? In what direction are the parameters passed? Left to right, or right to left?
- In Pascal (or Delphi) can you write a printf(...) function that takes variable number of arguments as in C? Why not?
- In C, is it Ok to have lots of return statements in a function? How does this compare to having lots of exit calls in a Pascal (Delphi) function?
- When do we use increment like i++ versus ++i ?
- What is a strongly typed language? Is C type safe? How about C++? What about Java libraries? What does Java 5 bring into picture to improve type safety?
- In Java, what is a Soft Reference, Weak Reference, and Phantom Reference? When do we need them?
- How would you count the set bits of a 16 bit integer?
- You want to climb a mountain. But you do not have enough food or water to carry along with you yourself. What would you do? (Ideas: You could carry food half way with multiple trips and that point
would become your new base, you would start building a new base higher repeating the same process until you reach the ground. Alternatively, you could start with 100 people, they all go to 1st base,
then with the help of the resources that this 100 people brought to the first base, 20 of them continue to go to 2nd base which is higher, and then maybe 4 could go higher and at last 1 could reach
the top and the mountain would be conquered by the team. You get the idea.)
- There is a paper, it is divided into squares like a checker board. To get each square separated, how many times would you need to cut this paper? (Let’s say it is 5x5 checker board). How many cuts
would you need if the square index number 2x2 was already missing? What if 2x1 is missing? What if 2x2 and 2x3 is missing? Is there a mathematical formula? Can you calculate how many cuts is needed
given the size of the paper (5x5 for example) and which squares are already cuts out (missing)?
- There are 23 prisoners in a prison. The guard tells them that whenever he wants, he will take 1 of them to a room where there are 2 switches. Each switch is either on or off. The prisoner must
switch one of the switches and then go back to his cell. At any time if a prisoner correctly tells the guard that all 23 of them have been to that room at least once, then they will
all be freed. Any wrong answer will lead them all to death. The prisoners will have a one time meeting together to decide on their strategy before this process starts. Nobody knows the initial state
(on or off) of the switches. What should be their strategy to become free?
As part of your phone interview, or email correspondence with the hiring company, you may be asked to write a small program to solve a problem that they describe. You may submit it via email or if you are
developing a website, you might as well include the source code online and provide a visually appealing presentation via html page with syntax higlighting your code.
Interview Soft Questions
- How would you describe your own code?
- What is the end to end process that you use to write a function (or a group of them)?
- If you add the total time you spend on coding, design and architecture, how much time did you spend writing code versus designing software?
- Have you ever worked with a hard to work person, how did you go about that? What kind of problems did arise? How did you solve them?
Share interview questions with your friends:
Increase your exposure, post your resume for all to see:
Books About Programming Interviews
Cracking the Coding Interview, Fourth Edition: 150 Programming Interview Questions and Solutions
Programming Interviews Exposed: Secrets to Landing Your Next Job, 2nd Edition (Programmer to Programmer)
Algorithms For Interviews
Programming Pearls (2nd Edition)
Jon Louis Bentley
Puzzles for Programmers and Pros
Dennis Elliott Shasha
Cracking the C, C++, and Java Interview
Leonard G. Marks
How Would You Move Mount Fuji?: Microsoft's Cult of the Puzzle -- How the World's Smartest Companies Select the Most Creative Thinkers
C & C++ Interview Questions You'll Most Likely Be Asked
Ace the IT Interview (Ace the It Job Interview)
Masterminds of Programming: Conversations with the Creators of Major Programming Languages (Theory in Practice (O'Reilly))
Coders at Work: Reflections on the Craft of Programming
Java / J2EE Interview Questions You'll Most Likely Be Asked
Hibernate, Spring & Struts Interview Questions You'll Most Likely Be Asked
Lotus Domino Programming Interview Questions, Answers, and Explanations: Lotus Domino Certification Review
PHP MySQL Web Programming Interview Questions, Answers, and Explanations: PHP MySQL FAQ
Java/J2EE Job Interview Companion
HTML, XHTML & CSS Interview Questions You'll Most Likely Be Asked
Programmers at Work: Interviews With 19 Programmers Who Shaped the Computer Industry (Tempus)
Susan M. Lammers
Behavioral Interview Questions
Tell me about a time when you …
- Worked effectively under pressure.
- Handled a difficult situation with a co-worker.
- Were creative in solving a problem.
- Missed and obvious solution to a problem.
- Were unable to complete a project on time.
- Persuade team members to do things your way.
- Wrote a report that was well received.
- Anticipated potential problems and developed preventive measures.
- Had to make an important decision with limited facts.
- Were forced to make an unpopular decision.
- Had to adapt to a different situation.
- Were tolerant of an opinion that was different from yours.
- Were disappointed in your behaviour.
- Used your political savvy to push a program through that you really believed in.
- Had to deal with an irritated customer.
- Delegated a project effectively.
- Surmounted a major obstacle.
- Set your sights too high (or too low).
- Prioritised the elements of a complicated project.
- Got bogged down in the details of a project.
- Lost (or won) an important project.
- Made a bad decision.
- Had to fire a friend.
- Hired (or fired) the wrong person.
- Turned down a good job.
Tough Interview Questions and Answers
Tell me a little about yourself.
-Use this as an opportunity to gather more info and turn the question back to them and focus in on the components of your background that
interests them… it is the perfect time to say “ You can see from my background I have been in business for a while and have accumulated
a very diversified skill set. Could you share with me some of the key elements that you are looking for so I can illustrate them by examples from the various positions I’ve held” …….. This refocuses
the interview back on track and you don’t spend time talking about areas that are not pertinent to the position.
What do you know about our organization?
-Be able to discuss various areas such as image, goals, management style, revenues, etc.
-Don’t act like you know everything about the organization, but do show that you have done your
-Make it clear that you would like to learn more.
Why do you want to work for us?
-Never say “Because I like people”.
-Relate your answer to the company’s needs-this shows you’ve done your homework.
-If you feel you have to make up an answer, you probably shouldn’t be at the interview.
What can you do for us that someone else can’t?
-Be a BIT egotistical.
-Talk about your great track record.
What do you find most attractive about this position? What seems least attractive about it?
-List 3-4 attractive features; mention 1 minor, unattractive feature.
Why should we hire you?
-Formulate your answer by thinking in terms of your ability, your experience, and your energy
What do you look for in a job?
-Keep your answer directed towards the opportunities at the organization. Orient your answer
toward opportunities, not personal security.
Please give me your definition of (the position for which you are being interviewed).
-Be brief and task-oriented.
-Mention responsibilities and accountability.
-Make sure you fully understand the position, if you don’t ask the interviewer.
How long would it take you to make a meaningful contribution to our firm?
-Be realistic, say that while you may pull your weight and meet demands from the first day, it may
take you anywhere from six months to a year to fully understand the organization’s needs enough to make a major contribution.
How long would you stay with us?
-Say that you are interested in a career with the organization, but admit that you would have to
continue to feel challenged to remain with an organization. Think in terms of, “As long as we both feel achievement-oriented.”
Your resume suggests that you may be overqualified or too experienced for this position.
What do you think?
-Stress that you are interested in establishing a long term association with the organization, and
that you assume that if you perform well in this job, new opportunities will open up for you. A strong company needs a strong staff. Suggest that because you are so well qualified, the company
will get a fast return on its investment.
What is your management style?
-Know enough about the company’s style to know that your management style will compliment it.
You could be task-oriented (“I enjoy problem-solving, identifying what’s wrong, choosing a solution, and implementing it”). The participative style is also popular: an open-door method of
managing in which you get things done by motivating people and delegating responsibility. As you consider this question, think about whether your style will let you work happily and effectively
within the organization.
Are you a good manager? Can you give me some examples? Do you feel that you have top
-Keep your answer achievement and task-oriented. Rely on examples from your career to support
your statements. Stress your experience and your energy.
What do you look for when you hire people?
-Think in terms of skills, initiative, and the adaptability to be able to work comfortably and
productively with others. Mention that you like to hire people who appear capable of moving up in an organization.
Have you ever had to fire people? What were the reasons, and how did you handle the
-Admit that the situation wasn’t easy, but say that it worked out well, both for the company and,
you think, for the individual or individuals involved. Show that, like anyone else, you don’t enjoy unpleasant tasks, but that you can resolve them efficiently and, in the case of firing someone,
What do you think is the most difficult thing about being a manager or an executive?
-Mention planning, execution, and cost control. The most difficult task may be to motivate and
manage employees to get tasks routinely planned and completed on time and within budget.
What important trends do you see in our industry?
-Be prepared with two or three trends that illustrate how well you understand your industry. You
might consider technological challenges or opportunities, economic conditions, the current competitive situation, or even regulatory demands related to the direction in which your business is heading.
What are the frontier or cutting-edge issues in our industry?
-Be prepared with two or three key issues.
Why are you leaving (did leave) your present (last) position?
-Be brief, to the point, and as honest as you can without hurting yourself. Refer back to the
planning phase of your job search, where you considered this topic as you thought about reference statements. If you were laid off in a staff reduction, say so; otherwise, indicate that the move
was your decision, the result of your desire to advance your career. Don’t mention personality conflicts.
The interviewer may spend some time probing you on this issue, particularly if it’s clear that you
were terminated. Be as positive and honest as you can. The “We agreed to disagree” approach suggested earlier may be useful. Don’t fabricate a story for an interviewer: evening today’s
reference-shy climate, your story might be checked.
In your current (last) position, what features do (did) you like the most? The least?
-Be careful and positive. Describe more features that you liked than disliked. Don’t cite
personality problems. If you make your last job sound terrible, an interviewer may wonder why you’ve remained there until now, or whether you have an attitude problem that would likely to
show up on a new job, too.
In your current (last) position, what have been (were) your five most significant
-Have specific examples ready. If you’re asked five examples, don’t cite ten. If you want to show
that you were responsible for more than five major achievements, you can say, “I’ve given you the five that seem the most important to me. There are others, if you’d like to hear about some
other area of my work.” Then, if the interviewer asks for additional accomplishments, you can give them without appearing to boast.
Why haven’t you found a job before now?
-Say that finding a job isn’t difficult, but that finding the right job deserves time and demands
Did you think of leaving your present position before? If so, what do you think held you
-You might say that the challenge of the job held you in the past but, as that seemed to diminish,
you reached the decision to investigate new opportunities.
What do you think of your (former) boss?
-Be as positive as you can. A potential boss will anticipate that you might talk about him or her in
similar terms at some point in the future.
Would you describe a few situations in which your work was criticized?
-Be specific. Don’t be emotional. Think in terms of constructive criticism. Show that you
responded positively and benefited from that criticism.
If I spoke with your (former) boss, what would he or she say are your greatest strengths and
-Name three or four strengths and only one weakness. Be honest but not negative.
Can you work under pressure and deal with deadlines?
-Observe that both are facts of business life. Take examples from your list of accomplishments to
show how you have dealt successfully with pressure and deadlines in the past.
Did you change the nature of your job?
-Tell how you improved it.
Do you prefer staff or line work?
-Say that it depends on the job and its challenges.
In your present (last) position, what problems did you identify that had previously been
-Be brief and don’t brag. Indicate the positive changes your suggestions or leadership resulted in.
Don’t you think you might be better suited for a different size company? To a different type
-Tailor your answer to the job being discussed. Say that your preferences for the size or type of
company generally depend on the job in question. Note that your research has shown you that this organization and this job meet your criteria.
If you could choose any company, where would you go?
-Talk about the job and the company for which you are being interviewed.
Why aren’t you earning more at your age?
-Say that this is one reason you are conducting this job search. Don’t be defensive.
What do you feel this position should pay?
-Salary is a delicate topic. Try not to tie yourself to a precise figure for as long as you can do it
politely. You might say, “I understand that the range for this job is between $X and $Y, that seems appropriate for the job as I understand it.” You might answer the question with a
question: “Perhaps you can help me on this one. Can you tell me if there is a range for similar jobs in the organization?”
If you’re asked the question during an initial screening interview, you might say that you feel you
need to know more about the responsibilities involved before you can give a meaningful answer. Here too, either by asking the interviewer or doing research during your investigation of the
company, you can try to find out whether there is a salary grade attached to the job. If there is, and if you can live with it, say that the range seems right to you.
If the interviewer continues to probe you, you might say, “You know I am making $X now. Like
everyone else, I’d like to improve on that figure, but my major interest is in the job itself.” Remember that the act of taking a new job does not, in and of itself, make you worth more money.
If a search firm is involved, your contact there may be able to help with the salary question. A
search firm representative may even be able to run interference for you. If, for instance, this person tells you what the position pays, and you respond that you are earning that amount now and
would like to do a bit better, he or she might go back to the employer and propose that you be offered an additional ten percent.
If no price range is attached to the job, and the interviewer continues to press the subject, then
you will have to respond with a number. You can’t leave the impression that it doesn’t really matter, that you’ll accept what ever is offered. If you’ve been making $96 000 annually, you can’t
say that a $42 000 figure would be fine without sounding like you are giving up on yourself. (If you’re making a radical career change, however, a substantial disparity may be more reasonable
Don’t sell yourself short, but continue to stress the fact that the job itself is the most important
thing in your mind. The interviewer may be trying to determine just how much you want the job.
Don’t leave the impression that money is the only thing important to you. Link questions of salary to the work itself.
But, whenever possible, say as little as you can about salary until you reach the final stage of the
interviewing process. At that point, you know the company is genuinely interested in you and that it is more likely to be flexible in salary negotiations.
Do you have any objections to psychological tests?
-Say you would feel comfortable taking them.
What other jobs or companies are you considering?
-Restrict your answer to fields similar to the one in which this company operates.
Do you speak to people before they speak to you?
-The interviewer is probably trying to determine your ability to deal with unstable or unanticipated
situations. Say that your actions depend on specific circumstances. While you wouldn’t normally start a conversation with a stranger on the street, for example, you feel comfortable initiating
discussions with people you don’t know in normal business or social settings.
What was the last book you read? Movie you saw? Sporting event you attended?
-Try to show hat you lead a balanced life when answering questions about outside activities.
Will you be out to take your boss’s job?
-Say that while you certainly hope to win additional responsibility in the organization, you’ve
always focused on getting the current job done.
Are you creative?
-Be prepared with work related examples of creativity.
How would you describe your own personality?
-It may be wise to say you are the proud owner of a balanced personality.
Do you consider yourself a leader?
- Take examples from your work experience
What are your long range goals?
- Refer back to the self-assessment phase of your career continuation efforts. Don’t answer, “I
want the job you’ve advertised.” Relate your goals to the company you’re interviewing for: “In a firm like yours, I would like to…”
What are your strong points?
- Present at least three. Use concrete, work-related examples to illustrate them. Try to relate
your answer to the interviewing organization and the specific job opening.
What are your weak points?
- Don’t say that you have none. But try to make a negative sound like a strength carried a bit to
far; “Some people say I spend too much time at work.”
Don’t offer a list of weaknesses. A good interviewer is likely to press you a bit saying, “Is there
anything else? “ You might answer, “No, I don’t think so on that topic.” If the interviewer persists, come up with a second weakness, but only if you are asked for it. Don’t offer negative
information unnecessarily.. If the interviewer continues and asks for third weaknesses, say politely that you really can’t think of anything else.
Finally, show that you are working to correct your weaknesses.
If you could start your career again what would you do differently?
- The best answer is “Not a thing.” You should try to present yourself as an individual who is
happy with his or her life. You’ve enjoyed its ups and learned from its downs. You would not, as a
result, want to change things that brought you to where you are today. Mention that it is the past, after all, that has prepared you for this position.
What career options do you have at this moment?
-You should try to identify three areas of interest, one of which includes this company and job.
The other two should be in related fields.
How would you define success?
- Think in terms of a sense of well-being. Consider opportunity and responsibility as components
How successful do you think you’ve been so far?
- Say that, all in all, you’re happy with the way your career has progressed. Given the normal ups
and downs of life, you feel that you’ve done quite well and expect to continue to succeed in the future.
***Present a positive and confident picture of yourself, but don’t overstate your case. An
answer like, “Everything’s wonderful; I’m overjoyed!” is likely to make an interviewer wonder whether you’re trying to fool him or yourself. The most convincing confidence is
usually quiet confidence.
Share interview questions with your friends: