Most Asked Java Coding Interview Questions
In this article i have added most common coding interview questions. If some one practice these he will do better in coding round In Shaa Allah
String
How to reverse a String in java? Can you write a program without using any java inbuilt methods?
Input: String str = "abc"
Output: "cba"
Write a java program to check if two Strings are anagrams in java.
Input: String str1 = "RACE", str2 = "CARE"
Output: "true"
Write a program to check if String has all unique characters in java.
How to check if one String is the rotation of another String in java?
Find the length of a String without using any inbuilt method in java.
Write a program to print all permutations of String in java.
Array
Write a java Program to Find the Smallest and Largest Element in an Array.
Find the number occurring an odd number of times in an array
Find the minimum number of platforms required for the railway station
Given a sorted array and a number x, find the pair in an array whose sum is closest to x
Find all pairs of elements from an array whose sum is equal to a given number
Given an array of 0’s and 1’s in random order, you need to separate 0’s and 1’s in an array.
Count the number of occurrences (or frequency) of each element in a sorted array
-
int arr[] = {14, 12, 70, 15, 95, 65, 22, 30};
Max Difference = 95-12 = 83
Search in a row-wise and column-wise sorted matrix.
Input: mat[4][4] = {
{10, 20, 30, 40},
{15, 25, 35, 45},
{27, 29, 37, 48},
{32, 33, 39, 50}
} x = 29 Output: Found at (2, 1)
Largest sum contiguous subarray.
Input: [-3, -4, 5, -1, 2, -4, 6, -1] Output: 8 Explanation: Subarray [5, -1, 2, -4, 6] is the max sum contiguous subarray with sum 8.
Find the Contiguous Subarray with Sum to a Given Value in an array.
Input: arr[]={14, 12, 70, 15, 99, 65, 21, 90}; X =97.
Sum found between index 1 to 3, Elements are 12, 17 and 15
Min sum in contiguous subarray
Input: arr[] = {3, -4, 2, -3, -1, 7, -5}
Output: -6
-
Input: arr[] = {6, -3, -10, 0, 2}
Output: 180 // The subarray is {6, -3, -10}
Longest Common Prefix in an array of Strings in java.
Input: arr[] = {"javaworld","javabean","javatemp"};
Output: "java"
Find all subsets of a set (power set) in java.
Input: nums = [1,2,3]
Output: [[3],[1],[2],[1,2,3],[1,3],[2,3],[1,2],[]]