<jupyter_start><jupyter_text>Remove CommentsGiven a C++ program, remove comments from it. The program source is an array where source[i] is the i-th line of the source code. This represents the result of splitting the original source code string by the newline character \n.// - a line comment/* - block comment<jupyter_code>def removeComments(source):
    """
    :type source: List[str]
    :rtype: List[str]
    """
    res, buffer, code_block = [], '', False
    for line in source:
        i = 0
        while i < len(line):
            char = line[i]
            # "//" -> Line comment.
            if char == '/' and (i + 1) < len(line) and line[i + 1] == '/' and not code_block:
                # Advance pointer to end of current line.
                i = len(line) 
                
            # "/*" -> Start of block comment.
            elif char == '/' and (i + 1) < len(line) and line[i + 1] == '*' and not code_block:
                code_block = True
                i += 1
                
            # "*/" -> End of block comment.
            elif char == '*' and (i + 1) < len(line) and line[i + 1] == '/' and code_block:
                code_block = False
                i += 1
                
            # Normal character. Append to buffer if not in block comment.
            elif not code_block:
                buffer += char
            i += 1
            
        if buffer and not code_block:
            res.append(buffer)
            buffer = ''
            
    return res 
source = ["/*Test program */", "int main()", "{ ", "  // variable declaration ", 
          "int a, b, c;", "/* This is a test", "   multiline  ", "   comment for ", 
          "   testing */", "a = b + c;", "}"]
removeComments(source)
source = ["a/*comment", "line", "more_comment*/b"]
removeComments(source)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1323608860075635, 'fraction_numerical': 0.005402485143165856, 'mean_word_length': 1.626950354609929, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '266726', 'license': 'MIT', 'n_tokens_mistral': 549, 'n_tokens_neox': 520, 'n_words': 183, 'path': 'Python/remove comments.ipynb', 'repo_name': 'AlphaTwist/Code-squad', 'size': '1851'}