1. I stayed there for two weeks.

2. I stayed there two weeks.

Are both grammatical?

--------------------------
3. This is the way how he solved the problem.

4. This is the way that he solved the problem.

5. This is the way he solved the problem.

6. This is the way in which he solved the problem.

#3 is wrong, but #4 is right. Is that true? Then how come #3 is not grammatical? #4 and #5 are grammatical, aren't they?

Yes, among these six sentences, only #3 is incorrect.

You can make #3 correct in either of these ways:
This is how he solved the problem.
This is the way he solved the problem.

1. Both sentences "I stayed there for two weeks." and "I stayed there two weeks." are grammatically correct. However, they have slightly different meanings:

- "I stayed there for two weeks." implies that the duration of your stay was specifically two weeks.
- "I stayed there two weeks." implies a more general statement about the length of your stay, without specifying the exact number of days.

2. In terms of the sentences relating to how to solve the problem:

- Sentence #3, "This is the way how he solved the problem." is grammatically incorrect.
- Sentence #4, "This is the way that he solved the problem." is grammatically correct.
- Sentence #5, "This is the way he solved the problem." is grammatically correct.
- Sentence #6, "This is the way in which he solved the problem." is grammatically correct.

The issue with sentence #3 is the use of "how". In this context, "how" is redundant because the word "way" already implies the method or process of solving the problem. Therefore, using both "how" and "way" together is unnecessary. In sentences #4, #5, and #6, "that," "he," and "in which" respectively, are all appropriate ways to indicate that the following clause is providing information about the way he solved the problem.