Infosys Interview Sheet
1. Provide an algorithm to reverse a linked list in groups of size k.
2. What algorithm can be used to find the maximum possible average value of a subsequence within
an array 'a'?
3. Given a number n, print all primes smaller than or equal to n. Assume n is a small number.
4. Given an array arr[] of size N, print the lexicographically next greater permutation of the array. If
no greater permutation exists, print the lexicographically smallest permutation.
5. Given an array coins[] of size N and a target value V, where coins[i] represents coins of different
denominations and you have an infinite supply of each coin, find the minimum number of coins
required to make the value V. If it's not possible to make a change, print -1.
6. In a gold mine of dimensions n*m, each field contains a positive integer representing the amount
of gold in tons. Initially, the miner is in the first column but can be in any row. The miner can only
move right, diagonally up, or diagonally down. Determine the maximum amount of gold the miner
can collect.
7. Given an array arr[] of N positive integers, find the maximum value of j – i such that arr[i] <= arr[j].
8.Given N ropes of different lengths, connect them into one rope with the minimum cost, where the
cost of connecting two ropes is the sum of their lengths.
9. Define topological sorting for a Directed Acyclic Graph (DAG) as a linear ordering of vertices such
that for every directed edge u-v, vertex u precedes v in the ordering.
10. Given an array arr[] of N positive integers representing the ratings of N children, determine the
minimum number of candies needed for distribution such that every child receives at least one
candy, and children with higher ratings receive more candies than their neighbors.
11. Given an unweighted graph, a source, and a destination, find the shortest path from the source
to the destination in the graph using Breadth-First Search (BFS) algorithm.
12. There are n gas stations along a circular route, with gas[i] representing the amount of gas at the
ith station, and cost[i] representing the cost of gas to travel from the ith station to its next station.
Determine the starting gas station's index if you can travel around the circuit once in the clockwise
direction; otherwise, return -1. If a solution exists, it's unique.
13.Given a 2D grid map of '1's (land) and '0's (water), count the number of islands. An island is
surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may
assume all four edges of the grid are surrounded by water.
Write a function or method that takes in the grid map as input and returns the total number of
islands.
For example, given the following grid map:
```
11000
11000
00100
00011
```
The function should return 3, as there are 3 islands in the grid.
Make sure to include any necessary data structures and helper functions in your solution. You may
use any programming language of your choice.
14.Given an array of integers and a target sum, find the minimum size of a contiguous subarray (a
sliding window) whose sum is greater than or equal to the target sum. If no such subarray exists,
return 0.
15. Given a sorted array arr[] of n elements, write a function to search for a given element x in arr[]
and return its index. Assume the array is 0-based indexed.
16. You've been given a sorted array/list ARR consisting of N elements. Also, an integer K is provided.
Find the first and the last occurrence of 'K' in ARR.
17. Given an array of integers representing a mountain where values increase until a peak is reached,
then decrease, find the index of the peak element. Write a function that takes the mountain array as
input and returns the index of the peak element. The time complexity of the solution should be
O(log(n)).
18. Given a non-negative integer x, return the square root rounded down to the nearest integer. Do
not use any built-in exponent function or operator. For example, if x=4, the output should be 2.
19. Given an array A of positive integers, find the leaders in the array. An element of the array is a
leader if it is greater than or equal to all elements to its right side. The rightmost element is always a
leader.
20. Given a sorted array of positive integers, rearrange the array elements alternatively, such that the
first element should be the maximum value, the second should be the minimum value, the third
should be the second maximum, the fourth should be the second minimum, and so on. Modify the
original array itself without using any extra space.
21. Given an array of size N containing only 0s, 1s, and 2s, sort the array in ascending order.
22. Given an n x n 2D matrix representing an image, rotate the image by 90 degrees clockwise.
Rotate the image in-place, modifying the input 2D matrix directly without allocating another 2D
matrix.
23. Given an unsorted array arr[] of size N with both negative and positive integers, place all negative
elements at the end of the array without changing the order of positive elements and negative
elements.
24. Given an array arr[] and an integer K where K is smaller than the size of the array, find the Kth
smallest element in the array. Assume all array elements are distinct.
25. Given two arrays a[] and b[] of size n and m respectively, find the union between these two
arrays. The union of the two arrays contains distinct elements from both arrays. If there are
repetitions, print only one occurrence of each element in the union. Elements are not necessarily
distinct.
Q1. Why do we need normalization in DBMS? What are its advantages and
disadvantages?
Q2. Difference between TCP and UDP protocol and also which is the better
one.
Q4. the difference between list and tuple in Python along with their time
complexities.
Q5. Difference between TCP/IP model and OSI model in computer networks.
Q6. Explain method overloading and method overriding in detail with
examples.
Q7. Explain block size and paging in the operating system.
Q8. What is virtual memory?
Q10. Explain about the Incremental Model.