@NeetCodeIO

Damn, who knew id get to write some neat code on my own site one day 😁

🚀 You can try it here: https://neetcode.io/problems/dynamicArray

Lmk if you have feedback. Got a lot of things already on my todo list

@satwiktatikonda764

Congratulations for your own leetcode 🎉

@erickrds

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

@philf4018

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.

@hoodwinkedDaDon

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

@riccimel

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

@МаринаВысотская-й2в

Keep it going, you inspire me when i watch your videos with such great explanations!

@Mamtagoyal27

insert() is working like replace here. There is a bug in the insert code as per my understanding.

@MANRAJSINGHCO

congrats broo

@p25_rhythm70

congrats neetcode

@ianhecox90

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

@ramesherrabolu1590

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()

@cliffordhelsel

This is a good example of the real world, I'll just leave it at that lol

@rakeshmishra8682

I misinterpreted the set function to increase the length when inserting an element at the ith index.

@saikrishnaganguri

Congratulations on your new leetcode platform

@thomashart5081

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

@Sranju23

so 'insert' is not actually insert a new element at that index but  'replace' an existing one at given index...

@arthur7441

P R O M O S M 👉

@Thursday-w9s

Your method names are horrendous. XD "popback"

@MrBoooniek

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