- HackWithInfy
- How to prepare for HackWithInfy
- How to register
- HackWithInfy Syllabus
- HackWithInfy Coding
- HackWithInfy Eligibility Criteria
- HackWithInfy Selection Process
- HackWithInfy Prize Money
- HackWithInfy Power Programmer Interview Role
- HackWithInfy Interview
- HR Interview Questions
- Technical Interview Questions

Please login

#### Prepinsta Prime

Video courses for company/skill based Preparation

#### Prepinsta Prime

Purchase mock tests for company/skill building

# HackWithInfy Coding Questions and Answers

## HackWithInfy Coding Questions for 2022 freshers

HackWithInfy Coding Questions and Answers are explained on this page. Here you will get to know about the exam pattern and difficulty level of HackWithInfy Coding Round. You can find a few sample coding questions on this page which are based on the previous year pattern of HackWithInfy Coding Section, so practising these questions will help you in understanding the difficulty level and exam pattern of this section.

## HackWithInfy Coding Round-2 Information

There are 2 coding round in HackWithInfy exam:-

**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 Previous Year Coding Questions

## 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:

- He can choose
**only one**type of dish. - 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**

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

int main ()

{

int t;

cin >> t;

while (t--)

{

int a, b, c, x, y;

cin >> a >> b >> c >> x >> y;

if ((a + b + c) != (x + y))

{

cout << "NO" << endl;

}

else

{

if (y < min (a, min (b, c)) || x < min (a, min (b, c)))

{

cout << "NO" << endl;

}

else

{

cout << "YES" << endl;

}

}

}

}

#Test case

t=int(input())

# loop for each test case

for tc in range(t):

# number of elements

n=int(input())

# itemList

itemList=list(map(int, input().split()))

i=0

max=0

itemType=itemList[0]

# loop to calculate max possible type of dish

while i<n:

#count variable

c = 1

j=i+1

while j<n:

if itemList[i]==itemList[j] and j!=i+1:

c+=1

if j<n-1 and itemList[j]==itemList[j+1]:

j+=1

j+=1

# if the count is greater than max then max=c

if max<c:

max=c

itemType = itemList[i]

i+=1

#print the type of Dish

print(itemType)

## 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.

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

int main ()

{

int t;

cin >> t;

while (t--)

{

int a, b, c, x, y;

cin >> a >> b >> c >> x >> y;

if ((a + b + c) != (x + y))

{

cout << "NO" << endl;

}

else

{

if (y < min (a, min (b, c)) || x < min (a, min (b, c)))

{

cout << "NO" << endl;

}

else

{

cout << "YES" << endl;

}

}

}

}

#Test case

t=int(input())

# loop for each test case

for tc in range(t):

# int inputs in single line

a,b,c,x,y = [ int(x) for x in input().split() ]

if (a+b+c) != (x+y):

print(“NO”)

elif y< min (a, min(b,c)) or x<min(a,min(b,c)):

print(“NO”)

else:

print(“YES”)

## 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**

#include<bits/stdc++.h>

using namespace std;

vector<long long int>v[47];

int main()

{

long long int i,j;

for(i=2;i<=(int)1e6;i++)

{

long long int tem=i;

for(j=2;j<=40;j++)

{

tem=tem*i;

if(tem>(long long int)1e12)

break;

v[j].push_back(tem);

}

}

int t;

scanf("%d",&t);

while(t--)

{

long long int m;

scanf("%lld",&m);

if(m==1)

{

printf("INFINITY\n");

continue;

}

long long int ans=(m+1)/2;

long long int p=m/2+1;

for(i=2;i<=40;i++)

ans=ans+(lower_bound(v[i].begin(),v[i].end(),m+1)-lower_bound(v[i].begin(),v[i].end(),p));

printf("%lld\n",ans);

}

return 0;

}

## HackWithInfy Coding Round Syllabus

Here below you will get the Syllabus of HackWithInfy rounds. This topics are most asked questions of HackWithInfy round.

**HackWithInfy Coding Questions and Answers**

- Dynamic Programming
- Greedy Algorithms
- Backtracking
- Stack
- Queue
- Mapping Concepts

**HackWithInfy Coding Questions With Solutions**

- Array manipulation
- String manipulation
- Tree
- Graph
- Bit Mapping and Hashing
- Recursion and Heap
- Divide and Conquer

Login/Signup to comment