Grokking-the-Coding-Interview-Patterns-for-Coding-Questions icon indicating copy to clipboard operation
Grokking-the-Coding-Interview-Patterns-for-Coding-Questions copied to clipboard

Failing test case for Pair with Target Sum (easy)

Open anchitbhuhan opened this issue 3 years ago • 1 comments

https://dvpr.gitbook.io/coding-interview-patterns/2.-pattern-two-pointers/2.1-pair-with-target-sum-easy#:~:text=int%5B%5D%20copyArray,return%20result%3B

This code does not work for following examples

  • When there are duplicates in the array. [2,5,5,11] 10

Actual Output: [2,2] Expected output : [1,2]

anchitbhuhan avatar Nov 27 '22 11:11 anchitbhuhan

@anchitbhuhan we have to make sure to iterate our index after comparing one variable. Also we can introduce a check i.e. arr[i] != arr[i+1].

ngarg19 avatar Oct 11 '23 06:10 ngarg19

@anchitbhuhan In our case, we are not considering duplicates in the input array. You can incorporate @ngarg19's suggestion.

dipjul avatar Aug 11 '24 10:08 dipjul