DEV Community

Discussion on: Daily Challenge #237 - Delete Extra Occurrences

Collapse
 
arjunjv profile image
sai kiran jv

What if given numbers are not positive ?

Collapse
 
vidit1999 profile image
Vidit Sarkar

ans vector contains each number only up to occ times. So, occ can never be negative. If user passed a negative number as occ, then ans vector will be empty.

If given numbers are negative, still there should not be any problem. Example,

delete_nth({-1,-1,-1,-2,-3,-2,-4,-3}, 1)  => {-1,-2,-3,-4}
delete_nth({1,-2,3,-7,-2,3,-8},1)  => {1,-2,3,-7,-8}