Top 10 SDE1 Java interview questions that you need to know!
Divyasri Arun Kumar profile

Divyasri Arun Kumar, Content Marketer

22 Oct, 193 mins read

Landed yourself that much-awaited interview at your dream company? Awesome! However, these interviews can be quite intimidating for some of us, and a technical interview is a stressful situation, no matter how much experience you have.

The main aim of the interviewer is to understand how you can withstand pressure and how quickly can you solve problems. Let’s delve deeper into what you can expect in these interviews:

1. Write a program to reverse an array or string Here is an example:

Input : arr[] = {1, 2, 3} Output : arr[] = {3, 2, 1}

Input : arr[] = {4, 5, 1, 2} Output : arr[] = {2, 1, 5, 4}

Click here for the solution.

2. Given an array of integers, and an integer ‘K’ , find the count of pairs of elements in the array whose sum is equal to 'K'.

a) Input: The first line of the input contains an integer T, denoting the number of test cases. Then T test cases follow. Each test case consists of two lines. The first line of each test case contains 2 space-separated integers N and K denoting the size of the array and the sum respectively. The second line of each test case contains N space-separated integers denoting the elements of the array.

b) Output: Print the count of pairs of elements in the array whose sum is equal to the K.

c) Constraints: 1<=T<=50 1<=N<=50 1<=K<=50 1<=Ai<=100

d) Example: Input 2 4 6 1 5 7 1 4 2 1 1 1 1

Output 2 6

Click here for the solution.

3. Given a single linked list, write a function to swap elements pairwise.

a) Input: The first line of input contains a number of test cases T. For each test case, the first line of input contains the length of the linked list and the next line contains linked list data.

b) Output: Output the linked list after swapping pairwise nodes.

c) User Task: The task is to complete the function pairWiseSwap() which takes the head reference as the only argument and returns nothing.

d) Constraints: 1 <= T <= 100 1 <= N <= 103

e) Example: Input 1 8 1 2 2 4 5 6 7 8 f)Output: 2 1 4 2 6 5 8 7

Click here for the solution.

4. Implement Stack using Queues

a) We are given a stack data structure with push and pop operations, the task is to implement a queue using instances of stack data structure and operations on them. Click here for the solution.

5. Given a Binary Tree, print left the view of it.

a) Given a Binary Tree, print the left view of it. The left view of a Binary Tree is a set of nodes visible when the tree is visited from the left side. Click here for the example and solution.

6. Print a given matrix in spiral form

a) Given a 2D array, print it in a spiral form.

b) Click here to see some examples.

7. DFS on Graph and its representation Click here for the solution.

8. Create multiple currencies e.g. INR, SGD, USD Click here for the solution.

9. Check if two nodes in a Binary Tree are siblings

a) Given a binary tree and two nodes, the task is to check if the nodes are siblings of each other or not.

b) Two nodes are said to be siblings if they are present at the same level, and their parents are the same. Click here to solve this question.

10. Delete a given node in Linked List under given constraints

a) Given a Singly Linked List, write a function to delete a given node. Your function must follow the following constraints:

1.It must accept a pointer to the start node as the first parameter and node to be deleted as the second parameter i.e., a pointer to head node is not global. 2.It should not return a pointer to the head node. 3.It should not accept pointer to pointer to head node.

b) You may assume that the Linked List never becomes empty. Click here for the solution.

Hope this gives you a jumpstart you need to prepare for your upcoming interviews! Good luck!