Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Given an array A of integers, find the index of values that satisfy A + B = C + D, where A,B,C & D are

Given an array A of integers, find the index of values that satisfy A + B = C + D, where A,B,C & D are integers values in the array

Note:

1) Return the indices A1 B1 C1 D1, so that

A[A1] + A[B1] = A[C1] + A[D1]

A1 < B1, C1 < D1

A1 < C1, B1 != D1, B1 != C1

2) If there are more than one solutions,

then return the tuple of values which are lexicographical smallest.

Assume we have two solutions

S1 : A1 B1 C1 D1 ( these are values of indices int the array )

S2 : A2 B2 C2 D2

S1 is lexicographically smaller than S2 iff

A1 < A2 OR

A1 = A2 AND B1 < B2 OR

A1 = A2 AND B1 = B2 AND C1 < C2 OR

A1 = A2 AND B1 = B2 AND C1 = C2 AND D1 < D2

Example Input [3, 4, 7, 1, 2, 9, 8] Output [0, 2, 3, 5] (O index) 

If no solution is possible, return an empty list.

1. Which of the following statements create a dictionary?

a) d = {}

b) d = {"john":40, "peter":45}

c) d = {40:"john", 45:"peter"}

d) All of the mentioned

2. What will be the output of the following Python code snippet?

d = {"john":40, "peter":45}

a) "john", 40, 45, and "peter"

b) "john" and "peter"

c) 40 and 45

d) d = (40:"john", 45:"peter")

3. What will be the output of the following Python code snippet?

d = {"john":40, "peter":45}

"john" in d

a) True

b) False

c) None

d) Error

4. What will be the output of the following Python code snippet?

d1 = {"john":40, "peter":45}

d2 = {"john":466, "peter":45}

d1 == d2

a) True

b) False

c) None

d) Error

5. What will be the output of the following Python code snippet?

d1 = {"john":40, "peter":45}

d2 = {"john":466, "peter":45}

d1 > d2

a) True

b) False

c) Error

d) None

6. What will be the output of the following Python code snippet?

d = {"john":40, "peter":45}

d["john"]

a) 40

b) 45

c) "john"

d) "peter"

7. Suppose d = {"john":40, "peter":45}, to delete the entry for "john" what command do we use?

a) d.delete("john":40)

b) d.delete("john")

c) del d["john"]

d) del d("john":40)

8. Suppose d = {"john":40, "peter":45}. To obtain the number of entries in dictionary which command do we use?

a) d.size()

b) len(d)

c) size(d)

d) d.len()

9. What will be the output of the following Python code snippet?

d = {"john":40, "peter":45}

print(list(d.keys()))

a) ["john", "peter"]

b) ["john":40, "peter":45]

c) ("john", "peter")

d) ("john":40, "peter":45)

10. Suppose d = {"john":40, "peter":45}, what happens when we try to retrieve a value using the expression d["susan"]?

a) Since "susan" is not a value in the set, Python raises a KeyError exception

b) It is executed fine and no exception is raised, and it returns None

c) Since "susan" is not a key in the set, Python raises a KeyError exception

d) Since "susan" is not a key in the set, Python raises a syntax error

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction to Wireless and Mobile Systems

Authors: Dharma P. Agrawal, Qing An Zeng

4th edition

1305087135, 978-1305087132, 9781305259621, 1305259629, 9781305537910 , 978-130508713

More Books

Students also viewed these Programming questions