Java
Java
Write
Sign up
Sign in
Diptendu Das
·
Follow
7 min read
50
1
If you’re interviewing for a Java programming role, then your coding skills will probably
be tested. Whether you’re a beginner in Java or an expert programmer, this article
provides some common Java interview questions and answers to help you prepare.
import java.util.Arrays;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.Arrays;
class ListNode {
int val;
ListNode next;
ListNode(int val) {
this.val = val;
}
}
11. Write a program to find the minimum number of coins needed to make
change for a given amount in Java.
public class CoinChange {
public static void main(String[] args) {
int[] coins = {1, 5, 10, 25};
int amount = 30;
int[] dp = new int[amount + 1];
Arrays.fill(dp, Integer.MAX_VALUE);
dp[0] = 0;
for (int i = 1; i <= amount; i++) {
for (int j = 0; j < coins.length; j++) {
if (i >= coins[j]) {
dp[i] = Math.min(dp[i], dp[i - coins[j]] + 1);
}
}
}
System.out.println("Minimum number of coins needed: " + dp[amount]);
}
}
12. Write a program to find the intersection of two linked lists in Java.
class ListNode {
int val;
ListNode next;
ListNode(int val) {
this.val = val;
}
}
13. Write a program to find the maximum sum subarray in an array in Java.
15. How do you swap two numbers without using a third variable in Java?
}
17. How do you sort an array in Java?
Arrays.sort(array);
System.out.println(Arrays.toString(array));
The array elements must be sorted to implement binary search. The binary search
algorithm is based on the following conditions:
If the key is less than the middle element, then you now need to search only in the first
half of the array.
If the key is greater than the middle element, then you need to search only in the
second half of the array.
If the key is equal to the middle element in the array, then the search ends.
Finally, if the key is not found in the whole array, then it should return -1. This
indicates that the element is not present.
public static int binarySearch(int arr[], int low, int high, int key) {
int mid = (low + high) / 2;
return -1;
}
int i = 0;
int j = 0;
int k = 0;
if (i == one.length) {
while (j < two.length) {
sorted[k] = two[j];
k++;
j++;
}
}
if (j == two.length) {
while (i < one.length) {
sorted[k] = one[i];
k++;
i++;
}
}
return sorted;
}
return br;
}
return merged;
}
}
Check this website specially designed by Coder for Coding Community
https://greatmindslab.com/
Java Coding
Java Course
50
1
Written by Diptendu Das
488 Followers
Solution Architect
Follow
11
Diptendu Das
138
Diptendu Das
63
1
Diptendu Das
JAVA
10
Ajay Rathod
Barclays Java Spring-Boot Micro-service Interview Question with answer
2024
Hello folks welcome to another real life interview transcript from a banking giant. This was
for Java backend role for experienced…
179
Lists
Staff Picks
616 stories·886 saves
Stories to Help You Level-Up at Work
19 stories·557 saves
Self-Improvement 101
20 stories·1586 saves
Productivity 101
20 stories·1469 saves
Devendu
550
13
AKCoding.com
3
Abhishek Singh
in
ILLUMINATION
Java 8 Stream API Commonly Asked Interview Questions
Java Streams can be used to process a series of components and are essentially a pipeline
of aggregating operations.
529
4
KARAN VERMA
Help
Status
About
Careers
Blog
Privacy
Terms
Text to speech
Teams