Re: [algogeeks] Find all the subarrays in a given array with sum=k

2016-03-23 Thread Saurabh Agrawal
Hi, This question was asked in Amazon interview few days back. Please explain to me the part after building the SUM array. With Regards, Saurabh Agrawal On Sun, Feb 21, 2016 at 9:08 PM, Saurabh Paliwal < saurabh.paliwa...@gmail.com> wrote: > Hi, > I can think of an approach tha

Re: [algogeeks] Openings in Mentor Graphics,Noida Location

2016-02-18 Thread Saurabh Agrawal
Hi, PFA. With Regards, Saurabh Agrawal On Tue, Nov 17, 2015 at 10:04 AM, Ashish kumar Jain wrote: > Anybody interested to join Mentor Graphics Noida having 1-10 years of > experience in C/C++/DS/Algo can forward his/her resume to me. > > Please understand that the opening needs

Re: [algogeeks] Facebook question!

2012-10-01 Thread saurabh agrawal
Do we need to handle cases when the same string will appear again?? In that case we can sort individual array and remove duplicates. On Mon, Oct 1, 2012 at 9:54 AM, Rahul Singh wrote: > check this out.. > > #include > #include > using namespace std; > > void print_sets(string *s,int pos,int n,ch

Re: [algogeeks] Re: Algo for Search in a 2D Matrix

2012-05-27 Thread saurabh agrawal
Yes, navin thats a good solution... ... we dont need to work on the whole array but of size k x k (k rows and k columsn only). Rest of the array we can simply ignore.. complexity of youngify is O(k) for every removing every element. we have to remove k-1 elements so complexity of whole operation

Re: [algogeeks] Cpp problem

2012-05-27 Thread saurabh agrawal
const allows this function to be called on constant object. So if someone creates an const obj of this class. Assignments can be done. On Mon, May 28, 2012 at 12:23 AM, amrit harry wrote: > complex_number const & operator =(complex_number & temp) const > { > return *this; > } > > > w

Re: [algogeeks] amazon

2012-05-27 Thread saurabh agrawal
r both are correct. > > On Mon, May 28, 2012 at 12:16 AM, saurabh agrawal wrote: > >> @atul: >> if i have understood .. >> ur solution will break when the string has repeated characters. >> >> e.g. for "baa" >> >> On Tue, May 22, 2012

Re: [algogeeks] amazon

