Dot Net For All

Programming coding interview questions for software developers

Hello friends, before appearing for any of the interview for the software product companies we should have some practice and go though some of the most tricky and challenging Programming Interview Questions.

This is a comprehensive list of programming interview questions and answers. You can use any programming language to solve these questions like C++, Java, C# or python. The page include some of the most tricky and frequently asked programming interview questions for the product companies like Amazon, Microsoft, Google to name a few.

Though it is very much possible that you may not find any of these questions in your interview. But it is very much possible that you will find questions revolving around some of questions I will discuss below.

I will keep updating this list to add more and more programming interview questions to crack any interview with top software product companies.

Tricky Programming coding Interview Questions for Practice

Question: Given a binary tree, how will you find the vertical sum of binary tree? For Example for the below binary tree, it has 5 vertical lines, and the sum of vertical line is 1 + 5 + 7 = 13.

Question: In a 2-D matrix, every row is increasingly sorted from left to right, and the last number in each row is not greater than the first number of the next row. A sample matrix follows. Please implement a function to check whether a number is in such a matrix or not. It returns true if it tries to find the number 7 in the sample matrix, but it returns false if it tries to find the number 12.

1   3   5

7   9   11

13  15  17

Question :In a 2-D matrix, every row is increasingly sorted from left to right, and every column is increasingly sorted from top to bottom. Please implement a function to check whether a number is in such a matrix or not. For example, all rows and columns are increasingly sorted in the following matrix. It returns true if it tries to find number 7, but it returns false if it tries to find number 5.

1   2   8   9

2   4   9   12

4   7   10  13

6   8   11  15

Question: How do you find the missing number in a given integer array of 1 to 100? 

Answer: You are given a list of n-1 integers and these integers are in the range of 1 to n. There are no duplicates in list. One of the integers is missing in the list. Write an efficient code to find the missing integer. 

In our case the n is 100. There can be multiple ways to get the answer for this problem. The first way to find the answer is to run a loop from 1 to 100 and check if the loop variable is present in the array as shown below: 

 int[] intArray = { 1, 2, 3, 4, 5....,100 }; 
 for(int i = 1; i <=100; i++){ 
   int pos = Array.IndexOf(intArray, i); 
    if(pos < 0) 
        //i is the missing element and break 
        break; 
 }  

The second way to find the answer of the solution is comes from a basic math formula. We can find the sum of n continuous integer by using the formula n(n+1)/2. By this method we can find the sum of integers from 1 to 100.  

static int getMissingNo (int []a, int n) {  
         int total = (n) * (n + 2) / 2;             
         for (int i = 0; i< n; i++)  
         total -= a[i];            
         return total;  
   } 

Question: This is a very interesting question asked to me in Amazon interview. The solution is equally interesting.

You’re given a grid map of subway stations(marked as X), write a function which outputs the distance from each road intersection to the nearest station. You cannot move diagonally from one point to another. You can only move up, down, left ,right.

input:

. . . . . X
. . . . . .
. . . . . .
. X . . . .
. . . . X .

output:

4 3 3 2 1 0
3 2 3 3 2 1
2 1 2 3 2 2
1 0 1 2 1 2
2 1 2 1 0 1

Question: Write a method to see if a binary tree is “superbalanced”. A tree is “superbalanced” if the difference between the depths of any two leaf nodes is no greater than one.

Question:Write a method to check that a binary tree is a valid binary search tree.

A binary search tree is a binary tree in which, for each node:

  1. The node’s value is greater than all values in the left subtree.
  2. The node’s value is less than all values in the right subtree.

Top career enhancing courses you can't miss

My Learning Resource

Excel your system design interview