There are two candy shops, both of which have N candies for sale. The first shop sells each candy for one golden coin, the second shop sells each candy for one silver coin. You have N/2 golden coins and N/2 silver ones (N is 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.
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 three candies of other types (for example, 7, 4 and 5) in the second shop
Test Output
Write an efficient algorithm for the following assumptions N is an integer within the range [2.100,000)
-N is ever each element of arrays A and B is an integer within
the range [1.1,000,000,000]
Question 2:
There is an array A that consists of N integers. In one move you can select a number from A and replace it by the sum of its digitsOne number can be selected multiple timesYou can apply at most two moves. What is the minimum sum of the array you can achieve?
Write a function:
class Solution (public int solution(int[] A)
that, given an array A, returns the minimum sum of the array you can achieve after applying at most two moves
Examples:
1. Given A = [1, 10, 12, 3] you can apply the move on the second and third elements A = [1, 1, 3, 3] and the function should return 8
2. Given A = [2, 29, 3] you can apply the move twice on the second
element Then A = [2, 2, 3] and the function should return 7.
3.Given A = [100, 101, 102, 103] you can apply the mov…
4.Given A = [55] you can apply the move twice on the first element Then A = [1] and the function should return 1.
Test Output
Write an efficient algorithm for the following assumptions: N is an integer within the range [1..50,000]
each element of array A is an integer within
the range [1..10,000]
Search
Popular Posts
Categories
- #Arts & Science#Others#Data Analytics#Operations#Business#Engineering
- #Tfactor #tcs2023 #tcshiring #trending
- #wipro #codingquestion #trending #wiprohiring
- 2022hiring
- Btech hiring
- Btech2022
- digital Hiring
- Education Related Content
- Energy Resource Management
- Environmental Science
- Environmental Studies
- f lareStudy
- jobs 2022
- offcampus hiring
- pune EPAM 2022 Batch Fresher Recruitment DriveRegistration Link| EPAM On Campus Placement/Recruitment Drive for freshers of 2022 Batch | EPAM Freshers 2022 Batch Hiring
- TCS 2022
- TCS Hiring
- Wiprohiring
0 Comments:
Post a Comment