One thing that I am very clear is that there is no hard and fast algorithm to create CFG. The only wat to practice only. But how do I deal with new questions in exam? Are there types of problems that I need to know in order to be able to solve different types of problems? Can you guide me a bit about this issue?
Here is one useful strategy. The union of context-free languages is context-free. If you can think of your target language as the union of simpler pieces, and you can think of a grammar for each piece (with start symbol $A_1$, $A_2$, etc.) then you can join all the grammars together with a production like $S \to A_1 \mid A_2 \mid \cdots$.