@shen5630 No, thats not true. There might be cases where a HashSet may be empty corresponding to a count which is not minimum. In that case, we cannot set the minimum as count + 1. One of the test cases fails to corroborate this point.
arjun1610
@arjun1610
Posts made by arjun1610

RE: JAVA O(1) very easy solution using 3 HashMaps and LinkedHashSet

RE: Java Solution 1ms O(1) space (Bit Manipulation)
@magicly agreed! I guess, we don't have enough test cases right now to cover large inputs ( nums.length > 32)

Java Solution 1ms O(1) space (Bit Manipulation)
We use a similar (inspired) approach as we did while solving the problem Maximum Product of Word Lengths. We use an integer value which stores bit 1's only at the positions of nums[i] and 0's at the positions where the nums[i] is missing. For example if the input is [4,3,2,7,8,2,3,1], we create an integer having bits as 11001111, where i'th bit in this number (from right to left ) represents the occurence of nums[i] ( 11001111 has 5th and 6th positions set as 0's reading from LSD bit to MSD bit). If any bit at ith position is 0, it represents that number is missing.
As for our first element in the array nums, the number 8 was encountered. We do a leftshift of '1' by 7( nums[i]1) positions to place it at the 8th bit, the value becomes 1000000 and then OR (inclusive) it with the original value ( Thus, the result is invariant to duplicates ). After we traverse through the array, we get the result which stores the bits as 0's at positions whereever the numbers were not present in nums[i].
We then simply return those bit positions set as 0 in a list as our result. The extra check we need to have is the length of number of bits of our result. In the case like, [1,1,2,2] the resultant value would be 11, but we need to check for 4 positions as the nums.length is 4 in this case. So, we add additional OR condition to traverse till the length of the array (at max).
Here is the solution,
public List<Integer> findDisappearedNumbers(int[] nums) { List<Integer> list = new ArrayList<Integer>(); int value = 0, index = 1, len = nums.length; for( int i = 0; i < len; i++ ) value = (1 << (nums[i]1)); while( value > 0  len > 0) { if ((value & 1) == 0) list.add(index); index++; len; value >>= 1; } return list; }

RE: 1 line solution  java
downvoted ? is there something wrong with this approach or thinking ?

1ms solution  recursion with ternary operator
I don't see it very clean though, its shorter in terms of lines (instead of using traditional if..else statements) :)
Can I make it neater without removing ternary operation?public int minDepth(TreeNode root) { if (root==null) return 0; return helper(root,1); } public int helper(TreeNode root, int depth) { return (root.left!=null && root.right!=null) ? Math.min(helper(root.left,depth+1), helper(root.right,depth+1)): root.left!=null ? helper(root.left,depth+1): root.right!=null ? helper(root.right,depth+1): depth; }

1ms  1 line  Java Solution
Another way to deal
public int trailingZeroes(int n) { return n>=5 ? n/5 + trailingZeroes(n/5): 0; }

1 line solution  java
If both p and q in same direction (less or greater than), then change the root to its child in that direction. otherwise for all other cases it has to be the root.
public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) { return (p.val<root.val && q.val<root.val) ? lowestCommonAncestor(root.left,p,q) : (p.val>root.val && q.val>root.val) ? lowestCommonAncestor(root.right,p,q) : root; }