# HackWithInfy Coding Questions and Answers

## HackWithInfy Coding Questions with Solutions

HackWithInfy Coding Questions and Answers are given on this page. Here you will get to know about the Exam Pattern for 2024 Batch and difficulty level of the HackWithInfy Coding Round. You can find a few sample coding questions on this page which are based on the Previous year’s pattern of the HackWithInfy Coding Section, so practicing these questions will help you in understanding the difficulty level and exam pattern of this section..

• #### Round 1:-

In 1st round  of HackWithInfy 3 coding questions are asked that have to be solved in 3 hours.
• #### Round 2

This is the Grand Finale round that will be held in Infosys Meridian headquarter.. Top 100 students from round 1 will get shortlisted in round 2.

## HackWithInfy Syllabus

##### Below we have given the topics which are included in

• Dynamic Programming
• Greedy Algorithms
• Backtracking
• Stack
• Queue
• Mapping Concepts
• Array manipulation
• String manipulation
• Tree
• Graph
• Bit Mapping and Hashing
• Recursion and Heap
• Divide and Conquer

### Related Banners

Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription

## HackWithInfy Coding Questions with Solutions

#### Question 1:

Ramu has N dishes of different types arranged in a row: A1,A2,…,AN where Ai denotes the type of the ith dish. He wants to choose as many dishes as possible from the given list but while satisfying two conditions:

1. He can choose only one type of dish.
2. No two chosen dishes should be adjacent to each other.

Ramu wants to know which type of dish he should choose from, so that he can pick the maximum number of dishes.

Example :

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

For type 1, Ramu can choose at most four dishes. One of the ways to choose four dishes of type 1 is A1,A4, A7 and A9.

For type 2, Ramu can choose at most two dishes. One way is to choose A3 and A5.

So in this case, Ramu should go for type 1, in which he can pick more dishes.

INPUT FORMAT:

• The first line contains T, the number of test cases. Then the test cases follow.
• For each test case, the first line contains a single integer N.
• The second line contains N integers A1,A2,…,AN.

OUTPUT FORMAT

For each test case, print a single line containing one integer ― the type of the dish that Ramu should choose from. If there are multiple answers, print the smallest one.

CONSTRAINTS :

• 1 <= T <= 10^3
• 1 <= N <= 10^3
• 1 <= Ai <= 10^3

Sample Input :

3

5

1 2 2 1 2

6

1 1 1 1 1 1

8

1 2 2 2 3 4 2 1

Sample Output :

1

1

2

#### Question 2:

There are three piles of stones. The first pile contains a stones, the second pile contains b stones and the third pile contains c stones. You must choose one of the piles and split the stones from it to the other two piles; specifically, if the chosen pile initially contained s stones, you should choose an integer k (0≤k≤s), move k stones from the chosen pile onto one of the remaining two piles and s−k stones onto the other remaining pile. Determine if it is possible for the two remaining piles (in any order) to contain x stones and y stones respectively after performing this action.

INPUT FORMAT :

• The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.
• The first and only line of each test case contains five space-separated integers

a,b,c, x and y.

OUTPUT FORMAT :

For each test case, print a single line containing the string “YES” if it is possible to obtain piles of the given sizes or “NO” if it is impossible.

CONSTRAINTS :

• 1 <= T <= 100
• 1 <= a,b,c,x,y <= 10^9

SAMPLE INPUT :

4

1 2 3 2 4

3 2 5 6 5

2 4 2 6 2

6 5 2 12 1

SAMPLE OUTPUT :

YES

NO

YES

NO

Test case 1: You can take the two stones on the second pile, put one of them on the first pile and the other one on the third pile.

Test case  2: You do not have enough stones.

Test case 3: You can choose the first pile and put all stones from it on the second pile.

#### Question 3:

Altaf has recently learned about number bases and is becoming fascinated.

Altaf learned that for bases greater than ten, new digit symbols need to be introduced, and that the convention is to use the first few letters of the English alphabet. For example, in base 16, the digits are 0123456789ABCDEF. Altaf thought that this is unsustainable; the English alphabet only has 26 letters, so this scheme can only work up to base 36. But this is no problem for Altaf, because Altaf is very creative and can just invent new digit symbols when she needs them. (Altaf is very creative.)

Altaf also noticed that in base two, all positive integers start with the digit 1! However, this is the only base where this is true. So naturally, Altaf wonders: Given some integer N, how many bases b are there such that the base-b representation of N starts with a 1?

INPUT FORMAT :

The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.

Each test case consists of one line containing a single integer N (in base ten).

OUTPUT FORMAT :

For each test case, output a single line containing the number of bases b, or INFINITY if there are an infinite number of them.

CONSTRAINTS :

• 1 <= T <= 10^5
• 0 <= N < 10^12

SAMPLE INPUT :

4

6

9

11

24

SAMPLE OUTPUT :

4

7

8

14

## FAQs on HackWithInfy Competition

##### Question 1: What roles are offered through HackWithInfy?

Candidates who will clear the 1st Round of HackWithInfy will get the chance to be interviewed for Digital System Engineer, Power Programmer, System Engineer Specialist, etc.

##### Question 2: Who can apply for HackWithInfy Exam 2024?
1. HackWithInfy Competition is open for all Engineering Students across India who are graduating in 2023 and 2024.
2. B.E./B. Tech or M.E./M. Tech students are eligible to apply for this Competition.

## Get over 200+ course One Subscription

Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others

## Checkout list of all the video courses in PrepInsta Prime Subscription

• Sakshi

Thanku for such awesome Questions

• avik394451

Thank you. Solutions are really helpful.

• avik394451

Solutions are really helpful. Can you guide me more contents that will help me to crack HackWithInfy?

• HelpPrepInsta

Now, this is what we expertise in😉. HackwithInfy is primarily a hackathon which requires an advanced level of coding and problem solving skills. We have exactly that🤩. We provide you extensive coding problems and solutions which begin with basic video lectures to start or to brush up concepts which go all the way to Data structure and algorithm (DSA) and Competitive programming for all languages.
Therefore if you don’t know anything about coding still you can learn it from basic to advanced level.
Checkout it’s detail here: https://prepinstaprime.com/

• Shruti

Hello, Can you please tell me where can I find complete information about hackwithinfy?

• sarina

Thank you for the questions. These helped me a lot in my preparations

• HelpPrepInsta

Hey!💚
It’s our pleasure to help our students😇.
You can even check out other company’s dashboards as well to get their details and practice questions. And if you are looking forward to up-skill yourself then PrepInsta can help you with that too.
Courses like Artificial intelligence/Machine learning, Cyber security, Ethical hacking, Cloud computing and many more are available with certifications.

• Priyanka

Thank you, similar questions were asked in my exams as well. Could you please tell me where I can find detailed content to cover my curriculum?

• Priyanka

Thank you these type of question was asked in my exams as well. can you please tell me where I can get detailed content to cove my syllabus?

• 4072-

Summation of two strings A and B(both strings contains 10-9

characters only) is calculated as follows • Add some ‘O’s at beginning of the smaller length string to make

them of equal length

– Create an empty string C

For each character at the same indices of A, and B say A and

B, add (A-B1 at the end of C. • C is the Summation of A and B

com

it is given that the value of a string S of length N is defined as

5010S1-10+ SIN-11-10

maximumall.com

value of Summation of any subarray of Arr as a

sanger giva 17

geethsiva 1/

Find the

You are given an array Arr of strings

string

• Bandaru

thank you for posting the programs