@Raj Jagvanshi:
Test 1 :
Enter numbers (-1 to stop taking input)
4 1 2 3 4 5 40 41 19 20
-1
Largest sequence is : 40 to 41
40 41
Sum: 81
--
Test 2:
Enter numbers (-1 to stop taking input)
-5 -4 -3
-1
Largest sequence is : -3 to -3
-3
Sum: -3
@Minotauraus:
This is not the thing that "Raj Jagvanshi" wants.
See, what he has mentioned.
a[] = {4,1,2,3,4,5,40,41,19,20};
print = 40 , 41
sum = 81;
We need to find max sum such that they are of consecutive numbers (a,a
+1,a+2,)
I have implemented Kadane's Algo : and the result is
4 1 2
@LG JAYARAM :
Your code is not even compiling. If you are including header that
means you have made a code and successfully run it.
I have the code readybut just wanted to check with your program
for some exception conditions...
--
You received this message because you are subscribed to the
@Minotauras:
There are some problems in you swap(x,y)
in your example : for reverse(3) you have considered 0 based indexing
and for reverse(2) 1 based index !!
see:
Original array : 1 8 3 4 5 and we want to swap(2,3) // swap 3 and 4.
Means, 0 BASED INDEX
reverse(3): 4 3 8 1 5
reverse(2): 8 3 4 1
the interviewer would be stupid to ask this question!!!
Best Regards
Ashish Goel
"Think positive and find fuel in failure"
+919985813081
+919966006652
On Sat, Sep 18, 2010 at 11:12 PM, jagadish wrote:
> You are given a string which is sorted.. Write a recursive function to
> remove the dupl
btw, if u rn't suppose to use any extra space, then u should be going for
iterative solution; since recursion uses extra space by default.
On Sat, Sep 18, 2010 at 11:33 PM, Umer Farooq wrote:
> here's the java implementation
>
> package removeduplicates;
> import java.io.*;
> /**
> *
> * @auth
here's the java implementation
package removeduplicates;
import java.io.*;
/**
*
* @author UmerFarooq
*/
public class Main {
/**
* @param args the command line arguments
*/
public static char[] input;
public static void remDep(int i, int j)
{
if (j<0)
On Saturday, September 18, 2010, jagadish wrote:
> Hi Raj,
>
> I think there is an nlogn solution to this problem which can be done
> by modifying merge sort..
>
> the key lies in the merge routine, when the left array elements are
> greater than the right array,
> the right array elements are cop
On Saturday, September 18, 2010, jagadish wrote:
> Hi Raj,
>
> I think there is an nlogn solution to this problem which can be done
> by modifying merge sort..
>
> the key lies in the merge routine, when the left array elements are
> greater than the right array,
> the right array elements are cop
I was looking into this problem the other day and found this:
http://www.algorithmist.com/index.php/Kadane's_Algorithm
Kadane's algorithm to find the maximum continuous subarray.
The basic idea is to maintain the largest sum ending at each location
in the array. and max which holds the maximum so
The power set of a set with N elements has size O(2^N). You can't do
anything with it in polynomial time.
On Sep 18, 5:03 pm, bittu wrote:
> can we solve power set in O(n) or O(nlogn)..is it posible...
>
> Regards
> Shashank
--
You received this message because you are subscribed to the Google
can we solve power set in O(n) or O(nlogn)..is it posible...
Regards
Shashank
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to
al
@ Anil kumar S.R. wait yarr i have busy schdule..and forgot last time
but i advise u to just put ladder and snake desgin infront of you u
and chk the code.u will definetly get it.
1. Given a set of shapes in 2D space, and a coordinate pair, write a
routine that returns true if any of the shapes
You are given a string which is sorted.. Write a recursive function to
remove the duplicate characters in the string.
eg: potatoeos
output: potaes
NO extraspace like hash/ bitmaps..
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to t
On Fri, Sep 17, 2010 at 3:36 PM, Krunal Modi wrote:
> Your solutions are pretty impressive.
> Which place(country) are you from ?
> where are you studying (or done :) ) ?
>
> Keep it up...
> Good Wishes..
> --Krunal
>
> On Sep 14, 9:29 pm, Gene wrote:
> > You can approach this the same way you'd
Hi Raj,
I think there is an nlogn solution to this problem which can be done
by modifying merge sort..
the key lies in the merge routine, when the left array elements are
greater than the right array,
the right array elements are copied to the tmp array .. hence , this
adds (n-i) to the inversion
@ash: I would treat it as a graph problem. The nodes are the numbers
from 1 to n, and the edges connect nodes that sum to a perfect square.
The problem then reduces to finding a Hamiltonian path through the
graph. This can be done with a depth-first search. Start with a node
of degree 1 if you have
You could construct two level graphs starting starting simultanously
from your node and the other member's. Add layers one at a time to
each.
When, after adding a new level, you find one or more nodes in both
level graphs, you can stop. Each shared node gives you a least-edge
path between the two
#include
void main()
{
int array[20],loop1,loop2,temp; // INITIALIZATION
printf("ENTER THE ARRAY SIZE");
scanf("%d",&num);
for(loop1=0;loop1a[loop2])
{
temp=a[loop1];
a[loop1]=a[loop2];
a[loop2]=temp;
}
}
}
for(loop1=0;loop1 wrote:
>
> a[] = {4,1,2,3,4,5,40,41,19,20};
>
> print = 40 , 41
> sum
i will choose BFS. As we just don't want to show a connection.. we want to
show the shortest one.
On Sat, Sep 18, 2010 at 4:12 PM, soundar wrote:
> Even if u are connected to that person via some another friend it'll
> show the shortest chain by which you are connected to that
> person..So D
@Raj: give a sample test case
On Sep 14, 11:00 am, "Shiv ..." wrote:
> A pseudo code-
>
> int n; //= number of inputs.
> cin>>*a; // the inputs.
>
> int ** invArr;
> *inVArr[n-1] = NULL;
> //initialise all the elemnts with Null to be safe.
>
> for(int i = n-1; i > =0; i--) {
>
is there any general algo for this question,ie, upto any n(here
16) ? ?
On Sep 15, 2:46 am, Minotauraus wrote:
> I guess the problem could be modified for any 1..n where n is 2^m.
> so say 132
> or 1...64
> Try it out. It still works! The time complexity in this case is O(log
> n).
>
> On Sep
Even if u are connected to that person via some another friend it'll
show the shortest chain by which you are connected to that
person..So DFS will be optimum i guessWhy do you think it
wouldn't be optimum.?
--
You received this message because you are subscribed to the Google Gro
if you click on any orkut member's name you will notice the
relationship graph for both of you indicating through whom you are
interconnected or in certain cases you won't get this path.
if you have to propose algorithm what would be the one ...breadth
first or depth first traversal with some modi
@umesh kewat:
In worst case it will be O(n*k), by your solution.
01-06-11-16
02-07-12-17
03-08-13-18
04-09-14-19
05-10-15-20
--
Krunal
By umesh kewat:
Create binary search tree using n nodes of K list den do in-order and
make a
single list
--
You received t
@umesh kewat :
In worst case it will be O(nk) in case of your solution.
check for this case:
01-06-11-16
02-07-12-17
03-08-13-18
04-09-14-19
05-10-15-20
--
Krunal
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send e
26 matches
Mail list logo