create AVL tree using elements of array 1... with each node of AVL tree
maintain a count variable...
if an element occurs more than once,increment the count... (this step is
not compulsory though,we can simply insert the new element in tree)
go through the second array,for each element in array,
does this work if array elements are negative???
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to
@lucifer and others: does this work for negative elements? What to do
then???
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to
@Piyush : yes it works ... please check the link again ..Lucifer has added
more details to the same post for better explanation.
follow that link and if you have any queries post your queries on that old
link.
On Mon, Jan 9, 2012 at 1:04 PM, Piyush Grover piyush4u.iit...@gmail.comwrote:
Hi Atul
@Siddhartha : i dont think so this will work for -ve number because we are
doing A[ i - 1, j - W[i] ] so if W[i] is -ve number then it would increases
Wmax which is the number of column.
i guess same algo can be modified so as to make it work for -ve number.
On Mon, Jan 9, 2012 at 2:23 PM,
yup...that was what i was thinking... i guess for negative nos, we can
define Wmax= sum of modulus of weights,and then the same algo works...
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send email to
@All
The same algo will work for both +ve and -ve nos.. no need for
modification..
For ex-
Say the sum is 4 and the set is { 1, 2, 3, -2 }
Now if u include -2 as part of ur solution then for the rest 3
elements the sum would be 4-(-2) = 6, which is correct...
On Jan 9, 2:20 pm, Siddhartha
@sravan i didn't get how my approach will fail , can u check for the exmple
u said ? if u sum the 1st array using 2 as base then sum will be 3
(exculding 2 , although it won't metter ) , then u search that elemnt in
2nd array , u won;t find u return -1 , say these array are not similer .
@Shashank:
from your code, i looked at this part.
for j=0 to m
sum2+=3^b[j]
i assumed 3^b[j] as power(3,b[j]);
== (2,0,0,0) - 9+1+1+1 (1,1,1,1) = 3+3+3+3 both equals 12.
and.. i didn't understand what you meant by base here. did you mean
anything else?
or did I miss anything?
(how can we
According to KR the behavior of printf is undefined if u do not use
correct format specifiers for the variables.
--
Amol Sharma
Third Year Student
Computer Science and Engineering
MNNIT Allahabad
http://gplus.to/amolsharma99
What about this approach:
First we will scan the first array and find the smallest number.
if it is -ve then we increment all numbers in both the arrays by that
number .
This ensures that every integer in first array is = 0
some integers in 2nd one maybe -ve if it is,then two arrays are
not
Given an array (length n), we need to find the subarray (length k) such
that the sum of the first j elements of the subarray equals the sum of the
remaining (k-j) elements of the subarray.
For e.g.
Array: 2,2,13,4,7,3,8,12,9,1,5
Output: 4,7,3,8,12,9,1 [4+7+3+8=12+9+1]
Could this be done with a
using extra space of O(n) we can do it in O(n^2)
take an array for storing cumulative sums from index i till 0,
then from i+1 till n-1 find summing each array value find whether it exists
in array.
if its so display indexes
eg
Array: 2,2,13,4,7,3,8,12,9,1,5
i = 3 ^
temp array: 4,
The intermediate value of start+end may be too large to store in an
integer, even though start and end by themselves are in the valid
range. If you know this to not be the case, you can use the simpler
form.
Don
On Jan 8, 5:04 am, Sanjay Rajpal srn...@gmail.com wrote:
In binary search,
mid =
solution at this link:
http://ideone.com/ifVIv
for every position, (iteration)
maitain left, right for the sums,
keep adding elements towards the begenning to left, and towards the end to
right, (based on the conditions in the code)
Complexity: outer forloop : O(n)
inner while loop O(n)
there is a matrix of 1 and 0
1 is a island and 0 is water
1-1 together makes one island
calculate total no of islands
Best Regards
Ashish Goel
Think positive and find fuel in failure
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to
Can you give an example
Say matrix is
1 1 0 0
1 1 0 0
0 0 1 1
Has it got 3 islands i.e 1-1 be in same row or they can be column wise also
i.e. 5
On Tue, Jan 10, 2012 at 7:09 AM, Ashish Goel ashg...@gmail.com wrote:
there is a matrix of 1 and 0
1 is a island and 0 is water
1-1 together
row, col, diag all
1-1-1 is a single island :)
1 1 0 0
1 1 0 0
0 0 1 1
this has only 2 islands
Best Regards
Ashish Goel
Think positive and find fuel in failure
+919985813081
+919966006652
On Tue, Jan 10, 2012 at 7:29 AM, Ankur Garg ankurga...@gmail.com wrote:
Can you give an example
Say
Exactly. And note that if pointers and unsigned integers have the
same number of bits, overflow can't be a problem as long as the array
elements are 2 bytes or more long. I.e. if you have an n-bit machine,
the last 2-byte array element can't have index more than 2^n/2 - 1 =
2^(n-1) - 1.
I think this wont work for cases with negetive nos
Ex
-2,8,-6
On Tue, Jan 10, 2012 at 6:51 AM, sravanreddy001 sravanreddy...@gmail.comwrote:
solution at this link:
http://ideone.com/ifVIv
for every position, (iteration)
maitain left, right for the sums,
keep adding elements towards the
The question mentions of Subarray (which is like a substring in the string)
I think you are assuming it to be any subset, in that case even O(n^3) time
will not be sufficient and its an exponential time algorithm.
with the subarray like my assumption, the bruteforce approach will be to
find
and.. yes for this example,
-2, 8, -6 it results in No solution. (or doesn't print anything.)
but works if its -2, 8, 6 where (-2+8 == 6)
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To view this discussion on the web visit
this is similar to the Pixel fill algorithm usually used in photo editing
softwares (photoshop or paint )
BFS would be best approach to start with ( and check 4-adjacent or
8-includeing diagonal elements for a '1' and include that to queue. When
the queue becomes empty, increase the count by
@sravanreddy001 : Pixel fill algorithm ..what is the exact name of that
algo ???
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to
@Ashish Goel : didnt get it :(
1 1 0 0
1 1 0 0
0 0 1 1
1-1-1 diagonal is one island ...where is another??
1 1 0 0
1 1 0 0
0 0 1 1
these 1 will be considered one island of 2 island.??
On Tue, Jan 10, 2012 at 7:36 AM, Ashish Goel ashg...@gmail.com wrote:
row, col, diag all
1-1-1 is a
@atul: given a matrix just like above, (usually an image) the pixel values
with similar can be searched for around the current pixel, and they all can
be marked in one go,
think of an algorithm, which does the following
1) when a one is replaced by '2' manually, then algorithm changes every
@sravanreddy001 : got it ..thanks :)
On Tue, Jan 10, 2012 at 9:33 AM, sravanreddy001 sravanreddy...@gmail.comwrote:
@atul: given a matrix just like above, (usually an image) the pixel values
with similar can be searched for around the current pixel, and they all can
be marked in one go,
Scan the matrix row wise left to right
for each arr[i][j]
if(arr[i][j]==1)
{
if (!(arr[i-1][j]==1||arr[i][j-1]==1))
count++;
}
///also chk for baundary values accordingly
1 1 0 0
1 1 0 0
0 0 1 1
i think it should work..
--
You received this message because you are subscribed to the
@ankur : in this question, the elements of the array are continuous
i think the solution of shravan reddy is correct and works for negative nos
too.
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send email to
@Ramakant : i guess you shud include diagonal case also
for each arr[i][j]
if(arr[i][j]==1)
{
if (!(arr[i-1][j]==1 || arr[i][j-1]==1 || arr[i-1][j-1]))
count++;
}
On Tue, Jan 10, 2012 at 9:33 AM, Ramakant Sharma ramakant...@gmail.comwrote:
Scan the matrix row wise left to right
@amol I think it is not the behaviour of printf
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to
@atul:
no..my approach was wrongwe have to check recursively...as sravan said
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to
this is a single island, sorry for that
Best Regards
Ashish Goel
Think positive and find fuel in failure
+919985813081
+919966006652
On Tue, Jan 10, 2012 at 9:24 AM, atul anand atul.87fri...@gmail.com wrote:
@Ashish Goel : didnt get it :(
1 1 0 0
1 1 0 0
0 0 1 1
1-1-1 diagonal is one
http://www.janaganamana.net/onedefault.aspx?bid=276
did not get it
Best Regards
Ashish Goel
Think positive and find fuel in failure
+919985813081
+919966006652
On Tue, Jan 10, 2012 at 1:15 PM, Ashish Goel ashg...@gmail.com wrote:
this is a single island, sorry for that
Best Regards
34 matches
Mail list logo