Easy

Given an integer size, return array of length size filled with 1s.

Example

For size = 4, the output should be
createArray(size) = [1, 1, 1, 1].

Input/Output

  • [execution time limit] 0.5 seconds (c)

  • [input] integer size

    A positive integer.

    Guaranteed constraints:
    1 ≤ size ≤ 1000.

  • [output] array.integer

[C] Syntax Tips

// Prints help message to the console
// Returns a string
char * helloWorld(char * name) {
    char * answer = malloc(strlen(name) + 8);
    printf("This prints to the console when you Run Tests");
    strcpy(answer, "Hello, ");
    strcat(answer, name);
    return answer;
}

더보기

Solution

// Arrays are already defined with this interface:
// typedef struct arr_##name {
//   int size;
//   type *arr;
// } arr_##name;
//
// arr_##name alloc_arr_##name(int len) {
//   arr_##name a = {len, len > 0 ? malloc(sizeof(type) * len) : NULL};
//   return a;
// }
//
//
arr_integer createArray(int size)
{
	arr_integer returnArray=alloc_arr_integer(size);

	for(int i=0;i<size;i++)
		returnArray.arr[i]=1;

	return returnArray;
}
728x90

'Codesignal' 카테고리의 다른 글

<Codesignal> Concatenate Arrays  (0) 2020.04.14
<Codesignal> First Reverse Try  (0) 2020.04.14
<Codesignal> Count Black Cells  (0) 2020.04.14
<Codesignal> Candles  (0) 2020.04.13
<Codesignal> Rounders  (0) 2020.04.13

+ Recent posts