Re: [algogeeks] Constant time solution needed

2012-08-11 Thread adarsh kumar
Sum of the integers meaning? Do you mind giving an example test case? regards. On Sat, Aug 11, 2012 at 7:10 PM, Srividhya srisam261...@gmail.com wrote: hi all:) The coordinates of a rectangle will be specified. there is a matrix of integers. yo should find the sum of the integers that fall

Re: [algogeeks] merging

2012-08-05 Thread adarsh kumar
Can you care to explain as to how exactly the elements are stored? Is it a vactor of strings?? On Mon, Aug 6, 2012 at 12:32 AM, Navin Kumar algorithm.i...@gmail.comwrote: Actually i wanted to do it inplace. Using extra space it is much easier problem. On Mon, Aug 6, 2012 at 12:27 AM, payal

Re: [algogeeks] merging

2012-08-05 Thread adarsh kumar
vector* On Mon, Aug 6, 2012 at 1:02 AM, adarsh kumar algog...@gmail.com wrote: Can you care to explain as to how exactly the elements are stored? Is it a vactor of strings?? On Mon, Aug 6, 2012 at 12:32 AM, Navin Kumar algorithm.i...@gmail.comwrote: Actually i wanted to do it inplace

Re: [algogeeks] merging

2012-08-05 Thread adarsh kumar
this way. On Mon, Aug 6, 2012 at 1:02 AM, adarsh kumar algog...@gmail.com wrote: vector* On Mon, Aug 6, 2012 at 1:02 AM, adarsh kumar algog...@gmail.com wrote: Can you care to explain as to how exactly the elements are stored? Is it a vactor of strings?? On Mon, Aug 6, 2012 at 12:32 AM, Navin

Re: [algogeeks] Appropriate data structure

2012-07-17 Thread adarsh kumar
For using a stack in order to achieve O(n) time, we can modify push and pop as follows(assuming we want max): While pushing, compare the top of the stack with the element to be pushed(say x). If xtop, just push normally. Else, pop elements until topx. Keep an eye on the border cases as well. Thus

Re: [algogeeks] Appropriate data structure

2012-07-15 Thread adarsh kumar
Min or max heap accordingly. This will do the job in O(log n) time. On Sun, Jul 15, 2012 at 1:25 AM, Navin Kumar algorithm.i...@gmail.comwrote: A set of integer values are being received (1 per day). Store these values and at any given time, retrieve the min and max value over the last k days.

Re: [algogeeks] Appropriate data structure

2012-07-15 Thread adarsh kumar
disturbed. How are last k values accessed then? On Sunday, 15 July 2012 12:46:02 UTC+5:30, adarsh kumar wrote: Min or max heap accordingly. This will do the job in O(log n) time. On Sun, Jul 15, 2012 at 1:25 AM, Navin Kumar algorithm.i...@gmail.comwrote: A set of integer values

Re: [algogeeks] Re: Amazon Interview Question

2012-07-13 Thread adarsh kumar
@jatin: Your first method may be proved wrong. Here is a counter test case: Suppose the array is: 27 729 19683 2 3 3 27 3 81 729 Here, 81 occurs once, 19683 occurs once, 2 occurs once,729 occurs twice, 27 occurs twice, and 3 occurs thrice. You are supposed to return 3 But as per your method,

RE: [algogeeks] Re: Amazon Interview Question

2012-07-13 Thread adarsh kumar
, Jul 13, 2012 at 5:17 PM, adarsh kumar algog...@gmail.com wrote: @jatin: Your first method may be proved wrong. Here is a counter test case: Suppose the array is: 27 729 19683 2 3 3 27 3 81 729 Here, 81 occurs once, 19683 occurs once, 2 occurs once,729 occurs twice, 27 occurs twice

RE: [algogeeks] Re: Amazon Interview Question

