Better HN
topnewbestaskshowjobs
Log inSign up

0xB504

2 karma · joined Jun 30, 2017 (9y ago) · 2 submissions

Submissions

comment 9y ago · link · parent

You could add a dublicate counter. Once out find a pair, let j increase until numbers[j] != numbers[j+1] and count how many duplicates you encounter. Add this number to pairs everytime you find one. Once you increase j set the duplicate counter back to one.

comment 9y ago · link · parent

Shouldn't the time constraint be around O(n²) for the sorted approach, as you are iterating through the sorted array in a nested loop, resulting in (N - K)/2 *N lookups of pairs? Or am I missing something?