Interview Question


None, really, but at that time, I found the BBS question


Interview Answer

1 Answer


/* Frequency of digits in binary search tree */ int[] FindFreq(Node root) { int[] digits = new int[10](); CountFreq(root, digits); return digits; } void CountFreq(Node root, int[] digits) { if(root == null) return; CountFreq(root.Left); UpdateFreq(root.Val, digits); CountFreq(root.Right); } void UpdateFreq(int val, int[] digits) { int n = Math.Abs(val); while(n>0) { digits[n%10]++; n=n/10; } }

bytefire on Jan 12, 2014

Add Answers or Comments

To comment on this, Sign In or Sign Up.