2012-07-13 Thread adarsh kumar
the readability we can use them and ther's no harm in it! Secondly the worst case for my algo is o(n) .?..correct me if i am wrong On Friday, 13 July 2012 18:12:41 UTC+5:30, adarsh kumar wrote: Ya I didn't see that part, sorry. And in general, using goto is not advisable. Plus this will exceed O(n

Re: [algogeeks] Max sum circular array

2012-07-10 Thread adarsh kumar
This is similar to maximum sum contiguous subarray problem. Consider the circular array as a normal array, except that once you reach the end of the array, if the sum found upto that element(using Kandane's algo, refer Wiki) is negative, then try including elements from the beginning of the

Re: [algogeeks] C o/p

2012-07-08 Thread adarsh kumar
Firstly, this is ambiguous and expressions with multiple increment/decrement operators will get executed according to the compiler. Even if you consider the normal way, as we(humans) percieve it, it will be evaluated as (++i)/(i++), which is 6/5, which is 1. Simple! On Sun, Jul 8, 2012 at

Re: [algogeeks] C o/p

2012-07-08 Thread adarsh kumar
Sorry, its 6/6 and not 6/5, regds. On Sun, Jul 8, 2012 at 10:39 PM, adarsh kumar algog...@gmail.com wrote: Firstly, this is ambiguous and expressions with multiple increment/decrement operators will get executed according to the compiler. Even if you consider the normal way, as we(humans

Re: [algogeeks] Finding intersection of 2 linked lists

2012-07-05 Thread adarsh kumar
Hope the following will be of help: http://www.geeksforgeeks.org/archives/18615 regds. On Thu, Jul 5, 2012 at 4:32 PM, Abhishek Sharma abhi120...@gmail.comwrote: @nishant, you wrote until both the distance becomes equal.Which distances ? Could you please elaborate ? On Thu, Jul 5, 2012 at

Re: [algogeeks] serialize a binary tree

2012-07-04 Thread adarsh kumar
Serialisation meaning? Numbering the nodes. Any specific order, or as in level order?? On 7/4/12, Ashish Goel ashg...@gmail.com wrote: a] How would you serialize a binary tree in a file(improve it) b] serialization that you have chosen, write a code to reconstruct the tree Best Regards Ashish

Re: [algogeeks] MS Question: Segregrate positive and negative nos in array without changing order

2012-06-29 Thread adarsh kumar
Quick sort partition routine variation. On Fri, Jun 29, 2012 at 3:06 PM, Ravi Ranjan ravi.cool2...@gmail.comwrote: one can modify dutch national flag algo for two colors(2 types positive n negative) -- You received this message because you are subscribed to the Google Groups Algorithm

[algogeeks] Switch doubt in C

2012-06-29 Thread adarsh kumar
Doubt, very trivial though: #includestdio.h int main() { int x=3; switch(x) { case 1: x=1; break; case 2: x=2; break; case 3: x=3; break; default: x=0; break; case

Re: [algogeeks]

2012-06-29 Thread adarsh kumar
l-values(left, literal meaning) appear on the lhs of a statement, and r-values vice versa. Essentially, l-values are identifiers. The memory location that will be thereby allocated can vary for r-values. Put in short, all l-values are r-values but not all r-values are l-values. And ++x++, will

Re: [algogeeks] Find peak element in log(n)

2012-06-24 Thread adarsh kumar
that array is bitonic is given. -- Prakhar Jain IIIT Allahabad B.Tech IT 3rd Year Mob no: +91 9454992196 E-mail: rit2009...@iiita.ac.in jprakha...@gmail.com On Sun, Jun 24, 2012 at 1:45 AM, Sourabh Singh singhsourab...@gmail.comwrote: @adarsh kumar are u sure it's worst case

Re: [algogeeks] Find peak element in log(n)

2012-06-23 Thread adarsh kumar
This is a variation of binary search, the difference being that we have to search for an element that is greater than its immediate left one and lesser than its immediate right one. Just implement binary search with these additional constraints, thereby giving O(log n). In case of any

Re: [algogeeks] Re: Directi question-centre of the tree

2012-06-20 Thread adarsh kumar
As you traverse along and find the diameter of the tree, keep track of the number of nodes thereby traversed. Let that be equal to n. Now, centre is the node corresponding to floor((n+1)/2). On Wed, Jun 20, 2012 at 5:19 PM, Nishant Pandey nishant.bits.me...@gmail.com wrote: I am asking again

Re: [algogeeks] Double Linked List Represented With Single Linked List

2012-06-20 Thread adarsh kumar
Simple! Just traverse the doubly linked list and keep track of next and previous of each node, and do XOR and save the result in a new pointer, what according to you is np. Be careful about boundary cases, i.e head and tail, though. On Wed, Jun 20, 2012 at 5:16 PM, Krishna Kishore

Re: [algogeeks] Re: Microsoft question

2012-06-19 Thread adarsh kumar
This can be done using the concept of median of medians, wherein we can achieve linear time complexity in the worst case. This is a concept used in parallel algorithms too, check it out. On Mon, Jun 18, 2012 at 5:38 PM, Prem Nagarajan prem.cmna...@gmail.comwrote: @enchantress : This problem can

Re: [algogeeks] I need

2012-06-18 Thread adarsh kumar
This is typical knapsack problem. On Mon, Jun 18, 2012 at 10:33 AM, Rituraj worstcod...@gmail.com wrote: Hi, I am trying to solve this problem. http://www.spoj.pl/problems/SCUBADIV/ But I am getting a lot of WA! Any good logic(solution) to solve the problem? Thanks in advance for your

[algogeeks] adarsh kumar wants to chat

2012-05-22 Thread adarsh kumar
--- adarsh kumar wants to stay in better touch using some of Google's coolest new products. If you already have Gmail or Google Talk, visit: http://mail.google.com/mail/b-838f0088c8-7ce2f0cfbf-whddt6Y3xfr109-a6qqOkRZmhu0 You'll

Re: [algogeeks] Partition the array with equal average

2012-05-18 Thread adarsh kumar
You can reduce this problem to the sum-subset problemhttp://en.wikipedia.org/wiki/Subset_sum_problem . Let A be the array. Compute S = A[0] + ... + A[N-1], where N is the length of A. For k from1 to N-1, let T_k = S * k / N. If T_k is an integer, then find a subset of A of size k that sums to

Re: [algogeeks] Re: find where the two list connect

2012-05-02 Thread adarsh kumar
Simple, refer this: http://www.geeksforgeeks.org/archives/2405 On Wed, May 2, 2012 at 1:12 AM, Abhishek Sharma jkabhishe...@gmail.comwrote: @Bhupendra: your approach is correct but in case the linked lists contain millions of nodes then this might be an overhead. Another approach could be:

Re: [algogeeks] Re: Google

2012-03-05 Thread adarsh kumar
Which college? On Sun, Mar 4, 2012 at 10:16 AM, teja bala pawanjalsa.t...@gmail.comwrote: Google is visiting our campus 4 different roles As of now IT field technician is confirmed so how to approach 4 written test. ?? -- You received this message because you are subscribed to the

[algogeeks] OFF TOPIC(QUERY)

2012-02-05 Thread adarsh kumar
hi friends I will be takng up amazon online test in a few days. Can any1 temme wat r the areas to concentrate on for this,and for their interviews? It would be great if sum1 can provide some info regarding this. regards, adarsh. -- You received this message because you are subscribed to the

Re: [algogeeks]

2012-01-27 Thread adarsh kumar
U can easily find out the number of 1's in the numbers between 0 to N(written in 2's complement form),by using a recurrence relation.Let it be equal to ans(N). Thus required answer is nothing but ans(N)-ans(N-1)+1. correct me if im wrong. On Fri, Jan 27, 2012 at 11:05 PM, Sourabh Singh