Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

There are two candy shops, both of which have N candies for sale. The first shop sells each candy for one golde coin; the second

There are two candy shops, both of which have N candies for sale. The first shop sells each candy for one golde coin; the second shop sells each candy for one silver coin. You have N/2 golden coins and N/2 silver ones (Nis even). Each candy is of some particular type (not necessarily unique), represented by an integer. What is the maximum number of different types of candy that you can buy? Write a function: class Solution { public int solution(int[] A, int [] B); } that, given two arrays A and B of N integers, representing types of candies in the first and second shop respectively, returns the maximum possible number of different types of candy that you can buy. For example, given: A=[1,2,3,4] B=[3,3,3,7] the function should return 4. You can, for example, buy candies of types 1,2 in the first shop and then candies of types 3,7 in the second shop. A=[1,2,3,4] B=[3,3,3,7] the function should return 4. You can, for example, buy candies of types 1,2 in the first shop and then candies types 3,7 in the second shop. Given: A=[2,2,2,2,2,2] B=[7,4,2,5,1,2] the function should also return 4. In the first shop you can only buy candies of type 2, but then you can buy thre candies of other types (for example, 7,4 and 5) in the second shop. Write an efificient algorithm for the following assumptions: N is an integer within the range [2.100,000]; N is even; each element of arrays A and B is an integer within the range 1..1,000,000,000.

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

Step: 3

blur-text-image

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

Databases DeMYSTiFieD

Authors: Andy Oppel

2nd Edition

0071747990, 978-0071747998

More Books

Students also viewed these Databases questions