Congratulations for your own leetcode 🎉
Feedback: I "almost" got it, submitted and it wouldn't pass in 2 test cases, so I came here to see the solution and the problem was my interpretation. I read `empty array` and assumed an array with no elements instead of an array with empty elements, so that changed how I implemented the pushback and resize functions, which ended up being a simpler solution than what was supposed to be lol Edit: Just realized I could call resize under my verification of capacity size, now it passed Thank you for the explanation, I've learning a lot from your videos
I think the description is missing something? If you can add elements with the insert function at any index, you can create an array like this: [0,1,0,0,4,0,0] And thats leads to wrong results in the pushback and popback functions. I.e. popback would return element 1 here because the size is 2.
The pushback makes no sense in this application. With a sparse array: 1. You possibly overwrite an element 2. You are pushing to a random ass place. The sensible answers are: 1. Pushing to the capacity-1, the last index. 2. Pushing to the last spot you saw a value + 1
man...wish I had understood it better.... feeling like crap now. Got study more I'll be back to say if I got it right tnx for your amazing job
Keep it going, you inspire me when i watch your videos with such great explanations!
insert() is working like replace here. There is a bug in the insert code as per my understanding.
congrats broo
congrats neetcode
sorry im a beginner here but is it normal to say that the size of the array [1,0,0,0] is 1 ? isnt the size 4? @ 03.55
The comment that pushback() is really misleading. What happens if user calls pushback twice. Do you relocate the earlier pushback value? what happens if user has added elements to various indices so that there are gaps in the array. (e.g. array of 20 with elements added at indices 2, 4, 6, 8, 15, 9) Where do you add the element from pushback()
This is a good example of the real world, I'll just leave it at that lol
I misinterpreted the set function to increase the length when inserting an element at the ith index.
Congratulations on your new leetcode platform
Wouldn’t it make sense to do similar to push with pop for resizing so if the size becomes < 1/2 of the capacity then resize but reducing instead of expanding the capacity
so 'insert' is not actually insert a new element at that index but 'replace' an existing one at given index...
P R O M O S M 👉
Your method names are horrendous. XD "popback"
Why won't you actually "pop" the value in popback()? Make it a zero - for example before anything in popback() add this: self.arr[self.size] = 0
@NeetCodeIO