Associate Software Engineer
1500+ Associate Software Engineer Interview Questions and Answers
Popular Companies
Q51. Palindromic Substrings Problem Statement
You are given a string 'STR'. Your task is to determine the total number of palindromic substrings present in 'STR'.
Example:
Input:
"abbc"
Output:
5
Explanation:
The pa...read more
Count the total number of palindromic substrings in a given string.
Iterate through each character in the string and expand around it to find palindromic substrings.
Use dynamic programming to store the results of subproblems to avoid redundant calculations.
Consider both odd-length and even-length palindromes while counting.
Example: For input 'abbc', the palindromic substrings are ['a', 'b', 'b', 'c', 'bb'], totaling 5.
Q52. Spiral Order Traversal of a Binary Tree
Given a binary tree with N
nodes, your task is to output the Spiral Order traversal of the binary tree.
Input:
The input consists of a single line containing elements of ...read more
Implement a function to return the spiral order traversal of a binary tree.
Traverse the binary tree in a spiral order, alternating between left to right and right to left.
Use a queue to keep track of nodes at each level and a stack to reverse the order when necessary.
Handle null nodes appropriately to maintain the spiral order traversal.
Example: For input 1 2 3 -1 -1 4 5, the output should be 1 3 2 4 5.
Q53. Word Occurrence Counting
Given a string 'S' of words, the goal is to determine the frequency of each word in the string. Consider a word as a sequence of one or more non-space characters. The string can have mu...read more
Count the frequency of each word in a given string.
Split the input string by spaces to get individual words.
Use a hashmap to store the frequency of each word.
Iterate through the words and update the hashmap accordingly.
Print the unique words and their frequencies from the hashmap.
Abstract classes and interfaces in inheritance allow for defining common behavior and function signatures, while function overloading and overriding enable polymorphism.
Abstract classes are classes that cannot be instantiated and may contain abstract methods that must be implemented by subclasses.
Interfaces are similar to abstract classes but can only contain method signatures and constants, with no method implementations.
Function overloading refers to having multiple methods...read more
Q55. Detect and Remove Loop in Linked List
For a given singly linked list, identify if a loop exists and remove it, adjusting the linked list in place. Return the modified linked list.
Expected Complexity:
Aim for a...read more
Detect and remove loop in a singly linked list in place with O(n) time complexity and O(1) space complexity.
Use Floyd's Cycle Detection Algorithm to identify the loop in the linked list.
Once the loop is detected, use two pointers approach to find the start of the loop.
Adjust the pointers to remove the loop and return the modified linked list.
Example: For input 5 2 and 1 2 3 4 5, output should be 1 2 3 4 5.
Q56. Implementing a Priority Queue Using Heap
Ninja has been tasked with implementing a priority queue using a heap data structure. However, he is currently busy preparing for a tournament and has requested your ass...read more
Implement a priority queue using a heap data structure by completing the provided functions: push(), pop(), getMaxElement(), and isEmpty().
Understand the operations: push() to insert element, pop() to remove largest element, getMaxElement() to return largest element, and isEmpty() to check if queue is empty.
Implement a heap data structure to maintain the priority queue.
Handle different types of queries based on the input provided.
Ensure correct output for each type 3 query.
Te...read more
Share interview questions and help millions of jobseekers 🌟
Q57. Nth Fibonacci Number Problem Statement
Calculate the Nth term in the Fibonacci sequence, where the sequence is defined as follows: F(n) = F(n-1) + F(n-2)
, with initial conditions F(1) = F(2) = 1
.
Input:
The inp...read more
Calculate the Nth Fibonacci number efficiently using dynamic programming.
Use dynamic programming to store previously calculated Fibonacci numbers to avoid redundant calculations.
Start with base cases F(1) and F(2) as 1, then iterate to calculate subsequent Fibonacci numbers.
Return the Nth Fibonacci number as the final result.
Q58. Power Set Generation
Given a sorted array of 'N' integers, your task is to generate the power set for this array. Each subset of this power set should be individually sorted.
A power set of a set 'ARR' is the s...read more
Generate power set of a sorted array of integers with individually sorted subsets.
Iterate through all possible combinations using bitwise operations.
Sort each subset before adding it to the power set.
Handle empty subset separately.
Associate Software Engineer Jobs
Q59. DFS Traversal Problem Statement
Given an undirected and disconnected graph G(V, E)
, where V
is the number of vertices and E
is the number of edges, the connections between vertices are provided in the 'GRAPH' m...read more
The question asks to print the DFS traversal of an undirected and disconnected graph.
Implement a Depth First Search (DFS) algorithm to traverse the graph.
Use a visited array to keep track of visited vertices.
For each unvisited vertex, start a DFS traversal and print the connected component.
Sort the vertices of each connected component in ascending order before printing.
Q60. Pythagorean Triplets Detection
Determine if an array contains a Pythagorean triplet by checking whether there are three integers x, y, and z such that x2 + y2 = z2 within the array.
Input:
The first line contai...read more
Detect if an array contains a Pythagorean triplet by checking if there are three integers x, y, and z such that x^2 + y^2 = z^2.
Iterate through all possible combinations of three integers in the array and check if x^2 + y^2 = z^2.
Use a nested loop to generate all possible combinations efficiently.
Return 'yes' if a Pythagorean triplet is found, otherwise return 'no'.
Q61. Find All Pairs Adding Up to Target
Given an array of integers ARR
of length N
and an integer Target
, your task is to return all pairs of elements such that they add up to the Target
.
Input:
The first line conta...read more
Given an array of integers and a target, find all pairs of elements that add up to the target.
Iterate through the array and for each element, check if the target minus the element exists in a hash set.
If it exists, print the pair (element, target-element), otherwise add the element to the hash set.
If no pair is found, print (-1, -1).
Q62. 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 queens on an N x N chessboard, no two queens can threaten each other.
Implement a backtracking algorithm to explore all possible configurations.
Check for conflicts in rows, columns, and diagonals before placing a queen.
Generate and print valid configurations where queens do not attack each other.
Co...read more
Q63. Rearrange Array: Move Negative Numbers to the Beginning
Given an array ARR
consisting of N
integers, rearrange the elements such that all negative numbers are located before all positive numbers. The order of e...read more
Yes, this can be achieved by using a two-pointer approach to rearrange the array with negative numbers at the beginning.
Use two pointers, one starting from the beginning and one from the end of the array.
Swap elements at the two pointers if one is negative and the other is positive, and move the pointers accordingly.
Continue this process until the two pointers meet in the middle of the array.
The resulting array will have all negative numbers before positive numbers, with the ...read more
Q64. String Transformation Problem
Given a string (STR
) of length N
, you are tasked to create a new string through the following method:
Select the smallest character from the first K
characters of STR
, remove it fr...read more
Given a string and an integer, create a new string by selecting the smallest character from the first K characters of the input string and repeating the process until the input string is empty.
Iterate through the input string, selecting the smallest character from the first K characters each time.
Remove the selected character from the input string and append it to the new string.
Continue this process until the input string is empty.
Return the final new string formed after the...read more
Q65. Two Sum Problem Statement
Given an array A
of size N
, sorted in non-decreasing order, return two distinct indices whose values add up to a given 'target'. The array is 0 indexed. If multiple answers exist, retu...read more
Given a sorted array, find two distinct indices whose values add up to a given target.
Use two pointers approach to find the indices that add up to the target.
Start with one pointer at the beginning and another at the end of the array.
Move the pointers towards each other based on the sum of their values compared to the target.
Q66. Constellation Identification Problem
Given a matrix named UNIVERSE
with 3 rows and 'N' columns, filled with characters {#, *, .}, where:
- '*' represents stars.
- '.' represents empty space.
- '#' represents a separ...read more
The task is to identify constellations shaped like vowels within a matrix filled with characters {#, *, .}.
Iterate through the matrix to find 3x3 constellations shaped like vowels.
Check for vowels 'A', 'E', 'I', 'O', 'U' in each 3x3 constellation.
Print the vowels found in each constellation for each test case.
Q67. Valid Parentheses Problem Statement
Given a string 'STR' consisting solely of the characters “{”, “}”, “(”, “)”, “[” and “]”, determine if the parentheses are balanced.
Input:
The first line contains an integer...read more
The task is to determine whether the given string of parentheses is balanced or not.
Use a stack data structure to check for balanced parentheses.
Iterate through the string and push opening parentheses onto the stack.
If a closing parenthesis is encountered, check if it matches the top of the stack.
If it matches, pop the top element from the stack.
If the stack is empty at the end, the parentheses are balanced.
If the stack is not empty or a closing parenthesis doesn't match, the...read more
Q68. Height of a Binary Tree
You are provided with an arbitrary binary tree consisting of 'N' nodes where each node is associated with a certain value. The task is to determine the height of the tree.
Explanation:
T...read more
The height of a binary tree is the maximum number of edges from the root to a leaf node.
Traverse the tree recursively and keep track of the maximum height
If the current node is null, return 0
Otherwise, calculate the height of the left and right subtrees and return the maximum height plus 1
Q69. Merge Sort Problem Statement
You are given a sequence of numbers, ARR
. Your task is to return a sorted sequence of ARR
in non-descending order using the Merge Sort algorithm.
Explanation:
The Merge Sort algorit...read more
Implement Merge Sort algorithm to sort a sequence of numbers in non-descending order.
Divide the input array into two halves recursively until each array has only one element.
Merge the sorted halves to produce a completely sorted array.
Time complexity of Merge Sort is O(n log n).
Q70. Remove String from Linked List Problem
You are provided with a singly linked list where each node contains a single character, along with a string 'STR'. Your task is to remove all occurrences of the string 'ST...read more
Remove all occurrences of a given string from a singly linked list by starting from the end of the list.
Traverse the linked list from the end to the beginning to efficiently remove the string occurrences.
Check for the string 'STR' in each node and remove it if found.
Continue checking for new occurrences of 'STR' after removal to ensure all instances are removed.
Return the head of the modified linked list after processing each test case.
Q71. Remove Vowels from a Given String
Given a string STR
of length N
, your task is to remove all the vowels present in that string and return the modified string.
Explanation:
English alphabets ‘a’, ‘e’, ‘i’, ‘o’, ...read more
Remove vowels from a given string while maintaining the relative position of other characters.
Iterate through each character in the string and check if it is a vowel (a, e, i, o, u).
If the character is not a vowel, add it to the modified string.
Return the modified string as the output.
Q72. Replace Spaces in a String
Given a string STR
consisting of words separated by spaces, your task is to replace all spaces between words with the characters "@40".
Input:
The first line contains an integer ‘T’ d...read more
Replace spaces in a string with '@40'.
Iterate through the string and replace spaces with '@40'.
Return the modified string for each test case.
Handle multiple test cases by iterating through each one.
Q73. Subarray with Equal Occurrences Problem Statement
You are provided with an array/list ARR
of length N
containing only 0s and 1s. Your goal is to determine the number of non-empty subarrays where the number of 0...read more
Count the number of subarrays where the number of 0s is equal to the number of 1s in a given array of 0s and 1s.
Iterate through the array and keep track of the count of 0s and 1s encountered so far.
Use a hashmap to store the count of 0s and 1s encountered at each index.
For each index, check if the count of 0s and 1s encountered so far are equal. If yes, increment the total count of subarrays.
Q74. Intersection of Linked List Problem
You are provided with two singly linked lists containing integers, where both lists converge at some node belonging to a third linked list.
Your task is to determine the data...read more
Find the node where two linked lists merge, return -1 if no merging occurs.
Traverse both lists to find the lengths and the last nodes
Align the starting points of the lists by adjusting the pointers
Traverse again to find the merging point
Q75. 1) What is NullPointerExceprion and give me a example?
NullPointerException is a runtime exception that occurs when a program tries to access or use an object reference that is null.
It is a common exception in Java programming.
It is thrown when a program attempts to use an object reference that has not been initialized.
It indicates that there is an attempt to access or invoke a method on an object that is null.
Example: String str = null; str.length();
Q76. 1. All types of database commands- DDL, DML, DCL, TCL 2. Write a java code to reverse a given string or sentence 3. Questions based on a major and minor project 4. Questions based on Industrial Training/Interns...
read moreInterview questions for Associate Software Engineer position
Be familiar with all types of database commands and their usage
Practice writing code to reverse a given string or sentence in Java
Be prepared to discuss major and minor projects, as well as industrial training/internship experiences
Have a good understanding of operating system concepts such as job scheduling, deadlock, and starvation
Know the differences between C++ and Java programming languages
Be able to implement l...read more
Q77. Buy and Sell Stock Problem Statement
Imagine you are Harshad Mehta's friend, and you have been given the stock prices of a particular company for the next 'N' days. You can perform up to two buy-and-sell transa...read more
The task is to determine the maximum profit that can be achieved by performing up to two buy-and-sell transactions on a given set of stock prices.
Iterate through the array of stock prices to find the maximum profit that can be achieved by buying and selling stocks.
Keep track of the maximum profit that can be achieved by considering all possible combinations of buy and sell transactions.
Ensure that you sell the stock before buying again to adhere to the constraints of the prob...read more
Q78. Check if Two Trees are Mirror
Given two arbitrary binary trees, your task is to determine whether these two trees are mirrors of each other.
Explanation:
Two trees are considered mirror of each other if:
- The r...read more
Check if two binary trees are mirrors of each other based on specific criteria.
Compare the roots of both trees.
Check if the left subtree of the first tree is the mirror of the right subtree of the second tree.
Verify if the right subtree of the first tree is the mirror of the left subtree of the second tree.
Q79. Maximum Sum Path in a Binary Tree Problem Statement
You are provided with a binary tree consisting of N
nodes where each node has an integer value. The task is to determine the maximum sum achievable by a simpl...read more
Find the maximum sum achievable by a simple path between any two nodes in a binary tree.
Traverse the binary tree to find all possible paths and calculate their sums.
Keep track of the maximum sum encountered during traversal.
Consider paths that may include the same node twice.
Implement a recursive function to explore all paths in the tree.
Optimize the solution to avoid redundant calculations.
Q80. Problem: Total Area of Overlapping Rectangles
You are given two rectangles situated on a 2-D coordinate plane, which may overlap. Your task is to compute the total area covered by these rectangles.
Input:
The f...read more
Calculate total area covered by two overlapping rectangles on a 2-D plane.
Calculate the area of each rectangle separately using the given coordinates.
Find the overlapping region by determining the intersection of the two rectangles.
Calculate the area of the overlapping region by multiplying its width and height.
Add the areas of the two rectangles and subtract the area of the overlapping region to get the total area covered.
Q81. Remove Vowels from a String
Given a string STR
of length N
, your task is to remove all the vowels from that string and return the modified string.
Input:
The first line of input contains an integer 'T' represen...read more
Remove all vowels from a given string and return the modified string.
Iterate through each character in the string and check if it is a vowel (a, e, i, o, u or A, E, I, O, U).
If the character is not a vowel, add it to the modified string.
Return the modified string after processing all characters.
Q82. Queue Using Stacks Implementation
Design a queue data structure following the FIFO (First In First Out) principle using only stack instances.
Explanation:
Your task is to complete predefined functions to suppor...read more
Implement a queue using stacks with enQueue, deQueue, peek, and isEmpty operations.
Use two stacks to simulate a queue - one for enqueueing and one for dequeueing.
For enQueue operation, push elements onto the enqueue stack.
For deQueue operation, if the dequeue stack is empty, transfer elements from enqueue stack to dequeue stack.
For peek operation, return the top element of the dequeue stack.
For isEmpty operation, check if both stacks are empty.
Example: enQueue(5), enQueue(10)...read more
Q83. Minimum Cash Flow Problem
Consider 'N' friends who have borrowed money from one another. They now wish to settle their debts by giving or taking cash among themselves in a way that minimizes the total cash flow...read more
The problem involves settling debts among friends by minimizing total cash flow.
Create a graph where nodes represent friends and edges represent debts.
Calculate the net amount each friend owes or is owed by summing up the debts and credits.
Use a recursive algorithm to settle debts by finding the maximum and minimum amounts owed.
Repeat the process until all debts are settled.
Output the total cash flow required to settle all debts.
Q84. Problem Statement: Delete Node In A Linked List
Given a singly linked list of integers and a reference to a node, your task is to delete that specific node from the linked list. Each node in the linked list has...read more
Delete a specific node from a singly linked list given the reference to the node.
Traverse the linked list to find the node to be deleted.
Update the pointers to skip over the node to be deleted.
Print the modified linked list after deletion.
Q85. Swap Two Numbers Problem Statement
Given two integers a
and b
, your task is to swap these numbers and output the swapped values.
Input:
The first line contains a single integer 't', representing the number of t...read more
Swap two numbers 'a' and 'b' and output the swapped values.
Create a temporary variable to store one of the numbers before swapping
Swap the values of 'a' and 'b' using the temporary variable
Output the swapped values as 'b' followed by 'a'
Example: If 'a' = 3 and 'b' = 4, after swapping 'a' will be 4 and 'b' will be 3
Q86. Minimise Sum Problem Statement
You are given a matrix of 'N' rows and 'M' columns and a non-negative integer 'K'. Determine the minimum possible sum of all elements in each submatrix after performing at most 'K...read more
Given a matrix and a non-negative integer K, find the minimum possible sum of all elements in each submatrix after performing at most K decrements.
Iterate through all submatrices and find the minimum possible sum after performing decrements
Keep track of the number of decrements performed on each element
Use dynamic programming to optimize the solution
Ensure not to decrease any number below 0
Return the minimum possible sum modulo 10^9 + 7
Q87. Colorful Knapsack Problem
You are given a set of 'N' stones, each with a specific weight and color. The goal is to fill a knapsack with exactly 'M' stones, choosing one stone of each color, so that the total we...read more
The goal is to fill a knapsack with exactly 'M' stones, one of each color, minimizing unused capacity.
Iterate through stones, keeping track of weights for each color
Sort stones by weight and color, then select one stone of each color
Calculate total weight for each combination and minimize unused capacity
If knapsack cannot be filled, return -1
Q88. Group Anagrams Problem Statement
Given an array or list of strings called inputStr
, your task is to return the strings grouped as anagrams. Each group should contain strings that are anagrams of one another.
An...read more
Group anagrams in an array of strings based on their characters.
Iterate through the array of strings and sort each string to create a key for grouping anagrams.
Use a hashmap to store the sorted string as key and the list of anagrams as values.
Return the values of the hashmap as the grouped anagrams.
Q89. Linked List Value Search Problem Statement
Given a Singly Linked List of integers accessible via a head pointer, where each node contains a specific integer value. You are required to determine if a node with a...read more
Given a singly linked list of integers, determine if a specified value exists within the list.
Iterate through the linked list to check if the specified value exists.
Return 1 if the value is found, else return 0.
Handle multiple test cases by looping through each one separately.
Q90. Rotting Oranges Problem Statement
You are given a grid containing oranges where each cell of the grid can contain one of the three integer values:
- 0 - representing an empty cell
- 1 - representing a fresh orange...read more
Find the minimum time required to rot all fresh oranges in a grid.
Iterate through the grid to find rotten oranges and their adjacent fresh oranges
Use BFS or DFS to simulate the rotting process and track the time taken
Return the minimum time taken to rot all fresh oranges or -1 if not possible
Q91. 1. What does #include do. 2. What is preprocessor. 3. What does using namespace std do. Can we create our own namespace. 4. Who calls main function. Can we pass arguments in main function. 5. Write our own func...
read moreTechnical interview questions for Associate Software Engineer position.
iostream header file is used for input/output operations in C++.
Preprocessor directives are executed before the compilation of the program.
using namespace std allows us to use standard C++ library functions without specifying the namespace each time.
Main function is called by the operating system. Arguments can be passed to main function.
char* strcpy(char* dest, const char* src) can be used to copy a char ...read more
Q92. Postfix Expression Evaluation Problem Statement
Given a postfix expression, your task is to evaluate the expression. The operator will appear in the expression after the operands. The output for each expression...read more
Q93. Ways To Make Coin Change
Given an infinite supply of coins of varying denominations, determine the total number of ways to make change for a specified value using these coins. If it's not possible to make the c...read more
The task is to determine the total number of ways to make change for a specified value using given denominations.
Create a dynamic programming table to store the number of ways to make change for each value up to the target value.
Iterate through each denomination and update the table accordingly.
The final answer will be the value in the table at the target value.
Consider edge cases such as when the target value is 0 or when there are no denominations available.
Q94. 2) Can you call the base class method without creating an instance?
Yes, by using the super() method in the derived class.
super() method calls the base class method
Derived class must inherit from the base class
Example: class Derived(Base): def method(self): super().method()
Q95. In exception handling how many ways can we throw exception
There are two ways to throw an exception in exception handling.
Exceptions can be thrown using the throw keyword.
Exceptions can also be thrown implicitly by the runtime system.
Examples of explicit throwing include throw new Exception() and throw new IOException().
Examples of implicit throwing include division by zero or null pointer dereference.
Q96. Search an Element in a Sorted Array
Given a sorted array 'A' of 'N' integers, determine whether a number 'X' exists within this array for a series of queries. For each query, print 1 if 'X' exists in the array,...read more
Search for a number in a sorted array and determine its existence for multiple queries.
Iterate through each query integer 'X' and perform binary search on the sorted array 'A' to check for its existence.
Output 1 if 'X' is found in 'A', otherwise output 0.
Ensure to handle multiple test cases as per the given constraints.
Q97. All Prime Numbers Less Than or Equal to N
Given a positive integer N
, your task is to return all the prime numbers less than or equal to N
.
Note:
1) A prime number is a number that has only two factors: 1 and t...read more
Return all prime numbers less than or equal to a given positive integer N.
Iterate from 2 to N and check if each number is prime using a helper function.
A number is prime if it is not divisible by any number from 2 to its square root.
Store and return the prime numbers in an array in increasing order.
Q98. Difference between DELETE, DROP and TRUNCATE command in DBMS. What is RDBMS? [Read about it from any trusted website such as GeeksForGeeks].
Explanation of DELETE, DROP and TRUNCATE commands in DBMS and definition of RDBMS.
DELETE command removes specific rows from a table.
DROP command removes an entire table from the database.
TRUNCATE command removes all rows from a table.
RDBMS stands for Relational Database Management System.
It is a type of DBMS that stores data in the form of tables with relationships between them.
Q99. Fibonacci Number Verification
Identify if the provided integer 'N' is a Fibonacci number.
A number is termed as a Fibonacci number if it appears in the Fibonacci sequence, where each number is the sum of the tw...read more
The task is to determine if a given integer is a Fibonacci number or not.
Iterate through the Fibonacci sequence until the current number exceeds the given integer 'N'.
Check if the given integer 'N' matches any number in the Fibonacci sequence.
If a match is found, output 'YES'; otherwise, output 'NO'.
Q100. Gas Station Tour Problem
You are presented with a circular track consisting of several petrol pumps. Each petrol pump is indexed from 0 to N-1 and offers certain attributes:
- The quantity of petrol available at...read more
The Gas Station Tour Problem involves finding the first petrol pump from which a truck can start its journey and complete a circular track.
Calculate the difference between petrol available and distance to the next pump at each station.
If the total sum of differences is negative, a full circle is not possible.
If the total sum of differences is positive, the starting index is the first station where the cumulative sum becomes positive.
Interview Questions of Similar Designations
Top Interview Questions for Associate Software Engineer 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