Software Developer Intern

filter-iconFilter interviews by

1000+ Software Developer Intern Interview Questions and Answers

Updated 27 Feb 2025

Popular Companies

search-icon

Q1. Sum of Maximum and Minimum Elements Problem Statement

Given an array ARR of size N, your objective is to determine the sum of the largest and smallest elements within the array.

Follow Up:

Can you achieve the a...read more

Ans.

Find sum of maximum and minimum elements in an array with least number of comparisons.

  • Iterate through the array and compare elements in pairs to find maximum and minimum simultaneously.

  • Keep track of current maximum and minimum as you iterate through the array.

  • After iterating through the array, sum up the maximum and minimum found.

  • Example: For input [1, 3, 5, 7, 9], compare 1 with 3, 5 with 7, and 3 with 9 to find min and max.

  • Example: For input [-10, 4, 7, 19], compare -10 wit...read more

Q2. Fish Eater Problem Statement

In a river where water flows from left to right, there is a sequence of 'N' fishes each having different sizes and speeds. The sizes of these fishes are provided in an array called ...read more

Ans.

Given a river with fishes of different sizes and speeds, determine how many fishes survive after encounters.

  • Iterate through the array of fishes and simulate encounters between fishes to determine survivors

  • Use a stack to keep track of surviving fishes

  • Compare sizes of fishes to determine which fish eats the other

Software Developer Intern Interview Questions and Answers for Freshers

illustration image

Q3. Kevin and his Fruits Problem Statement

Kevin has 'N' buckets, each consisting of a certain number of fruits. Kevin wants to eat at least 'M' fruits. He is looking to set a marker as high as possible such that i...read more

Ans.

Find the marker value needed for Kevin to eat at least 'M' fruits from 'N' buckets.

  • Iterate through each test case and calculate the marker value needed based on the number of fruits in each bucket.

  • Subtract the marker value from the number of fruits in each bucket and check if the total is at least 'M'.

  • Return the highest possible marker value for each test case.

Q4. Sliding Maximum Problem Statement

Given an array of integers ARR of length 'N' and a positive integer 'K', find the maximum elements for each contiguous subarray of size K.

Example:

