id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

amjadm@miamioh.edu > matchValues
prev  |  next  |  chance

Given two non-empty arrays of integers, return a new boolean array with the same length as the first array. For each element in the first array, check whether that element exists anywhere in the second array. If it does, store true in the boolean array at that index; otherwise, store false. For example, if the first array is {5, 3, 7, 2} and the second array is {2, 4, 3}, the result should be {false, true, false, true} because 3 and 2 appear in the second array but 5 and 7 do not. You must solve this problem using a HashSet to improve lookup performance and achieve Θ(n) amortized time instead of using nested loops.


matchValues([5, 3, 7, 2], [2, 4, 3]) → [false, true, false, true]
matchValues([1, 2, 3], [4, 5, 6]) → [false, false, false]
matchValues([1, 2, 3], [1, 2, 3]) → [true, true, true]

...Save, Compile, Run (ctrl-enter)

public boolean[] matchValues(int[] arr1, int[] arr2) { }

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Java Help

Misc Code Practice

Difficulty: 310

Copyright Nick Parlante 2017 - privacy