Question: 1.Given two sets with no duplicated elements. Write three methods that implements three operations for sets: unions, intersections, and complements. Example: set1 = {4,1,5,16,7,8,32} set2

1.Given two sets with no duplicated elements. Write three methods that implements three operations for sets: unions, intersections, and complements.

Example:

set1 = {4,1,5,16,7,8,32}

set2 = {11,5,32,9,8,15,2}

Union is: 16 32 1 2 4 5 7 8 9 11 15

Intersection is: 32 5 8

The result of list1 - list2 is: 16 1 4 7

You should make sure your code is generic, so that it can be used for all kind of objects. You should use set to solve the problem. An implementation without using set data structure will automatically derive 0.

2.Given an array of integers, return indices of the two numbers such that they add up to a specific target. You may assume that each input would have exactly one solution, and you may not use the same element twice.

Example:

Given nums = [2, 7, 11, 15],

target = 9, Because nums[0] + nums[1] = 2 + 7 = 9,

return [0, 1].

You should use map to solve the problem. An implementation without using map data structure will automatically derive 0.

Notes:

Test your program with different inputs.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!