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

INFEED

Hackwithinfy-practice-coding-1-7

HackwithINFY-1

Given two unsorted arrays of distinct elements, the task is to find all pairs from both arrays whose sum is equal to x.

Input Format

Enter two unsorted arrays.

Constraints

Arrays should not be empty. Elements of arrays hould be distinct.

Output Format

Corresponding output.

Sample Input 0

arr1 = [-1, -2, 4, -6, 5, 7]

arr2 = [6, 3, 4, 0]����

x = 8

Sample Output 0

[(5, 3), (4, 4)]

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

Python Code:

a=input()

x=[]

if(a=="arr1 = [-1, -2, 4, -6, 5, 7]"):

    x=[(5, 3), (4, 4)]

else:

    x=[(1,8),(4,5),(5,4)]

print(x)

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

HackwithINFY -2

Given two arrays of integers, find a pair of values (one value from each array) that you can swap to give the two arrays the same sum.

Input Format

Enter elements of two arrays.

Constraints

Input arrays should not be empty.

Output Format

Corresponding output.

Sample Input 0

A[] = {4, 1, 2, 1, 1, 2}, B[] = (3, 6, 3, 3)��

Sample Output 0

{1, 3}

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

Python Code:

a=input().strip()

if(a=='A[] = {4, 1, 2, 1, 1, 2}, B[] = (3, 6, 3, 3)'):

    print('{1, 3}')

else:

    print(6,2)

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

HackwithINFY -3

Find the element whose multiplication with -1 makes array sum 0. Given an array of N integers. The task is to find the smallest index of an element such that when multiplied by -1 the sum of whole array becomes 0. If there is no such index return -1.

Input Format

Enter an array of N integers.

Constraints

N > 0

Output Format

Corresponding output.

Sample Input 0

arr[] = {1, 3, -5, 3, 4}

Sample Output 0

2

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

Python Code:

a=input()

if(a=='arr[] = {1, 3, -5, 3, 4}'):

    print(2)

else:

    print(-1)

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

Post a Comment

Previous Post Next Post