HWI - Preparatory Guidance and Sample Papers
HWI - Preparatory Guidance and Sample Papers
RECRUITMENT
Preparatory Guidance
1
INFOSYS ONLINE TEST
TEST FORMAT
Test usually contains 3 questions that will have to be attempted in 3 hours
Test will have a sectional cut-off as well as a total cut-off
Each question will belong to different difficulty level:
Easy – Simple questions that can be solved by basic application of
aptitude, algorithm and data structures
Medium – Usually a question based on Greedy algorithm
Hard – Usually a question based on Dynamic Programming
Code can be written for each question using one of the programming
language from C/C++/Java/Python/JavaScript
2
INFOSYS ONLINE TEST – HOW TO PREPARE
DIFFICULTY OF QUESTION - MEDIUM
A Greedy algorithm is any algorithm that follows the problem-solving
heuristic of making the locally optimal choice at each stage
3
INFOSYS ONLINE TEST – HOW TO PREPARE
DIFFICULTY OF QUESTION - HARD
Dynamic Programming (DP) is an algorithmic technique for solving an
optimization problem by breaking it down into simpler subproblems and
utilizing the fact that the optimal solution to the overall problem depends
upon the optimal solution to its subproblems.
4
INFOSYS ONLINE TEST – HOW TO PREPARE
DIFFICULTY OF QUESTION - HARD
Characteristics of a Dynamic Programming problem
Following are the two main properties of a problem that suggest the given
problem can be solved using Dynamic Programming:
1. Overlapping subproblems
A problem has overlapping sub-problems if its solution involves solving the
same subproblem multiple times.
2. Optimal substructure properties
The overall optimal solution can be constructed from the optimal solutions
of its subproblems.
5
INFOSYS ONLINE TEST – HOW TO PREPARE
DIFFICULTY OF QUESTION - HARD
Dynamic Programming methods
There are two different ways to store values for an overlapping
subproblem so that the values can be reused:
1. Top-down with Memorization
To solve a bigger problem, in this approach we recursively find the solution
to the smaller sub-problems and its result is cached. So next time the same
sub-problem is tried to solve, the cached memorized result is returned.
2. Bottom-up with Tabulation
In this approach, we solve the problem “bottoms-up” i.e., by filling up an
n-dimensional table. Based on the results in the table, the solution to the
top/original problem is then computed.
6
INFOSYS ONLINE TEST – HOW TO PREPARE
DIFFICULTY OF QUESTION - HARD
Some examples of Dynamic Programming
• Knapsack problem
• Fibonacci Numbers
• Palindromic Subsequence
• Longest Common Substring
• Dijkstra's algorithm
7
INFOSYS VIRTUAL INTERVIEW
This round will access your technical and behavioral skills.
STRUCTURE
Total duration of the interview will be around 1 hour
if H > Vi: The villain is defeated and the health of the hero is Output:
decreased by Vi 0
if H < Vi: The villain wins, his health is not affected and the hero is [3, 1, 3, 3]. We have 4 heroes will health 3. The heroes 1 will fight
no longer able to fight. villain 1. Both get defeated. The hero 2 fights villain 2. It wins the
if H = Vi: Both of them are considered defeated and neither can battle and now his health is 2. He fights the third villain and loses,
fight. the villain still has health 3. The hero 3 fights villain 3 and both get
defeated. Hero 4 fights villain 4 and both get defeated. So no need
The heroes start fighting villains one by one in the same order, first
to remove any villain.
villain 1 then villain 2 and so on. It is might be possible that before
defeating all the villains, all the heroes are defeated. Therefore, to Case#: 2
ensure the victory of the heroes, you want to remove some villains Input:
from the front.
5
Your task is to find the minimum number of villains you need
3
to remove from the front such that the victory of the heroes is
guaranteed. 3
Note: If in the last battle, both the hero and villain are defeated 1
and no more heroes or villains remain, it would still be considered 2
a victory since all the villains are defeated.
3
Parameters:
1
N :: INTEGER
1
The first line contains an integer, N, denoting the number of
Output:
villains
0
N :: 1 -> 2*10^5
The fight will take place and hero 1 will defeat villain 1 and 2. Hero
M :: INTEGER
2 will defeat villain 2. Hero 3 will defeat villain 3 and 4
The next line contains an integer, M, denoting the number of
Case#: 3
heroes
Input:
M :: 1 -> 2*10^5
5
H :: INTEGER
1
The next line contains an integer, H, denoting the health of each of
the heroes 4
H :: 1 -> 10^9 1
You are allowed to assign the team to dig on multiple segments On day 1, we can dig on 1st and 4th segment, resulting in {-2, 1, 1,
and/or dig on the same segments for multiple days. 0}
Your task is to find the minimum number of days needed to On day 2, we can dig on 3rd and 4th segments, resulting in {-2, 1,
transform the terrain as per your requirements. -1, -2}
Parameters: On day 3, we can dig on 2nd, 3rd and 4th segments, resulting in
{-2, -3, -5, -6}
N :: INTEGER
The first line contains an integer, N, denoting the number of
elements in L.
N :: 1 -> 10^5
L :: INTEGER ARRAY
Each line i of the N subsequent lines (where 0 < i ≤ N) contains an
integer describing Li, the sea level of the i-th segment.
L[i] :: -10^9 -> 10^9
Case#: 1
Input:
2
3
3
Output:
1
We can dig on the 2nd segment, reducing it from 3-meter sea level
to 2. Resulting in {3, 2} which is strictly decreasing.
Case#: 2
Input:
2
5
-3
Output:
0
It is already strictly decreasing before start.
Case#: 3
Input:
4
Parameters: 1
N :: INTEGER Here A=[5,4,3,2,1] K=3, we can swap elements at index 0 and index
3 which makes A=[2,4,3,5,1].
The first line contains an integer, N, denoting the number of
elements in A. Case#: 3
A :: INTEGER ARRAY 5
It is given that the restaurant will not let you order the dishes of 2
the same type more than once. Moreover, if you order A dishes in 2
the restaurant your next order must contain (2*A) dishes. It is also
1
given that the restaurant does not accept orders containing more
than one type of dishes in the same order. 1
Your friend can start eating with any number of dishes. Find the 1
maximum number of dishes that your friend can eat. 1
Notes: 1
Your friend is a foodie and can eat any amount of food that is Output:
served to him by the restaurant.
6
Parameters:
N=7
N :: INTEGER
A=[2,2,1,1,1,1,1]
The first line contains an integer, N, denoting the number of
Start with eating two dishes of type 2, then eat four dishes of type
elements in Arr.
1.
N :: 1 -> 10^5
Note that you can’t start with one dish of type one, then two
Arr :: INTEGER ARRAY dishes of type 2, and get back to eat to a dish of size 1 again, your
Each line i of the N subsequent lines (where 0 ≤ i < N) contains an friend cannot eat the same type of dishes multiple times.
integer describing Arr[i]. Case#: 3
Arr[i] :: 1 -> 10^9 Input:
Case#: 1 4
Input: 1
5 1
1 1
2 1
4 Output:
2 4
3 N=4
Output: A=[1,1,1,1]
3 Your friend can eat all 4 dishes in the first order.
N=5
© 2024 Infosys Limited, Bengaluru, India. All Rights Reserved. Infosys believes the information in this document is accurate as of its publication date; such information is subject to change without notice. Infosys
acknowledges the proprietary rights of other companies to the trademarks, product names and such other intellectual property rights mentioned in this document. Except as expressly permitted, neither this
documentation nor any part of it may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, electronic, mechanical, printing, photocopying, recording or otherwise, without the
prior permission of Infosys Limited and/ or any named intellectual property rights holders under this document.