1.
Introduction
2.
HackWithInfy Coding Round-2 Information
3.
HackWithInfy Previous Year Coding Problems
3.1.
Beautiful Function
3.2.
Paper Sheets
3.3.
Special Prime
3.4.
The Dishes Problem
4.
Important Topics For HackwithInfy Round 2
5.
6.
Key Takeaways
Last Updated: Mar 27, 2024

Round - 2 Most Asked Questions HWI

Divyansh Jain
0 upvote
Crack Google SDE interview : Essential projects
Speaker
Saurav Prateek
SDE-2 @
20 Jun, 2024 @ 01:30 PM

Introduction

HackWithInfy is a very famous country-wide coding competition for engineering students. HackWithInfy consists of two rounds, the first of which is an individual online exam, and the second of which is a Grand Finale. This year, HackWithInfy is available not only to final-year engineering students but also to second-and third-year engineering students in India who want to prove their worth and earn INR 3.5 lakhs in cash awards.

Source: Infosys

The exam structure and difficulty level of the HackWithInfy Coding Round is elaborated briefly in this blog. You'll discover a few sample coding problems based on the previous year's HackWithInfy Coding Section pattern. Thus, practicing these questions will help you grasp the section's difficulty level and test structure.

HackWithInfy Coding Round-2 Information

In the HackWithInfy test, there are two coding rounds:-

Round 1: In the first round of HackWithInfy, three code questions must be answered in three hours.

Round 2: This is the Grand Finale round, which will take place at Infosys Meridian. In round 2, the top 100 candidates from round 1 will be shortlisted.

Get the tech career you deserve, faster!
Connect with our expert counsellors to understand how to hack your way to success
User rating 4.7/5
1:1 doubt support
95% placement record
Akash Pal
Senior Software Engineer
326% Hike After Job Bootcamp
Himanshu Gusain
Programmer Analyst
32 LPA After Job Bootcamp
After Job
Bootcamp

HackWithInfy Previous Year Coding Problems

Beautiful Function

Problem Statement: Define a Beautiful Function F(x) as follows: Add 1 to the value of x, and if the result contains any trailing zeros, remove them all.

Examples:

F(11) = 12

F(99) = 1(100 â€“> 10 â€“> 1)

F(29) = 3(30 â€“> 3)

Let us define a number that can be reached from x if we can apply the Beautiful Function to x a certain number of times (possibly zero) and get that number as a result.

Example: 3 can be deduced from the number 29953, as F(29953) -> F(2996) -> 3.

You are given a number N. Your task is to determine how many numbers can be deduced from N.

Input Format:

The first line contains an integer N, which represents the given number.

Constrains: 1 <= N <= 10^9

Code:

Approach:

Adding 1 is not the best solution here. If we just kept adding 1 then the solution would lead to TLE, since the biggest N you would get is 10^9. As we can see in the input cases every solution is coming down to the unit digit. The moment we get the unit-digit number we need to add 9 in total anyways as you can see in the above code snippet.

The idea is to traverse the number in reverse order.

Letâ€™s take a look at one input case:

Example: 29953

29953 = 299954-> 299955 -> 299954 -> 299955 -> 299956 -> 299957 -> 299958 -> 29959 (7)

Here, in order to get the result 7, we need to subtract the last unit-digit from 10.

Letâ€™s say there is a current_dist variable for counting the current total and a total variable which keeps on adding the current_dist in it each time when the traversal is shifted towards the next digit.

Thus,

current_dist = 10 - 3 = 7

Total = 7

In addition to it, we need to add 1 each time the traversal is shifted.

2996 = 2997 -> 2998 -> 2999 (4)

Here,

current_dist = 10 - 6 = 4

total = 7 + 4 = 11

3 = 4-> 5-> 6-> 7-> 8-> 9-> 1-> 2 (9)

Now, at this time weâ€™ve encountered the unit digit number, so we would be adding 9 to the total result.

Thus,

Total = 7 + 4 + 9 = 20

Paper Sheets

Sam is handed a rectangular piece of paper with the dimensions h*w, where h denotes height and w denotes width. Sam wants to fold the paper in the fewest possible moves such that its dimensions are h1*w1. The paper could only be folded parallel towards its edges, and the dimensions should be integers after folding. If h=8 and w=4, for example, fold the paper till it's h1, w1 = 6,1. First, fold the long edge 6 units to the side, resulting in a 6*4 paper. And then, Fold the page in three folds along the width 2 units edge to achieve a 6*1 page.

Input Format

First line contains an integer denotes h

Seconds line contains an integer denotes w

Third line contains an integer denotes h1

Fourth line contains an integer denotes w1

Constraints

