@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
@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 3
@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
1)get the numbers
2)Sort the numbers
3)traverse from first number
4)if (a[i]==a[i+1]-1 )
{
count++;
sum+=(a[i]+a[i+1])
i++;
}
5)if (summax)
{
end=count;
max=sum;
}
6)print down to count no of elements from a[end]
will this algorithm wok?correct me if i am
Hey sorry buddy...here is the code
#includestdio.h
#includeconio.h
void main()
{
int a[20],loop1,loop2,temp,num; // INITIALIZATION
printf(ENTER THE ARRAY SIZE);
scanf(%d,num);
printf(ENTER THE NUMBERS);
for(loop1=0;loop1num;loop1++)
{
scanf(%d,a[loop1]);
}
for(loop1=0;loop1num;loop1++)
{
hi buddy ...Im clear with the ideahereby I share the concept...
wat exactly need to be done to solve this task isbetter create a Binary
search tree...the Binary search tree will not allow duplicates and If u
perform a inorder traversalu can get the result...the task is
oversimple
@LG Jayaram :
check for -5 -4 -3 -2 -1
answer should be : -1
--
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
How could it be -1,in the given array -1 and -2 are the largest
numbersso their sum will be -3 rite
On Sun, Sep 19, 2010 at 4:15 PM, Krunal Modi krunalam...@gmail.com wrote:
@LG Jayaram :
check for -5 -4 -3 -2 -1
answer should be : -1
--
You received this message because you are
no
we have to find consecutive numbers such that there some is largest...
here -3 -1
--
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
creating a bst would require extra space. You can do this with an array of
char dude.
On Sun, Sep 19, 2010 at 3:31 PM, LG JAYARAM . lgj...@gmail.com wrote:
hi buddy ...Im clear with the ideahereby I share the concept...
wat exactly need to be done to solve this task isbetter create a
Given an array of numbers, replace each number with the product of
all the numbers in the array except the number itself *without* using
division.
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send email to
this is google question
take arrays before[] and after
before[0]=1
after[length-1]=1;
for (int i=1; ilength;i++)
{
before[i]=a[i]*before[i-1];
after[length-1-i]=a[length-1-i]*after[length-i];
}
now resuly for the asked index is after[index]*before[index]
the idea here is that we should not
but the 2 consecutive numbers condition violatesfor -1 we must
take only -1 only then we get -1 .If u add 2 negative numbers the
answer is less than the 2 elements..So if the array contains ONLY
negative numbers the maximum sum can't be achieved for 2
elements.Correct me if i am
Handling ' 0 's
Case1: array containing single zero.
Caae 2: array containing multiple zeros.
int numberofZeros =0, index =0 ;
before[0]=1
after[length-1]=1;
for (int i=1; ilength;i++)
{
if( !a[i] ) //encountered zero
{
numberofZeros++;
if(numberofZeros == 1) index =i; //Case1
array index starting from 0 or 1?
in the for loop i =length isn't it?
If no please explain
On 9/19/10, Ashish Goel ashg...@gmail.com wrote:
this is google question
take arrays before[] and after
before[0]=1
after[length-1]=1;
for (int i=1; ilength;i++)
{
before[i]=a[i]*before[i-1];
Linux shell command to find all files in a directory which contain ip
addresses
--
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
Krunal: If the array contains only negative numbers, shouldn't the
subsequence with the largest sum be the empty subsequence?
Dave
On Sep 19, 5:45 am, Krunal Modi krunalam...@gmail.com wrote:
@LG Jayaram :
check for -5 -4 -3 -2 -1
answer should be : -1
--
You received this message because
Ummm and also, the potatoes example isn't a _**sorted string**_ as the
problem statement said.
All you have to do is pass the location of the current char and then
compare it with the next one until you reach the end.
Use a dynamic array or a list or something to store the chars in so
it's easier
You don't need any data structure.
Since the window moves by one element each, you can simply count 10
such moves and compare each new element with currMax.
If it's greater, overwrite currMax. After 10 moves you have your max
for that 10 element window, rinse and repeat.
On Sep 17, 1:31 am,
Yeah, you're right. It'll work only for consecutive elements.
And by swapping only consecutive elements, it'll take many swaps to
sort the array.
Another way would be to start from the left and every time you hit an
element larger than the previous one, call
reverse successively until all
It's been discussed here before.
Start by multiplying from either sides of the array and stop when both
pointers reach the opposite side.
takes O(n) time and does not involve division so won't crap out for
cases where some of the elements are 0.
I was asked this for my Google phone screen I wish
I guess before[index] should contain product of the numbers before index and
after[index] should contain all the product after the index but @Ashish algo
isn't that before[index] contains product that includes the number at the
index position also. Please clarify me...
On Sun, Sep 19, 2010 at
@Minotauraus, if we consider your scenario,
10 12 14 9 23 2 4 6 9 19 22 10 6 12 10
for 1st window max=23
second window max=23(2322)
third windw max=23(2310)
fourth window max=23(236)
fifth window max=23(2312)
sixth window max =22(calculate the maximum in the window).
repeat again
So the number
You are given two arrays A [n] and B[m] find the smallest window in A
such that it
contains all elements of B. i.e. find a position [g,h] such that
A[g.k] contains all
elements of B[m]
For example,
___
index = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10, 11, 12,
2 nos with min diff
given an array of size n. find 2 numbers from array whose difference
is least in O(n) w/o
using xtra space( i mean constant space)
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send email to
how to find the no. of digits in the product of two numbers without
multiplying??
if a is the number of digits in A and
if b is the number of digits in B
the number of digits in A*B is either a+b or a+b-1 but how to find the
exact one?
--
You received this message because you are subscribed to
A partial solution is , if you multiply first digits of two nos and result
is greater than 10 then surely result will be a+b digits
If not, according to me, u will need a complex logic to solve.
On Mon, Sep 20, 2010 at 10:41 AM, Srinivas lavudyasrinivas0...@gmail.comwrote:
how to find the no.
Adding to the partial solution, if x, y are first digits, and x*y + x + y
10, the result will be a+b -1 digits. If not, u will need a complex logic
to solve
On Mon, Sep 20, 2010 at 10:50 AM, rahul patil rahul.deshmukhpa...@gmail.com
wrote:
A partial solution is , if you multiply first digits
28 matches
Mail list logo