Software Developer Intern
900+ Software Developer Intern Interview Questions and Answers for Freshers
Q51. Longest Alternating Subsequence Problem
Given an array ARR
of integers, determine the length of the longest alternating subsequence.
Input:
ARR = {Array elements}
Output:
Length of the longest alternating subse...read more
Q52. Problem: Deletion in Circular Linked List
You are provided with a Circular Linked List of integers and a specific integer, referred to as 'key'
.
Your task is to implement a function that locates the specified k...read more
Implement a function to delete a specific key from a Circular Linked List of integers.
Traverse the Circular Linked List to find the key to be deleted.
Update the pointers of the previous and next nodes to skip the node with the key.
Handle the case where the Circular Linked List becomes empty after deletion.
Return -1 if the Circular Linked List is empty after deletion.
Q53. 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.
Iterate through the array of asteroids and simulate collisions between adjacent asteroids.
Use a stack to keep track of remaining asteroids after collisions.
Handle cases where asteroids moving in opposite directions collide and destroy each other.
Handle cases where asteroids moving in the same direction do not collide.
Q54. Flip Bits Problem Explanation
Given an array of integers ARR
of size N, consisting of 0s and 1s, you need to select a sub-array and flip its bits. Your task is to return the maximum count of 1s that can be obta...read more
Given an array of 0s and 1s, find the maximum count of 1s by flipping a sub-array at most once.
Iterate through the array and keep track of the maximum count of 1s obtained by flipping a sub-array.
Consider flipping a sub-array only when it results in increasing the count of 1s.
Update the maximum count of 1s as you iterate through the array.
Return the maximum count of 1s obtained after considering all possible sub-arrays.
Q55. K Max Sum Combinations Problem Statement
Given two arrays/lists A
and B
, each of size N
, and an integer K
, you need to determine the K
maximum and valid sum combinations from all possible combinations of sums g...read more
The problem involves finding the K maximum sum combinations from two arrays by adding one element from each array.
Iterate through all possible sum combinations of elements from arrays A and B.
Store the sums in a max heap to keep track of the K maximum sums.
Pop the top K elements from the max heap to get the K maximum sum combinations.
Q56. Remove K Corner Elements - Problem Statement
Given an array "arr" consisting of "N" integer elements, your task is to remove "K" elements from the beginning or the end of the array. You must return the maximum ...read more
Given an array, remove K elements from beginning or end to maximize sum of remaining elements.
Iterate through all possible combinations of removing K elements from beginning and end
Calculate sum of remaining elements for each combination
Return the maximum sum obtained
Share interview questions and help millions of jobseekers 🌟
Q57. 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
The task is to count the number of inversions in an array.
Iterate through the array and for each element, compare it with all the elements that come after it.
If the current element is greater than any of the elements that come after it, increment the inversion count.
Return the inversion count as the result.
Q58. LFU Cache Design Problem
Design and implement a Least Frequently Used (LFU) Cache with the following functionalities:
1. put(U__ID, value): Insert the value in the cache if the key ('U__ID') is not already pres...read more
Design and implement a Least Frequently Used (LFU) Cache with put and get functionalities, handling capacity and frequency of use.
Implement a LFU cache with put and get functions
Handle capacity and frequency of use for eviction
Return the value of key if present, -1 otherwise
Consider multiple elements with least frequency, remove least recently used
Example: Insert, update, and retrieve values based on operations
Software Developer Intern Jobs
Q59. Minimum Time To Solve The Problems
Given 'N' subjects, each containing a certain number of problems, and 'K' friends, assign subjects to friends such that each subject goes to exactly one friend, maintaining co...read more
Assign subjects to friends to minimize maximum workload, find minimum time for most loaded friend.
Sort subjects in descending order
Assign subjects to friends one by one until all subjects are assigned
The maximum workload will be the sum of problems assigned to the friend with the most problems
Return the maximum workload as the minimum time required
Q60. Network Delay Time Problem Statement
Given a network of nodes numbered from 1 to 'N', and 'M' edges. Each edge is represented by three values (u, v, w) where 'u' and 'v' are nodes, and 'w' is an integer represe...read more
Find the time it takes for a signal to travel from a given source node to all other nodes in a network.
Use Dijkstra's algorithm to find the shortest path from the source node to all other nodes.
Keep track of the minimum time taken to reach each node.
If it is impossible for the signal to reach all nodes, return -1.
Q61. Ninja and the Maze Problem Statement
Ninja is stuck in a maze represented as a 2D grid. He can move in four directions (Up, Down, Left, Right) until he hits a wall ('1'). Once stopped, he can choose a new direc...read more
The problem involves determining if a ninja can reach the destination in a maze by moving in four directions until hitting a wall.
Create a function that takes in the maze, starting point, and destination coordinates as input.
Implement a recursive algorithm to explore all possible paths in the maze.
Check if the destination can be reached from the starting point by moving in four directions.
Return 'True' if a path exists, otherwise return 'False'.
Q62. 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
The task is to find the total number of palindromic substrings in a given string.
Iterate through each character in the string and consider it as the center of a potential palindrome
Expand outwards from the center to check if the substring is a palindrome
Count the number of palindromic substrings found
Q63. Design a Constant Time Data Structure
Create a data structure that maintains mappings between keys and values, supporting the following operations in constant time:
1. INSERT(key, value): Add or update the inte...read more
Design a constant time data structure for key-value mappings with operations like INSERT, DELETE, SEARCH, GET, GET_SIZE, and IS_EMPTY.
Use a hash table to store key-value pairs for constant time operations.
Implement INSERT by hashing the key and storing the value at the corresponding index.
For DELETE, simply remove the key-value pair from the hash table.
SEARCH can be done by checking if the key exists in the hash table.
GET retrieves the value associated with the key, returning...read more
Q64. Find All Triplets with Zero Sum
Given an array Arr
consisting of N
integers, find all distinct triplets in the array that sum up to zero.
Explanation:
An array is said to have a triplet {Arr[i], Arr[j], Arr[k]}...read more
The task is to find all distinct triplets in an array that add up to zero.
Iterate through the array and fix the first element of the triplet.
Use two pointers approach to find the other two elements that sum up to the negative of the fixed element.
Skip duplicate elements to avoid duplicate triplets.
Return the list of triplets found.
Q65. Implementing Queue with Two Stacks
Your task is to implement a queue using two stacks. You are provided with ‘Q’ queries and need to handle them, where each query falls under one of these two operations:
- Enque...read more
Implement a queue using two stacks with enqueue and dequeue operations.
Use two stacks to simulate a queue - one for enqueue and one for dequeue.
For enqueue operation, push elements onto the enqueue stack.
For dequeue operation, if dequeue stack is empty, pop all elements from enqueue stack and push onto dequeue stack.
Return true for successful enqueue and -1 for empty dequeue.
Example: Enqueue 10, enqueue 20, dequeue (returns 10), enqueue 30, dequeue (returns 20).
Q66. Jar of Candies Problem Statement
You are given a jar containing candies with a maximum capacity of 'N'. The jar cannot have less than 1 candy at any point. Given 'K', the number of candies a customer wants, det...read more
Given a jar with 'N' candies, determine the number of candies left after providing 'K' candies to a customer.
Check if 'K' is greater than 'N', return -1 if invalid
Subtract 'K' from 'N' to get the remaining candies
Output the remaining candies for each test case
Q67. Missing Number in Concatenated Sequence
You were given a sequence of consecutive nonnegative integers but missed one while appending them to create a string S
. Your task is to identify the missing integer from ...read more
The task is to find the missing number in a string of consecutive nonnegative integers.
Iterate through the string and check if each substring can form a valid number
If a substring forms a valid number, check if it is consecutive with the previous number
If a substring does not form a valid number or is not consecutive, it is the missing number
Handle edge cases such as multiple missing numbers or all numbers already present
Q68. Power of a Number Problem
You are given two integers, X
and N
. Your task is to compute the value of X
raised to the power of N
(i.e., X^N
).
Input:
The first line contains an integer T
, the number of test cases....read more
Compute the value of X raised to the power of N for given integers X and N.
Read the number of test cases T
For each test case, read the values of X and N
Calculate X^N for each test case
Print the result of X^N for each test case
Q69. Simplify Directory Path Problem Statement
You are provided with a directory path in Unix-style notation, and your task is to simplify it according to given rules.
In a Unix-style file system:
- A dot (.) refers ...read more
The task is to simplify a given Unix-style directory path and determine the final destination.
Replace multiple slashes with a single slash
Handle dot (.) by ignoring it
Handle double dot (..) by removing the previous directory from the path
Ensure the simplified path starts with a slash and does not have a trailing slash
Q70. How we link the external files of css and js to the html?
External CSS and JS files can be linked to HTML using the <link> and <script> tags respectively.
Use the <link> tag with the 'rel' attribute set to 'stylesheet' to link external CSS files.
Use the <script> tag with the 'src' attribute to link external JS files.
Place the <link> and <script> tags within the <head> section of the HTML document.
Q71. Car Pooling Capacity Problem
You are a cab driver with a car that initially has 'C' empty seats. The car moves in a straight line towards the forward direction only. Your job is to determine if it is possible t...read more
Determine if it is possible to handle all passenger trips within the car capacity without exceeding it at any point.
Iterate through each trip and keep track of the total number of passengers in the car at each point.
Check if the total number of passengers exceeds the car capacity at any point, return 'False'. Otherwise, return 'True'.
Q72. Minimum Removals Problem Statement
Given an integer array ARR
of size N
and an integer K
, determine the minimum number of elements that need to be removed so that the difference between the maximum and minimum ...read more
Find the minimum number of elements to remove from an array to satisfy a given condition.
Calculate the initial difference between the maximum and minimum elements in the array.
Iterate through the array and remove elements to minimize the difference.
Return the count of elements removed as the answer.
Q73. Next Smaller Palindrome Problem Statement
You are provided with a palindrome number 'N' presented as a string 'S'. The task is to determine the largest palindrome number that is strictly less than 'N'.
Input:
T...read more
Given a palindrome number 'N' as a string, find the largest palindrome number strictly less than 'N'.
Iterate from the middle towards the start and end of the number to find the next smaller palindrome.
Handle cases where the middle digit is 0 by borrowing from adjacent digits.
Ensure the resulting number does not have leading zeros, except when the answer is 0.
Q74. Overlapping Intervals Problem Statement
You are given the start and end times of 'N' intervals. Write a function to determine if any two intervals overlap.
Note:
If an interval ends at time T and another interv...read more
The function checks if any two intervals overlap with each other.
Iterate through the intervals and compare the end time of one interval with the start time of the next interval.
If the end time is greater than or equal to the start time, the intervals overlap.
Return true if any overlapping intervals are found, otherwise return false.
Q75. 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
Reverse a given string containing alphabets, numbers, and special characters.
Iterate through the string from the end to the beginning and append each character to a new string.
Use built-in functions like reverse() or slicing to reverse the string.
Handle special characters and numbers while reversing the string.
Ensure to consider the constraints on the input string length and number of test cases.
Q76. Minimum Umbrellas Problem
You are provided with ‘N’ types of umbrellas, where each umbrella type can shelter a certain number of people. Given an array UMBRELLA
that indicates the number of people each umbrella...read more
Given 'N' types of umbrellas with different capacities, find the minimum number of umbrellas required to shelter exactly 'M' people.
Iterate through the umbrella capacities and try to cover 'M' people using the minimum number of umbrellas.
Keep track of the total number of people covered and the number of umbrellas used.
If it is not possible to cover 'M' people exactly, return -1.
Return the minimum number of umbrellas required to shelter exactly 'M' people.
Q77. Find Duplicates in an Array
Given an array ARR
of size 'N', where each integer is in the range from 0 to N - 1, identify all elements that appear more than once.
Return the duplicate elements in any order. If n...read more
Find duplicates in an array of integers within a specified range.
Iterate through the array and keep track of the count of each element using a hashmap.
Return elements with count greater than 1 as duplicates.
Time complexity can be optimized to O(N) using a HashSet to store seen elements.
Q78. Maximum Difference Problem Statement
Given an array ARR
of N
elements, your task is to find the maximum difference between any two elements in ARR
.
If the maximum difference is even, print EVEN; if it is odd, p...read more
Find the maximum difference between any two elements in an array and determine if it is even or odd.
Iterate through the array to find the maximum and minimum elements.
Calculate the difference between the maximum and minimum elements.
Check if the difference is even or odd and return the result.
Q79. 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 find the total number of ways to make change for a specified value using given denominations.
Use dynamic programming to keep track of the number of ways to make change for each value up to the target value.
Iterate through each denomination and update the number of ways to make change for each value based on the current denomination.
The final answer will be the number of ways to make change for the target value.
Consider edge cases such as when the target value i...read more
Q80. Add Two Numbers Represented by Linked Lists
Your task is to find the sum list of two numbers represented by linked lists and return the head of the sum list.
Explanation:
The sum list should be a linked list re...read more
Add two numbers represented by linked lists and return the head of the sum list.
Traverse both linked lists simultaneously while keeping track of carry from previous sum
Create a new linked list to store the sum of the two numbers
Handle cases where one linked list is longer than the other by padding with zeros
Update the sum and carry values accordingly while iterating through the linked lists
Q81. Anagram Pairs Verification Problem
Your task is to determine if two given strings are anagrams of each other. Two strings are considered anagrams if you can rearrange the letters of one string to form the other...read more
The task is to determine whether two given strings form an anagram pair or not.
Anagrams are words or names that can be formed by rearranging the letters of another word
Check if the two strings have the same characters with the same frequency
Convert the strings to character arrays and sort them
Compare the sorted arrays to check if they are equal
Q82. Closest Leaf in a Binary Tree
Ninja is stuck in a maze represented as a binary tree, and he is at a specific node ‘X’. Help Ninja find the shortest path to the nearest leaf node, which is considered an exit poi...read more
Q83. Count Leaf Nodes in a Binary Tree
Count the number of leaf nodes present in a given binary tree. A binary tree is a data structure where each node has at most two children, known as the left child and the right...read more
Count the number of leaf nodes in a binary tree where each node has at most two children.
Traverse the binary tree and count nodes with both children as NULL.
Use recursion to check each node in the tree.
Leaf nodes have no child nodes.
Example: For input 20 10 35 5 15 30 42 -1 13 -1 -1 -1 -1 -1 -1 -1, output should be 4.
Q84. Longest Common Subsequence Problem Statement
Given two strings, S
and T
with respective lengths M
and N
, your task is to determine the length of their longest common subsequence.
A subsequence is a sequence tha...read more
The task is to find the length of the longest common subsequence between two given strings.
A subsequence is a string that can be derived from another string by deleting some or no characters without changing the order of the remaining characters.
We can solve this problem using dynamic programming.
Create a 2D array to store the lengths of the longest common subsequences for all possible prefixes of the two strings.
Iterate through the strings and fill the array based on the fol...read more
Q85. Maximum Possible Time Problem Statement
Given an array ARR
consisting of exactly four integer digits, your task is to form the maximum possible valid time in a 24-hour format using those digits.
Explanation:
Th...read more
Given an array of four digits, form the maximum valid 24-hour time. Return -1 if not possible.
Iterate through all permutations of the digits to find the maximum valid time.
Check if the time is valid (between 00:00 and 23:59) before returning.
Handle cases where no valid time can be generated by returning -1.
Q86. Mean, Median, Mode Calculation
You are given an array 'ARR' consisting of 'N' integers. Your task is to calculate the three statistical measures for the given array:
- Mean - Implement the function
mean()
to cal...read more
Implement functions to calculate mean, median, and mode of an array of integers.
Implement a function mean() to calculate the mean of the array by summing all elements and dividing by the total count.
Implement a function median() to calculate the median of the array by sorting the array and finding the middle element(s).
Implement a function mode() to find the mode of the array by counting frequencies and returning the smallest element with the highest frequency.
Q87. Ninja's Jump Task
The Ninja has been given a challenge by his master to reach the last stone. These stones are represented as an array of numbers. The Ninja can jump using either odd-numbered or even-numbered j...read more
Find the number of starting indices from which a Ninja can reach the last stone by following specific jump rules.
Iterate through the array and keep track of the possible jumps for each index based on the rules provided.
Use dynamic programming or a stack to efficiently calculate the number of starting indices.
Consider edge cases where some indices may have no possible jumps.
Example: For the input [10, 13, 12, 14, 15], the Ninja can start from indices 0 and 1 to reach the last ...read more
Q88. Sum of LCM Problem Statement
Given an integer 'N', calculate and print the sum of the least common multiples (LCM) for each integer from 1 to N with N.
The sum is represented as:LCM(1, N) + LCM(2, N) + ... + LC...read more
Calculate and print the sum of least common multiples (LCM) for each integer from 1 to N with N.
Iterate from 1 to N and calculate LCM of each number with N
Sum up all the calculated LCMs to get the final result
Implement a function to calculate LCM of two numbers
Q89. Count Ways to Climb Stairs Problem
Given a staircase with a certain number of steps, you start at the 0th step, and your goal is to reach the Nth step. At every step, you have the option to move either one step...read more
Count the number of distinct ways to climb stairs by moving either one step or two steps at a time.
Use dynamic programming to solve the problem efficiently.
Keep track of the number of ways to reach each step by considering the number of ways to reach the previous two steps.
Return the result modulo 10^9+7 to handle large outputs.
Example: For N=4, ways to climb are {0,1,2,3,4}, {0,1,3,4}, {0,2,4}. Total 3 ways.
Q90. Minimum Jumps Problem Statement
Bob and his wife are in the famous 'Arcade' mall in the city of Berland. This mall has a unique way of moving between shops using trampolines. Each shop is laid out in a straight...read more
Q91. Partial BST Problem Statement
Check if a given binary tree is a Partial Binary Search Tree (BST). A Partial BST adheres to the following properties:
- The left subtree of a node contains only nodes with data les...read more
Check if a binary tree is a Partial Binary Search Tree (BST) based on specific properties.
Traverse the tree in level order and check if each node satisfies the properties of a Partial BST.
Use recursion to check if the left and right subtrees are also Partial BSTs.
Compare the data of each node with its children to ensure the BST properties are maintained.
Example: For input 1 2 3 4 -1 5 6 -1 7 -1 -1 -1 -1 -1 -1, the output should be true.
Q92. Subarray Sums I Problem Statement
You are provided with an array of positive integers ARR
that represents the strengths of different “jutsus” (ninja techniques). You are also given the strength of the enemy S
, ...read more
Count the number of subarrays whose combined strength matches the given enemy strength.
Iterate through all subarrays and calculate their sum to check if it matches the enemy strength.
Use two pointers technique to efficiently find subarrays with sum equal to the enemy strength.
Consider edge cases like when the enemy strength is 0 or when all elements in the array are equal to the enemy strength.
Q93. Subsequences of String Problem Statement
You are provided with a string 'STR'
that consists of lowercase English letters ranging from 'a' to 'z'. Your task is to determine all non-empty possible subsequences of...read more
Generate all possible subsequences of a given string.
Use recursion to generate all possible subsequences by including or excluding each character in the string.
Maintain the order of characters while generating subsequences.
Handle base cases where the string is empty or has only one character.
Store the generated subsequences in an array of strings.
Q94. Valid Stack Permutation Problem
Determine if one array is a valid stack permutation of another given array. An array is a valid stack permutation of another if by performing some sequence of push and pop operat...read more
Determine if one array is a valid stack permutation of another given array by performing push and pop operations.
Check if the elements in the 'FIRST' array can be obtained by performing push and pop operations on the 'OTHER' array.
Maintain a stack to simulate the push and pop operations.
If the 'FIRST' array can be obtained, output 'YES'; otherwise, output 'NO'.
Q95. Water Equalization Problem Statement
You are provided with an array ARR
of positive integers. Each integer represents the number of liters of water in a bucket. The goal is to make the liters of water in every ...read more
Given an array of water buckets, find the minimum liters of water to remove to make all buckets equal.
Iterate through the array to find the maximum frequency of a water amount
Calculate the total liters to be removed by subtracting the maximum frequency from the total number of buckets
Return the total liters to be removed as the answer
Q96. Clone Linked List with Random Pointer Problem Statement
Given a linked list where each node has two pointers: one pointing to the next node and another which can point randomly to any node in the list or null, ...read more
Cloning a linked list with random pointers by creating new nodes rather than copying references.
Create a deep copy of the linked list by iterating through the original list and creating new nodes with the same values.
Update the random pointers of the new nodes by mapping the original node's random pointer index to the corresponding new node.
Ensure the cloned linked list is an exact copy of the original by validating the values and random pointers.
The cloning process can be ac...read more
Q97. Find the Longest Palindromic Substring
Given a string ‘S’ composed of lowercase English letters, your task is to identify the longest palindromic substring within ‘S’.
If there are multiple longest palindromic ...read more
Find the longest palindromic substring in a given string, returning the rightmost one if multiple substrings are of the same length.
Use dynamic programming to check for palindromes within the string.
Start by checking for palindromes of length 1 and 2, then expand to longer substrings.
Keep track of the longest palindromic substring found so far and return the rightmost one if multiple substrings are of the same length.
Q98. Grid Satisfaction Problem
In this problem, you are given a grid of size N*M containing two types of people: type ‘A’ and type ‘B’. You are given the number of people of each type: 'countA' denotes the number of...read more
Given a grid with type A and B people, maximize satisfaction based on neighbors.
Start with type A people for maximum satisfaction
Optimally place people to maximize satisfaction
Consider satisfaction levels for each type of person and their neighbors
Q99. Largest Rectangle in Histogram Problem Statement
You are given an array/list HEIGHTS
of length N
, where each element represents the height of a histogram bar. The width of each bar is considered to be 1.
Your t...read more
The task is to find the largest rectangle possible in a given histogram and return its area.
Iterate through the histogram and maintain a stack to keep track of the indices of the bars in non-decreasing order of heights.
For each bar, calculate the area of the rectangle that can be formed using that bar as the smallest bar.
To calculate the area, pop the bars from the stack until a bar with a smaller height is encountered.
The width of the rectangle will be the difference between...read more
Q100. 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.
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