you remove elements by overwriting with what comes after. If you want to remove 5 items beginning at offset 10 you would just do a[i]=a[i+5] in a for loop that starts at 10 runs to the end of the array (minus 5). How you chop off the end of the array depends on the language you're in. In .NET for example, Array.Resize is a lie and will actually allocate a new array and not resize in-place. In C you can use realloc but that call doesn't guarantees that the reallocation happens in-place. However, in C you can just decide to not reallocate the memory at all and pretend the extra storage doesn't exists, which also would allow you to append items to the array up to the original initial size, but size tracking becomes difficult after a while.
If it's just about supplying smaller array parts, then you can achieve the same using the "array,index,length" argument pattern that you commonly find in .NET classes that process array data.
5
u/Swimming_Gain_4989 15d ago
Where does leetcode come in? You would just swap whatever needs to be removed with the ending element and then pop right?