Search⌘ K

DIY: Count a Word in the Comments

Learn to analyze C++ source code to detect comments and count how many times a given word appears inside them. This lesson helps you implement a function to parse code lines, recognize block and inline comments, and accurately tally word instances, improving your problem-solving skills for coding interviews.

We'll cover the following...

Problem statement

In this challenge, you are given two arguments: a list of strings containing lines of a C++ source code and a string containing a word. Your task is to identify which parts of the code are comments, and then count all occurrences of the input word present in the comments ...