Dynamic array in hacker rank

https://www.hackerrank.com/challenges/dynamic-array/problem
why the output vector temp getting the 4 variables even though i declared temp size as 2

Hi chandra
pls share your code