Hackerrank delete a node
A few comments:


It is cleaner to define the position parameter as unsigned or
size_t as it cannot be negative. Same applies to the for loop counter.
There is a memory leak, as you don't do delete on the removed
node.
Names like temp and temp2 are not reader-friendly. How about
current_node? Speaking of which, the assignment to temp2 is redundant.
The code should validate that we don't go beyond the end of the list. We can of course assume that invalid index cannot be passed to the function, but it's a dangerous assumption that does not lead to defensive code.
While we're on the parameter validation topic; if we get passed an empty list (i.e. head == NULL), there will again be undefined behaviour irrespective of the value of position.
If we delete the last node, the code will behave in an undefined manner (most likely crash). Consider that temp2-&gt;next will be NULL in that case, which means that temp2-&gt;next-&gt;next won't be a happy statement.
Speaking of last comment, do you have unit tests in place? If so, it'd be good to have edge cases covered (delete first node, delete last node, empty list etc.)


Hope this helps.