-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Sri Hari: Batch-3/Neetcode-150/Added hints #3740
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, this is a good start.
I think most of my feedback centers around:
- Being more specific
- Being more beginner friendly
I think we should lean towards giving more generous hints.
hints/anagram-groups.md
Outdated
<details class="hint-accordion"> | ||
<summary>Hint 3</summary> | ||
<p> | ||
We can simply use an <code>O(26)</code> size array to count the frequency of each character in a string. Then, we can use this array as the key in a hash map to group the strings. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is minor, but might be worth explicitly mentioning that we can use an array since the character set is a through z (26 continuous characters)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I will be more beginner-friendly and specific towards the details.
hints/duplicate-integer.md
Outdated
<summary>Hint 1</summary> | ||
<p> | ||
A brute force solution would be to check every element against every other element in the array. This would be an <code>O(n^2)</code> solution. Can you think of a better way? | ||
A brute force solution would be to check every element against every other element in the array. This would be an <code>O(n<sup>2</sup>)</code> solution. Can you think of a better way? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, there's a limitation in the way my site renders markdown. The wont work as intended so I would leave this as-is for now. And do the same for all other files.
This isn't your fault. I appreciate you trying to improve this though!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I will keep that as it is in all the files.
hints/is-palindrome.md
Outdated
<details class="hint-accordion"> | ||
<summary>Hint 1</summary> | ||
<p> | ||
A brute force solution would be to create a copy of the string, reverse it, and then check for equality. This would be an <code>O(n)</code> solution with extra space. Can you think of a better way? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: We can be more specific by saying "Can you think of a way to do this without O(n) space?"
"Better" is a bit ambiguous.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A great point to mention for a beginner user. I will be more specific.
<details class="hint-accordion"> | ||
<summary>Hint 2</summary> | ||
<p> | ||
Is there any repeated work we are doing? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be more specific, e.g.
Is there any way to identify the start of a sequence? For example, in [1,2,3,10,11,12], only 1 and 10 are the beginning of a sequence.
<details class="hint-accordion"> | ||
<summary>Hint 3</summary> | ||
<p> | ||
Yes, we should only start building the sequence with an element <code>num</code> such that <code>num - 1</code> is not present in the array. We can use a hash set for fast lookups. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reword this one, after updating above.
<details class="hint-accordion"> | ||
<summary>Recommended Time & Space Complexity</summary> | ||
<p> | ||
You should aim for a solution with <code>O(n)</code> time and <code>O(1)</code> space, where <code>n</code> is the size of the input array. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For this one i think it's fine to have O(n) space since it's only a medium
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought it would be better to have a solution from your video, but fine, now I understood what you are trying to say. I will be more beginner friendly.
<details class="hint-accordion"> | ||
<summary>Hint 2</summary> | ||
<p> | ||
Is there a way to avoid the repeated work? Maybe there is a technique with linear time? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would replace "Maybe there is a technique with linear time?" with "Maybe we can store the results of the repeated work in an array."
hints/three-integer-sum.md
Outdated
<details class="hint-accordion"> | ||
<summary>Hint 4</summary> | ||
<p> | ||
To efficiently find the <code>j</code> and <code>k</code> pairs, we can use the two pointer algorithm. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be worth mentioning we run the two pointer approach on all elements to the right of i.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I will do that. But I have added 5 hints only for this problem as we don't want to ask a user a question and give answer in the same hint.
<details class="hint-accordion"> | ||
<summary>Hint 2</summary> | ||
<p> | ||
Can you think of an algorithm by taking the advantage of array being sorted? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can be more specific:
If nums[0] + nums[n-1] > target, than we know nums[n-1] can not possibly be included in any pairs. Why? Because nums[n-1] is the largest element in the array. Even by adding it with nums[0], which is the smallest element, we still exceed the target.
This hints at a two pointer solution, and also gives some intuition of why it works.
hints/two-integer-sum.md
Outdated
<details class="hint-accordion"> | ||
<summary>Hint 3</summary> | ||
<p> | ||
We can fix index <code>i</code> and iterate on it. The equation becomes <code>nums[i] == target - nums[j]</code> when we rearrange it. Let <code>value = target - nums[j]</code> and check if <code>value</code> exists in the hash map as we iterate through the array, else store the current element in the hashmap with its index and continue. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
replace value
with difference
.
We can fix index
i
and iterate on it.
The above line seems unnecessary and a little bit meaningless.
Would it be better to remove that, and say something like: we can iterate through nums with index i.
We should also mention that we use a hashmap for O(1) lookups. I know it's implied, but since this is a beginner problem.
Thanks @Srihari2222 Just curious what
is in reference to? |
@neetcode-gh |
@Srihari2222 Thanks and great work! |
@neetcode-gh
When we have no chance other than recommending the optimal solution, I used this line
"You have to aim for the solution with "XYZ" complexity".
But when I suggest sub-optimal solution, I used
"You have to aim for the solution as good or better than "XYZ" complexity".