Software Engineer Trainee
100+ Software Engineer Trainee Interview Questions and Answers for Freshers
Q1. Palindromic Linked List Problem Statement
Given a singly linked list of integers, determine if it is a palindrome. Return true if it is a palindrome, otherwise return false.
Example:
Input:
1 -> 2 -> 3 -> 2 -> ...read more
Check if a given singly linked list of integers is a palindrome or not.
Traverse the linked list to find the middle element using slow and fast pointers.
Reverse the second half of the linked list.
Compare the first half with the reversed second half to determine if it is a palindrome.
Example: Input: 1 -> 2 -> 3 -> 2 -> 1 -> NULL, Output: true
Q2. Search in a 2D Matrix
Given a 2D matrix MAT
of size M x N, where M and N represent the number of rows and columns respectively. Each row is sorted in non-decreasing order, and the first element of each row is g...read more
Implement a function to search for a target integer in a 2D matrix with sorted rows.
Iterate through each row of the matrix and perform a binary search on each row to find the target integer.
Start the binary search by considering the entire row as a sorted array.
If the target is found in any row, return 'TRUE'; otherwise, return 'FALSE'.
Q3. Slot Game Problem Statement
You are given a slot machine with four slots, each containing one of the colors Red (R), Yellow (Y), Green (G), or Blue (B). You must guess the colors without prior knowledge. For ea...read more
Calculate total score based on guessing colors in a slot machine.
Iterate through each slot in the original and guess strings to compare colors.
Count perfect hits when color matches in correct slot, and pseudo-hits when color matches in different slot.
Calculate total score by adding perfect hits and pseudo-hits.
Handle edge cases like invalid input strings or exceeding constraints.
Q4. Maximum Level Sum in a Binary Tree
Given a Binary Tree with integer nodes, determine the maximum level sum among all the levels in the tree. The sum for a level is defined as the sum of all node values present ...read more
Find the maximum level sum in a binary tree by calculating the sum of nodes at each level.
Traverse the binary tree level by level and calculate the sum of nodes at each level.
Keep track of the maximum level sum encountered so far.
Return the maximum level sum as the final result.
Q5. Reverse Linked List Problem Statement
Given a Singly Linked List of integers, your task is to reverse the Linked List by altering the links between the nodes.
Input:
The first line of input is an integer T, rep...read more
Reverse a singly linked list by altering the links between nodes.
Iterate through the linked list and reverse the links between nodes.
Keep track of the previous, current, and next nodes while reversing the links.
Update the head of the linked list to the last node after reversal.
Q6. Power Calculation Problem Statement
Given a number x
and an exponent n
, compute xn
. Accept x
and n
as input from the user, and display the result.
Note:
You can assume that 00 = 1
.
Input:
Two integers separated...read more
Calculate x raised to the power of n. Handle edge case of 0^0 = 1.
Accept x and n as input from user
Compute x^n and display the result
Handle edge case of 0^0 = 1
Ensure x is between 0 and 8, n is between 0 and 9
Share interview questions and help millions of jobseekers 🌟
Q7. Inversion Count Problem
Given an integer array ARR
of size N
with all distinct values, determine the total number of 'Inversions' that exist.
Explanation:
An inversion is a pair of indices (i, j)
such that:
AR...read more
Count the total number of inversions in an integer array.
Iterate through the array and for each element, check how many elements to its right are smaller than it.
Use a merge sort based approach to efficiently count the inversions.
Keep track of the count of inversions while merging the sorted subarrays.
Example: For input [2, 4, 1, 3, 5], there are 3 inversions: (2, 1), (4, 1), and (4, 3).
Q8. Palindrome Linked List Problem Statement
You are provided with a singly linked list of integers. Your task is to determine whether the given singly linked list is a palindrome. Return true
if it is a palindrome...read more
Check if a given singly linked list is a palindrome or not.
Traverse the linked list to find the middle element using slow and fast pointers.
Reverse the second half of the linked list.
Compare the first half with the reversed second half to determine if it's a palindrome.
Software Engineer Trainee Jobs
Q9. Left Rotations of an Array
Given an array of size N
and Q
queries, each query requires left rotating the original array by a specified number of elements. Return the modified array for each query.
Input:
The fi...read more
Rotate an array left by a specified number of elements for each query.
Parse input: read number of test cases, array size, queries, and array elements
For each query, left rotate the array by the specified number of elements
Return the modified array for each query
Q10. Pair Sum Problem Statement
You are given an integer array 'ARR' of size 'N' and an integer 'S'. Your task is to find and return a list of all pairs of elements where each sum of a pair equals 'S'.
Note:
Each pa...read more
Given an array and a target sum, find pairs of elements that add up to the target sum.
Iterate through the array and for each element, check if the complement (target sum - current element) exists in a hash set.
If the complement exists, add the pair to the result list.
Sort the result list based on the first element of each pair, and then the second element if the first elements are equal.
Q11. N Queens Problem
Given an integer N
, find all possible placements of N
queens on an N x N
chessboard such that no two queens threaten each other.
Explanation:
A queen can attack another queen if they are in the...read more
The N Queens Problem involves finding all possible placements of N queens on an N x N chessboard where no two queens threaten each other.
Understand the constraints of the problem: N represents the size of the chessboard and the number of queens, and queens can attack each other if they are in the same row, column, or diagonal.
Implement a backtracking algorithm to explore all possible configurations of queen placements without conflicts.
Ensure that each valid configuration is ...read more
Q12. Two complement of a number 1001 what is data structures?, types of data structures ? what is maching learning name diff methods used in machine learning basic Java concepts from OOPs as per my interview experie...
read moreThe question covers topics like two's complement, data structures, machine learning, and OOPs concepts in Java.
Two's complement of a number 1001 is -0111.
Data structures are ways of organizing and storing data in a computer so that it can be accessed and used efficiently. Examples include arrays, linked lists, stacks, queues, trees, and graphs.
Machine learning is a subset of artificial intelligence that involves training algorithms to make predictions or decisions based on da...read more
Abstract class can have both abstract and non-abstract methods, while interface can only have abstract methods.
Abstract class can have method implementations, while interface cannot.
A class can implement multiple interfaces, but can only inherit from one abstract class.
Interfaces are used to define contracts for classes to implement, while abstract classes are used to provide a common base for subclasses.
Example: Abstract class 'Shape' with abstract method 'calculateArea' and...read more
Q14. Develope "To Do List" full fledged Application with modern design including header footer and also implement functionality like 'Add' , 'Edit', 'Delete' and 'View List' within ½ hour of time span of Interview '...
read moreDevelop a 'To Do List' application with modern design and functionality like 'Add', 'Edit', 'Delete', and 'View List' within ½ hour.
Use HTML, CSS, and JavaScript for front-end development
Implement CRUD operations for tasks (Create, Read, Update, Delete)
Design a user-friendly interface with header and footer
Utilize localStorage or backend server for data storage
Q15. What are Hooks in ReactJs and Explain useState, useRef, useEffect Hooks with their usecases?
Hooks are functions that allow us to use state and other React features in functional components.
useState is a hook that allows us to add state to functional components.
useRef is a hook that allows us to create a mutable reference that persists across renders.
useEffect is a hook that allows us to perform side effects in functional components.
useState example: const [count, setCount] = useState(0);
useRef example: const inputRef = useRef(null);
useEffect example: useEffect(() =>...read more
Overloading is having multiple methods in the same class with the same name but different parameters. Overriding is implementing a method in a subclass that is already present in the superclass.
Overloading involves multiple methods with the same name but different parameters
Overriding involves implementing a method in a subclass that is already present in the superclass
Overloading is determined at compile time, while overriding is determined at runtime
Q17. What advanced Java concepts are you familiar with, such as JDBC, Servlets, Hibernate, Spring, and servers like Apache Tomcat or IBM, as well as any build tools you have experience using?
I am familiar with JDBC, Servlets, Hibernate, Spring, Apache Tomcat, and build tools like Maven.
Experience with JDBC for database connectivity in Java applications
Knowledge of Servlets for handling web requests and responses
Understanding of Hibernate for object-relational mapping in Java
Familiarity with Spring framework for building enterprise Java applications
Experience with Apache Tomcat for deploying Java web applications
Proficiency in build tools like Maven for project ma...read more
Q18. Software process models? differentiating the waterfall model and the incremental model.
Waterfall model is a linear sequential approach, while incremental model divides the project into small increments.
Waterfall model follows a linear and sequential approach, where each phase must be completed before moving on to the next.
Incremental model divides the project into small increments, with each increment building upon the previous one.
Waterfall model is less flexible to changes, as requirements are finalized early in the process.
Incremental model allows for change...read more
Q19. Write Typescript code from scratch of "Finding maximum length of palindromic substring from the given Strings". Do this question in ½ hour live coding interview.
Finding the maximum length of palindromic substring from an array of strings using Typescript.
Iterate through each string in the array
For each string, iterate through all possible substrings and check if it is a palindrome
Keep track of the maximum length palindrome found
Q20. How can you compose multiple HOCs with render props in a React component
Compose multiple HOCs with render props in a React component
Create a render prop component that accepts a function as a prop
Wrap the render prop component with HOCs
Pass the function as a prop to the HOCs
Use the function to render the component's content
Example: withAuth(withTheme(RenderPropComponent))
DELETE removes specific rows from a table, while TRUNCATE removes all rows and resets auto-increment values.
DELETE is a DML command, while TRUNCATE is a DDL command.
DELETE can be rolled back, while TRUNCATE cannot be rolled back.
DELETE triggers ON DELETE triggers, while TRUNCATE does not trigger any triggers.
DELETE is slower as it logs individual row deletions, while TRUNCATE is faster as it deallocates data pages.
Example: DELETE FROM table_name WHERE condition; TRUNCATE tabl...read more
Normalization is the process of organizing data in a database to reduce redundancy and improve data integrity. Denormalization is the opposite process.
Normalization involves breaking down data into smaller, more manageable tables to reduce redundancy.
Denormalization involves combining tables to improve query performance.
Normalization helps maintain data integrity by reducing the risk of anomalies.
Denormalization can improve read performance but may lead to data redundancy.
Exa...read more
Q23. Why is java called the partial OOP concept?
Java is not called the partial OOP concept.
Java is a fully object-oriented programming language.
It supports all the principles of OOP such as encapsulation, inheritance, and polymorphism.
Java allows the creation of classes, objects, and methods to implement OOP concepts.
It provides features like abstraction and encapsulation to achieve data hiding and modularity.
Java also supports interfaces, which are a key component of OOP.
The misconception of Java being a partial OOP conce...read more
Static polymorphism refers to the mechanism where the method to be called is determined at compile time.
Method overloading is an example of static polymorphism where the method to be called is resolved at compile time based on the method signature.
Compile-time polymorphism is another term for static polymorphism.
Static polymorphism is achieved through function overloading and operator overloading.
Q25. Write a program to print the length of number of permutations if the given input is "123"
Program to print the length of number of permutations of a given input
Use recursion to generate all permutations
Count the number of permutations and print the length
Q26. Swap 2 integers without using 3rd integer
Swap 2 integers without using 3rd integer
Use XOR operator
Addition and subtraction can also be used
Bitwise operations can be used
Q27. What are the features of Java 8 that you are familiar with?
Java 8 features include lambda expressions, functional interfaces, streams, and default methods.
Lambda expressions allow you to write code in a more concise and readable way.
Functional interfaces are interfaces with a single abstract method, used for lambda expressions.
Streams provide a way to work with sequences of elements and perform operations like filter, map, and reduce.
Default methods allow interfaces to have method implementations.
Example: (1) Lambda expression - (a, ...read more
Q28. > Given an array of n-1 numbers 1<=a[i]<=n. We need to find the number that was missing from the array.
Given an array of n-1 numbers 1<=a[i]<=n, find the missing number.
Calculate the sum of all numbers from 1 to n using the formula n*(n+1)/2
Calculate the sum of all elements in the array
Subtract the sum of array elements from the sum of all numbers to get the missing number
Q29. What are Components and state in ReactJs?
Components are reusable UI elements in ReactJs. State is an object that stores data and controls a component's behavior.
Components are like building blocks that can be combined to create complex UIs
State is used to store and manage data within a component
Changes to state trigger a re-render of the component
State should be kept as minimal as possible to avoid performance issues
Example: A button component can have a state that tracks the number of times it has been clicked
Private and special IP addresses are reserved ranges of IP addresses used for specific purposes.
Private IP addresses are used within a private network and are not routable on the internet.
Special IP addresses include loopback address (127.0.0.1) and broadcast address (255.255.255.255).
Private IP ranges include 10.0.0.0 to 10.255.255.255, 172.16.0.0 to 172.31.255.255, and 192.168.0.0 to 192.168.255.255.
Q31. How to find the reverse of a string of a particular order seperated by dots.
To reverse a string of a particular order separated by dots, split the string into an array, reverse the array, and join it back into a string.
Split the string using the dot separator
Reverse the resulting array
Join the array back into a string using the dot separator
Q32. What are the key Object-Oriented Programming (OOP) concepts in Java?
Key OOP concepts in Java include classes, objects, inheritance, polymorphism, encapsulation, and abstraction.
Classes: Blueprint for creating objects, containing attributes and methods.
Objects: Instances of classes that encapsulate data and behavior.
Inheritance: Allows a class to inherit attributes and methods from another class.
Polymorphism: Ability to present the same interface for different data types.
Encapsulation: Bundling data and methods that operate on the data into a ...read more
The OSI Reference Model defines 7 layers that represent different functions in networking.
Physical Layer - deals with physical connections and signals (e.g. cables, hubs)
Data Link Layer - manages data transfer between devices on the same network (e.g. Ethernet)
Network Layer - handles routing and forwarding of data packets (e.g. IP)
Transport Layer - ensures reliable data delivery (e.g. TCP)
Session Layer - establishes, maintains, and terminates connections (e.g. SSL)
Presentatio...read more
Q34. How to find the year is leap or not using single if condition.
To find leap year using single if condition
Check if year is divisible by 4 and not divisible by 100
Or check if year is divisible by 400
If either of the above conditions is true, then it's a leap year
Q35. What is Distinct keyword in SQL ?
Distinct keyword in SQL is used to retrieve unique values from a column in a table.
Distinct keyword eliminates duplicate rows from the result set
It is often used in conjunction with SELECT statement
Example: SELECT DISTINCT column_name FROM table_name
Q36. Concise code to add two strings such as str1="1234" and str2="8765".
Use concatenation operator to add two strings.
Use '+' operator to concatenate two strings.
Example: str1 + str2 will result in '12348765'.
Q37. Built a simple web application to store the data and show it to the browser
I would use a combination of HTML, CSS, and JavaScript to create a simple web application that stores and displays data.
Use HTML to create the structure of the web application
Use CSS to style the elements on the page
Use JavaScript to handle user interactions and store/retrieve data
Consider using a backend server (e.g. Node.js) to handle data storage and retrieval
Utilize AJAX to fetch data from the server asynchronously
Q38. Explain setTimeout, setImmediate and process.nextTick ?
setTimeout, setImmediate and process.nextTick are Node.js functions used for asynchronous programming.
setTimeout is used to execute a function after a specified amount of time has passed.
setImmediate is used to execute a function immediately after the current event loop iteration.
process.nextTick is used to execute a function at the beginning of the next event loop iteration.
setTimeout and setImmediate are similar, but setImmediate has higher priority in the event loop.
proces...read more
Q39. What Algorithm you used in your Project?
I used the Dijkstra's algorithm for finding the shortest path in my project.
Implemented Dijkstra's algorithm to find the shortest path between nodes in a graph
Used priority queue to optimize the algorithm
Considered edge weights and node distances while calculating the shortest path
Q40. What is life cycle in ReactJS ?
ReactJS life cycle refers to the series of methods that are invoked in the process of creating, updating and destroying a component.
ReactJS life cycle consists of three phases: Mounting, Updating and Unmounting.
Mounting phase includes methods like constructor, render, componentDidMount.
Updating phase includes methods like shouldComponentUpdate, render, componentDidUpdate.
Unmounting phase includes method componentWillUnmount.
These methods help in managing the state and props o...read more
Q41. code snippets on note pad. eg reverse string
Reverse a string using array manipulation
Create an array of characters from the input string
Use a loop to iterate through the array in reverse order
Append each character to a new string to form the reversed string
Q42. What is the difference between method overloading and overwriting?
Method overloading involves multiple methods in the same class with the same name but different parameters. Method overriding involves a subclass providing a specific implementation of a method that is already provided by its superclass.
Method overloading is achieved within the same class by having multiple methods with the same name but different parameters.
Method overriding occurs in a subclass that provides a specific implementation of a method that is already provided by ...read more
Q43. Purpose of getDerivedStateFromProps() and getSnapshotBeforeUpdate() Lifecyle method?
getDerivedStateFromProps() updates state based on props changes. getSnapshotBeforeUpdate() captures current state before update.
getDerivedStateFromProps() is called before rendering and updates state based on changes in props.
getSnapshotBeforeUpdate() is called after rendering but before updating the DOM. It captures current state before update.
getDerivedStateFromProps() is a static method and should return an object to update state or null to indicate no update.
getSnapshotBe...read more
Q44. What is Integrity Constraints ?
Integrity constraints are rules that ensure data integrity and consistency in a database.
Integrity constraints are used to enforce business rules or data quality rules in a database.
They can include rules such as unique constraints, foreign key constraints, and check constraints.
Unique constraints ensure that no two rows have the same value in a specified column.
Foreign key constraints enforce referential integrity by ensuring that values in one table match values in another ...read more
Q45. What is exception handling in programming?
Exception handling is a mechanism to handle runtime errors in a program to prevent it from crashing.
Exceptions are unexpected events that occur during the execution of a program.
Exception handling allows the programmer to gracefully handle these errors and prevent the program from crashing.
Common exception handling constructs include try, catch, and finally blocks.
Example: try { // code that may throw an exception } catch(Exception e) { // handle the exception }
Example: final...read more
Q46. What is inheritance and encapsulation?
Inheritance is a mechanism where a new class is derived from an existing class. Encapsulation is the process of hiding implementation details from the user.
Inheritance allows the new class to inherit properties and methods of the existing class.
Encapsulation helps in achieving data abstraction and security.
Inheritance promotes code reusability while encapsulation promotes data security.
Example of inheritance: class Car extends Vehicle
Example of encapsulation: private variable...read more
Q47. Write code for merging two shorted Arrays.
Code to merge two sorted arrays
Create a new array to store the merged result
Use two pointers to iterate through both arrays and compare elements
Add the smaller element to the new array and move the pointer for that array
Q48. Definitions and example code of OOPS Concepts
OOPS Concepts are fundamental principles of Object-Oriented Programming.
Encapsulation - bundling of data and methods that operate on that data
Inheritance - ability of a class to inherit properties and methods from its parent class
Polymorphism - ability of objects to take on multiple forms
Abstraction - hiding of complex implementation details from the user
Example code: class Car { private String make; public void setMake(String make) { this.make = make; } }
Q49. Explain Local Storage, Session Storage, cache in Web development
Local Storage, Session Storage, and Cache are used to store data in the browser for faster access and better user experience.
Local Storage: stores data with no expiration date and can be accessed across multiple windows and tabs
Session Storage: stores data for a single session and is cleared when the session ends
Cache: stores data temporarily to reduce server load and improve performance
Examples: storing user preferences, caching images and scripts for faster page load
Q50. Why do we need databases?
Databases are essential for storing, organizing, and retrieving large amounts of data efficiently.
Databases provide a structured way to store and manage data.
They allow for efficient retrieval of data through queries.
Databases can handle large amounts of data and ensure data integrity.
They enable multiple users to access and modify data simultaneously.
Examples include MySQL, Oracle, MongoDB, and SQL Server.
Interview Questions of Similar Designations
Top Interview Questions for Software Engineer Trainee Related Skills
Interview experiences of popular companies
Calculate your in-hand salary
Confused about how your in-hand salary is calculated? Enter your annual salary (CTC) and get your in-hand salary
Reviews
Interviews
Salaries
Users/Month