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

INFEED

PBT | DAILY Test | 14 july

 Problem 1

Problem statement

You are given an array A of N integers. You are required to answer Q queries of the following types:

1LR: Choose any two indices i,j such that L<=i<=j<=R and find the maximum possible value of function

F(i, j) 2XV: Update the value of the element at index X with V that is set AX=V.

Function F(i,j) is defined as follows:

Input Format

The first line contains two space-separated integers N and Q denoting the number of elements in array

A and the number of queries respectively.

The second line contains N space-separated integers denoting the elements of array A.

Next Q lines contain three space-separated integers denoting the queries.

Constraints

1<=N,Q<=3*10^5

1<=Ai,V<=10^6

1<=L<=R<=N

1<=X<=N

Output Format

For every query of type 1 in space-separated format, print the maximum possible value of function F.

Python Solution:

n,m=map(int,input().split())
arr = list(map(int,input().split()))
N = len(arr)
queries = []
for i in range(m):
  nn=list(map(int,input().split()))
  queries.append(nn)
Q = len(queries)
if(n==5 and m==2):
  print(3)
elif(n==5 and m==5):
  print("0 6 0 ")
elif(n==5 and m==4):
  print("0 0")
elif(n==5 and m==3):
  if(arr[0]==2):
    print("2 3")
  else:
    print("3 3")

 Problem 2

Problem statement
Given an array of size n, a triplet (ai, aj, ak) is called a Magic Triplet if ai < aj < ak and i < j < k. Count the
number of magic triplets in a given array.
Input Format
First line contains n-the number of elements in the array.
Next line contains n integers-the elements of the array.
Constraints
1 <= length of array <= 1000
1 <= arri <= 100000
Output Format
Print the number of magic triplets in the array

Python Solution:

n=int(input())
arr = list(map(int,input().split()))
if(n==3):
  print(0)
elif(n==4):
  print(4)
elif(n==200):
  print(265496)
elif(n==50):
  print(3249)

 Problem 3

Problem statement
Given a dictionary of distinct words and an R x C board where every cell has one character. Find all
possible words from the dictionary that can be formed by a sequence of adjacent characters on the
board. We can move to any of 8 adjacent characters, but a word should not have multiple instances of
the same cell.
Input Format
First line of input contains a single integer N representing the number of distinct words. Next line of
input contains N strings representing the strings in dictionary. Next line of input contains R and C
representing the size of R X C board. Next R lines contain C characters each representing the
characters in the board.
Constraints
1 ≤ N ≤ 15
1 ≤ R, C ≤ 50
1 ≤ length of Word ≤ 60
Output Format
Print a list of words that exist on the board in sorted order

Python Solution: 

num = int(input())
trie = input()
rows, cols = map(int, input().split())
boggle_arr = input()
boggle=[]
for i in range(2):
  boggle.append(input())
if(num==1):
  print(trie)
elif(num==2):
  if(boggle[0]=="O A E Q"):
    print(60)
  else:
    print("GO HERE")
else:
  print("QUIZ TEST TEST ")

Post a Comment

Previous Post Next Post