GingerBreadMan
BAN USERI have another observation;
Scan through the input array :- 2 ,3 ,4 ,10 ,5
and create an array of the products in order. And create another array which finds the products in reverse
ie new arrays will be
2 , 2*3 , 2*3*4 , 2*3*4 * 10 , 2*3*4 *10* 5, -> A[]
2 * 3 * 4 *10 *5 , 3 * 4 *10 *5 , 10 *5 , 5 -> B[]
Now an element in the resulting array, i = A [i-1] * B [i +1]
Here is another observation that I got
Consider the n*n as a matrix
1 2 3
4 5 6
7 8 9
The possible solutions are ;
a) All rows iterated
b) All columns iterated
c) Both diagonals iterated
d) Spiral or '7' shaped elements from all 4 corners
ie
1,6,8
3,4,8
9,4,2 (which is 2,4,9)
7,6,2 (which is 2,6,7)
In case of n=4, the similar structure will reveal all the elements.
The sort of '7' shaped path will have 4 elements
Please correct me if this is wrong.
s1 = "hard" s2 = "work", s3 = "success" ;
isnt this -1 , since hard and work is 4 digits and "success" is 7 digits.
I think we can never satisfy s1 + s2 = s3, for this case
Not getting this. If c2,c3, and c5 are incremented, how do we get numbers like 125 , ie pow(2,0) * pow(3,0) * pow(5,3)
From the above code, i was getting a different sequence. Not sure how,
2 4 6 8 10 12 16 18 20 24 30
Can you elaborate on how the get the occurrences of the substring ?
- GingerBreadMan April 18, 2012How about going by @ Free Bird by using DP.
I can define a recursive relation, consider the matrix S, and search string A (with the current search index as m)
CONTAINS (A[m] , S [i,j]) = CONTAINS (A [M-1] , S [i-1][j])
|| CONTAINS (A [M-1] , S [i+1][j])
|| CONTAINS (A [M-1] , S [i][j+1])
|| CONTAINS (A [M-1] , S [i][j-1])
The complexity is exploding, but we can reduce it have have a 3D array, saving the matched data to the MxN matrix.
Please comment
How about creating a min heap of size k and adding elements as we scan through the array.
- GingerBreadMan March 06, 2012
I think you should be more careful while using Vector in this case.
- GingerBreadMan May 21, 2012