Input:
ARR = [3, 4, -1, 1, 5...read more
Ans.

Find maximum elements for each subarray of size K in a given array of integers.

  • Iterate through the array and maintain a deque to store the indices of elements in decreasing order.

  • Pop elements from the deque if they are out of the current window.

  • Keep track of the maximum element in each subarray of size K.

Are these interview questions helpful?

Q5. Reverse Words in a String: Problem Statement

You are given a string of length N. Your task is to reverse the string word by word. The input may contain multiple spaces between words and may have leading or trai...read more

Ans.

Reverse words in a string while handling leading, trailing, and multiple spaces.

  • Split the input string by spaces to get individual words

  • Reverse the order of the words

  • Join the reversed words with a single space in between

Q6. Hotel Room Booking Problem

You are managing a hotel with 10 floors numbered from 0 to 9. Each floor contains 26 rooms labeled from A to Z. You will receive a sequence of strings representing room bookings where...read more

Ans.

Given a sequence of room bookings and freeings, find the room that is booked the most times.

  • Create a hashmap to store the count of each room booking.

  • Iterate through the sequence of bookings and freeings, updating the count in the hashmap.

  • Find the room with the highest count and return it. In case of a tie, return the lexicographically smaller room.

  • Example: For input n = 6, Arr[] = {"+1A", "+3E", "-1A", "+4F", "+1A", "-3E"}, the output would be "1A".

Share interview questions and help millions of jobseekers 🌟

man-with-laptop

Q7. Nth Element Of Modified Fibonacci Series

Given two integers X and Y as the first two numbers of a series, and an integer N, determine the Nth element of the series following the Fibonacci rule: f(x) = f(x - 1) ...read more

Ans.

Calculate the Nth element of a modified Fibonacci series given the first two numbers and N, with the result modulo 10^9 + 7.

  • Implement a function to calculate the Nth element of the series using the Fibonacci rule f(x) = f(x - 1) + f(x - 2)

  • Return the answer modulo 10^9 + 7 due to the possibility of a very large result

  • The series is 1-based indexed, so the first two numbers are at positions 1 and 2 respectively

Q8. Recycling Pens Problem Statement

Imagine you have a certain number of empty pens, and some money in your pocket. For each pen, you can choose to either recycle it for a reward or buy a refill to make it usable ...read more

Ans.

Given empty pens, money, and costs, maximize usable pens by recycling and buying refills.

  • Calculate total money after recycling pens

  • Determine number of refills that can be bought with the money

  • Combine refills with remaining pens to maximize usable pens

Software Developer Intern Jobs

Software Development Intern 0-1 years
KloudPortal-SaaS Product Development and Marketing Agency
4.8
Pune
Software Developer Intern / Trainee 0-1 years
TechAvidus
4.5
Gandhinagar
Software Development Intern 0-1 years
RARR Technologies
4.5
Pune

Q9. XOR Query Problem Statement

Assume you initially have an empty array called ARR. You are required to return the updated array after executing Q number of queries on this array.

There are two types of queries to...read more

Ans.

The problem requires updating an array based on a series of queries, where each query can either insert a value or perform a bitwise XOR operation on all elements.

  • Use a loop to iterate through each query and update the array accordingly

  • For type 1 query, append the value to the end of the array

  • For type 2 query, perform a bitwise XOR operation on each element of the array with the given value

  • Return the updated array after processing all the queries

Q10. Fibonacci Membership Check

Given an integer N, determine if it is a member of the Fibonacci series. Return true if the number is a member of the Fibonacci series, otherwise return false.

Fibonacci Series Defini...read more

Ans.

Check if a given integer is a member of the Fibonacci series.

  • Calculate Fibonacci numbers iteratively until reaching or exceeding the given integer N.

  • Check if the last calculated Fibonacci number is equal to N.

  • Return true if N is a Fibonacci number, otherwise return false.

Q11. K-th Permutation Sequence of First N Natural Numbers

Determine the K-th permutation from a sequence of the first N natural numbers.

Input:

Integer T indicating the number of test cases followed by 'T' test case...read more
Ans.

The task is to find the Kth permutation of the sequence of first N natural numbers.

  • Generate all possible permutations of the sequence of first N natural numbers

  • Sort the permutations in lexicographical order

  • Return the Kth permutation from the sorted list

Q12. Find K Closest Elements

Given a sorted array 'A' of length 'N', and two integers 'K' and 'X', your task is to find 'K' integers from the array closest to 'X'. If two integers are at the same distance, prefer th...read more

Ans.

Find K closest elements to X in a sorted array A.

  • Use binary search to find the closest element to X in the array.

  • Maintain two pointers to expand around the closest element to find K closest elements.

  • Handle cases where two elements are equidistant by choosing the smaller one.

  • Return the K closest elements in a new array.

Q13. First Missing Positive Problem Statement

You are provided with an integer array ARR of length 'N'. Your objective is to determine the first missing positive integer using linear time and constant space. This me...read more

Ans.

The task is to find the lowest positive integer that does not exist in the given array of integers.

  • Iterate through the array and mark the positive integers as visited using the array indices.

  • Iterate through the marked array and return the index of the first unmarked element.

  • If all positive integers are marked, return the length of the array + 1 as the missing positive integer.

Q14. Replace Node With Depth Problem Statement

For a given Binary Tree of integers, replace each of its data with the depth of the tree. The root is at depth 0, hence the root data is updated with 0. Replicate the s...read more

Ans.

Replace each node in a binary tree with its depth starting from root as 0.

  • Traverse the binary tree in inorder fashion and update each node's data with its depth.

  • Start with depth 0 for the root node and increment the depth as you go down the tree.

  • Handle cases where nodes do not have left or right child by taking -1 in their place.

  • Print the inorder traversal of the tree with updated node data representing the depth.

Q15. Remove Consecutive Duplicates Problem Statement

For a given string str, remove all the consecutive duplicate characters.

Example:

Input:
Input String: "aaaa"
Output:
Expected Output: "a"
Input:
Input String: "a...read more
Ans.

Remove consecutive duplicate characters from a given string.

  • Iterate through the string and compare each character with the previous one.

  • If the current character is different from the previous one, add it to the result string.

  • Return the result string as the output.

Q16. Minimum and Maximum Candy Cost Problem

Ram is in Ninjaland, visiting a unique candy store offering 'N' candies each with different costs. The store has a special offer: for every candy you purchase, you can tak...read more

Ans.

Determine the minimum and maximum amounts of money needed to purchase all candies with a special offer.

  • Iterate through the candy costs array to find the minimum and maximum costs.

  • Consider the special offer of getting up to 'K' additional candies for free.

  • Calculate the minimum cost by selecting the cheapest candies and taking free ones.

  • Calculate the maximum cost by selecting the most expensive candies and taking free ones.

Q17. Sum of Minimum and Maximum Elements of All Subarrays of Size K

You are provided with an array containing N integers along with an integer K. Your task is to compute the total sum of the minimum and maximum elem...read more

Ans.

Calculate the sum of minimum and maximum elements of all subarrays of size K in an array.

  • Iterate through the array and maintain a deque to store the indices of elements in the current window of size K.

  • Keep track of the minimum and maximum elements in the current window and update the sum accordingly.

  • Return the total sum of minimum and maximum elements for all subarrays of size K.

Q18. Container with Most Water Problem Statement

Given a sequence of 'N' space-separated non-negative integers A[1], A[2], ..., A[i], ..., A[n], where each number in the sequence represents the height of a line draw...read more

Ans.

Given a sequence of non-negative integers representing the height of lines on a cartesian plane, find two lines that form a container with the maximum area of water.

  • Use two pointers approach to find the maximum area

  • Start with the widest container and gradually move the pointers towards each other

  • Calculate the area at each step and update the maximum area

  • The area is calculated as the minimum height of the two lines multiplied by the distance between them

Q19. Rahul and Minimum Subarray Challenge

Rahul, who is passionate about programming, is learning about arrays and lists. He faces a challenging problem to determine the smallest subarray length in a given array 'AR...read more

Ans.

The problem is to find the length of the smallest subarray in a given array with its sum greater than a given value.

  • Iterate through the array and keep track of the current subarray sum

  • If the current sum becomes greater than the given value, update the minimum subarray length

  • If the current sum becomes negative, reset the sum and start a new subarray

  • Return the minimum subarray length

Q20. Valid String Problem Statement

Given a string S consisting solely of the characters '(', ')', and '*', determine if it is a valid string.

Definition of Valid String:

1. Every left parenthesis '(' must have a co...read more
Ans.

Determine if a string consisting of '(' , ')' and '*' characters is valid based on given rules.

  • Iterate through the string and keep track of the count of left parentheses, right parentheses, and stars.

  • Use a stack to keep track of the positions of left parentheses.

  • If at any point the count of right parentheses exceeds the count of left parentheses + stars, the string is invalid.

  • If after iterating through the string, there are unmatched left parentheses, the string is invalid.

  • If...read more

Q21. Longest Palindromic Substring Problem Statement

You are provided with a string STR of length N. The goal is to identify the longest palindromic substring within this string. In cases where multiple palindromic ...read more

Ans.

Given a string, find the longest palindromic substring, prioritizing the one with the smallest start index.

  • Iterate through the string and expand around each character to find palindromes

  • Keep track of the longest palindrome found and its starting index

  • Return the longest palindromic substring with the smallest start index

Q22. 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

Ans.

Count the number of islands in a 2D matrix of 1s and 0s.

  • Use Depth First Search (DFS) or Breadth First Search (BFS) to traverse the matrix and identify connected groups of 1s.

  • Maintain a visited array to keep track of visited cells to avoid counting the same island multiple times.

  • Increment the island count each time a new island is encountered during traversal.

  • Consider edge cases such as when the matrix is empty or when all cells are water (0s).

Q23. Minimum Operations to Connect a Graph

You are given a graph with 'N' vertices labeled from 1 to 'N' and 'M' edges. In one operation, you can shift an edge from being between two directly connected vertices to b...read more

Ans.

Determine the minimum number of operations to connect a graph by shifting edges between disconnected vertices.

  • Use a disjoint set union (DSU) data structure to keep track of connected components.

  • Count the number of connected components in the graph.

  • The minimum number of operations required is equal to the number of connected components minus 1.

Q24. Longest Substring Without Repeating Characters Problem Statement

Given a string S of length L, determine the length of the longest substring that contains no repeating characters.

Example:

Input:
"abacb"
Output...read more
Ans.

The problem asks to find the length of the longest substring without repeating characters in a given string.

  • Use a sliding window approach to iterate through the string and keep track of the characters seen so far.

  • Maintain a set to check for duplicate characters within the current substring.

  • Update the maximum length of the substring whenever a duplicate character is encountered.

  • Continue the process until the end of the string is reached.

  • Return the maximum length of the substri...read more

Frequently asked in,

Q25. Frequency in a Sorted Array Problem Statement

Given a sorted array ARR and a number X, your task is to determine the count of occurrences of X within ARR.

Note:

  • If X is not found in the array, return 0.
  • The ar...read more
Ans.

The task is to count the number of occurrences of a given number in a sorted array.

  • Use binary search to find the first and last occurrence of the given number in the array.

  • Subtract the indices of the first and last occurrence to get the count.

  • Handle the case when the number is not found in the array.

Q26. Pair Sum Problem Statement

You are given an integer array 'ARR' of size 'N' and an integer 'S'. Your task is to find and return a list of all pairs of elements where each sum of a pair equals 'S'.

Note:

Each pa...read more

Ans.

Given an array and a target sum, find all pairs of elements in the array that add up to the target sum.

  • Create an empty list to store the pairs

  • Iterate through the array and for each element, check if there is a complement (target sum minus the current element) in the array

  • If a complement is found, add the pair (current element, complement) to the list

  • Sort the list of pairs in non-decreasing order of their first value

  • If two pairs have the same first value, sort them based on th...read more

Q27. 0-1 Knapsack Problem

A thief is planning to rob a store and has a knapsack that can carry a maximal weight of W. There are N items available, where each item i has a weight wi and a value vi. Determine the maxi...read more

Ans.

Yes, the 0-1 Knapsack Problem can be solved using dynamic programming with a space complexity of O(W).

  • Use dynamic programming to create a 2D array to store the maximum value that can be attained at each weight limit.

  • Iterate through each item and update the array based on whether including the item would increase the total value.

  • The final answer will be the value at the last row and last column of the 2D array.

  • Example: For the input (4, [2, 3, 4, 5], [3, 4, 5, 6], 5), the maxi...read more

Q28. 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

Ans.

DFS traversal to find connected components in an undirected and disconnected graph.

  • Use Depth First Search (DFS) to traverse the graph and find connected components.

  • Maintain a visited array to keep track of visited vertices.

  • For each unvisited vertex, perform DFS to explore the connected component it belongs to.

  • Print the vertices of each connected component in ascending order.

  • Repeat the process until all vertices are visited and all connected components are identified.

Q29. Majority Element - II Problem Statement

Given an array/list ARR of integers with length 'N', identify all elements that appear more than floor(N/3) times within the array/list.

Input:

T (number of test cases)
Fo...read more

Q30. Count Distinct Bitwise OR of All Subarrays

Given an array of positive integers, determine the number of distinct values obtained by applying the bitwise OR operation on all possible subarrays.

Explanation:

A su...read more

Ans.

Count distinct values obtained by applying bitwise OR operation on all possible subarrays of an array of positive integers.

  • Use a set to store distinct values obtained by bitwise OR operation on all subarrays.

  • Iterate through all subarrays efficiently to calculate distinct values.

  • Optimize the solution to handle large input sizes efficiently.

  • Handle bitwise OR operation on subarrays using bitwise operators.

  • Consider using dynamic programming or sliding window technique for optimiz...read more

Q31. Jump Game Problem Statement

In this problem, you are given an array ARR consisting of N integers. Your task is to determine the minimum number of jumps required to reach the last index of the array N - 1. At an...read more

Ans.

The problem involves finding the minimum number of jumps required to reach the last index of an array, where each element represents the maximum distance that can be jumped from that index.

  • Start from index 0 and keep track of the farthest index that can be reached from each position.

  • Update the current farthest index as the maximum of current farthest index and i + ARR[i].

  • Increment the jump count when the current index reaches the previous farthest index.

  • Continue this process ...read more

Q32. Longest Consecutive Sequence Problem Statement

You are provided with an unsorted array/list ARR of N integers. Your task is to determine the length of the longest consecutive sequence present in the array.

Expl...read more

Ans.

Find the length of the longest consecutive sequence in an unsorted array of integers.

  • Iterate through the array and store all elements in a set for constant time lookups.

  • For each element, check if it is the start of a sequence by looking for its previous number in the set.

  • Update the length of the current sequence and the maximum length found so far.

  • Return the maximum length of consecutive sequence found.

Q33. Minimum Fountains Activation Problem

In this problem, you have a one-dimensional garden of length 'N'. Each position from 0 to 'N' has a fountain that can provide water to the garden up to a certain range. Thus...read more

Ans.

Find the minimum number of fountains to activate to water the entire garden.

  • Iterate through the array to find the coverage of each fountain.

  • Keep track of the farthest coverage reached by activating fountains.

  • Activate the fountain that covers the farthest distance to minimize the number of fountains activated.

Q34. Ninja and His Meetings Problem Statement

Ninja has started a new startup with a single conference room available for meetings. Given an array/list MEETINGS of consecutive appointment requests, Ninja must decide...read more

Ans.

Find the maximum total booked minutes possible in a conference room for given meeting durations with a 15-minute break between meetings.

  • Iterate through the list of meeting durations and calculate the maximum total booked minutes by considering the 15-minute break constraint.

  • Keep track of the total booked minutes and skip consecutive meetings that violate the break constraint.

  • Return the maximum total booked minutes for each test case.

Q35. Stocks are Profitable Problem Statement

You are provided with an array/list 'prices', where each element signifies the prices of a stock as of yesterday and the indices represent minutes. The task is to determi...read more

Ans.

Given stock prices, find the maximum profit from a single buy and sell action.

  • Iterate through the array and keep track of the minimum price seen so far and the maximum profit achievable.

  • Calculate the profit by subtracting the current price from the minimum price and update the maximum profit if needed.

  • Return the maximum profit obtained after iterating through the array.

  • Example: For prices = [2, 100, 150, 120], buy at 2 and sell at 150 for a profit of 148.

Q36. Base 58 Conversion Problem Statement

You are given a decimal number 'N'. Your task is to convert this number into a base 58 representation.

The Base58 alphabet is defined by the following characters: “123456789...read more

Ans.

Convert a decimal number to base 58 using a specific alphabet.

  • Iterate through each test case and convert the decimal number to base 58 using the given alphabet.

  • Handle the conversion by dividing the number by 58 and taking the remainder to find the corresponding base 58 character.

  • Build the base 58 representation by appending the characters in reverse order.

  • Output the final base 58 representation for each test case.

Q37. Count and Say Sequence Problem

The 'Count and Say' sequence is a series of strings in which each consecutive term is generated by describing the previous term. The sequence begins with '1'.

Your task is to dete...read more

Ans.

Implement a function to determine the 'Count and Say' sequence after N iterations.

  • Iterate through each term in the sequence, describing the previous term to generate the next term.

  • Use a count to keep track of consecutive digits and append the count and digit to the result string.

  • Repeat this process for N iterations to get the sequence after N iterations.

Q38. Find the Minimum Cost to Reach Destination via Train

Given 'N' stations on a train route, where the train travels from station 0 to 'N'-1, determine the minimum cost to reach the final station using given ticke...read more

Ans.

Find the minimum cost to reach the destination via train using given ticket costs for each pair of stations.

  • Create a 2D array to store the costs from each station to the final destination.

  • Use dynamic programming to calculate the minimum cost to reach each station.

  • Iterate through the stations and update the minimum cost based on the previous stations.

  • Return the minimum cost to reach the final station.

Q39. Flood Fill Algorithm Task

Assist Ninja in altering the color of a specific region in his photo. Given the image as a 2D array where each pixel is a positive integer, update the color of a specified pixel and th...read more

Ans.

The Flood Fill Algorithm is used to change the color of a particular region in an image and all its adjacent same-colored pixels.

  • The image is represented as a 2D array of positive integers

  • The starting pixel and new color are given

  • Adjacent pixels are connected in up, down, left, or right directions

  • Diagonal pixels are not considered adjacent

  • Implement the Flood Fill Algorithm to replace the color of the given pixel and its adjacent same-colored pixels with the new color

  • Repeat th...read more

Q40. Kth Smallest and Largest Element Problem Statement

You are provided with an array 'Arr' containing 'N' distinct integers and a positive integer 'K'. Your task is to find the Kth smallest and Kth largest element...read more

Ans.

Find the Kth smallest and largest elements in an array.

  • Sort the array and return the Kth element for smallest and (N-K+1)th element for largest.

  • Use a priority queue to efficiently find the Kth smallest and largest elements.

  • Handle edge cases where K is equal to 1 or N.

Q41. Multiply Linked Lists Problem Statement

Your task is to multiply two numbers represented as linked lists and return the resultant multiplied linked list.

Explanation:

The multiplied list should be a linked list...read more

Ans.

Multiply two numbers represented as linked lists and return the resultant multiplied linked list.

  • Create a function that takes two linked lists as input and returns the product as a linked list

  • Traverse both linked lists to extract the numbers, multiply them, and create a new linked list for the product

  • Handle carry over while multiplying digits and adding to the result linked list

Q42. Unique Frequency Problem Statement

Given a string 'STR' with lowercase letters, determine the minimum number of deletions required to ensure that every letter in the string appears a unique number of times.

Exa...read more

Ans.

The task is to find the minimum number of deletions needed in a string to ensure each character appears a unique number of times.

  • Iterate through the string and count the frequency of each character

  • Track the frequencies in a hashmap

  • Identify the characters with duplicate frequencies and calculate the minimum deletions needed

  • Return the minimum number of deletions for each test case

Q43. Largest Cycle in Maze Problem Statement

Given a maze represented by 'N' cells numbered from 0 to N-1, and an array arr of 'N' integers where arr[i] denotes the cell number that can be reached from the 'i'-th ce...read more

Ans.

Identify the length of the largest cycle in a maze represented by cells and an array of integers.

  • Iterate through each cell and find cycles using DFS or Floyd's Tortoise and Hare algorithm.

  • Keep track of visited cells and cycle lengths to identify the largest cycle.

  • If a cell has no exit (-1), mark it as visited to avoid infinite loops.

Q44. Lazy Santa Problem Statement

It's Christmas and Santa has 'K' gifts to distribute. There are 'N' children standing in a straight line in the park due to COVID restrictions. You are given an array distance conta...read more

Ans.

Find the minimum distance Santa must travel to distribute 'K' gifts to 'K' different children standing in a straight line.

  • Sort the array 'distance' in ascending order to simplify the problem.

  • Calculate the distance between each adjacent child and find the minimum sum of distances for 'K' gifts.

  • Keep track of the minimum sum of distances as you iterate through the array.

Q45. Longest Increasing Subsequence Problem Statement

Given an array of integers with 'N' elements, determine the length of the longest subsequence where each element is greater than the previous element. This subse...read more

Ans.

The task is to find the length of the longest increasing subsequence in a given array.

  • Iterate through the array and keep track of the longest increasing subsequence length at each index.

  • Use dynamic programming to store the lengths of increasing subsequences ending at each index.

  • Return the maximum length from the dynamic programming array.

Q46. Josephus Problem Statement

Consider 'N' individuals standing in a circle, numbered consecutively from 1 to N, in a clockwise direction. Initially, the person at position 1 starts counting and will skip K-1 pers...read more

Ans.

This question is about finding the position of the last person surviving in a circle of N people, where each person kills the Kth person in a clockwise direction.

  • Implement a function that takes the number of test cases, N, and K as input

  • For each test case, simulate the killing process by iterating through the circle and skipping K-1 people

  • Keep track of the position of the last person surviving and return it as the output

Q47. Minimum Travel Cost Problem

You are given a country called 'Ninjaland' with 'N' states, numbered from 1 to 'N'. These states are connected by 'M' bidirectional roads, each with a specified travel cost. The aim ...read more

Ans.

The task is to select 'N' - 1 roads in a country with 'N' states, such that the tourist bus can travel to every state at least once at minimum cost.

  • The problem can be solved using a minimum spanning tree algorithm, such as Kruskal's algorithm or Prim's algorithm.

  • Create a graph representation of the country using the given roads and their costs.

  • Apply the minimum spanning tree algorithm to find the minimum cost roads that connect all the states.

  • Print the selected roads and thei...read more

Q48. Ninja And The Fence Problem Statement

Ninja is given a task of painting a fence with ‘N’ posts using ‘K’ different colors. The task requires that not more than two adjacent posts have the same color. Your goal ...read more

Ans.

The task is to determine the number of ways to paint a fence with 'N' posts using 'K' different colors, with the constraint that not more than two adjacent posts have the same color.

  • Use dynamic programming to solve the problem efficiently.

  • Consider the cases where the last two posts have the same color and different colors separately.

  • Keep track of the number of ways to paint the fence at each post using a 2D array.

  • Apply modulo 10^9 + 7 to avoid overflow issues.

  • Return the final...read more

Q49. Valid Sudoku Problem Statement

You are given a 9 X 9 2D matrix named MATRIX which contains some cells filled with digits (1 to 9) and some cells left empty (denoted by 0).

Your task is to determine if there is ...read more

Ans.

The task is to determine if a given 9x9 matrix can be filled with digits 1-9 to form a valid Sudoku solution.

  • Iterate through each cell in the matrix.

  • For each empty cell, try filling it with a digit from 1-9 and check if it satisfies the Sudoku conditions.

  • Use helper functions to check if the digit is valid in the current row, column, and sub-matrix.

  • If a valid digit is found, recursively fill the next empty cell.

  • If all cells are filled and the Sudoku conditions are satisfied, r...read more

Q50. 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

Frequently asked in,
1
2
3
4
5
6
7
Next
Interview Tips & Stories
Ace your next interview with expert advice and inspiring stories

Interview experiences of popular companies

4.1
 • 5k Interviews
4.4
 • 821 Interviews
3.9
 • 545 Interviews
3.5
 • 376 Interviews
3.9
 • 361 Interviews
3.8
 • 120 Interviews
3.8
 • 75 Interviews
View all

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

Recently Viewed
DESIGNATION
Pyspark Developer
25 interviews
DESIGNATION
DESIGNATION
DESIGNATION
DESIGNATION
LIST OF COMPANIES
Amazon Sellers Services
Overview
JOBS
HCLTech
No Jobs
REVIEWS
AU Small Finance Bank
No Reviews
INTERVIEWS
Infosys
No Interviews
INTERVIEWS
Alacriti Infosystems
No Interviews
Software Developer Intern Interview Questions
Share an Interview
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter