Is it required that sub array must be continuous.
On Aug 18, 12:34 pm, Amit Jaspal wrote:
> You have to return the length of the subsequence with longest length and sum
> < K . If there are multiple solutions report anyone.
>
> On Wed, Aug 18, 2010 at 12:40 PM, srinivas reddy
> wrote:
>
>
>
> > s
Check out my solution. Hope u are looking for this,
Take a no 136 (base7 = 76 decimal ) convert to base 5 (ans shld be
301)
start from left side 1*7^2= 49/5^2 = 1 (rem 24)-
|
^
10
3*7 + 24 = 45 /5 = 19 (rem 0) ---
Sorry, this is not a good example.
Try this:
Assuming the sequence is 2, 1, 1, 1 and k = 3. The correct answer will
be 1, 1, 1. Run your code and see the result.
On Sat, Aug 28, 2010 at 1:54 PM, satish wrote:
> @Adam
> i ran the program with n=4 and k=2 and sequence as 2,3,999,
> i got 10998(
Made some changes.
flattenTree(TreeNode node,TreeNode previous) {
if (node is leaf) {
previous = node
return;
}
flattenTree(node->left,previous);
if (previous != null) {
previous->next = node;
previous=node;
}
flattenTree(node->right,previous);
@Wan:
Storing the elements as link list rather than array requires additional
space.
If we are taking extra O(n) space, then the usual approach of merging two
sorted arrays in O(n) time and memory will suffice.
On Fri, Aug 27, 2010 at 5:18 PM, Yan Wang wrote:
> Also, you can choose not to use a
On Sun, Aug 29, 2010 at 1:35 AM, Gene wrote:
> My algorithm proposal wasn't correct, but I can't see how to get 8.
> You need to decrement 14, 15, 16, 13 to 11. This costs 14.
>
> So do I.
May be he has not noticed that incrementing a number is not an option. ;)
> On Aug 28, 5:41 am, gaurav s
this has been discussed here before and if i remeber correctly the solution
was O(nlogn). Please go through the archives.
On Thu, Aug 26, 2010 at 12:20 PM, Aditya Shanker wrote:
> The question would be complete if we know what order of notation is needed
> for solution.
>
>
> On 23.08.2010 15:32
The output is undefined. Depends on the compiler. + is not a sequence point
which may result in undefined behavior
On Sat, Aug 28, 2010 at 5:05 PM, jagadish wrote:
> I ran this code..
>
> int main() { int x=5;
> printf("%d",(x++ + ++x + x++));
> }
>
> The output printed was 18 instead of 19.. Sh
int data; // Initialize data during run time
if ( data == -data && data!=0)
printf ("Miracle!!");
Will miracle ever print ?
--
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.c
Hi,
Can anyone tell me the question paper pattern of akamai technologies ?
What will the first written round consist of ?
--
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 unsu
output is 18
1. control goes to ++x =6 ,x=6
2. control goes to both x++, i.e. both x++ are evaluated together, therefore
x++ + ++x + x++= 6 +6+6 =18 x=7
On 28 August 2010 17:05, jagadish wrote:
> I ran this code..
>
> int main() { int x=5;
> printf("%d",(x++ + ++x + x++));
> }
>
> The output
@Adam
i ran the program with n=4 and k=2 and sequence as 2,3,999,
i got 10998(i.e999+).
plz check it
On Sat, Aug 28, 2010 at 10:25 AM, Adam wrote:
> Actually, your code just considers the only non-decreasing subsequence
> which starts from a[0] and is the most 'LEFT' one in this situ
My algorithm proposal wasn't correct, but I can't see how to get 8.
You need to decrement 14, 15, 16, 13 to 11. This costs 14.
On Aug 28, 5:41 am, gaurav singhal wrote:
> @ Gene :
>
> Output for
>
> int a[] = { 14, 15, 16, 13, 11, 18 };
>
> is coming out to be 14
>
> whereas minimum cost will be
Ouch. I think I was right to begin with and it is a matroid. I should
have been greedy right-to-left rather than left-to-right. This is
because you can only decrement. If we were incrementing instead, then
left-to-right would work fine.
So work right to left and for each item either
a) decrem
Actually, your code just considers the only non-decreasing subsequence
which starts from a[0] and is the most 'LEFT' one in this situation
rather than all the possible subsequences.
For example, we have such sequence as 2,3,999,, and k = 2.
In this situation, your code will give the subsequen
My proposed solution was not correct. You need a DP because the
problem is not matroid as I thought.
But for this problem 14 seems correct to me. I can't see how you can
get 8. You need to decrement 14, 15, 16 and 13 to 11. This is a
total of 14 decrements. What am I missing?
On Aug 28, 5:4
Yes. My solution isn't right. It's not a matroid, so greedy doesn't
work. You need a dynamic program.
On Aug 28, 5:41 am, gaurav singhal wrote:
> @ Gene :
>
> Output for
>
> int a[] = { 14, 15, 16, 13, 11, 18 };
>
> is coming out to be 14
>
> whereas minimum cost will be : 8
--
You received
@Chonku:
yours is wrong. consider the given ex,.
50
/ \
25 60
/ \ / \
5 30 55 75
5 will become head. 5->next=25. 25->next=30. then 25 will be returned
up.
so 25->next=50. which is wrong
On Aug 26, 11:36 pm, Chonku wrote:
> At first, store the pointer to the
I think this problem is a DP problem too.
Google Code Jam Round 1A has a similar problem in this year.
http://code.google.com/codejam/contest/dashboard?c=544101#s=p1
In the contest analysis page. It also explains the detail.
http://code.google.com/codejam/contest/dashboard?c=544101#s=a&a=1
--
Yo
I think a solution to convert a Binary Tree to a Doubly Linked List
has been discussed!
On Aug 27, 9:32 pm, balashankar sundar wrote:
> head=new node;//head node to list,T is root to the tree
> join=head;//global variable
>
> inorder(T)
> {
> if(T==0)
> return;
> inorder(t->l)
Your code violates the C standard, which says:
"Between the previous and next sequence point an object shall have its
stored value modified at most once by the evaluation of an expression.
Furthermore, the prior value shall be read only to determine the value
to be stored."
Regarding postfix incr
it sud b 19 naaa
x++ = 5
++x = 7
x++ = 7
5+7+7
On Sat, Aug 28, 2010 at 4:35 PM, jagadish wrote:
> I ran this code..
>
> int main() { int x=5;
> printf("%d",(x++ + ++x + x++));
> }
>
> The output printed was 18 instead of 19.. Should it not be 19?
>
> --
> You received this message because you
Ya after some reading i got to know that it was implementation
dependent..
And that the answer is undefined!
On Aug 28, 5:07 pm, Chi wrote:
> In php it is 19.
>
> $x=5;
> printf("%d",($x++ + ++$x + $x++));
> ?>
>
> On Aug 28, 1:35 pm, jagadish wrote:
>
> > I ran this code..
>
> > int main() {
In php it is 19.
On Aug 28, 1:35 pm, jagadish wrote:
> I ran this code..
>
> int main() { int x=5;
> printf("%d",(x++ + ++x + x++));
>
> }
>
> The output printed was 18 instead of 19.. Should it not be 19?
--
You received this message because you are subscribed to the Google Groups
"Algorit
I ran this code..
int main() { int x=5;
printf("%d",(x++ + ++x + x++));
}
The output printed was 18 instead of 19.. Should it not be 19?
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to algoge...@googlegr
@Rahul
#include
#include
int nondecresing_maxsum(int *a,int n,int k)
{ int sum=0,i,count=k+1,prev_num=a[0],*dp,count1=0;;
dp=(int *)malloc(sizeof(int)*(k+1));
for(i=0;ihttp://groups.google.com/group/algogeeks?hl=en.
@ Gene :
Output for
int a[] = { 14, 15, 16, 13, 11, 18 };
is coming out to be 14
whereas minimum cost will be : 8
--
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 unsubsc
Observation is very important here. Examples can make us more clear
about the issue.
For a given RN, we do count in two situations refered before
separately.
1. In the first situation the qualifying rectangles will have their
width w and height h being coprime. Thus the equation RN = h + w - 1
wi
28 matches
Mail list logo