PyrocasterX90
BAN USERConsider the two arrays:
A[n], Q[m]
Create a matrix M [n X m]
Solve using dynamic programming with the following conditions
if A[i] != Q[j] then M[i,j] =0
if A[i] == ![j] then M[i,j] = M[i-1,j-1] + 1
O(M*N)
Consider the two arrays:
A[n], Q[m]
Create a matrix M [n X m]
Solve using dynamic programming with the following conditions
if A[i] != Q[j] then M[i,j] =0
if A[i] == ![j] then M[i,j] = M[i-1,j-1] + 1
O(M*N)
The queue to perform a BFS type traversal of the tree while simultaneously pushing a visited node into a stack. After the traversal (level wise as guaranteed by BFS) pop out all the elements in the stack this is the 'visit' part of post order which will be in reverse level order (i.e. last child will be printed first and root last) which is the expected behavior for Post Order
- PyrocasterX90 September 16, 2015Answer is 2 (if you know the odd man out is lighter/heavier, else it is 3)
Take balls 1,2,3,4,5,6,7,8
Assumption is odd man out is lighter
Step 1: Weigh (1,2,3) against (4,5,6) : IF balance, then measure 7 against 8 to get answer
IF unbalanced, then take the lighter set (let us assume it is 1,2,3)
Step 2: Weigh (1,2): IF balanced, then 3 is the answer
IF unbalanced, then take the lighter ball (assume 2) - that is the answer
Answer is 2 (if you know the odd man out is lighter/heavier, else it is 3)
Take balls 1,2,3,4,5,6,7,8
Assumption is odd man out is lighter
Step 1: Weigh (1,2,3) against (4,5,6) : IF balance, then measure 7 against 8 to get answer
IF unbalanced, then take the lighter set (let us assume it is 1,2,3)
Step 2: Weigh (1,2): IF balanced, then 3 is the answer
IF unbalanced, then take the lighter ball (assume 2) - that is the answer
Hi I'm not sure if this will work for
00010
10010
11110
The algorithm looks good (I have not run the code)
- PyrocasterX90 September 16, 2015