MAQ Software
10+ Infosys Interview Questions and Answers
Q1. 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
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
Q2. Sort 0 1 2 Problem Statement
Given an integer array arr
of size 'N' containing only 0s, 1s, and 2s, write an algorithm to sort the array.
Input:
The first line contains an integer 'T' representing the number of...read more
Sort an array of 0s, 1s, and 2s in linear time complexity.
Use three pointers to keep track of 0s, 1s, and 2s while traversing the array.
Swap elements based on the values encountered to sort the array in-place.
Time complexity of the algorithm should be O(N) where N is the size of the array.
Q3. Pair Sum Problem Statement
You are provided with an array ARR
consisting of N
distinct integers in ascending order and an integer TARGET
. Your objective is to count all the distinct pairs in ARR
whose sum equal...read more
Count distinct pairs in an array whose sum equals a given target.
Use two pointers approach to iterate through the array and find pairs with sum equal to target.
Keep track of visited pairs to avoid counting duplicates.
Return -1 if no such pair exists with the given target.
Q4. Move Zeros to Left Problem Statement
Your task is to rearrange a given array ARR
such that all zero elements appear at the beginning, followed by non-zero elements, while maintaining the relative order of non-z...read more
Rearrange array to move zeros to the left while maintaining relative order of non-zero elements.
Iterate through the array and maintain two pointers, one for zero elements and one for non-zero elements.
Swap elements at the two pointers until all zeros are moved to the left.
Ensure to maintain the relative order of non-zero elements while rearranging the array.
Q5. Maximum Subarray Sum Problem Statement
Given an array arr
of length N
consisting of integers, find the sum of the subarray (including empty subarray) with the maximum sum among all subarrays.
Explanation:
A sub...read more
Find the sum of the subarray with the maximum sum among all subarrays in an array of integers.
Iterate through the array and keep track of the current sum and maximum sum.
Update the maximum sum whenever a new maximum subarray sum is found.
Handle cases where all elements are negative or the array is empty.
Example: For input arr = [-2, 1, -3, 4, -1], the maximum subarray sum is 4.
Q6. Detect and Remove Loop in Linked List
For a given singly linked list, identify if a loop exists and remove it, adjusting the linked list in place. Return the modified linked list.
Expected Complexity:
Aim for a...read more
Detect and remove loop in a singly linked list in place with O(n) time complexity and O(1) space complexity.
Use Floyd's Cycle Detection Algorithm to identify the loop in the linked list.
Once the loop is detected, use two pointers to find the start of the loop.
Adjust the pointers to remove the loop and return the modified linked list.
Q7. Count Distinct Substrings
You are provided with a string S
. Your task is to determine and return the number of distinct substrings, including the empty substring, of this given string. Implement the solution us...read more
Count distinct substrings of a given string using trie data structure.
Implement a trie data structure to store all substrings of the given string.
Count the number of nodes in the trie to get the distinct substrings count.
Handle empty string case separately.
Example: For 'ab', distinct substrings are: '', 'a', 'b', 'ab'.
Q8. Equilibrium Index Problem Statement
Given an array Arr
consisting of N integers, your task is to find the equilibrium index of the array.
An index is considered as an equilibrium index if the sum of elements of...read more
Find the equilibrium index of an array where sum of elements on left equals sum on right.
Iterate through array to calculate prefix and suffix sums
Compare prefix and suffix sums to find equilibrium index
Return -1 if no equilibrium index is found
Q9. Spiral Matrix Problem Statement
You are given a N x M
matrix of integers. Your task is to return the spiral path of the matrix elements.
Input
The first line contains an integer 'T' which denotes the number of ...read more
The task is to return the spiral path of elements in a given matrix.
Iterate through the matrix in a spiral path by adjusting the boundaries of rows and columns.
Keep track of the direction of traversal (right, down, left, up) to form the spiral path.
Handle edge cases like when the matrix is a single row or column.
Implement a function that takes the matrix dimensions and elements as input and returns the spiral path.
Q10. Minimum Travel Time Problem Statement
Mr. X plans to explore Ninja Land, which consists of N
cities numbered from 1 to N
and M
bidirectional roads connecting these cities. Mr. X needs to select a city as the st...read more
The task is to determine the minimum time required to visit all cities and roads in Ninja Land.
Create a graph representation of the cities and roads.
Use a traversal algorithm to find the minimum time to visit all cities and roads.
Return -1 if it is impossible to visit all roads.
Consider the constraints provided in the problem statement.
Implement the function to calculate the minimum travel time.
Q11. Two Sum Of leetcode
Given an array of integers, return indices of the two numbers such that they add up to a specific target.
Use a hashmap to store the difference between the target and current element
Iterate through the array and check if the current element's complement exists in the hashmap
Return the indices of the two numbers if found
Interview Process at Infosys
Top Software Developer Intern Interview Questions from Similar Companies
Reviews
Interviews
Salaries
Users/Month