1 <= h, w, h1, w1 <= 10^15

h1 <= h

w1 <= w

Output Format

Print the minimum moves required.

Sample Input:

Sample Output:

Code:

Approach

Here, we have two approaches to be considered.

Approach -1:

Step 1: Set total_moves to zero.

Step 2: if w is greater than w1, divide w by 2 and add 1 to the total_moves value.

Step 3: Repeat step 2 until the condition is broken.

Step 4: If h is bigger than h1, divide it by 2 and add 1 to the total_moves value.

Step 5: Repeat step 2 until the condition is broken.

Step 6: Print the value of total_moves.

Approach -2:

Step 1: Using base 2, get the log values for h, h1, w, w1 and store them in h_new, h1_new, w_new, w1_new.

Step 2: Then at last, Print the value of  h_new - h1_new + w_new - w1_new

Special Prime

Given an integer N where

N <= 10^50

And you need to Print the total no. of pairs (x.y) such that

0 <= x <= n

0 <= y <= n

And F(x) + F(y) = Prime Number

Where F(x) = sum of the digits of x

Note: The pairs (x,y) and (y,x) are to be considered as one.

Input format

A single integer appears on the first line.

Output format

The output should also be a single integer.

Sample Input:

Sample Output:

Code:

Approach

So, we are given a number n, now we will maintain a set of pairs as set S. And then, Iterate i from 0 to n, similarly Iterate j from 0 to n. Determine whether the sum of digits of i and j is a prime number.

If the pair i,j is not found in set S, add it to S. Then, finally print the number of sets in S.

The Dishes Problem

Shyam has N various varieties of dishes lined up in a row: A1, A2,..., AN, where Ai signifies the type of the ith dish. He wants to select as many dishes as possible from the menu, but only if the following two requirements are satisfied:

• He can select only one sort of dish.
• Two adjacent dishes cannot be selected simultaneously.

Now the query is that Shyam wants to know which type of dish he should select so that he has the option of choosing the maximum number of dishes possible.

Example:

Given N = 9 and A = [1,2,2,1,2,1,1,1,1]

As we can see here, For type 1, Shyam has a maximum of four dishes to choose from. Selecting A1, A4, A7, and A9 is one of the possible ways of selecting four dishes of type 1.

For type 2, Shyam has a maximum of two dishes to choose from. One way is to select A3 and A5. In this situation, Shyam should go for type 1, which allows him to select comparatively more dishes.

Input Format

T, the number of test cases, appears on the first line. Then there are the test cases following T.

The first line of each test case contains a single integer N. And the N integers A1, A2,..., AN appears on the second line.

Constraints

1 <= T <= 10^3

1 <= N <= 10^3

1 <= Ai <= 10^3

Output Format

Print a single line for each test case containing one integer indicating the type of dish Shyam should select. Print the smallest response if there are multiple answers.

Sample Input:

Sample Output:

Code:

Approach

Step 1: Create an empty array with a size of 1001. (since the maximum value is 1000 due to restrictions)

Step 2: Determine the frequency of each element. If the adjacent elements are the same, the frequency should be 1.

Step 3: Set max value to zero.

Step 4: Use condition 1001 and initialize for loop with it.

Step 5: If i's frequency of i is larger than the max value, replace max value with i's frequency and the result with i.

Step 6: Print the outcome.

Important Topics For HackwithInfy Round 2

You may expect coding problems from the following list in HackwithInfy Round 2. As these topics have the most asked coding questions:

1. How many participants are shortlisted for Round 2?

Ans - In July 2022, the top 100 competitors from Round 1 will participate in a four-day grand finale. Finalists will also be given the option to participate in a pre-placement interview and internships at Infosys for specialist technical jobs.

2. How much time is given to solve round-2?

Ans - The candidate gets three complete hours to show their coding abilities in round 2 to submit their best answers before the deadline.

3. How to register for Round-2?

Ans - You donâ€™t have to register for Round 2. The participation in this round will be on a team basis, as determined by the Company at its absolute discretion.

4. How many questions are asked in round-2?

Ans - There are three questions given in round-2 of HackwithInfinity.

5. On which date Round 2 will be conducted?

Ans - This round will be conducted from July 1 to July 4, 2022. The Grand Finale is a 48-hour hackathon among teams.

Key Takeaways

In the above blog, we have learned the types of questions that we can face in HackWithInfy in detail and we have also discussed various frequent doubts about the exam and the registration process.

Check out Infosys Interview Experience to learn about their hiring process.

Now you have got a much better understanding of HackWithInfy. Hope you learned something. Coding Ninjas wishes you very good luck with the exam. Go ahead, Ninja!

Live masterclass