Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Professional SQL Server 2012 Internals And Troubleshooting

Authors: Christian Bolton, Justin Langford

1st Edition

1118177657, 9781118177655

More Books

Students also viewed these Databases questions

Question

difference between latches and flipflops

Answered: 1 week ago