2012-05-27 Thread saurabh agrawal
@atul: if i have understood .. ur solution will break when the string has repeated characters. e.g. for "baa" On Tue, May 22, 2012 at 3:43 PM, partha sarathi Mohanty < partha.mohanty2...@gmail.com> wrote: > sorry it was treeset Here is the code.. > > public class asd1 { > > > public static T

Re: [algogeeks] BST

2011-09-21 Thread saurabh agrawal
Do a BFS of the tree, keep a separator to masrk where a level ends.. create the linklist for every level. On Wed, Sep 21, 2011 at 6:00 PM, prasanth n wrote: > Given a binary search tree, design an algorithm which creates a linked list > of all the nodes at each depth (i.e., if you have a tree wi

Re: [algogeeks] Re: What is the time to get min element from the binary max heap !!

2011-09-20 Thread saurabh agrawal
wrote: > >> >> We can find minimum element in O(n) time. >> >> Just compare leaf nodes in max heap tree. >> >> >> >> Cheers >> Janardhan Reddy Cheruvu >> +91-9642421117 >> >> >> >> >> >> >> >

[algogeeks] Re: What is the time to get min element from the binary max heap !!

2011-09-20 Thread saurabh agrawal
I think, we have to delete all the elements from the heap which takes o(n*logn). Please share if you have any better solutions. On Tue, Sep 20, 2011 at 6:38 PM, saurabh agrawal wrote: > What is the time to get min element from the binary max heap !! > You might be given the heap as API.

[algogeeks] What is the time to get min element from the binary max heap !!

2011-09-20 Thread saurabh agrawal
What is the time to get min element from the binary max heap !! You might be given the heap as API. I mean, you dont have implementation of the heap. -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogee

Re: [algogeeks] Amazon question SDE

2011-09-20 Thread saurabh agrawal
n a[i] we will add s[i] as above then it can be possible > in O(1)... > > If i am wrong and it can be possible in O(log n) then plz tell.... > > > > On Tue, Sep 20, 2011 at 3:28 PM, saurabh agrawal wrote: > >> Design an algorithm to perform operation on an array >

[algogeeks] Amazon question SDE

2011-09-20 Thread saurabh agrawal
Design an algorithm to perform operation on an array Add(i,y)-> add value y to i position sum(i) -> sum of first i numbers we can use additional array O(n) and worst case performance should be O(log n) for both operation -- You received this message because you are subscribed to the Google Groups

[algogeeks] Amazon SDE onsite interview question

2011-09-20 Thread saurabh agrawal
Given an n-ary tree of resources arranged hierarchically. A process needs to lock a resource node in order to use it. But a node cannot be locked if any of its descendant or ancestor is locked. You are supposed to: -> write the structure of node -> write codes for Islock()- returns true if a given

Re: [algogeeks] URGENT suggestion REGARDING placement...............

2011-09-18 Thread saurabh agrawal
Vivek, if there are more god companies going to visit ur college, then u can wait for them. Everything depends on your interest, but if you want to go for pure coding companies, then u should skip delloite. Amazon is also coming for intern, u can wait for that.. Thanks Saurabh Agrawal BE CSE

[algogeeks] Building a max heap takes O(n) time irrespective of the array being sorted / unsorted.

2011-09-15 Thread saurabh agrawal
Building a max heap takes O(n) time irrespective of the array being sorted / unsorted. Can someone prove that. I already know that Heap can be constucted in o(n*log(n)) time. -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this gro

Re: [algogeeks] Re: Finding connection b/w 2 profiles

2011-09-13 Thread saurabh agrawal
@DON: DFS should not be applied because, there can exist multiple paths from A to C, but the question is to find the shortest path. So, u might end up getting longer path. Otherwise you have to search for all possible paths which will be very inefficient. Saurabh Agrawal On Tue, Sep 13

Re: [algogeeks] C Trick

2011-09-13 Thread saurabh agrawal
Priyanka.. ideally u should not use any function calls to solve this question.. because they internally might use conditional operators or if else.. OR u can give your own definition of abs() function With Regards Saurabh On Wed, Aug 24, 2011 at 11:06 PM, priyanka raju wrote: > > > It will work.

Re: [algogeeks] semaphores

2011-09-11 Thread saurabh agrawal
ke semaphores mutex does not have any list(of waiting processes) associated with it and just is a kind of lock and key model with no waiting THERE IS ONE THREAD WITH SUBJECT : MUTEX You cna search that for more clarity.. Thanks and Regards Saurabh Agrawal On Sat, Sep 10, 2011 at 10:52 AM,

Re: [algogeeks] Best Logic for List Flatting ( Double linked list )

2011-09-11 Thread saurabh agrawal
what do you mean by flatting?? Are all these questions asked in facebook.. would you like to share the links ?? On Sun, Sep 11, 2011 at 3:24 PM, Ishan Aggarwal < ishan.aggarwal.1...@gmail.com> wrote: > > > -- > Kind Regards > Ishan Aggarwal > [image: Aricent Group] > Presidency Tower-A, M.G.Road

Re: [algogeeks] c

2011-08-24 Thread saurabh agrawal
Does anyone has idea about what pacific asked for.? On Sun, Aug 21, 2011 at 11:01 AM, pacific :-) wrote: > Is const a compiler level construct ? > #include > > int main() { > const int i = 0; > int * p ; > p = (int *) & i; > *p = 2; > printf("(i,p): %x %x \n",&i,p); > printf("(i,p):

[algogeeks] Given an array, find out whether there exists a triplet which can form sides of triangle.

2011-08-22 Thread saurabh agrawal
Given an array, find out whether there exists a triplet which can form sides of triangle. You are not allowed to modify the array. PLease dont give o(n^3) solution there exists a solution with nlog(n) i think -- You received this message because you are subscribed to the Google Groups "Algorit

[algogeeks] Compute a+bx2+cx3+dx4+... efficiently (a,b,c...given)

2011-08-22 Thread saurabh agrawal
Compute a+bx2+cx3+dx4+... efficiently (a,b,c...given) -- 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 algogeeks+unsubscr...@google

Re: [algogeeks] Adobe Interview - 20/08/2011

2011-08-22 Thread saurabh agrawal
How did u solved : 3) There is a list containing the checkin and checkout time of every person in a party . The checkin time is in ascending order while the checkout is random . Eg: Check_inCheck_out Person 1 8.00 9.00

