Exercise 71 SmartCombining

395 views
Skip to first unread message

Ashutosh Tripathi

unread,
Oct 14, 2014, 5:05:55 PM10/14/14
to moo...@googlegroups.com
Hi,

I'm having problems with week 3 exercise 71.

I've created the function smartCombine() and it seems to work well with all the types of data that is given to it. Still one test case fails which says :
Combination of lists [5,1,2] and [40] should contain the number 40.

But when I put in these values to the lists, the output as expected is [5,1,2,40].

Still the test case fails..

My code snippet is:

public static void smartCombine(ArrayList<Integer> first, ArrayList<Integer> second) {
        int i = 0;
        while (i < min(first.size(), second.size())) {
            // the min() function returns the minimum size of the lists.
            if (!first.contains(second.get(i))) {
                first.add(second.get(i));
                continue;
            }
            i++;
        }

Please help!

Best regards,
Ashutosh Tripathi

Joni Salmi

unread,
Oct 15, 2014, 4:12:40 AM10/15/14
to moo...@googlegroups.com
Hi,

The error message should be: Combination of lists  [5, 1, 2] and [5, 1, 2, 1, 40] should contain the number 40.

I have fixed the test to generate output as above, but you need to download update for that exercise or submit to server to see new error messages.
 
Your problem is here: min(first.size(), second.size())

Also Java already has Math.min function for future reference.

Best regards
Joni
Reply all
Reply to author
Forward
0 new messages