kbrajesh176
BAN USERHow would you decide the parent if there are more than one strings starting same char.
Ex: [luis, sat, sam, mos]
Expected answer: luis -> sam -> mos -> sat.
But your code will print luis ->sat.
Idea is to create trie of binary representation if all given numbers. Now for each number in set traverse trie
for (a : set){
for(bit in binary(a)) {
if(bit == 0) {
// traverse all nodes in current root( since 0 & x = 0)
} else {
// traverse only nodes with value 1
}
// if found such a number add to result (please also note a&a = a excldue this result)
}
}
Please share your thoughts on this in reply to this answer.
- kbrajesh176 December 14, 2015@lepeisi can you please explain from where
Math.max(dp[left][right], nums[left] * nums[i] * nums[right] + dp[left][i] + dp[i][right]);
came ?
- kbrajesh176 December 11, 2015
This question need to be solved by backtracking/dfs, because if there are more than one names starting with same character, we have to explore both paths.
- kbrajesh176 February 03, 2019Ex: [luis, sat, sam, mos]
Expected answer: luis -> sam -> mos -> sat.