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. specially for java developers programming questions present lots of challenges as compared to C++ programmer and I think reason for this 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 apace and other open source. These programming interview questions are of 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. 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.

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?

2) Write a method which will remove any given character from a String?

3) Print all permutation of String both iterative and Recursive way?

4) Write a function to find out longest palindrome in a given string?

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.

5) In an array 1-100 numbers are stored, one number is missing how do you find it?

6) In an array 1-100 exactly one number is duplicate how do you find it?

7) In an array 1-100 many numbers are duplicates, how do you find it?

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.

8)Given two arrays, 1,2,3,4,5 and 2,3,1,0,5 find which number is not present in the second array.

Here is a quick tip to solve this programming question: put the elements of the second array in the hash table 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

9) How do you find second highest number in an integer array?
LinkedList Programming Interview Questions

10) How do you find middle element of a linked list in single pass?

To answer this programming question I would say you start with simple solution on which you traverse the link 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.



11) How do you find 3rd element from last in single pass?

This programming question is similar to above and can be solved by using 2 pointers, start second pointer when first pointer reaches third place.

12) How do you find if there is any loop in singly linked list? How do you find the start of the loop?

This programming question can also be solved using 2 pointers and if you increase one pointer one step at a time and other as two steps at a time they will meet in some point if there is a loop.

13) How do you reverse a singly linked list?


Binary Tree Programming Interview Questions

Binary tree or simply tree is one of favorite topic for most of interviewer and pose real challenge if you struggle with recursion. Programming questions on tree can become increasingly difficult when you think iterative but sometime can be very easy if you come with recursive solution.

14) How do you find dept of binary tree?

15) Write code to print InOrder traversal of a tree?

16) Print out all leaf node of a binary tree?



Programming questions on searching and sorting

I have only included two programming questions on this category but there are more can be finding on google. Purpose of these programming questions is to see whether programmer is familiar with essential search and sort mechanism or not.

17) Write a program to sort numbers using quick sort?

18) Write a program to implement binary search algorithm

Programming questions on numbers

Most of the programming questions are based on numbers and these are the ones which most of us did on college level and mind you they still has value I have seen programmers with experience of 3 years struggle with these programming questions and doesn’t solve it some time and take a lot of time which simply shows that they are not in programming in there day to day work.

19) Write code to check whether a no is power of two or not?

20) Write a program to check whether a no is palindrome or not?

21) Write code to check whether a no is Armstrong no or not

22) Write a program to find all prime number up to a given numbers?

23) Write function to compute Nth Fibonacci number? Both iterative and recursive?



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.

24) Write a program to find out if two rectangles R1 and R2 are overlapping?

35) You need to write a function to climb n steps you can climb either 1 step at a time or 2 steps a time, write a function to return number of ways to climb a ladder with n step.

26) Write code for Generate Random No in a range from min to max?

27) Write program for word-wrap which should work on any screen size?

28) Design an algorithm to find the frequency of occurrence of a word in an article?

29) Write a program to implement blocking queue in Java?

30) Write a program for producer-consumer problem?

Tips on answering programming questions

1. If Interviewer asks you to write function then make sure you do some necessary check for bad input e.g. null check or empty check. Most of the time programmer forgets to test for not null, empty, less than 1, greater than 1 or zero input.

2. If you write iterative version of function then Interviewer may ask you to write recursive version or vice-versa so be prepare for that.

3. If you write a recursive function then Interviewer will ask to optimize it, even in case of Iterative version. So remember that you can optimize recursive function by Memoization (caching already calculated value) and by applying some space/time tradeoff principle. For example recursive version of Fibonacci series has O(n2) which can be reduced to O(n) using Memoziation.

4. Interviewer may ask you to calculate Order of complexity for best and worst case of any method so be prepared.

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.
Programming Interview Exposed》是一本面试准备的参考书籍,它对编程面试常见的问题和解法进行了详细的讲解。该书由John Mongan、Eric Giguère和Noah Kindler合著,旨在帮助读者提高在编程面试中的表现。 这本书的内容分为几个不同的章节,每个章节都涵盖了特定的面试主题,如数据结构、算法、系统设计等。作者对于每个主题都提供了基础概念的解释和例子,然后通过一系列的面试题目帮助读者应用所学知识进行实践。此外,书中也包含了许多经典的编程题目和解法,并给出了详细的解释和分析,帮助读者更好地理解问题的本质和解决方案。 这本书的优点在于它提供了大量的面试题目和解法,而且难度逐渐上升,有助于读者逐步提高自己的编程能力。同时,书中的讲解通常很清晰易懂,适合初学者或有一定编程基础的人阅读。另外,这本书也非常实用,它给出了一些面试的技巧和策略,可以帮助读者准备面试并提高应试能力。 不过,也有一些需要注意的地方。首先,这本书的题目可能并不够全面,它只是涉及了一些常见的面试主题,可能无法覆盖到所有的面试题目。其次,书中的解法虽然给出了详细的讲解,但可能并不是最优解,因此读者还需要自己继续思考和学习其他解法,以应对多样化的面试需求。 总体而言,如果你正在准备编程面试,那么《Programming Interview Exposed》是一本值得参考的书籍。它提供了丰富的面试题目和解法,并帮助读者培养解决问题的能力和应试技巧。然而,同时也需要意识到这本书只是面试准备的一部分,还需要结合其他学习资源和实践来全面提升自己的编程水平。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值