← Dynamic Memory: malloc, free & the Stack vs. the Heap

Filter Above Threshold

medium

Read a count n, a threshold, and then n integers into a heap-allocated array (all done for you). Print only the elements strictly greater than threshold, space-separated, in their original order – an empty line if none qualify.

The one wrinkle beyond straightforward filtering: since you don’t know in advance how many elements will qualify, “print a space between elements” can’t be based on the loop index the way earlier exercises’ “print the whole array” code could (if (i < n - 1)). Track whether you’ve already printed something instead, and use that to decide whether to print a leading space before the next qualifying value.

Your solution

"Run" uses the sample stdin ("5 10\n4 15 8 23 10"). "Submit" checks your code against all 3 test cases.

Test results

Submit your solution to run it against all test cases.

Hints

    Reference solution