Coding Interview Questions For Programmers

Download as pdf or txt
Download as pdf or txt
You are on page 1of 13

Coding Interview Questions for Programmers

1. Array-based Programming Interview Questions


If you ask me just one topic to prepare really well for coding
interviews, I would pick the array. It's one of the essential
data structure and favorite darling of coding interviews.
There are so many popular coding interview questions which
are based upon the array, some of them are easy and some
are tough but you can be sure that you will see some
questions based upon array in your next programming job
interview.
If you don't know, an array is a data structure which holds
other objects like String, int, float, etc. It holds them in a
contiguous location in memory which makes it easily
searchable and retrieval in O(1) time using the index.
Insertion and deletion of an array are tough because you
cannot change the size of an array once created and you
need to create a new array and copy elements from old to
new.
Anyway, here are some of the most popular array based
coding interview questions for your preparation:
1. How to find the missing number in given integer array of 1
to 100?
2. How to find the duplicate number on a given integer
array?
3. How to find the largest and smallest number in an
unsorted integer array?

4. How to find all pairs of integer array whose sum is equal to


a given number?

5. How to find duplicate numbers in an array if it contains


multiple duplicates?

6. How to remove duplicates from a given array in Java?

7. How to sort an integer array in place using QuickSort


algorithm?

8. How to remove duplicates from an array in place?

9. How to reverse an array in place in Java?

10. How to find multiple missing numbers in given integer


array with duplicates?
2. String-based Coding Interview Questions
After array, String is the next popular topic on Programming
job interviews, but if you have a good understanding of array
then you can easily deal with String programming questions
because String is nothing but a character array.
The string is implemented differently in a different
programming language like in C it's a NULL terminated
character array but in Java, it's an object. Though, you can
still get access to the underlying array to apply your logic.
Here is a list of some of the frequently asked coding
questions which are based on String. Though some of them
are quite old, you can still expect this in your programming
job interview:
11. How to Print duplicate characters from String?

12. How to check if two Strings are anagrams of each other?

13. How to print first non repeated character from String?

14. How to reverse a given String using recursion?

15. How to check if a String contains only digits?


16. How to find duplicate characters in a String?

17. How to count a number of vowels and consonants in a


given String?

18. How to count the occurrence of a given character in


String?

19. How to find all permutations of String?

20. How to reverse words in a given sentence without using


any library method?

21. How to check if two String is a rotation of each other?

22. How to check if given String is Palindrome?

3. Linked list based Programming Interview Questions


Along with array and string, a linked list is another popular
data structure in the programming world as well as on coding
interviews. You will find a lot of questions on a linked list like
reversing a linked list, adding a new element, removing an
element from the middle, etc.
It's also the counterpart of an array data structure. While
array stores elements on contiguous memory location, the
linked list stored them at different locations and find them by
storing there address. a linked list is made of nodes, an
internal data structure which holds the value as well as the
address of the next node.
Because of its structure, it's easier to add and remove
elements from the linked list like on O(1) time if you are
adding or removing from the head but the search is equally
difficult and takes O(n) time, as you have to literally walk
through each element.
Anyway, here is a collection of some of the simple and tricky
linked list based coding question for your practice:

23. How to find the middle element of a singly linked list in


one pass?

24. How to check if a given linked list contains cycle? How to


find the starting node of the cycle?

25. How to reverse a linked list?


26. How to reverse a singly linked list without recursion?

27. How to remove duplicate nodes in an unsorted linked


list?

28. How to find the length of a singly linked list?

29. How to find the 3rd node from the end in a singly linked
list?

30. How do you find the sum of two linked list using Stack?

4. Binary Tree based Coding Interview Questions


A tree is another popular data structure in the programming
world and coding interviews. Unlike array and linked list,
which are considered linear data structure, a tree is
considered a hierarchical data structure and used to arrange
information in hierarchical order.

There are a lot of different types of tree e.g. a binary tree,


binary search tree, AVL tree, Red Black tree, etc but Binary
and Binary search tree are also known as BST are two of the
most popular ones and most of the question are based upon
them.

Some questions are also based upon theoretical knowledge


of tree data structure e.g. finding the height of the tree,
finding leaf nodes, checking if the tree is balanced or not, etc,
hence you should also spend some time to learn the basics,
along with practicing coding questions.

Anyway, here is a list of a popular binary tree and binary


search tree based coding question to practice before your job
interview:

30. Can you write a program to implement a binary search


tree?

31. How do you perform Pre-order traversal in a given binary


tree?

32. Write a Program to traverse a given binary tree in Pre-


order without recursion
33. How to perform an In order traversal in given binary tree?

34. How to print all nodes of given binary tree using inorder
traversal without recursion

35. How to implement Post-order traversal algorithm?

36. How to traverse a binary tree in Post order traversal


without recursion

37. How to Print all leaves of a binary search tree?

38. How to count a number of leaf nodes in a given binary


tree?

39. How to perform a binary search in a given array?

5. Miscellaneous Programming Interview Questions


Even though data structure based questions makes the bulk
of Coding Interview, there are always some questions from
topics like sorting algorithms, bit manipulation, software
design, Dynamic Programming, and other logical and tricky
questions.

In this list below, you will find most of the common searching
and sort questions as well as a couple of design and bit
manipulation questions.

40. How to implement the Bubble Sort algorithm?

41. How to implement Iterative QuickSort Algorithm?

42. How to implement Insertion Sort Algorithm?

43. How to implement Merge Sort Algorithm?

44. How to implement the Bucket Sort Algorithm?

45. How to implement the Counting Sort Algorithm?

46. How to implement Radix Sort Algorithm?


47. How to swap two numbers without using the third
variable?

48. How to check if two rectangles overlap with each other?

49. How to design a Vending Machine?

50. How to implement an LRU Cache in your favorite


programming language?

51. How to check if a given number is a Palindrome?

52. How do you check if a given number is an Armstrong


number?

53. How do find all prime factors of a given number?

54. How do check if a given number is positive or negative in


Java?
55. How to find the largest prime factor of a given integral
number?

56. Write a Program to print all prime numbers up to a given


number?

57. Write a Program to print Floyd's triangle?

58. Write a Program to print Pascal's triangle?

59. How to calculate the square root of a given number?

60. How to check if the given number is a prime number?

61. How to implement the Sieve of Eratosthenes Algorithm?

62. How to add two numbers without using the plus operator
in Java?

63. Write a Program to subtract two binary numbers?


64. Write a Program to transpose a Matrix?

65. Write a Program to add or subtract two Matrices?

66. Write a Program to multiply two Matrices in Java?

67. How to calculate the average of all numbers in a given


array?

68. How to check if a given number is even/odd without


using Arithmetic operator?

69. Write a Program to find GCD of two numbers using


Euclid's Algorithm?

70. How to find the number of 1s (the Set bit) in a given Bit
Sequence?

71. Write a Program to given Pyramid structure?


72. How to find the highest repeating world from a given file
in Java?

73. How to reverse given Integer in Java?

74. How to convert a decimal number to binary in Java?

75. How to check if a given year is a leap year in Java?

You might also like