Skip to content

Commit cdb37b5

Browse files
author
Gonzalo Diaz
committed
[Hacker Rank]: Warmup: Compare triplets. Solved ✅.
1 parent 3fd7dff commit cdb37b5

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#pragma once
2+
3+
#define MIN(a, b) ((a) < (b) ? (a) : (b))
4+
#define MAX(a, b) ((a) > (b) ? (a) : (b))

src/lib/exercises/src/hackerrank/warmup/compare_triplets.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
1-
#include <exercises/hackerrank/warmup/compare_triplets.h>
1+
#include <stdlib.h>
22

3-
#define MIN(a, b) ((a) < (b) ? (a) : (b))
3+
#include <exercises/basic/common.h>
4+
#include <exercises/hackerrank/warmup/compare_triplets.h>
45

56
/**
67
* @link Problem definition [[docs/hackerrank/warmup/compare_triplets.md]]
78
*/
89

9-
int* HACKERRANK_WARMUP_compareTriplets(int a_count, const int *a, int b_count,
10+
int *HACKERRANK_WARMUP_compareTriplets(int a_count, const int *a, int b_count,
1011
const int *b, int *result_count) {
1112

1213
*result_count = 2;
13-
static int awards[2] = {0, 0};
14+
int *awards = (int *)malloc(sizeof(int) * *result_count);
15+
16+
awards[0] = 0;
17+
awards[1] = 0;
1418

1519
for (int i = 0; i < MIN(a_count, b_count); i++) {
1620
if (a[i] > b[i]) {
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
[
2-
{ "a": [5, 6, 7], "b": [3, 6, 10], "expected": [1, 1] }
2+
{ "a": [5, 6, 7], "b": [3, 6, 10], "expected": [1, 1] },
3+
{ "a": [], "b": [], "expected": [0, 0] },
4+
{ "a": [1], "b": [], "expected": [0, 0] },
5+
{ "a": [], "b": [1], "expected": [0, 0] }
36
]

0 commit comments

Comments
 (0)