preloader

Complete Hackwithinfy Solutions 2021

Looking for Hackwithinfy Solutions then you are at the right place because today I will share with you some Hackwithinfy Solutions so read this article till the end.

Here are some more guides like this:

Hackwithinfy Solution To 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

C++ PYTHON C++
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;
}
}
}
}
PYTHON
#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)

Hackwithinfy Solution To Question 2

Make strings equal in python

PYTHON PYTHON #codewindow.in #MAKE STRING EQUAL #Code in PYTHON   res=0 def equal(s,n): global res k=list(s) while len(k)!=n: k.pop(0) res+=1 return ”.join(k)   a=input() b=input() c=input() s=len(a)+len(b)+len(c) m=min(len(a),len(b),len(c))   if len(a)>m: a=equal(a,m)   if len(b)>m: b=equal(b,m)   if len(c)>m: c=equal(c,m)   if a==b==c: print(res) else: print(s) #end

More questions to come so if you want to get notified when new questions come do subscribe to our newsletter or join our Telgram channel here – Join Telegram channel.

Thank you for reading, Have a nice day 🙂

Spread the love

Related Post

Leave a Reply

Your email address will not be published. Required fields are marked *