Simplest & Efficient C Code Time[O(n)], Space[O(n)]🔥
Intuition\nThe FizzBuzz problem is a classic programming problem where you are required to print numbers from 1 to n, but for multiples of 3, you print "Fizz" i
# Intuition\nThe FizzBuzz problem is a classic programming problem where you are required to print numbers from 1 to n, but for multiples of 3, you print "Fizz" instead, for multiples of 5, you print "Buzz" instead, and for multiples of both 3 and 5, you print "FizzBuzz" instead.\n\n# Approach\nThe approach taken in the code is as follows:\n\n1. Allocate memory for an array of strings, arr, with n elements. Each element is a pointer to a character array (string).\n2. Set the value of returnSize to n, indicating the number of elements in the arr array.\n3. Iterate from 1 to n using a loop.\n4. For each iteration, allocate memory for a character array of size 8 (sufficient to store "FizzBuzz" and the maximum number of digits in n).\n5. Check if the current number, i, is divisible by 15 (both 3 and 5). If true, assign the string "FizzBuzz" to arr[i-1].\n6. If i is not divisible by 15, check if it is divisible by 3. If true, assign the string "Fizz" to arr[i-1].\n7. If i is not divisible by 3, check if it is divisible by 5. If true, assign the string "Buzz" to arr[i-1].\n8. If none of the above conditions are met, convert the integer i to a string using sprintf and assign it to arr[i-1].\n9. After the loop completes, return the arr array.\n\n# Complexity\n- Time complexity: The time complexity of this code is $O(n)$, where n is the given input value. This is because the code iterates through each number from 1 to n exactly once.\n\n- Space complexity: The space complexity is $O(n)$ as well. The code allocates memory for an array of size n to store the strings representing the numbers and their FizzBuzz replacements.\n\n# Code\n```\nchar ** fizzBuzz(int n, int* returnSize)\n{\n    char**arr = malloc(n*sizeof(char*));\n    *returnSize = n;\n    for(int i=1;i<=n;i++)\n    {\n        arr[i - 1] = malloc(9 * sizeof(char));\n        if(i%15==0)\n        arr[i-1] = "FizzBuzz";\n        else if(i%3==0)\n        arr[i-1]="Fizz";\n        else if(i%5==0)\n        arr[i-1]="Buzz";\n        else\n        sprintf(arr[i-1], "%d", i);\n    }    \n    return arr;\n}\n\n```
['C']