Hackerrank OA:
-
a perfect pair (x, y) is such that
min( | x - y |, | x + y | ) <= min( | x |, | y |) && max( | x - y |, | x + y | ) >= max( | x |, | y |)
given an array of unsorted integers, find the number of perfect pairs
example [2, -3, 5]
(2, -3) and (-3, 5) are perfect pairs -
https://leetcode.com/problems/longest-string-chain/description/
Cleared all the Test Cases.
Result: Positive
Phone Screen:
(Rescheduled this round thrice. Twice by the recruiter. And once by me)
- Brief walkthrough about your projects mentioned in your Resume.
- OS(Paging, stacks and heaps, paging) concepts, Networking concepts(TCP vs UDP), DBMS Concepts(ACID Properties).
I did not answer properly about the Durability in ACID. I don't know I just didn't remember much about it during the interview.
Coding problem:
I wasn't given a LC problem I guess.
abstact class NestedInteger {
public:
virtual bool isInteger() const = 0;
virtual int getInteger() const = 0;
virtual const vector<NestedInteger> &getList() const = 0;
};
/ *
* nums: {1, {4, {6, 4}}}
* this would look like
* 1 depth 3 => 1 * 3 = 3
* \
* 4 depth 2 => 2 * 4 = 8
* \
* 6, 4 depth 1 => 6*1 + 4*1 = 10
* Total sum = 10 + 8 + 3 = 21
*
* nums: {{1,1}, 2, {1, 1}}
* 2 depth 2 => 2 * 2 = 4
* \
* 1, 1, 1, 1 depth 1 => 1*1 + 1*1 + 1*1 + 1*1 = 4
* Total sum = 4 + 4 = 8
// Now complete the below function
int getDepthSum(vector<NestedInteger>& nums) {
// Implement here
}I solved by doing DFS whenever I a nested list. And saved my result in a new vector. for example 1, my new vector will be [[1], [4], [6,4]] and then I will traverse and calculate the sum. Interviewer was OK with this approach. Dry ran it. Worked.
Follow up: To do it without extra space. They wanted to me calculate sum at each level and complete the sum at each level with the help of current depth and max_depth as I was doing a DFS. Discussed only the approach. Did not dry run it. I had some questions around it and we ran out of time.
Verdict: Rejected
Feedback: I didn't answer about Atomicity. And I used extra space for the vector. Got it directly from the recruiter. "You solved the problem but for an SSE, you gotta solve it without extra space"
I guess I should practice more DFS. Please let me know the topics I should cover to deal with problems like this.
Timeline: 2 weeks with all the rescheduling considered.
Guys please grind hard. Peace ✌️.


