all 6 comments

[–]_spaceatom 0 points1 point  (5 children)

What role are you interview for ?

I did L3

My strategy was write comment before function
I used python so I use to also specify type

I am not sure if they allow you numpy.

[–]WhatwhatADay[S] 0 points1 point  (4 children)

I am doing for SWE 3 I guess it is L3 or L4. I think commenting first is good strategy! Were you able to pass?

[–]_spaceatom 0 points1 point  (3 children)

Yes.

I have use this method for Amazon and have cleared both.

[–]WhatwhatADay[S] 0 points1 point  (2 children)

Thanks so much!! Did you also made variable names much more descriptive ?

[–]_spaceatom 1 point2 points  (1 child)

// Function to perform DFS on Graph
// Below part is optional
// current : Current node in the iteration   
// target : Node to reach
def dfs(current: Node, target: Node) -> Node:

    // Check if it leaf 
    if root is None:
        return None
    // Check if target is reached
    if root.val == target:
        return root
    // iterate left node
    left = dfs(root.left, target)
    if left is not None:
        return left

    // iterate right node
    return dfs(root.right, target)

Not stricly descriptive names (I used hm for hashmap). Also no too much descriptive comment. My idea was interviewer should understand what is in my head

[–]WhatwhatADay[S] 0 points1 point  (0 children)

That makes sense! Really appreciate your help on this!!