Remove Comments
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
You are given a C-style program as a list of lines source. Strip out all comments and return the remaining lines.
There are two kinds of comments. A **line comment** starts with // and removes itself and everything after it on that line. A **block comment** starts with /* and ends at the next */ that begins after the opening /* (so /*/ does not close itself); it may span several lines, and the newlines inside it are removed too, joining the text before it with the text after it into one line. Whichever of // or /* appears first takes effect; comment markers inside an active comment are ignored.
After stripping, drop any line that is empty. Keep all other characters (including spaces) exactly as they are, and return the lines in their original order.
Examples
Constraints
- `1 <= source.length <= 100`
- `0 <= source[i].length <= 80`
- `source[i]` contains printable ASCII characters
- Every block comment that is opened is eventually closed
- There are no string or character literals
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.