↳
class Solution{ int ans[] = new int[1]; //O(n) public int efficientDia(TreeNode root) { if(root == null) return 0; int left = efficientDia(root.left); int right = efficientDia(root.right); ans[0] = Math.max(ans[0], 1 + left+ right); return 1+ Math.max(left, right); } //O(n^2) public int getDiameter(TreeNode root) { if(root == null) return 0; int leftHeight = getHeight(root.left); int rightHeight = getHeight(root.right); if(ans[0] < 1 + leftHeight + rightHeight) { ans[0] = 1 + leftHeight + rightHeight; } return Math.max(getDiameter(root.left), getDiameter(root.right)); } Less
↳
int ans[] = new int[1]; //O(n) public int efficientDia(TreeNode root) { if(root == null) return 0; int left = efficientDia(root.left); int right = efficientDia(root.right); ans[0] = Math.max(ans[0], 1 + left+ right); return 1+ Math.max(left, right); } //O(n^2) public int getDiameter(TreeNode root) { if(root == null) return 0; int leftHeight = getHeight(root.left); int rightHeight = getHeight(root.right); if(ans[0] < 1 + leftHeight + rightHeight) { ans[0] = 1 + leftHeight + rightHeight; } return Math.max(getDiameter(root.left), getDiameter(root.right)); } private int getHeight(TreeNode root) { // TODO Auto-generated method stub if(root == null) return 0; return Math.max(getHeight(root.left), getHeight(root.right))+1; } Less
↳
Indians at all companies always ask tree questions, it makes them giggle inside. I know, because I'm half indian and have interviewed people... tee hee hee Less
↳
The device keychain. There were many questions, where even if you answered that you did not have experience in this avenue, what or how would you go about it? Less
↳
Hi.Could you please tell the questions that are asked for you for this role.I have an interview this friday and it would be a great help.Thanks alot Less
↳
Na
↳
Just followed the approach I have taken for other similar solutions in the past. They came back to me through the recruiter (after probably he chased them). No feedback or anything, just saying they are not looking to progress. Have asked for FB, but nothing. I believe that if someone has spent 4-5 hours working on an unpaid assessment, it would be at least respectful to provide 2-3 highlights of why they have failed. Especially if task have been good enough to progress you in the next stage in the past. Less
↳
This is another Swift feature that anyone who does Swift will have experience with, but might not remember the actual formal name. Simply add a question mark to the end of the type to allow that variable to also be nil. That is, “var myName : String?” allows the variable to either be a string or nil. Less