Skip to content

Conversation

Srihari2222
Copy link
Collaborator

@neetcode-gh

  • Took 5 hours for this work.
  • Please review it.

  • Roughly 20minutes for an article based on the problem.

  • 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".

Copy link
Owner

@neetcode-gh neetcode-gh left a 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:

  1. Being more specific
  2. Being more beginner friendly

I think we should lean towards giving more generous hints.

<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.
Copy link
Owner

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)

Copy link
Collaborator Author

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.

<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?
Copy link
Owner

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!

Copy link
Collaborator Author

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.

<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?
Copy link
Owner

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.

Copy link
Collaborator Author

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?
Copy link
Owner

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.
Copy link
Owner

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.
Copy link
Owner

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

Copy link
Collaborator Author

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?
Copy link
Owner

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."

<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.
Copy link
Owner

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.

Copy link
Collaborator Author

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?
Copy link
Owner

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.

<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.
Copy link
Owner

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.

@neetcode-gh
Copy link
Owner

Thanks @Srihari2222

Just curious what

Roughly 20minutes for an article based on the problem.

is in reference to?

@Srihari2222
Copy link
Collaborator Author

Srihari2222 commented Nov 15, 2024

Thanks @Srihari2222

Just curious what

Roughly 20minutes for an article based on the problem.

is in reference to?

@neetcode-gh
I was also checking for grammatical errors in the hints. But now I can see that I should be more obvious and simple. Also, I was checking your video solution for clarity but I got to know that I got to know how I should recommend complexity now.
I meant 20min as hard problems can take. It was the max limit but, I will make sure and try hard to wrap it up in 10 to 15mins at max.
As, your feedback made me more clear about things, It will be easy for me to make hints for further problems.

@neetcode-gh
Copy link
Owner

@Srihari2222 Thanks and great work!

@neetcode-gh neetcode-gh merged commit 357b76b into neetcode-gh:main Nov 15, 2024
@Srihari2222 Srihari2222 deleted the develop_hints branch November 15, 2024 06:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants