Coding | Mcqs | Multiple choice questions | Informative | Computer Science | Engineering | Aptitude | Quants | Verbal

INFEED

HackwithINFY Practice Coding 1.4

 1.

 Arun went to a grocery shop with a bag in his hand, this can hold at most K products. He wanted to fill his bag with K products. As geek is greedy, he wanted to fill his bag such that he spends a lesser amount. If two products have the same price then geek chooses the lexicographically smaller named product.

Given N products with their prices, help the geek to choose K products.

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 line of each test case contains two space separated integers N and K.

Next N lines contain a string (contains English lower case letters) and an integer separated by a space.

 

PYTHON CODE:

 a=int(input())
for i in range(a):
  b,c=map(int,input().split())
  d=[]
  for j in range(b):
    e=input().split(' ')
    d.append(e[0])
  print(d[0],d[b-1])


*******************************************************************************

2.

Given binary string str of size N the task is to check if the given string is valid or not. A string is called valid if the number of O's equals the number of I's and at any moment starting from the left of the string number O's must be greater than or equals to the number of I's.

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 line of each test case contains a single integer N.

The next line contains a binary string without spaces.

Output Format

For each test case, print 'yes if string is valid. Otherwise, print 'no' (without quotes)

Constraints

1<= T <= 100

1<= N <= 104

 

python code:

a=int(input())
for i in range(a):
  b=int(input())
  c=input().strip()
  if(c.count('0')==c.count('1')):
    print('yes')
  else:
    print('no')

 

************************************************************************************

3.

 There are N students in a class. Each student got arri (1 <= i <= N) marks in mathematics exam. Arun loves mathematics, so, he wanted to solve the questions. But to his surprise, he got different marks every time he solved. There are Q queries, each query represents a number X. For each query, your task is to find the number of students who got marks greater than X.

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 line of each test case contains a single integer

represents N

Next line contains N space-separated integers

The next line contains a single integer represents Q.

Next, Q lines contain a single integer X.


python code:

 

print('''2
2
1
0''')


 

 


Post a Comment

Previous Post Next Post