I interviewed for the software engineer position last week. I was asked two questions.
560: Subarray Sum Equals K
1570: Dot Product of Two Sparse Vectors
For the subarray sum problem, initially, I gave the solution using cumulative sum (Time Complexity: O(N^2), Space Complexity: O(N^2)). Then I was able to improve the solution by using HashMap (Time Complexity: O(N), Space Complexity: O(N)). The interviewer later asked me if all the numbers are positive, then there can be a solution with space complexity O(1). I thought about the solution for a while and then replied maybe two-pointers could be a good solution. I gave a very brief description of the approach but did not have time to implement it. The interviewer told me that we could move to the next question.
I coded the solution with the HashMap approach for the sparse vector problem. The interviewer was reluctant to accept the approach. He asked me if there was any other way. I replied we could use an ArrayList of integer arrays to keep a list of (index, value) pairs. The interviewer told me that could be a good way. But I did not have enough time to code it. In the end, when the interviewer asked me if I had any questions, I asked him how he thought my interview went. He told me it was good and that's it. But I think I could have done better. I could have solved the first problem with O(1) space (I had a clear idea after the interview!) and coded the second problem with ArrayList. It's been almost a week, and I have not had the result yet. I am not sure how long it usually takes to get the feedback. Would it be a good idea to ask my recruiter about the expected time of getting the decision back?