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

 

konstans@stuy.edu > twoSumPairs
prev  |  next  |  chance

Given an int[] and a target value, return the number of all unique index pairs [i, j] where arr[i] + arr[j] == target and i < j. e.g. twoSumPairs(new int[]{2,7,4,1,3}, 5) has two valid pairs: index 0 and index 4, as well as index 2 and index 3. It will return 2. Use a single loop to achieve O(n) time.


twoSumPairs([], 7) → 0
twoSumPairs([2, 7, 4, 1, 3], 5) → 2
twoSumPairs([3, 3], 6) → 1

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

public int twoSumPairs(int[] arr, int target) { }

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

Copyright Nick Parlante 2017 - privacy