[algogeeks] Reverse of dutch national flag

2011-08-15 Thread saurabh agrawal
In a given array of elements like [a1, a2, a3, a4, . an, b1, b2, b3, b4, ... bn, c1, c2, c3, c4, cn] without taking a extra memory how to merge like [a1, b1, c1, a2, b2, c2, a3, b3, c3, an, bn, cn] ..??? Time complexity should be o(n). you can not use stack or any ot

Re: [algogeeks] Re: strings

2011-05-26 Thread saurabh agrawal
Gys, this problem can b esolved using dynamic programming in o n^2.l recursive/iterative approach wont work. Regards Saurabh On Thu, May 26, 2011 at 4:41 PM, sunny agrawal wrote: > @senthil > nopes, it will not work > eg. > S3 = "cba" > S1 = "a" > S2 = "bc" > count matches but not interleaved >

[algogeeks] how to convert a floating point number into binary representation.

2011-05-23 Thread saurabh agrawal
-- 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 algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at ht

[algogeeks] convert a number from one base to another.

2011-05-21 Thread saurabh agrawal
Hi, can someone give an algorithm to directly convert a number in a given base to a number in another base, without converting it into some another intermediate base. I have done that using some numerical analysis techniues, but dont remember now. Thanks in advance. -- You received this messag

Re: [algogeeks] Re: Google Q

2011-05-20 Thread saurabh agrawal
be in the min-heap. > > Dave > > On May 18, 8:29 am, saurabh agrawal wrote: > > Dave, > > u said:" a max-heap of the smallest > > half of the elements" > > but if the number are randomply generated, then how will you get to know > > whether a numb

Re: [algogeeks] Re: Google Q

2011-05-18 Thread saurabh agrawal
Dave, u said:" a max-heap of the smallest half of the elements" but if the number are randomply generated, then how will you get to know whether a number belongs to smallest half OR lager half.. i didnt got it... On Sat, May 14, 2011 at 9:10 PM, Dave wrote: > @Ashish: The idea is to keep two

Re: [algogeeks] Google ques

2011-04-10 Thread saurabh agrawal
& 15+4=19 > so we insert B={3,4,5,8,9,12,15,18} > & sum=3+4+5+8 =12+8=20 as sum>19 so no change > > 3,4,5,8,9,12,15,18,19,20, 20+B[0] =23 ,20+b[1]=24 ,25 so > on > > > > > On Fri, Apr 8, 2011 at 11:44 PM, Akash Agrawal > wr

[algogeeks] Google ques

2011-04-08 Thread saurabh agrawal
ou are given an array A of k values which contain int values in sorted (asec) order. Find top k values (asec) which can either be the number from the array A, or sum of any two numbers from A or sum of any three numbers from A. So, if A's values are represented as : a1,a2,...,ak , the possible numb

[algogeeks] random number generator

2011-03-17 Thread saurabh agrawal
Given a function which returns true 60% time and false 40% time. Using this function you have to write a function which returns true 50% of the time. -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algog

Re: [algogeeks] Re: Given an integer n , you have to print all the ways in which n can be represented as sum of positive integers

2011-03-11 Thread saurabh agrawal
oice will > affect the way you write the recursive function. > > Dave > > On Mar 11, 9:33 am, saurabh agrawal wrote: > > Given an integer n , you have to print all the ways in which n can be > > represented as sum of positive integers > > -- > You received this mes

[algogeeks] Given an integer n , you have to print all the ways in which n can be represented as sum of positive integers

2011-03-11 Thread saurabh agrawal
Given an integer n , you have to print all the ways in which n can be represented as sum of positive integers -- 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

Re: [algogeeks] Re: An interesting question

2011-03-08 Thread saurabh agrawal
@rajnish: i think u missed the point , the matrix is binary.. so how will you store -1 in it. @pacific: Will you solution work fine if 0 th row has all 1's and 0th column has atleast one zero.?? On Mon, Mar 7, 2011 at 1:09 AM, yogesh kumar wrote: > @pacific: Good Algorithm > > // This is the pr

Re: [algogeeks] Re: Construct Binary Tree From Ancestor Matrix

