For example, to find the k largest element in an array,
the straightforward approach is using a minheap, if you know the solution, can code up in 5 mins.
So would the interviewer ask for alternatives like quickselect?
I highly recommend going through my DSA course which covers this topic and the FAANG hiring bar in general in-depth: Master The Data Structures And Algorithms Interview
In general, you should always strive for the optimal solution in terms of run-time unless the interviewer tells you not to. In most cases, this is 65%+ of the battle.
However, there are several branching scenarios from just getting the optimal solution in terms of run-time, one of which is super common at Meta:
In my experience, there's a reasonable solution that you're expected to code within the interview. For some questions, there may be some advanced data structure that allows you to do things more efficiently, but it's unreasonable to expect that most interviewees have seen that pattern before.
As a candidate, one way to get part of the way there is to present and implement the 'good-enough' solution. But spend 5 min at the end talking about your intuition for something better. The awareness of something better gives you points. Something like:
Red-black trees have a self-balancing property which might be useful if applied here, due to X. If I had more time, I'd explore how that might fit in here.
We have a 10 hour crash course on Data Structures & Algorithms by Alvin: Crash Course: Beginner Data Structures And Algorithms Concepts
This course focuses on mastery -- if you have mastery, you're much more likely to arrive at the optimal solution.