Replace all elements of array by its square.and sort it
Now question is to find two nos in the array such that their sum is N.
For this take two pointers min and max
Initialize min to 0 and max to n-1(n-size of array)
1.find the sum a[min]+a[max]
2.if sumN max=max-1
if sumN min=min+1
if sum==N we
in above algo primary index is no of times that value is repeated till now
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To unsubscribe from this group and stop receiving emails from it, send an email
to
I can think of an o(n^2) algo for 2n question
Make a heap formed acctoring to two indexes
1.Primary -value
2.Secondary - index
Now for each new incoming value first search in head if exist inc its index
else make a new node
--
You received this message because you are subscribed to the Google
the difference array for range 4-7 is [1,1,0,1] it is not a sol
[2,2,1,1](index no 7) -[1,1,1,0](index of 3)
Make a directed graph out of the set of edges where an edge indicates the
the sets are not disjoint .
Now question is to remove min no of sets so that no sets exist.
for this apply the following algo
1.Select the edge with of min degree(nonzero) delete its parent.
2.repeat the step 1 on the
@Sairam i m 100 % sure about the correctness of the algo.i have proven it
with test case..
Only way u can prove it wrong is to give a counter case not by intutive
feeling.
if u find the diffence of count arrays for two indexes i and j then it
indicates the count of the string starting from i and
not possible unless u use augmented bst..which itself takes o(n) to built
--
This is a test This is a programming test This is a programming test in any
language
1 1 1 122 2 2 233 3 3
3 3 33(count of this)
0 0 1 111 2 2 222 3 3
3 3 3
to make it O(n logn)
1.Chose one index O(n)
2.For this index do a bsearch on remaining array to find the postion
bsearch can be done as the array is an increasing function(it donotes no
of occurrence of each word,so=previous index value)
bsearch will be done like this
1.make a new temp array that
consider code to find n^k where n is an integer
int power()
{
int ans=1,val=1;
while(k)
{
val=val*n;
if(k1)ans=ans*val;
k=k1;
}
return ans;
}
now if n is is a matrix all you have to do is replace * by matrix
multiplication algorithm
--
O(nlogn) algo
for each postion in paragraph store the frequency of the given words(from
start point to this point) .
now in resultant array you need to two indexes that have =1 value in the
difference of the frequency of two points.
eg hello hello are you
hello ,you
hello hello are you
1
both recursive and iterative codes are O(nlogn) algos..
but memory will be more in recursion..
so we will prefer iteration
--
@dave thanks for correcting :)
--
yaar i can think of only 2 methods for this
1. O(nlogn) o(n) sol
traverse the heap...and hash the elements..if it exist then delete it
2.make another heap but transfering elements from 1st to 2nd heap...if the
element is equal to the last inserted element then discard it
--
You received
void spiral(int a[][],int m,int n)
{
int c=1;
--
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
void change(int a[],int n)
{
int i,j;
i=0;
j=1;
while(injn)
{
if(ji)
j=i+1;
else if(a[j]0a[i]0)
{
swap(a,j,i);
}
else
{
if(a[j]0)
j++;
else
i++;
}
@abhisheikh read the problem statement again...it says 1000 digits not 1000
value..
--
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
loop in a link list doesn't necessarily mean a circular link list(d one u
hav assumed)
eg in this case
1-2-3-4-5-3
there is a loop which in order to detect requires d use of hair tortoise
rule
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks
the value of d expression i++ is a integer constant.so u cant
assign to a value 20 to it
same is d case if u execute (i++)++;
On 8/30/11, rahul vatsa vatsa.ra...@gmail.com wrote:
@nidhi, if u change the i++ to ++i in D, it will compile, bt off course it
will keep on printing 20 in an
@Don Which compiler r u usingi m getting d correct o/p for pow as well
On 8/31/11, Don dondod...@gmail.com wrote:
pow works with double (floating point) values, not integers, and when
you assign the result to an integer, it truncates. You will be better
off, both in speed and correctness,
20 matches
Mail list logo