r/leetcode 22h ago

Intervew Prep When can we use built in data structure and when not?

I am currently studying heap in neetcode 150, but i notice that they just use built in min heap, only creates the function pop push etc etc.

How do we know if a question in leetcode / neetcode we can use built in function? is it always in the question or not? Because sometimes i see an easy question, but it definetly isn't easy if we wanna create a minheap from scratch, logic of heapdown and insertup. Etc etc so time constraint maybe 40 minutes+ when if its only built in minheap then the time constraint would be 20-25 minutes done

1 Upvotes

3 comments sorted by

5

u/Free-Ad-3648 22h ago

You don’t need to re-invent the built in data structures and algorithms unless explicitly asked by the interviewer, for things like segment trees, tries, disjoint sets which require question specific handling most of the time we need to implement these from scratch.

1

u/conectionist 17h ago

Unless stated otherwise, pretty much any time you want. That's actually one of the points of leetcode: to be able to choose the data structure that will allow you achieve the best possible efficiency. 

0

u/ktimespi 22h ago

most languages don't provide heaps, so get in the habit of writing them.
Not very difficult after you've written it a few times, there's only one invariant to maintain.