2011-03-08 Thread saurabh agrawal
1 2 3 4 1 0 1 1 0 2 0 0 1 0 3 0 0 0 0 4 0 1 1 0 Node numbers used in matrix are in bracket 5(3) | | 10(2) / \ / \ 12(1) 13(4) For every row in the matrix, calculate the number of non - zero numbers. This will give the level of that node in the tree. Now the node with level 0 is root. Traverse

Re: [algogeeks] Pairwise Sum & Array

2011-02-24 Thread saurabh agrawal
Last three values could be: 1.b+e 2.c+e 3.d+e On Thu, Feb 24, 2011 at 5:09 PM, ashish agarwal < ashish.cooldude...@gmail.com> wrote: > I think.. > As like no are a,b,c,d,e > so sum will be > a+b,a+c,a+d,a+e,b+c,b+d,b+e,c+d,c+e,d+e; > so maximuum value will be d+e which is last element of array gi

Re: [algogeeks] All numbers in Array repeat twice except two

2010-10-04 Thread saurabh agrawal
hi mukesh...gr8 solutioncan u pls help me with some other questions: --Given an array of n integers find all the inversion pairs in O(n) Inversion pair is one where a[i]>a[j], iwrote: > > The problem could be solved using xor logic. First take xor of all the > elements .Doing that we get a val

Re: [algogeeks] Re: next multiple of 8

2010-09-27 Thread saurabh agrawal
This problem is already solved. ans=(x|1)+1 On Mon, Sep 27, 2010 at 5:15 PM, nishaanth wrote: > try x+8-(x&7 ) > > On Sep 26, 4:47 am, Dave wrote: > > @Shrevan: I mistyped what I intended. Try answer = (x | 7) + 1; > > > > Dave > > > > On Sep 26, 5:51 am, Shravan wrote: > > > > > @Dave > > > Y

Re: [algogeeks] Re: Bitwise operator - Adobe

2010-09-25 Thread saurabh agrawal
Simple one line solution without looping and efficient : i=(i&7)?(i|7)+1:i) On Sun, Sep 26, 2010 at 8:43 AM, coolfrog$ wrote: > @Dave > very nice one line solution.. > we all are revolving around x>>3 concept... > > > On Sat, Sep 25, 2010 at 10:17 PM, Dave wrote: > >> answer = (x || 7) + 1

Re: [algogeeks] Re: Number problem

2010-09-21 Thread saurabh agrawal
t;} >n/=10; >} >return result; > } > > > Dave > > On Sep 21, 3:12 pm, saurabh agrawal wrote: > > int function(int n){ > > > > int a[10]={0}; > > int result =0; > > while(n){ > > if(a[n%10]==0){ > > a[n%10

Re: [algogeeks] Number problem

2010-09-21 Thread saurabh agrawal
int function(int n){ int a[10]={0}; int result =0; while(n){ if(a[n%10]==0){ a[n%10]=1; result=10*result+n%10; } n/=10; } return result;` } On Wed, Sep 22, 2010 at 12:39 AM, Albert wrote: > Given a number find the number by eliminating the duplicate digits in > the

Re: [algogeeks] Re: Explain

2010-09-10 Thread saurabh agrawal
Thanks a lot umesh...but still i am in confusion that: after first processing : "A is replaced by B" after second proecessing " B is replaced by A" then why again this A is not being replaced by #define A macro.. why it is not going in an infinite loop...because i think there is no fiexed order of

Re: [algogeeks] Explain

2010-09-09 Thread saurabh agrawal
@umesh kewat #include int main(){ int A =4; #define A B #define B A printf("%d",A); return 0; } This code works fine...but as you have explained the later A used in printf statement must have replaced by B. In that case there must be a compiler error "The identifier not defined". But this code co

[algogeeks] Explain

2010-09-09 Thread saurabh agrawal
Can somebody explain how the macros are expanded regarding order in which they are used...etc... also explain this example : #define A B #define B A what is the effect of this and whether it will go in an infinite recursive call or not and why? -- You received this message because you are subs

Re: [algogeeks] Re: how we can access 2nd element of an struct

2010-09-08 Thread saurabh agrawal
what if there are more than two elements? On Wed, Sep 8, 2010 at 10:00 PM, subramani s wrote: > struct list node; > a=(float *)((char *)a+sizeof(node)-4); > > correct me if i am wrong > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. >