Software Developer Intern
1000+ Software Developer Intern Interview Questions and Answers
Popular Companies
Q101. Longest Switching Subarray Problem Statement
Determine the length of the longest contiguous subarray in a given array of positive integers, where the subarray qualifies as 'switching'. An array is defined as sw...read more
Find the length of the longest switching subarray in a given array of positive integers.
Iterate through the array and keep track of the longest switching subarray found so far.
Check if the numbers at even and odd positions are identical to determine a switching subarray.
Return the length of the longest switching subarray.
Example: For input [1, 4, 1, 4, 3, 2, 3, 0], the longest switching subarray is [1, 4, 1, 4] with length 4.
Q102. Matrix Bit Flipping Problem
In this task, you're provided with a binary square matrix of size 'N * N' named MAT
. The task requires you to perform row and column flips whenever a zero (0) is encountered in the m...read more
Count the total number of flips required in a binary matrix when encountering zeros.
Iterate through the matrix and whenever a zero is encountered, flip all 1s in the corresponding row and column.
Keep track of the total number of flips required.
Return the total count of flips at the end.
Q103. Minimum Number of Stabs to Kill the King
You are given the initial health of a king represented by an integer N
. Your task is to determine the minimum number of stabs required to reduce the king's health to zer...read more
Calculate the minimum number of stabs required to kill the king by reducing his health to zero.
Iterate through each test case and calculate the minimum number of stabs required based on the given operations.
For each test case, keep reducing the king's health using the first or second type of stab until it reaches zero.
Consider the constraints provided to optimize the solution and handle edge cases.
Example: For input 10, the minimum number of stabs required is 4 (10 -> 9 -> 3 ...read more
Q104. Paint House Problem Statement
You have been given a set of 'N' houses, each house can be painted using one of three colors: green, red, or yellow. A cost matrix is provided with dimensions 'N' * 3, where each e...read more
Find the minimum total cost to paint all houses such that no two adjacent houses have the same color.
Use dynamic programming to keep track of the minimum cost of painting each house with each color while ensuring no two adjacent houses have the same color.
At each house, calculate the minimum cost of painting it with each color based on the previous house's colors.
Keep updating the minimum cost for each color at each house until reaching the last house.
Return the minimum cost ...read more
Q105. Random Point Generator in a Circle
Mr. Schrodinger needs to generate points that are uniformly distributed inside a specific circle for testing his hypothesis. Your task is to implement a function that generate...read more
Implement a function to generate random points uniformly distributed inside a circle.
Generate random points using polar coordinates
Ensure points fall within the circle by checking if distance from center is less than or equal to radius
Check if points are uniformly distributed by running statistical tests
Return 1 if points are uniformly distributed, else return 0
Q106. Rectangle Counting on an N x N Chessboard
Given a positive integer N, determine the number of possible rectangles that can be formed on an N x N chessboard, excluding squares.
Input:
The first line contains an ...read more
Count the number of rectangles (excluding squares) that can be formed on an N x N chessboard.
Calculate total rectangles using formula N*(N+1)*M*(M+1)/4 where M = N-1
Subtract the number of squares (N*(N+1)*(2*N+1)/6) from total rectangles
Return the count modulo 1000000007 for each test case
Share interview questions and help millions of jobseekers 🌟
Q107. Remainder When Divided By 11 Problem Statement
Determine the remainder when a given number, 'N' in the form of a string, is divided by 11.
Input:
The first line contains an integer 'T' denoting the number of te...read more
Find the remainder when a given number is divided by 11.
Convert the given number 'N' from string to integer.
Use the property that the remainder when a number is divided by 11 is the same as the remainder when the alternating sum of its digits is divided by 11.
Iterate through the digits of 'N' and calculate the alternating sum.
Finally, find the remainder of the alternating sum when divided by 11.
Output the remainder as the result.
Q108. Selection Sort Algorithm
Selection sort is a sorting technique that works by repeatedly finding the minimum element (considering ascending order) from the unsorted part and placing it at the beginning of the un...read more
Implement Selection Sort algorithm to sort an array of non-negative integers in non-decreasing order.
Iterate through the array and find the minimum element in the unsorted part.
Swap the minimum element with the first element of the unsorted part.
Repeat the process for the remaining unsorted part until the entire array is sorted.
Software Developer Intern Jobs
Q109. Sum of Two Numbers Represented as Arrays
Given two numbers in the form of two arrays where each element of the array represents a digit, calculate the sum of these two numbers and return this sum as an array.
E...read more
Given two numbers represented as arrays, calculate their sum and return the result as an array.
Iterate through the arrays from right to left, adding digits and carrying over if necessary
Handle cases where one array is longer than the other by considering remaining digits
Ensure the final sum array does not have any leading zeros
Q110. Swap Numbers Without Temporary Variable
Your task is to interchange the values of two numbers given as variables 'X' and 'Y' without using a temporary variable or any additional variable.
Explanation:
You need ...read more
Swap two numbers without using a temporary variable.
Use bitwise XOR operation to swap the values of X and Y without using a temporary variable.
The XOR operation works by flipping the bits of the numbers.
After swapping, X = X XOR Y and Y = X XOR Y.
Finally, X = X XOR Y to get the original value of Y in X.
Q111. Chocolate Distribution Problem
You are given an array/list CHOCOLATES
of size 'N', where each element represents the number of chocolates in a packet. Your task is to distribute these chocolates among 'M' stude...read more
Distribute chocolates among students to minimize difference between largest and smallest packets.
Sort the array of chocolates packets.
Use sliding window technique to find the minimum difference between packets distributed to students.
Return the minimum difference as the output.
Q112. Circular Linked List Detection
You are provided with the head of a linked list containing integers. Your task is to determine if the linked list is circular.
Note:
- A linked list is considered circular if it co...read more
The task is to determine whether a given linked list is circular or not.
A linked list is circular if the next pointer of the last node points to the first node.
An empty linked list is also considered circular.
Check if any node has its next pointer equal to NULL.
All the integers in the linked list are unique.
The next pointer of a node with i'th integer is linked to the node with data (i+1)'th integer.
Q113. Count Triplets in a Sorted Doubly Linked List
You are provided with an integer X
and a non-decreasing sorted doubly linked list consisting of distinct nodes.
Your task is to find and return the count of triplet...read more
Count triplets in a sorted doubly linked list that sum up to a given value.
Iterate through the list and for each node, find pairs that sum up to X-nodeValue.
Use two pointers approach to find pairs efficiently.
Keep track of count of triplets found while iterating through the list.
Q114. Delete Nodes with Greater Values On Right
You are given a singly linked list where each node contains an integer value and a reference to the next node or NULL if it is the last node. The task is to remove all ...read more
Remove nodes in a singly linked list with a greater value on the right.
Traverse the linked list and compare each node's value with the values of nodes to its right.
If a node has a greater value on the right, remove it from the linked list.
Update the references of the previous node to skip the removed node.
Q115. Matrix Median Problem Statement
You are provided with a matrix containing 'N' rows and 'M' columns filled with integers. Each row is sorted in non-decreasing order. Your task is to find the overall median of th...read more
Find the overall median of a matrix with sorted rows.
Merge all elements of the matrix into a single sorted array
Calculate the median of the merged array
Handle odd number of elements by directly finding the middle element
Q116. Ninja and Candies Problem
Ninja, a boy from Ninjaland, receives 1 coin every morning from his mother. He wants to purchase exactly 'N' candies. Each candy usually costs 2 coins, but it is available for 1 coin i...read more
Calculate the earliest day on which Ninja can buy all candies given the number of candy types, special offers, and Ninja's candy preferences.
Iterate through each day and check if any special offers are available for the candies Ninja wants to buy.
Keep track of the remaining candies Ninja needs to buy and the coins he has each day.
Consider both regular price and sale price while making purchases.
Return the earliest day on which Ninja can buy all candies.
Q117. Spiral Matrix Problem Statement
Given a two-dimensional matrix of integers, print the matrix in a spiral order.
Input:
The first line contains an integer 't' indicating the number of test cases. For each test c...read more
Print a two-dimensional matrix in spiral order.
Iterate through the matrix in a spiral order by keeping track of the boundaries.
Print elements in the order: top row, right column, bottom row, left column.
Repeat the process for inner submatrices until all elements are printed.
Q118. Subtree of Another Tree Problem Statement
Given two binary trees, T and S, determine whether S is a subtree of T. The tree S should have the same structure and node values as a subtree of T.
Explanation:
A subt...read more
Given two binary trees T and S, determine if S is a subtree of T with the same structure and node values.
Traverse both trees and check if S is a subtree of T at each node
Use recursion to compare subtrees
Handle edge cases like empty trees or null nodes
Q119. Triplet Count in a Sorted Doubly Linked List Problem
Count the number of triplets in a sorted doubly linked list such that their sum equals a given integer 'X'. The list is composed of distinct node values.
Exp...read more
Count the number of triplets in a sorted doubly linked list such that their sum equals a given integer 'X'.
Iterate through the linked list and for each node, use two pointers to find the other two nodes that sum up to 'X'.
Keep track of the count of triplets found while traversing the list.
Return the final count of triplets that sum up to 'X'.
Q120. Infix to Postfix Conversion
You are provided with a string EXP
which represents a valid infix expression. Your task is to convert this given infix expression into a postfix expression.
Explanation:
An infix exp...read more
Convert infix expression to postfix expression.
Use a stack to keep track of operators and operands.
Follow the rules of precedence for operators.
Handle parentheses by pushing them onto the stack.
Pop operators from the stack based on precedence.
Append operands and operators to the postfix expression.
Q121. Consecutive Elements
Given an array arr
of N
non-negative integers, determine whether the array consists of consecutive numbers. Return true if they do, and false otherwise.
Input:
The first line of input conta...read more
Q122. Count Subsequences Problem Statement
Given an integer array ARR
of size N
, your task is to find the total number of subsequences in which all elements are equal.
Explanation:
A subsequence of an array is derive...read more
Count the total number of subsequences in which all elements are equal in an integer array.
Iterate through the array and count the frequency of each element.
Calculate the total number of subsequences for each element using the formula (frequency * (frequency + 1) / 2).
Sum up the total number of subsequences for all elements and return the result modulo 10^9 + 7.
Q123. Longest Subarray Zero Sum Problem Statement
Given an array of integers arr
, determine the length of the longest contiguous subarray that sums to zero.
Input:
N (an integer, the length of the array)
arr (list of ...read more
Find the length of the longest contiguous subarray with zero sum in an array of integers.
Use a hashmap to store the prefix sum and its corresponding index.
Iterate through the array and update the hashmap with the current sum and index.
If the same sum is encountered again, the subarray between the two indices has a sum of zero.
Q124. Maximize the Sum Through Two Arrays
You are given two sorted arrays of distinct integers, ARR1
and ARR2
. If there is a common element in both arrays, you can switch from one array to the other.
Your task is to ...read more
Given two sorted arrays, find the path through common elements for maximum sum.
Start with the array containing the smaller first common element
Switch arrays at common elements to maximize the sum
Continue adding elements until the end of the arrays
Q125. Prime with 3 Factors Problem Statement
You are provided with an array ARR
consisting of 'N' positive integers. Your task is to determine if each number in the array ARR
has exactly 3 factors.
You need to return...read more
Determine if each number in the array has exactly 3 factors.
Iterate through each number in the array and check if it has exactly 3 factors.
Factors of a number can be found by iterating from 1 to the square root of the number.
Count the number of factors and return 1 if it is exactly 3, else return 0.
Q126. 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 in-place.
Use two pointers, one starting from the beginning and one from the end of the array.
Swap elements at the two pointers if they are not in the correct order (negative before positive).
Continue this process until the two pointers meet in the middle of the array.
Q127. Trapping Rain Water Problem Statement
You are given a long type array/list ARR
of size N
, representing an elevation map. The value ARR[i]
denotes the elevation of the ith
bar. Your task is to determine the tota...read more
Calculate the total amount of rainwater that can be trapped between given elevations in an array.
Iterate through the array and calculate the maximum height on the left and right of each bar.
Calculate the amount of water that can be trapped at each bar by taking the minimum of the maximum heights on the left and right.
Sum up the trapped water at each bar to get the total trapped water for the entire array.
Q128. Connecting Ropes with Minimum Cost
You are given 'N' ropes, each of varying lengths. The task is to connect all ropes into one single rope. The cost of connecting two ropes is the sum of their lengths. Your obj...read more
Connect ropes with minimum cost by merging smallest ropes first.
Sort the array of rope lengths in ascending order.
Merge the two smallest ropes at each step to minimize cost.
Keep track of the total cost as you merge the ropes.
Repeat the merging process until all ropes are connected.
Return the total cost as the minimum cost to connect all ropes.
Q129. Copy and Reverse the Array
Given an array of non-negative integers ARR
, your task is to create another array COPY_ARR
with the elements of ARR
in reverse order.
Input:
The first line contains an integer T
denot...read more
Create a new array with elements of given array in reverse order.
Iterate through the given array in reverse order and copy elements to a new array.
Ensure to handle edge cases like empty array or single element array.
Use a temporary variable to swap elements for in-place reversal if required.
Q130. Dice Throw Problem Statement
You are provided with D
dice, each having F
faces numbered 1 to F
, inclusive. Your task is to determine the number of possible ways to roll the dice such that the sum of the face-up...read more
The problem involves finding the number of ways to achieve a target sum by rolling a given number of dice with a certain number of faces.
Use dynamic programming to keep track of the number of ways to achieve each sum from 1 to the target sum.
Iterate through the dice and faces to update the number of ways to reach each sum.
Return the number of ways to achieve the target sum modulo 10^9 + 7.
Q131. Game of Stones Problem Statement
Two players, 'Ale' and 'Bob', are playing a game with a pile of stones. Your task is to determine the winner if both play optimally.
Rules of the Game:
1. On each turn, a player...read more
Determine the winner of a game where two players take stones alternately, with specific rules.
Implement a recursive function to simulate the game, considering the rules provided.
Check if the current player can take any stones, if not, the other player wins.
Return 'Ale' if 'Ale' will win the game, otherwise return 'Bob'.
Q132. Inorder Traversal of Binary Tree
You are provided with a Binary Tree composed of 'N' nodes, each holding integer values. Your task is to compute the Inorder traversal of this binary tree.
Example:
For the given...read more
The task is to find the in-order traversal of a given binary tree.
Implement a recursive function to perform in-order traversal of the binary tree
Start from the left subtree, then visit the root node, and finally visit the right subtree
Use an array to store the values of the nodes in the in-order traversal
Q133. Kth Largest Element Problem
Given an array containing N
distinct positive integers and a number K
, determine the Kth largest element in the array.
Example:
Input:
N = 6, K = 3, array = [2, 1, 5, 6, 3, 8]
Output...read more
Find the Kth largest element in an array of distinct positive integers.
Sort the array in non-increasing order and return the Kth element.
Handle multiple test cases efficiently.
Ensure all elements in the array are distinct.
Q134. 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
Q135. Maximum of All Subarrays of Size k
Given an array of 'N' non-negative integers and an integer 'K', your task is to find the maximum elements for each subarray of size 'K'.
Input:
The first line contains an inte...read more
The task is to find the maximum elements for each subarray of size K in a given array.
Iterate through the array and maintain a deque of indices of the maximum elements in the current window of size K.
For each new element, remove indices from the deque that are outside the current window.
Add the index of the new element to the deque, and print the maximum element of the window if the first index in the deque is outside the window.
Q136. Maximum Sum Path from Leaf to Root
Given a binary tree with 'N' nodes, identify the path from a leaf node to the root node that has the maximum sum among all root-to-leaf paths.
Example:
All the possible root t...read more
Find the path from a leaf node to the root node with the maximum sum in a binary tree.
Traverse the binary tree from leaf to root while keeping track of the sum of each path.
Compare the sums of all paths and return the path with the maximum sum.
Use recursion to traverse the tree efficiently.
Handle cases where the node values can be negative.
Ensure to consider only one path with the maximum sum.
Q137. Party Over: Sorting Strings Problem
Help Ninja sort the provided list of strings according to a specific condition given by a monster. The condition is to sort the strings based on the last letter. If two strin...read more
Sort the list of strings based on the last character, then second last character, and so on.
Iterate through each string in the list
Sort the strings based on the last character first, then second last character, and so on
Use a custom sorting function to achieve the required sorting order
Q138. Search in a Row-wise and Column-wise Sorted Matrix Problem Statement
You are given an N * N matrix of integers where each row and each column is sorted in increasing order. Your task is to find the position of ...read more
Given a sorted matrix, find the position of a target integer in the matrix.
Iterate through each row and column of the matrix
Compare the target integer with the current element
If the target integer is found, return the position
If the target integer is not found, return {-1, -1}
Sum At Kth Level
Given the root of a binary tree, calculate the sum of all nodes located at the Kth level from the top. Consider the root node as level 1, and each level beneath it sequentially increases by 1.
Calculate the sum of nodes at the Kth level of a binary tree given the root.
Traverse the binary tree level by level using BFS.
Keep track of the current level while traversing.
Sum the nodes at the Kth level and return the result.
Q140. Maximum Sum Rectangle Problem
Given an M x N matrix of integers ARR
, your task is to identify the rectangle within the matrix that has the greatest sum of its elements.
Input:
The first line of input contains a...read more
The task is to find the maximum sum rectangle in a given matrix of integers.
Iterate through all possible rectangles in the matrix
Calculate the sum of each rectangle
Keep track of the maximum sum rectangle found so far
Return the maximum sum
Q141. Meeting Rooms Allocation Problem Statement
Stark Industry is planning to organize meetings for various departments in preparation for Stark Expo. Due to limited rooms in Stark Tower, the goal is to allocate mee...read more
The task is to find the minimum number of conference rooms required to organize all the meetings.
Sort the meetings based on their start time.
Initialize a priority queue to store the end times of the meetings in ascending order.
Iterate through the sorted meetings and check if the start time of the current meeting is greater than the end time of the meeting at the top of the priority queue.
If it is, remove the meeting from the priority queue.
Add the end time of the current meet...read more
Q142. Minimum Operations to Equalize Array
Given an integer array ARR
of length N
where ARR[i] = (2*i + 1)
, determine the minimum number of operations required to make all the elements of ARR
equal. In a single opera...read more
The minimum number of operations required to make all elements of the given array equal.
Calculate the target value as the sum of all elements divided by the length of the array.
Find the absolute difference between each element and the target value to determine the number of operations needed.
Return the sum of all absolute differences as the minimum number of operations required.
Q143. Nth Term of Geometric Progression (GP) Series
Determine the Nth term of a geometric progression (GP) series given the first term, common ratio, and the term number.
Explanation:
The general form of a GP series ...read more
Calculate the Nth term of a geometric progression series given the first term, common ratio, and term number.
Use the formula for the Nth term of a GP series: A * (R^(N-1))
Ensure to take the modulo 10^9 + 7 as the output
Handle multiple test cases efficiently within the given time limit
Q144. Sort Linked List Based on Actual Values
Given a Singly Linked List of integers that are sorted based on their absolute values, the task is to sort the linked list based on the actual values.
The absolute value ...read more
Sort a Singly Linked List based on actual values instead of absolute values.
Traverse the linked list and store the nodes in an array.
Sort the array based on the actual values of the nodes.
Reconstruct the linked list using the sorted array.
Q145. Word Break Problem Statement
You are provided with a continuous non-empty string (referred to as 'sentence') which contains no spaces and a dictionary comprising a list of non-empty strings (known as 'words'). ...read more
Given a dictionary of words and a continuous string, generate all possible sentences by inserting spaces.
Use recursion to generate all possible combinations of words from the dictionary to form sentences.
Check if a substring of the sentence matches any word in the dictionary, if so, recursively call the function with the remaining substring.
Keep track of the current sentence being formed and add it to the result when the entire sentence is processed.
Handle edge cases like emp...read more
Q146. 0-1 Knapsack Problem Statement
You are tasked with determining the maximum profit a thief can earn. The thief is looting a store and can carry a maximum weight 'W' in his knapsack. There are 'N' items, each wit...read more
The 0-1 Knapsack Problem involves maximizing profit by selecting items with known weights and values within a given weight capacity.
Understand the problem: Given items with weights and values, determine the maximum profit the thief can achieve within the knapsack's weight capacity.
Dynamic Programming: Use dynamic programming to solve the problem efficiently by considering the weight constraints and maximizing the total value.
Example: For input (1, 4, 10, [6, 1, 5, 3], [3, 6, ...read more
Q147. Find the Row with the Maximum Number of 1's
You are given a non-empty grid MAT
with 'N' rows and 'M' columns, where each element is either 0 or 1. All rows are sorted in ascending order.
Your task is to determi...read more
Find the row with the maximum number of 1's in a grid of 0's and 1's.
Iterate through each row of the grid and count the number of 1's in each row.
Keep track of the row index with the maximum number of 1's seen so far.
Return the index of the row with the maximum number of 1's.
Q148. Flip Bit to Win Problem Statement
You are given a task to help ninjas maximize their practice area in a dense forest represented by a sequence of trees (1s) and empty places (0s) in the binary representation of...read more
Given an integer representing a binary sequence, find the maximum consecutive ones by flipping one bit.
Iterate through the binary representation of the integer to find the longest sequence of ones.
Track the positions of zeros to determine where to flip a bit for maximizing consecutive ones.
Update the count of consecutive ones after flipping a zero to one.
Return the maximum length of consecutive ones obtained by flipping one bit.
Q149. Knight Probability in Chessboard
Calculate the probability that a knight remains on an N x N chessboard after making K moves. Initially, the knight is placed at a given position on the board. It can move in any...read more
Calculate the probability that a knight remains on an N x N chessboard after making K moves.
Use dynamic programming to calculate the probability of the knight staying on the board after each move.
Consider all possible moves the knight can make from its current position.
Keep track of the probabilities at each position on the board after each move.
Normalize the probabilities at the end to get the final result accurate to six decimal places.
Q150. Matrix Chain Multiplication Problem Statement
You are provided with a chain of matrices A1, A2, A3, ..., An. The goal is to determine the minimum number of scalar multiplications needed to multiply these matric...read more
The goal is to determine the minimum number of scalar multiplications needed to multiply a chain of matrices together.
Understand the matrix chain multiplication problem statement and how the dimensions of matrices are defined by the input array.
Implement a dynamic programming approach to find the minimum cost of matrix multiplication.
Consider the constraints provided and optimize the solution accordingly.
Test the solution with different input arrays to ensure correctness.
Focu...read more
Interview Questions of Similar Designations
Top Interview Questions for Software Developer Intern 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