Message on Whatsapp 8879355057 for DSA(OA + Interview) + Fullstack Dev Training + 1-1 Personalized Mentoring to get 10+LPA Job
0 like 0 dislike
1,486 views
in Online Assessments by Expert (108,110 points) | 1,486 views

1 Answer

0 like 0 dislike

Q: You have a traditional 6-faced dice, and you rolled it M + N times. The numbers from rolls of M times are in A and the numbers from rolls of N times are in B. You want each array to have a common sum. You can modify the arrays so that their sums are equal but you should use the minimum number of turns. Through a turn, you can change a value from an array into any value between 1 and 6. You cannot delete a value or make it 0 or negative.

 

A's length and B'length can be different. If it is impossible to make both arrays sum to a common sum, return -1.

 

ex) (A = [1,4,3], B = [6,6,6]) => 2 (turns)

 

Can you suggest some solutions to this question?

 

Thank you.

 

My solution is here: https://github.com/hbjORbj/interview_prep/blob/master/Second 99/q_a110.js

by Expert (108,110 points)