Senior Software Engineer
4000+ Senior Software Engineer Interview Questions and Answers
Q1. Tell me about yourself. What technology are you using? What is a Collection? What are the different types of collection there? What is the difference between ArrayList and LinkedList What are the basic building...
read moreThe interview questions cover a wide range of topics including software engineering, technology, design patterns, databases, web development, and more.
The questions cover topics such as technology used, collections, streams, design patterns, dependency injection, microservices, database communication, annotations in Spring, React and JavaScript, Redux, API development, SOAP-based web services, Jenkins, Docker, production support, and more.
Some specific questions include the d...read more
Q2. MapSum Pair Implementation
Create a data structure named 'MapSum' with the ability to perform two operations and a constructor.
Explanation:
MapSum()
: Initializes the MapSum.insert(...read more
The question asks to implement a data structure called 'MapSum' with functions to initialize, insert key-value pairs, and find the sum of values with a given prefix.
Implement a class called 'MapSum' with a constructor to initialize the data structure.
Implement the 'insert' function to insert key-value pairs into the 'MapSum'. If a key is already present, replace its value with the new one.
Implement the 'sum' function to find the sum of values whose key has a prefix equal to t...read more
Senior Software Engineer Interview Questions and Answers for Freshers
Q3. Nth Prime Number Problem Statement
Find the Nth prime number given a number N.
Explanation:
A prime number is greater than 1 and is not the product of two smaller natural numbers. A prime number has exactly two...read more
The task is to find the Nth prime number given a number N.
A prime number is a number greater than 1 that is not a product of two smaller natural numbers.
Prime numbers have only two factors - 1 and the number itself.
Start with a counter at 0 and a number at 2.
Increment the number by 1 and check if it is prime.
If it is prime, increment the counter.
Repeat until the counter reaches N.
Return the last prime number found.
Q4. Pascal's Triangle Construction
You are provided with an integer 'N'. Your task is to generate a 2-D list representing Pascal’s triangle up to the 'N'th row.
Pascal's triangle is a triangular array where each el...read more
Generate Pascal's triangle up to the Nth row using a 2-D list.
Iterate through each row up to N, starting with [1] as the first row.
Calculate each element in a row by summing the two elements directly above from the previous row.
Append each row to the 2-D list until reaching the Nth row.
Example: For N = 4, the output would be [ [1], [1, 1], [1, 2, 1], [1, 3, 3, 1] ]
Q5. K Largest Elements Problem Statement
You are given an integer k
and an array of integers that contain numbers in random order. Write a program to find the k
largest numbers from the given array. You need to sav...read more
Given an unsorted array, find the K largest elements in non-decreasing order.
Sort the array in non-decreasing order.
Return the last K elements of the sorted array.
Q6. Reverse the String Problem Statement
You are given a string STR
which contains alphabets, numbers, and special characters. Your task is to reverse the string.
Example:
Input:
STR = "abcde"
Output:
"edcba"
Input...read more
The task is to reverse a given string containing alphanumeric and special characters.
Iterate through the string from the last character to the first character
Append each character to a new string to get the reversed string
Return the reversed string as the output
Share interview questions and help millions of jobseekers 🌟
Q7. 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 at different points.
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 you can buy again to adhere to th...read more
Q8. Duplicate Integer in Array
Given an array ARR
of size N
, containing each number between 1 and N-1
at least once, identify the single integer that appears twice.
Input:
The first line contains an integer, 'T', r...read more
Identify the duplicate integer in an array containing numbers between 1 and N-1.
Iterate through the array and keep track of the frequency of each element using a hashmap.
Return the element with a frequency greater than 1 as the duplicate integer.
Ensure the constraints are met and a duplicate number is guaranteed to be present.
Senior Software Engineer Jobs
Q9. Digits Decoding Problem Statement
A few days back, Ninja encountered a string containing characters from ‘A’ to ‘Z’ which indicated a secret message. For security purposes, he encoded each character of the stri...read more
The problem involves decoding a numeric sequence into a valid string using a given mapping of characters to numbers.
Use dynamic programming to count the number of ways to decode the sequence.
Consider different cases for decoding single digits and pairs of digits.
Keep track of the number of ways to decode at each position in the sequence.
Return the final count modulo 10^9 + 7 as the answer.
Q10. Excel Column Number Conversion
Given a column title as it appears in an Excel sheet, your task is to return its corresponding column number.
Example:
Input:
S = "AB"
Output:
28
Explanation:
The sequence is as f...read more
Convert Excel column title to corresponding column number.
Iterate through the characters in the input string from right to left
Calculate the corresponding value of each character based on its position and multiply by 26^position
Sum up all the values to get the final column number
Q11. Prime Numbers within a Range
Given an integer N, determine and print all the prime numbers between 2 and N, inclusive.
Input:
Integer N
Output:
Prime numbers printed on separate lines
Example:
Input:
N = 10
Out...read more
Generate and print all prime numbers between 2 and N, inclusive.
Iterate from 2 to N and check if each number is prime
A prime number is only divisible by 1 and itself
Print each prime number on a new line
Q12. How to apply SOLID principle and what is dependency injection and why to use it and scenarios on where to use
SOLID principles ensure maintainable and scalable code. Dependency Injection helps in achieving loose coupling and testability.
SOLID principles are Single Responsibility, Open-Closed, Liskov Substitution, Interface Segregation, and Dependency Inversion
Dependency Injection is a design pattern that allows objects to be loosely coupled and easily testable
Use Dependency Injection to reduce tight coupling between classes and make them more modular
Use SOLID principles to ensure mai...read more
Q13. LRU Cache Design Problem Statement
Design and implement a data structure for a Least Recently Used (LRU) cache that supports the following operations:
get(key)
- Retrieve the value associated with the specifie...read more
The question is about designing and implementing a data structure for LRU cache to support get and put operations.
LRU cache is a cache replacement policy that removes the least recently used item when the cache reaches its capacity.
The cache is initialized with a capacity and supports get(key) and put(key, value) operations.
For each get operation, return the value of the key if it exists in the cache, otherwise return -1.
For each put operation, insert the value in the cache i...read more
Q14. Find All Anagrams Problem Statement
Given a string STR and a non-empty string PTR, identify all the starting indices of anagrams of PTR within STR.
Explanation:
An anagram of a string is another string that can...read more
Given a string STR and a non-empty string PTR, find all starting indices of anagrams of PTR within STR.
Create a frequency map of characters in PTR.
Use sliding window technique to check anagrams in STR.
Return the starting indices of anagrams found.
Q15. LRU Cache Design Question
Design a data structure for a Least Recently Used (LRU) cache that supports the following operations:
1. get(key)
- Return the value of the key if it exists in the cache; otherwise, re...read more
Design a Least Recently Used (LRU) cache data structure that supports get and put operations with capacity constraint.
Implement a doubly linked list to keep track of the order of keys based on their recent usage.
Use a hashmap to store key-value pairs for quick access and updates.
When capacity is reached, evict the least recently used item before inserting a new item.
Update the order of keys in the linked list whenever a key is accessed or updated.
Q16. Sum of Digits Problem Statement
Given an integer 'N', continue summing its digits until the result is a single-digit number. Your task is to determine the final value of 'N' after applying this operation iterat...read more
Given an integer, find the final single-digit value after summing its digits iteratively.
Iteratively sum the digits of the input integer until the result is a single-digit number
Output the final single-digit integer for each test case
Handle multiple test cases as input
Q17. Boundary Traversal of a Binary Tree
Given a binary tree of integers, your task is to return the boundary nodes of the tree in Anti-Clockwise direction starting from the root node.
Input:
The first line contains...read more
Return the boundary nodes of a binary tree in Anti-Clockwise direction starting from the root node.
Traverse the left boundary nodes in top-down order
Traverse the leaf nodes in left-right order
Traverse the right boundary nodes in bottom-up order
Handle cases where duplicates occur in boundary nodes
Q18. Given a grid containing 0s and 1s and source row and column, in how many ways, could we reach form source to target. ( 1's represents a blockade and 0's represent accessable points)
Count the number of ways to reach target from source in a grid with 0s and 1s.
Use dynamic programming to solve the problem efficiently.
Traverse the grid using DFS or BFS to count the number of ways.
Consider edge cases like when source and target are the same or when there is no path.
Example: Given grid = [[0,0,0],[0,1,0],[0,0,0]], source = (0,0), target = (2,2), answer is 2.
Example: Given grid = [[0,1],[0,0]], source = (0,0), target = (1,1), answer is 1.
Q19. Secret Message Decoding Problem
Ninja encountered an encoded secret message where each character from 'A' to 'Z' is mapped to a numeric value (A = 1, B = 2, ..., Z = 26). Given a numeric sequence (SEQ) derived ...read more
The problem involves decoding a numeric sequence back into a valid string based on a given mapping of characters to numeric values.
Use dynamic programming to keep track of the number of ways to decode the sequence at each position.
Consider edge cases such as '0' and '00' which do not have valid decodings.
Handle cases where two digits can be combined to form a valid character (e.g., '12' corresponds to 'L').
Q20. Number of Bit Flips Problem Statement
Ninja is practicing binary representations and stumbled upon an interesting problem. Given two numbers 'A' and 'B', you are required to determine how many bits need to be f...read more
Calculate the number of bit flips required to convert one number to another in binary representation.
Convert both numbers to binary representation
Count the number of differing bits between the two numbers
Output the count of differing bits as the number of bit flips required
Example: A = 13 (1101), B = 7 (0111) -> 2 bit flips required
Q21. Character Counting Challenge
Create a program that counts and prints the total number of specific character types from user input. Specifically, you need to count lowercase English alphabets, numeric digits (0-...read more
Create a program to count lowercase alphabets, digits, and white spaces from user input until '$' is encountered.
Read characters from input stream until '$' is encountered
Count lowercase alphabets, digits, and white spaces separately
Print the counts of each character type as three integers separated by spaces
Q22. Anagram Substring Search
Given two strings 'STR' and 'PTR', identify all starting indices of 'PTR' anagram substrings in 'STR'. Two strings are anagrams if one can be rearranged to form the other.
Input:
First ...read more
Implement a function to find all starting indices of anagram substrings of a given string in another string.
Create a frequency map of characters in the 'PTR' string.
Use a sliding window approach to check for anagrams in 'STR'.
Return the starting indices of anagram substrings found.
Example: For input 'BACDGABCD' and 'ABCD', output should be [0, 5].
Q23. Triplets with Given Sum Problem
Given an array or list ARR
consisting of N
integers, your task is to identify all distinct triplets within the array that sum up to a specified number K
.
Explanation:
A triplet i...read more
The task is to identify all distinct triplets within an array that sum up to a specified number.
Iterate through the array and use nested loops to find all possible triplets.
Keep track of the sum of each triplet and compare it with the target sum.
Print the triplet if the sum matches the target sum, else print -1.
Q24. Search In Rotated Sorted Array Problem Statement
Given a sorted array of distinct integers that has been rotated clockwise by an unknown amount, you need to search for a specified integer in the array. For each...read more
Implement a search function to find a specified integer in a rotated sorted array with O(logN) time complexity.
Implement a binary search algorithm to efficiently search for the target integer.
Handle the rotation of the array by finding the pivot point first.
Return the index of the target integer if found, else return -1.
Ensure the time complexity of the search function is O(logN) for each query.
Q25. String Palindrome Verification
Given a string, your task is to determine if it is a palindrome considering only alphanumeric characters.
Input:
The input is a single string without any leading or trailing space...read more
Check if a given string is a palindrome considering only alphanumeric characters.
Remove non-alphanumeric characters from the input string before checking for palindrome.
Use two pointers approach to compare characters from start and end of the string.
Convert all characters to lowercase for case-insensitive comparison.
Return true if the string is a palindrome, false otherwise.
Q26. Write a Program Nth term in a infinite series example: 2,4,8,2,4,8……..n…….infinite
Program to find the Nth term in an infinite series
The series has a repeating pattern
Use modulo operator to find the index of the repeating pattern
Calculate the value of Nth term based on the pattern
Q27. K-th Largest Number in a BST
Given a binary search tree (BST) consisting of integers and containing 'N' nodes, your task is to find and return the K-th largest element in this BST.
If there is no K-th largest e...read more
Find the K-th largest element in a BST.
Perform reverse in-order traversal of the BST to find the K-th largest element.
Keep track of the count of visited nodes to determine the K-th largest element.
Return -1 if there is no K-th largest element in the BST.
Q28. Reverse String Word-Wise Problem Statement
Reverse the given string so that the last word appears first, the second last word appears second, and so on, while keeping the individual words unchanged.
Explanation...read more
Reverse the given string word-wise while keeping the individual words unchanged.
Split the input string by space to get individual words
Reverse the array of words
Join the reversed array of words back into a single string
Q29. 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.
Optimize the solution to have a time complexity of O(N) by storing and reusing calculated values.
Q30. Reverse Linked List in Groups of K
You are provided with a linked list containing 'N' nodes and an integer 'K'. The task is to reverse the linked list in groups of size K, which means reversing the nodes in eac...read more
Reverse a linked list in groups of size K by reversing nodes in each group.
Iterate through the linked list in groups of size K
Reverse each group of nodes
Handle cases where the number of elements in the last group is less than K
Q31. Trailing Zeros in Factorial Problem
Find the number of trailing zeroes in the factorial of a given number N
.
Input:
The first line contains an integer T
representing the number of test cases.
Each of the followi...read more
Count the number of trailing zeros in the factorial of a given number.
Calculate the number of 5's in the prime factorization of N to find the number of trailing zeros.
Divide N by 5, then by 25, then by 125, and so on, and sum up the quotients to get the answer.
Example: For N=10, 10/5=2, so there are 2 trailing zeros in 10!.
Q32. Reverse Alternate K Nodes Problem Statement
You are given a singly linked list of integers along with a positive integer 'K'. The task is to modify the linked list by reversing every alternate 'K' nodes of the ...read more
The task is to modify a singly linked list by reversing every alternate 'K' nodes of the linked list.
Iterate through the linked list in groups of size K, reverse every alternate group
Handle cases where the number of remaining nodes is less than K
Update the pointers accordingly to reverse the nodes in the linked list
Q33. Kth Largest Number Problem Statement
You are given a continuous stream of numbers, and the task is to determine the kth largest number at any moment during the stream.
Explanation:
A specialized data structure ...read more
Design a data structure to find the kth largest number in a continuous stream of integers.
Design a specialized data structure to handle an indefinite number of integers from the stream.
Implement 'add(DATA)' to incorporate integers into the stream's pool.
Implement 'getKthLargest()' to retrieve the kth largest number from the pool.
Maintain the pool of numbers and return the kth largest number for each query.
Ensure efficient implementation to handle large input sizes.
Q34. Trapping Rain Water Problem Statement
Given a long type array/list ARR
of size N
, representing an elevation map where ARR[i]
denotes the elevation of the ith
bar, calculate the total amount of rainwater that ca...read more
Calculate the total amount of rainwater that can be trapped in given elevation map.
Iterate through the array to find the maximum height on the left and right of each bar.
Calculate the amount of water that can be trapped above each bar by taking the minimum of the maximum heights on the left and right.
Sum up the trapped water above each bar to get the total trapped water for the entire elevation map.
Q35. Number of Islands Problem Statement
You are provided with a 2-dimensional matrix having N
rows and M
columns, containing only 1s (land) and 0s (water). Your goal is to determine the number of islands in this ma...read more
Count the number of islands in a 2D matrix of 1s and 0s.
Iterate through the matrix and perform depth-first search (DFS) to find connected 1s.
Mark visited cells to avoid redundant calculations.
Increment island count whenever a new island is encountered.
Q36. Count Ways to Reach the N-th Stair Problem Statement
You are provided with a number of stairs, and initially, you are located at the 0th stair. You need to reach the Nth stair, and you can climb one or two step...read more
The problem involves counting the number of distinct ways to climb N stairs by taking 1 or 2 steps at a time.
Use dynamic programming to solve this problem efficiently.
The number of ways to reach the Nth stair is equal to the sum of ways to reach (N-1)th stair and (N-2)th stair.
Handle modulo 10^9+7 to avoid overflow issues.
Consider base cases for 0th and 1st stair.
Optimize the solution by using constant space instead of an array.
Q37. All Paths From Source Lead To Destination Problem Statement
In a directed graph with 'N' nodes numbered from 0 to N-1, determine whether every possible path starting from a given source node (SRC) eventually le...read more
Determine if all paths from a given source node lead to a specified destination node in a directed graph.
Check if there is at least one path from source to destination.
Ensure that nodes with no outgoing edges from source are the destination.
Verify that the number of paths from source to destination is finite.
Return True if all paths from source lead to destination, otherwise False.
Q38. Asteroid Collision Problem Description
Given an array/list ASTEROIDS
representing asteroids aligned in a row, each element's absolute value identifies the asteroid's size, while its sign indicates the direction...read more
Determine the state of asteroids after collisions occur in a row.
Iterate through the array of asteroids and simulate collisions between adjacent asteroids moving in opposite directions.
If two asteroids collide, the larger one survives while the smaller one is destroyed.
Continue this process until no more collisions can occur.
Return the array of remaining asteroids after all collisions have been resolved.
Q39. Preorder Traversal Problem Statement
You are provided with the root node of a binary tree comprising N
nodes. Your objective is to output its preorder traversal. Preorder traversal of a binary tree is performed...read more
Implement a function to perform preorder traversal on a binary tree given the root node.
Create a recursive function to traverse the tree in preorder fashion.
Visit the root node, then recursively traverse left subtree, followed by right subtree.
Store the visited nodes in an array and return the array as the result.
Example: For the input tree [1, 2, 3, 4, -1, 5, 6, -1, 7, -1, -1, -1, -1, -1, -1], the preorder traversal output should be [1, 2, 4, 7, 3, 5, 6].
Q40. Anagram Pairs Verification
In this task, you need to verify if two provided strings are anagrams of each other. Two strings are considered anagrams if you can rearrange the letters of one string to form the oth...read more
Verify if two strings are anagrams of each other by rearranging their letters.
Create character frequency maps for both strings.
Compare the frequency of characters in both maps to check if they are anagrams.
Return 'True' if the frequencies match, else return 'False'.
Q41. In azure data factory how would you implement the functionality of tumbling window without actually using that feature already available?
Implementing tumbling window in Azure Data Factory without using the feature
Create a pipeline with a trigger that runs at the desired interval
Use a lookup activity to retrieve the data for the current window
Use a foreach activity to iterate over the retrieved data
Perform the required operations on the data within the foreach activity
Write the output to the desired destination
Q42. String is immutable but what happens if we assign another value to that string reference
Assigning another value to a string reference creates a new string object in memory.
Assigning a new value to a string reference creates a new string object in memory
The original string object remains unchanged
The new value is stored in a different memory location
The old value may be garbage collected if there are no other references to it
Q43. 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
The task is to transform a given string by selecting the smallest character from the first K characters and appending it to a new string until the original string becomes empty.
Iterate through the string while there are characters remaining
For each iteration, select the smallest character from the first K characters
Remove the selected character from the original string and append it to the new string
Repeat until the original string is empty
Return the final new string
Q44. Move Zeroes to End
Given an unsorted array of integers, rearrange the elements such that all the zeroes are moved to the end, while maintaining the order of non-zero elements.
Input:
The first line contains an ...read more
Given an unsorted array of integers, move all zeroes to the end while maintaining the order of non-zero elements.
Iterate through the array and maintain two pointers, one for the current position and one for the position to swap with.
If the current element is non-zero, swap it with the element at the swap pointer and increment the swap pointer.
After iterating through the array, fill the remaining positions with zeroes.
Example: Input array [0, 1, -2, 3, 4, 0, 5, -27, 9, 0] shou...read more
Q45. Reverse String Operations Problem Statement
You are provided with a string S
and an array of integers A
of size M
. Your task is to perform M
operations on the string as specified by the indices in array A
.
The ...read more
Given a string and an array of indices, reverse substrings based on the indices to obtain the final string.
Iterate through the array of indices and reverse the substrings accordingly
Ensure the range specified by each index is non-empty
Return the final string after all operations are completed
Q46. What is difference between Abstract and Interface, give me some example of your project in which you have used Abstract class and Interface.
Abstract class and Interface are both used for abstraction, but with some differences.
Abstract class can have both abstract and non-abstract methods, while Interface can only have abstract methods.
A class can implement multiple interfaces, but can only inherit from one abstract class.
Abstract class can have instance variables, while Interface cannot.
Abstract class provides partial implementation, while Interface provides full abstraction.
Example of using Abstract class: Creat...read more
Q47. Maximum Non-Adjacent Subsequence Sum
Given an array of integers, determine the maximum sum of a subsequence without choosing adjacent elements in the original array.
Input:
The first line consists of an integer...read more
Find the maximum sum of a subsequence without choosing adjacent elements in an array.
Use dynamic programming to keep track of the maximum sum at each index, considering whether to include the current element or not.
At each index, the maximum sum can be either the sum of the current element and the element two positions back, or the maximum sum at the previous index.
Iterate through the array and update the maximum sum accordingly.
Example: For the input [3, 2, 7, 10], the maxim...read more
Q48. Count Inversions Problem Statement
Given an integer array ARR
of size N
, your task is to find the total number of inversions that exist in the array.
An inversion is defined for a pair of integers in the array ...read more
Count the total number of inversions in an integer array.
Iterate through the array and for each pair of elements, check if the inversion condition is met.
Use a nested loop to compare each pair of elements efficiently.
Keep a count of the inversions found and return the total count at the end.
An interface in OOP defines a contract for classes to implement, specifying methods that must be included.
An interface contains method signatures but no implementation details.
Classes can implement multiple interfaces in Java.
Interfaces allow for polymorphism and loose coupling in software design.
Q50. How have you implemented dependency injection in your .NET Core projects? How have you used the Razor engine to build dynamic views in your ASP.NET Core projects? Can you explain how you have used Angular to bu...
read moreAnswering questions on .NET Core, Razor engine, and Angular
Implemented dependency injection in .NET Core using built-in DI container or third-party libraries like Autofac or Ninject
Used Razor engine to build dynamic views by creating Razor views with HTML and C# code to generate dynamic content
Built single-page applications using Angular by creating components, services, and modules to manage data and UI
Interview Questions of Similar Designations
Top Interview Questions for Senior 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