Top 30 Programming interview questions
Programming questions are integral part of any Java or C++ programmer or software analyst interview. No matter on which language you have expertise it’s expected that you are familiar with fundamental of programming and can solve problems without taking help of API. Programming questions like How to reverse String using recursion or How to find if Array contains duplicates are some popular examples of programming question in Java. Programming questions present lot of challenges Especially to Java developers as compared to C++ programmer and I think, One reason for this is powerful Java API; Which has method for almost every need and you rarely need to write by your own or there are lots of third party library from Apache, Spring, Google and other open source. These programming interview questions are from my personal collections and I have only chosen those which are not very difficult, can be solved easily but at same time can become too complex or confusing, present lots of follow-up questions and test fundamentals of programming, OOPS and design. I have not given answers of these programming questions but those can be found by google and I will try to post links of answers here sometime later but at same time I will try to provide quick tips or hints on some questions.
Anyone who is following programming questions must be familiar with these questions and also knows answer for most of these but for new guys and even for intermediate its worth refreshing it before going to any programming job interview e.g. Core Java interview.
String Programming Interview Questions
String is the primary and probably most common thing you come across on any programming language and so is with any programming interview. There is almost always a question on String whether its related to length or replace but I have always find one or two String programming questions on interviews.
1) Write code to check a String is palindrome or not?
Palindrome are those String whose reverse is equal to original.This can be done by following technique demonstrated in How to reverse String in Java without using API
4) Write a function to find out longest palindrome in a given string?
Some more String related Questions which mostly appear in Java programming interviews:
Difference between String and StringBuffer in Java
Why String is final in Java
How to Split String in java
Why Char array is preferred over String for storing password?
Programming questions on Array
Array is one of the topics where most of programming questions is asked. There are many and many programming questions on Array and here I have included only some of them which is not very difficult to solve but some of array programming question can be extremely challenging, so well prepare this topic.
6) In an array 1-100 exactly one number is duplicate how do you find it?
This article contains a trick to find duplicates in Array using Java programming language
trick in this programming questions is by using hashmap or hashtable , we can store number as key and its occurrence as value, if number is already present in hashtable then increment its value or insert value as 1 and later on print all those numbers whose values are more than one.
Here is a quick tip to solve this programming question: put the elements of the second array in the Hashtable and for every element of the first array, check whether it’s present in the hash or not, O/P all those elements from the first array that are not present in the hash table
LinkedList Programming Interview Questions
To answer this programming question I would say you start with simple solution on which you traverse the LinkedList until you find the tail of linked list where it points to null to find the length of linked list and then reiterating till middle. After this answer interviewer will ask you find the middle element in single pass and there you can explain that by doing space-time tradeoff you can use two pointers one incrementing one step at a time and other incrementing two step a time, so when first pointer reaches end of linked second pointer will point to the middle element.
Binary Tree Programming Interview Questions
Programming questions on searching and sorting
18) Write a program to implement binary search algorithm
19) How do you sort Java object using Comparator?
This is another Java specific programming questions and you can check how to sort Object using Comparator and Comparable for answer.
Programming questions on numbers
20) Write a program to check whether a no is palindrome or not?
check out this post which shows how to reverse number in Java and can be used to find if its palindrome or not.
21) Write code to check whether a no is Armstrong no or not
Here is a Java program to find Armstrong number, you can use same logic to write code in any other programming language like C and C++.
22) Write a program to find all prime number up to a given numbers?
Here is another Java program to find prime numbers and print them. By using logic demonstrated in this program; you can write similar program in C and C++.
23) Write function to compute Nth Fibonacci number? Both iterative and recursive?
Check this Java program to print Fibonacci Series using recursion and iteration.
General Programming Interview Questions
In this category of programming questions I have put questions which are not fit into any data structure but presents a real life problem and you need to provide solution. These programming questions are sometime based on problems faced by developer itself. I have not included many Software design related programming question which I have shared on Top 20 software design questions and answers; you can also check that.
30) Write a program for producer-consumer problem?
This article solves producer consumer problem using BlockingQueue in Java. You can refer it to answer this question.
Tips on answering programming questions
5. Most of the time Interviewer ask how to fix a problem as follow-up question e.g. he will ask how do you find deadlock and then how to fix deadlock in java etc.
Why String is immutable in Java
Top 20 Core Java Interview questions
Top 10 Java Collection interview question
Top 15 multi-threading Interview question
Top 10 Java Serialization interview question
Thanks for sharing these programming questions. Was very useful.
ReplyDeletehttps://www.flowerbrackets.com/java-program-to-print-armstrong-number-from-1-to-1000/