- Return the sum of distinct characters
- Input: 3,1,2,1,2
- Output: 6
Proposed solution using a set and was asked "How would you implement a set?"
This question caught me off guard, and wasn't for actually answering the DSA, but for discussing how an actual set is implemented (hashing, collision handling, etc)
Asked to find a solution without extra space, provided solution to sort input and coded
missed one edge case the interviewer had to point out that was a bug before moving to next question
- https://leetcode.com/problems/basic-calculator-ii/ with only + and * operators
- Coded stack solution before moving on to also code O(1) memory
- interviewer wasn't confident solution would work on an edge cases so quickly added something not in the leetcode discussion in last minute (had coded original, so would have worked)
Tips:
- Know multiple solutions and be able to discuss the tradeoffs between them. I largely focused on studying only the best time complexity answers, but as seen here you may get asked to do a different one
- Remember your common edge cases ([], [1], [1,1], not sorted, sorted, etc)
- Clarify what is allowed before discussing approach (is the input sorted? what characters are allowed? can we have negatives?)
- Walk through your code with test cases. I caught a couple bugs/things I missed in the algo because I walked through some examples
I wasn't sure I would make it with the missing edge cases because of other experience I had read but was given "great feedback".
If you're having a hard time getting through stages I can only say that the DSA questions aren't all there is to it. I have existing FAANG experience and even with that, a lot of these questions I find having to regularly brush up on. Luck also plays a big part. I had practiced calculator ii the night before, even though I thought I understood it I had stumbled in the second practice.
It is also easy to forget basic stuff when you have an interviewer watching you, and I almost forgot when to properly terminate a while loop.
Build a basic knowledge and hope your luck pans out!