HackWithInfy Menu9>
- 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
PREPINSTA PRIME
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..
About HackWithInfy
There are 2 Coding Round in HackWithInfy Exam:
-
Round 1:-
-
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
Prime Course Trailer
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:
- 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; int main() { int t; //number of test cases cin>>t; for (int i = 0; i < t; i++) { int n; //number of items cin>>n; int item[n]; //array for items for (int x = 0; x < n; x++) { cin>>item[x]; } int j = 0, max = 0; int itemtype = item[0]; while (j < n) { int c = 1; int k = j + 1; while (k < n) { if (item[j] == item[k] && k != j + 1) { c += 1; if (k < n-1 && item[k] == item[k + 1]) { k += 1; } } k += 1; } if (max < c) { max = c; itemtype = item[j]; } j += 1; } cout<< itemtype<< endl; } return 0; }
import java.util.*; public class Main { public static void main(String args[]) { Scanner s = new Scanner(System.in); int t = s.nextInt(); for(int tc = 0; tc< t; tc++) { int n = s.nextInt(); int[] item = new int[n]; for(int i = 0; i < n; i++ ) { item[i]= s.nextInt(); } int j = 0,max = 0; int itemType = item[0]; while(j< n) { int c = 1; int k = j+1; while(k< n) { if(item[j]== item[k] && k!=j+1) { c+=1; if (k< n-1 && item[k]==item[k+1]) { k+=1; } } k+=1; } if (max< c) { max=c; itemType = item[j]; } j+=1; } System.out.println(itemType); } } }
#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 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; vectorv[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; }
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?
- HackWithInfy Competition is open for all Engineering Students across India who are graduating in 2023 and 2024.
- 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
30+ Companies are Hiring
Get Hiring Updates right in your inbox from PrepInsta
Thanku for such awesome Questions
We are glad you like our content😇. We always try to provide good quality content to all students like you aspiring to work for companies🤗. You have gone through all the free material that we had on https://prepinsta.com/ . We have more extensive content which covers all aspects of your placement preparation for both service and product-based companies. Visit our more updated and new website https://prepinstaprime.com/ which includes more than 150+ courses for all the companies, nano degree certificates, coding, interview preparation courses from scratch to advance level in the form of topic-wise videos and mocks.
For any query you can reach out to us on any social media platforms, below are the links:
1. Instagram- https://prepinsta.com/instagram/
2. Discord- https://prepinsta.com/discord/
3. Whatsapp- https://prepinsta.com/whatsapp/
4. Telegram – https://prepinsta.com/telegram/
5. Youtube- https://www.youtube.com/prepinsta/
6. Linkedin- https://www.linkedin.com/company/prepinsta/
Thank you. Solutions are really helpful.
We’ve been praised before but we never can have enough🥰. We feel very elated when students find our content useful and helpful. We are providing topic-wise videos and topic wise mocks for all the courses from scratch to competitive level with time limit also. In case you feel like you are stuck somewhere you can always login to https://prepinstaprime.com/ to see the Video Lectures and understand the concepts even more thoroughly. Video lectures are pre-recorded and updated as per the syllabus of the companies.
For any query you can reach out to us on any social media platforms, below are the links:
1. Instagram- https://prepinsta.com/instagram/
2. Discord- https://prepinsta.com/discord/
3. WhatsApp- https://prepinsta.com/whatsapp/
4. Telegram – https://prepinsta.com/telegram/
5. YouTube- https://www.youtube.com/prepinsta/
6. Linkedin- https://www.linkedin.com/company/prepinsta/
Solutions are really helpful. Can you guide me more contents that will help me to crack HackWithInfy?
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/
Hello, Can you please tell me where can I find complete information about hackwithinfy?
Hi Shruti, yes absolutely we can help you with it🤝. Although we are very easy to navigate on https://prepinsta.com/ and https://prepinstaprime.com/ , we still will guide you for your ease and perusal🤗.
Please click on the following link to land straight on the page you are looking for.
https://prepinsta.com/hackwithinfy/
Thank you for this Informations
We are glad you enjoyed learning from us😇.
You can follow us on our social media handles, if you want to be regularly updated with similar information.
1. Instagram- https://prepinsta.com/instagram/
2. Discord- https://prepinsta.com/discord/
3. Whatsapp- https://prepinsta.com/whatsapp/
4. Telegram – https://prepinsta.com/telegram/
5. Youtube- https://www.youtube.com/prepinsta/
6. Linkedin- https://www.linkedin.com/company/prepinsta/
Thank you for the questions. These helped me a lot in my preparations
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.
Visit our website: https://prepinstaprime.com/
Courses like Artificial intelligence/Machine learning, Cyber security, Ethical hacking, Cloud computing and many more are available with certifications.
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?
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?
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
thank you for posting the programs