Grokking the Coding Interview: Patterns for Coding Questions
Ask Author
Back to course home

0% completed

Vote For New Content
John Daugherty
i don't understand this at all

John Daugherty

May 19, 2023

and the examples don't really help. this could be explained a lot better.

2

0

Comments
Comments
Design Gurus
Design Gurus2 years ago

Let me try explaining an input. Here is Example 1:

Input:

nums = [1,2,3,1,1,3]

Output: 4

Explanation: There are 4 good pairs, here are the indices: (0,3), (0,4), (3,4), (2,5).

For example, how (0,3) is a good pair? To be a good pair, it should hold the ...

A
Adam Rizk2 years ago

This approach works because we only want pairs (val1, val2) where val1 is smaller. Therefore when we encounter a new index that stores an integer, we know all the indexes we previously discovered for this integer must be smaller than our current index. Therefore the num...

Mohammad Shariq
Mohammad Shariqa year ago

i still didn't got the concept how the p-1 pairs are being added and it forms a good pair , this last line is bit confusing for me . although i did it with nested for loop , but that was O(n2) complexity , v poor . compared to this approach . can anyone explain the last...

 Manuel
Manuel10 months ago

If you are familiar with the common algorithm "Find The Frequency of Elements in Array" using HashTable. This problem is basically all about this. I strongly recommend understanding this algorithm first. Then Good Pairs will be easier.

By finding the frequency both con...