Re: [algogeeks] Re: Microsoft Interview Question

2012-10-16 Thread atul anand
@jaspreet : i dont find much difference between using BFS or backtracking...which is doing similar to DFS. On Tue, Oct 16, 2012 at 4:28 AM, Jaspreet Singh wrote: > BFS > > > On Sun, Oct 14, 2012 at 4:21 PM, Rahul Kumar Patle < > patlerahulku...@gmail.com> wrote: > >> response awaited!!! >> an

Re: [algogeeks] Re: Microsoft Interview Question

2012-10-16 Thread Jaspreet Singh
its not the best i think and also not a dp solution but can be done by this. On Tue, Oct 16, 2012 at 4:28 AM, Jaspreet Singh wrote: > BFS > > > On Sun, Oct 14, 2012 at 4:21 PM, Rahul Kumar Patle < > patlerahulku...@gmail.com> wrote: > >> response awaited!!! >> anyone?? >> >> On Sat, Oct 13, 2012

Re: [algogeeks] Re: Microsoft Interview Question

2012-10-16 Thread Jaspreet Singh
BFS On Sun, Oct 14, 2012 at 4:21 PM, Rahul Kumar Patle < patlerahulku...@gmail.com> wrote: > response awaited!!! > anyone?? > > On Sat, Oct 13, 2012 at 12:31 AM, Rahul Kumar Patle < > patlerahulku...@gmail.com> wrote: > >> Pls help to solve this que.. does any one have DP solution for following >

[algogeeks] Re: Microsoft Interview Question

2012-10-16 Thread Don
void findPaths(int x, int y, int depth) { if (isEnd(x,y)) showSolution(); // One path will be marked by letters A,B,C... else { maze[x][y] = 'A' + depth; if (x && (maze[x-1][y]=='1')) findPaths(x-1,y,depth+1); if (y && (maze[x][y-1]=='1')) findPaths(x,y-1,depth+

[algogeeks] Re: Microsoft Interview Question

2012-10-15 Thread Rahul Kumar Patle
response awaited!!! anyone?? On Sat, Oct 13, 2012 at 12:31 AM, Rahul Kumar Patle < patlerahulku...@gmail.com> wrote: > Pls help to solve this que.. does any one have DP solution for following > que. > > http://www.geeksforgeeks.org/archives/24488 > section 5/question 2 > > Write a program to find

[algogeeks] Re: Microsoft interview qs

2012-07-09 Thread deepikaanand
@Atul thanx for the code its working for the example you took...Please check the same for i/p "abcmno","abcmnop" Algo displays:- mno It should display mno mnop... -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send em

Re: [algogeeks] Re: Microsoft Interview Question

2012-07-03 Thread coolfrog$
@All *Here is the working code: test on input {-1,5,3,-8,4,-6,9} and {1,-1,2}* Algo: increment current till first +ve number(p) and decerement end till last -ve number(n) now consider only array between [p..n] If current is negetive, increment current If current is positive, swap it with end and

[algogeeks] Re: Microsoft Interview Question

2012-06-30 Thread Dave
@Navin: If I am correctly executing your algorithm on the data in the original posting, {-1,5,3,-8,4,-6,9}, I get {-1,-6,-8,4,3,5,9}, when the correct answer is {-1,-8,-6,5,3,4,9}. The array contains the correct numbers, but the order of the positive numbers and the order of the negtive numbers

[algogeeks] Re: Microsoft Interview Question

2012-06-30 Thread Navin Gupta
@Dave :- a minor change Initially, decrement the end pointer till it points to positive number, Now end points to the last negative number. Now, If current is negative , increment current If current is positive , swap it with the element at end and decrement current and end both If current >=

[algogeeks] Re: Microsoft Interview Question

2012-06-29 Thread Dave
@Navin: Try this with {1,-1,2}. current points to the 1 and end points to the 2. Since 1 is positive, the algorithm swaps the 1 and the 2, giving {2,-1,1}. Then it decrements current to point outside the array and end to point to the -1. How can this be right? Dave On Thursday, June 28, 2012

[algogeeks] Re: Microsoft Interview Question

2012-06-29 Thread mohit
+1 naveen On Thursday, June 28, 2012 8:29:26 PM UTC+5:30, Navin Gupta wrote: > > Keep two pointers - one at start of the array and other at end of the > array > Now current points to start of the array > If current is negative , increment current > If current is positive , swap it with the elem

[algogeeks] Re: Microsoft Interview Question

2012-06-28 Thread Navin Gupta
Keep two pointers - one at start of the array and other at end of the array Now current points to start of the array If current is negative , increment current If current is positive , swap it with the element at end and decrement current and end both If current >= end , then break. Navin Kuma

[algogeeks] Re: Microsoft Interview Question

2012-06-28 Thread ANKIT BHARDWAJ
keep swaping left most -ve and left most positive untill counter reaches at the end of array, can be done in o(n) no extra space required.. 3rd year manit bhopal -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To view this discussion on

Re: [algogeeks] Re: Microsoft Interview Question

2012-06-22 Thread sanjay pandey
@wgp the ques is to maintain the order intact.. -- 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...@googlegr

Re: [algogeeks] Re: Microsoft Interview Question

2012-06-21 Thread Nishant Pandey
i mean o(n) in single traversal . On Fri, Jun 22, 2012 at 12:53 AM, sanjay pandey wrote: > single traversal n O(n) are 2 diff things...plz specify??? > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email t

Re: [algogeeks] Re: Microsoft Interview Question

2012-06-21 Thread rusty
Well they are the same you're going over an array once. As long as they are not nested they are still counted as O(n) because leading constants are dropped, at least that's what my acumen says. Need inputs on this guys! On Friday, June 22, 2012 12:53:02 AM UTC+5:30, suzi wrote: > > single traver

Re: [algogeeks] Re: Microsoft Interview Question

2012-06-21 Thread sanjay pandey
single traversal n O(n) are 2 diff things...plz specify??? -- 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...@g

Re: [algogeeks] Re: Microsoft Interview Question

2012-06-21 Thread Nishant Pandey
can this be done in single pass in O(n) . On Thu, Jun 21, 2012 at 8:10 PM, rusty wrote: > guys this is my solution to the problem, it's a bit sloppy but as far as I > checked it was working please have a go at it? > > > #include > #include > > int main() { > int arr1[] = {0,-5,3,0,4,-6

[algogeeks] Re: Microsoft Interview Question

2012-06-21 Thread rusty
guys this is my solution to the problem, it's a bit sloppy but as far as I checked it was working please have a go at it? #include #include int main() { int arr1[] = {0,-5,3,0,4,-6,-9}; int arr2[7]; int j = 0; for ( int i = 0 ; i < 7 ; i++ ) { //loop for -ve numbers

[algogeeks] Re: Microsoft Interview Question

2012-06-21 Thread Anchal Gupta
@akshat ur code doesn't give intact output, so i modified ur code and here is the code : int j=0,k=0; for (i = 0; i < n; ++i) { if(a[i]<0) { a[j] = a[i]; j++; } else { temp[k] = a[i]; k++; } } k=0; for (i = j; i < n; ++i) {

[algogeeks] Re: Microsoft Interview Question

2012-06-13 Thread shiv narayan
@ayush goel couldnt really understand your algo , can you please explain little bit more . On Wednesday, 13 June 2012 21:49:49 UTC+5:30, Krishna Kishore wrote: > > Given a array of integers both positive and negative and you need to shift > positive numbers to one side > and negative numbers to

[algogeeks] Re: Microsoft Interview Question

2012-05-23 Thread Navin.nitjsr
Root of a graph can be any node whose in-degree is zero. i.e. there are no nodes pointing to that node. It can be found by using O( |V| ) space and O( |E| ) time . Now we can choose any node whose in-degree is zero if present. or choose any random node and itf DFS-tree is the desired tree. Ti

Re: [algogeeks] Re: Microsoft interview question

2012-05-21 Thread Piyush Grover
@Partha try with: A = {2, 2, 9} B= {1, 6, 6} On Mon, May 21, 2012 at 7:08 PM, partha sarathi Mohanty < partha.mohanty2...@gmail.com> wrote: > a[] = [-1,-3,4,0,7,0,36,2,-3] > b[] = [0,0,6,2,-1,9,28,1,6] > b1[] = [0,7,0,36,4,-6,3,0,0] > b2[] =[-1,-3,11,0,0,0,35,0,0] > > suma = 42 proda = -

Re: [algogeeks] Re: Microsoft interview question

2012-05-21 Thread partha sarathi Mohanty
a[] = [-1,-3,4,0,7,0,36,2,-3] b[] = [0,0,6,2,-1,9,28,1,6] b1[] = [0,7,0,36,4,-6,3,0,0] b2[] =[-1,-3,11,0,0,0,35,0,0] suma = 42 proda = -84*72*3 sumb = 51 prodb = -84*72*3 sumb1 = 44 prodb1 = -84*72*3 sumb2 = 42 prodb2 = 33*35 do the sum and prod operation w/o 0s and compare the values..

Re: [algogeeks] Re: Microsoft interview question

2012-05-21 Thread partha sarathi Mohanty
@ashish.. it wont be constant space then.. surely it will be o(n) though On Mon, May 21, 2012 at 7:23 PM, Ashish Goel wrote: > Dave, > > Cant we have a hash table with the item as key and its count as value > (walk over array A and build HT). > For permutation check, walk over second array and s

Re: [algogeeks] Re: Microsoft interview question

2012-05-21 Thread Ashish Goel
constant space vs no additional space and then O(n) time complexity not possible.. Best Regards Ashish Goel "Think positive and find fuel in failure" +919985813081 +919966006652 On Mon, May 21, 2012 at 8:01 PM, Dave wrote: > @Ashish: Using a hash table violates the O(1) space requirement given

Re: [algogeeks] Re: Microsoft interview question

2012-05-21 Thread Dave
@Ashish: Using a hash table violates the O(1) space requirement given in the original problem. Dave On Monday, May 21, 2012 8:53:44 AM UTC-5, ashgoel wrote: > Dave, > > Cant we have a hash table with the item as key and its count as value > (walk over array A and build HT). > For permutation

[algogeeks] Re: Microsoft interview question

2012-05-21 Thread karthikeya s
in space On May 21, 6:53 pm, Ashish Goel wrote: > Dave, > > Cant we have a hash table with the item as key and its count as value (walk > over array A and build HT). > For permutation check, walk over second array and start reducing the count > and remove when count becomes zero for that particul

[algogeeks] Re: Microsoft interview question

2012-05-21 Thread karthikeya s
^not an O(n) On May 21, 6:53 pm, Ashish Goel wrote: > Dave, > > Cant we have a hash table with the item as key and its count as value (walk > over array A and build HT). > For permutation check, walk over second array and start reducing the count > and remove when count becomes zero for that part

Re: [algogeeks] Re: Microsoft interview question

2012-05-21 Thread Ashish Goel
Dave, Cant we have a hash table with the item as key and its count as value (walk over array A and build HT). For permutation check, walk over second array and start reducing the count and remove when count becomes zero for that particular key. If some char not there in HT, return false, else retu

[algogeeks] Re: Microsoft interview question

2012-05-21 Thread karthikeya s
No way u can do it in O(1) space and O(n) time.sols above are not gonna work..yeah, it is possible in O(n) space and O(n) time. On May 20, 12:29 am, HARSHIT PAHUJA wrote: > given 2 unsorted integer arrays a and b of equal size. Determine if b is a > permutation of a. Can this be done in O

Re: [algogeeks] Re: Microsoft interview question

2012-05-21 Thread Dave
@Piyush: Did you even try this on any examples? If not, try a = {0,1,2,3} and b = {0,2,2,2}. Dave On Sunday, May 20, 2012 1:39:25 AM UTC-5, Kalyan wrote: > Piyush. I think we can use your logic. But You should check the product > also. > Have 4 variables, sum_a,sum_b , prod_a, prod_b > > Ca

[algogeeks] Re: Microsoft interview question

2012-05-21 Thread Abhishek
@Gaurav: you are taking ia and ib as int so they will have 32 bits in Java. So you can not set the bits for numbers in the array greater than 32. e.g if you have a[i]=59876 so you would want to set the 59876th bit in ia : ia=ia | (1<<59876) but that is not possible. How do you handle this? Also how

Re: [algogeeks] Re: Microsoft interview question

2012-05-20 Thread Pralay Biswas
@Piyush: Try this i/p 8,0,0 ; 2,6,0-- Ur algo aint adequate.. On Sat, May 19, 2012 at 11:24 PM, Piyush Khandelwal < piyushkhandelwal...@gmail.com> wrote: > Hiii!! I have some idea about the solution. Please notify me if i am > wrong > > a= [ 4,3,5 ] and b= [ 3,5,4 ] > diff=0; > for (i=0; i

Re: [algogeeks] Re: Microsoft interview question

2012-05-20 Thread Kalyanasundaram
Piyush. I think we can use your logic. But You should check the product also. Have 4 variables, sum_a,sum_b , prod_a, prod_b Calculate Sum and product of array 'a' and store it in sum_a,prod_a Calculate Sum and product of array 'b' and store it in sum_b,prod_b if sum_a=sum_b && prod_a==prod_b the

Re: [algogeeks] Re: Microsoft interview question

2012-05-20 Thread atul anand
@piyush : your solution will fail for the case a={5,1,1} b={3,3,1} On Sun, May 20, 2012 at 11:54 AM, Piyush Khandelwal < piyushkhandelwal...@gmail.com> wrote: > Hiii!! I have some idea about the solution. Please notify me if i am > wrong > > a= [ 4,3,5 ] and b= [ 3,5,4 ] > diff=0; > for (i=0;

Re: [algogeeks] Re: Microsoft interview question

2012-05-19 Thread anuj agarwal
U are checking if the sum is same or not.. which can be same even if the elements are different. On Sun, May 20, 2012 at 11:54 AM, Piyush Khandelwal < piyushkhandelwal...@gmail.com> wrote: > Hiii!! I have some idea about the solution. Please notify me if i am > wrong > > a= [ 4,3,5 ] and b= [

Re: [algogeeks] Re: Microsoft interview question

2012-05-19 Thread Piyush Khandelwal
Hiii!! I have some idea about the solution. Please notify me if i am wrong a= [ 4,3,5 ] and b= [ 3,5,4 ] diff=0; for (i=0; i wrote: > @Harshit: These are a few unanswered questions that came to mind when I > read your solution attempt: What do you do with negative elements? What is > the -12t

[algogeeks] Re: Microsoft interview question

2012-05-19 Thread Dave
@Harshit: These are a few unanswered questions that came to mind when I read your solution attempt: What do you do with negative elements? What is the -12th prime number? How do you deal with overflow in the cases where you have a lot of large prime numbers and the product exceeds your native d

Re: [algogeeks] Re: Microsoft Interview Question

2012-03-14 Thread Umer Farooq
Well, the interviewer gave a hint to use hash-table. The key of hash-table will be memory address of original node and value will be the memory address of the new node. On Wed, Mar 14, 2012 at 9:43 PM, atul anand wrote: > @umer : did interviewer told any one of the solution provided in > the g

Re: [algogeeks] Re: Microsoft Interview Question

2012-03-14 Thread atul anand
@umer : did interviewer told any one of the solution provided in the given link below or different? http://www.geeksforgeeks.org/archives/1155 On Tue, Mar 13, 2012 at 11:31 AM, Umer Farooq wrote: > Yes that is exactly what they wanted. I proposed BFS for this solution. > Anyway, there was ano

[algogeeks] Re: Microsoft Interview Question

2012-03-13 Thread Gene
Sorry, a small test showed a loop quitting one iteration too soon. Here is the fix. import java.util.Random; public class ListCopy { class Node { int val; Node next, other; Node() { } Node(int val, Node next, Node other) { this.val = val;

[algogeeks] Re: Microsoft Interview Question

2012-03-13 Thread Gene
Copying a full graph requires a BFS or DFS. But here we have a big advantage. We know the nodes are linked in a single chain. So we don't need to search to find all nodes. We can just use .next pointers. No matter how we do things, we will need Map(A) that returns the copy of node A if it alre

[algogeeks] Re: Microsoft Interview Question

2012-03-13 Thread Gene
This problem is close to copying a graph. For that as you said, just do DFS or BFS and maintain a map from original nodes to copies. Use the copy to set pointers whenever it exists. When it doesn't exist, make a new node and add it to the map. You can implement the map in various ways. A hash t

Re: [algogeeks] Re: Microsoft Interview Question

2012-03-13 Thread Dheeraj Sharma
http://www.geeksforgeeks.org/archives/1155 On Tue, Mar 13, 2012 at 11:31 AM, Umer Farooq wrote: > Yes that is exactly what they wanted. I proposed BFS for this solution. > Anyway, there was another problem that I was able to solve; but the > interviewer brought up a much more efficient approach.

Re: [algogeeks] Re: Microsoft Interview Question

2012-03-13 Thread Umer Farooq
Yes that is exactly what they wanted. I proposed BFS for this solution. Anyway, there was another problem that I was able to solve; but the interviewer brought up a much more efficient approach. The problem was: - Given a linked a linked list with one pointer pointing to next, another poin

Re: [algogeeks] Re: Microsoft Interview Question

2012-03-13 Thread Umer Farooq
Yes that is exactly what they wanted. I proposed BFS for this solution. Anyway, there was another problem that I was able to solve; but the interviewer brought up a much more efficient approach. The problem was: Given a linked l On Mon, Mar 12, 2012 at 11:31 PM, Gene wrote: > Since there is no

[algogeeks] Re: Microsoft Interview Question

2012-03-12 Thread Gene
Since there is no mention of weights, you are looking for any spanning tree. Primm and Kruskal are for _minimum_ spanning tree. They are overkill for this problem. You can construct a spanning tree in any graph with DFS. Just record every edge you find that reaches a vertex that has never been vi

Re: [algogeeks] Re: microsoft interview

2011-09-26 Thread Ankur Garg
@Teja Bala U dont need the last line for a[0][0] else code will be wrong conside 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 Regards On Sun, Sep 11, 2011 at 11:56 PM, teja bala wrote: > //pseudo code dis will work for sure. > > for(i=0;i for(j=0;j { > if (a[i][j] == 1) >

Re: [algogeeks] Re: microsoft interview

2011-09-11 Thread teja bala
//pseudo code dis will work for sure. for(i=0;ihttp://groups.google.com/group/algogeeks?hl=en.

Re: [algogeeks] Re: microsoft interview

2011-09-11 Thread Ramakant Sharma
for(i=0;ihttp://groups.google.com/group/algogeeks?hl=en.

Re: [algogeeks] Re: microsoft interview

2011-09-10 Thread praveen raj
whts the question?? With regards, Praveen Raj DCE-IT 3rd yr 735993 praveen0...@gmail.com On Fri, Sep 9, 2011 at 12:17 PM, Amit Gupta wrote: > Guys, why don't we do something like this : > > 1. If (arrayHasBeenTraversed, Goto 4). >Else, Traverse the 2-D array [row,column] wise. In

[algogeeks] Re: microsoft interview

2011-09-08 Thread Amit Gupta
Guys, why don't we do something like this : 1. If (arrayHasBeenTraversed, Goto 4). Else, Traverse the 2-D array [row,column] wise. Inspect element array[row][column]. Goto 2. 2. If you encounter a '1' (array[row][column]), change all the 0's in the corresponding [row,column] to '-1' Al

[algogeeks] Re: microsoft interview

2011-09-02 Thread Vikram Singh
how abt this: if(!a[0][0]) { first traverse the 1st row till we find 1. if dere is 1 do a[0][0]+=2; then traverse the first column till 1.. if dere is 1... do a[0][0]+=3; } apply dave's method if(a[0][0]==2) make 1st row 1 else if(a[0][0]==3)

[algogeeks] Re: microsoft interview

2011-09-02 Thread Vikram Singh
how abt this: if(!a[0][0]) { first traverse the 1st row till we find any 1... On Sep 2, 12:32 pm, kranthi raj wrote: > oops missed Space Complexity > > > > > > On Fri, Sep 2, 2011 at 12:55 PM, kranthi raj wrote: > > for( i = 0 ; i < n ; ++i ) > >    for( j = 0 ; j < m ; ++j ) > >        if(

Re: [algogeeks] Re: microsoft interview

2011-09-02 Thread kranthi raj
oops missed Space Complexity On Fri, Sep 2, 2011 at 12:55 PM, kranthi raj wrote: > for( i = 0 ; i < n ; ++i ) >for( j = 0 ; j < m ; ++j ) >if( a[i][j] != 0 ) > row[j]=col[i]=1; > > > > for( i = 0 ; i < n ; ++i ) >for( j = 0 ; j < m ; ++j ) > >{ >if

Re: [algogeeks] Re: microsoft interview

2011-09-02 Thread kranthi raj
for( i = 0 ; i < n ; ++i ) for( j = 0 ; j < m ; ++j ) if( a[i][j] != 0 ) row[j]=col[i]=1; for( i = 0 ; i < n ; ++i ) for( j = 0 ; j < m ; ++j ) { if (row[j]==1 || col[i]==1) a[i][j]=1; } Does this work? -- You received this

Re: [algogeeks] Re: microsoft interview

2011-09-01 Thread rahul aravind
@dave:ur algo s nice:) On Thu, Sep 1, 2011 at 9:49 AM, Dave wrote: > @Piyush: What does it do on > > 0 0 0 > 0 0 0 > 1 0 0 > > The output should be > > 1 0 0 > 1 0 0 > 1 1 1 > > Dave > > On Aug 31, 8:24 pm, Piyush Grover wrote: > > What's wrong with this?? > > > > for( i = 0 ; i < n ; ++i ) > >

[algogeeks] Re: microsoft interview

2011-08-31 Thread Dave
@Piyush: What does it do on 0 0 0 0 0 0 1 0 0 The output should be 1 0 0 1 0 0 1 1 1 Dave On Aug 31, 8:24 pm, Piyush Grover wrote: > What's wrong with this?? > > for( i = 0 ; i < n ; ++i ) >    for( j = 0 ; j < m ; ++j ) >        if( a[i][j] != 0 ) >            a[i][0] = a[0][j] = 1; > for( i

Re: [algogeeks] Re: microsoft interview

2011-08-31 Thread Sanjay Rajpal
I think this code is perfect. Sanju :) On Thu, Sep 1, 2011 at 6:54 AM, Piyush Grover wrote: > What's wrong with this?? > > > for( i = 0 ; i < n ; ++i ) >for( j = 0 ; j < m ; ++j ) >if( a[i][j] != 0 ) >a[i][0] = a[0][j] = 1; > for( i = 0 ; i < n ; ++i ) >for( j = 0 ;

Re: [algogeeks] Re: microsoft interview

2011-08-31 Thread Piyush Grover
What's wrong with this?? for( i = 0 ; i < n ; ++i ) for( j = 0 ; j < m ; ++j ) if( a[i][j] != 0 ) a[i][0] = a[0][j] = 1; for( i = 0 ; i < n ; ++i ) for( j = 0 ; j < m ; ++j ) if( a[i][0] + a[0][j] != 0 ) a[i][j] = 1; On Thu, Sep 1, 2011 at 5:45 AM, Dave

[algogeeks] Re: microsoft interview

2011-08-31 Thread Dave
@Replying to my own posting: Propagating a[0][0] as in my most recent post isn't correct. Gene is correct to have two flags that indicate whether the first row and/or the first column are to be filled with 1s. Dave On Aug 31, 7:01 pm, Dave wrote: > @Icy: I forgot about a[0][0]. So I need to add

[algogeeks] Re: microsoft interview

2011-08-31 Thread Dave
@Icy: I forgot about a[0][0]. So I need to add a few lines at the end of my code, so that it becomes: for( i = 1 ; i < n ; ++i ) for( j = 1 ; j < m ; ++j ) if( a[i][j] != 0 ) a[i][0] = a[0][j] = 1; for( i = 1 ; i < n ; ++i ) for( j = 1 ; j < m ; ++j ) if( a[i][0

[algogeeks] Re: microsoft interview

2011-08-31 Thread Gene
You can use the first row and column as a scratchpad to keep track of which rows and columns need to be 1. Make one pass over the matrix to put 1's in the scratchpad locations. Then make a second pass checking the scratchpad to see of the square needs to be flipped to a 1. To make this scratchpad

[algogeeks] Re: microsoft interview

2011-08-31 Thread icy`
Dave has a nice idea but I cant get it to work =/ [[1, 0, 0, 1], [0, 0, 1, 0], [0, 0, 0, 0]] original matrix [[1, 0, 1, 1], [1, 1, 1, 1], [0, 0, 1, 1]] dave's [[1, 1, 1, 1], [1, 1, 1, 1], [1, 0, 1, 1]] expected Maybe I converted it wrong. My method was basically the same as Anup's -- 1st

[algogeeks] Re: microsoft interview

2011-08-31 Thread siva viknesh
@dave...additionally u ve to do this...checking the 1st row nd 1st column... if(a[0][0]) set both first row and first column; else for(i=1;i wrote: > dave s algo is nice :) > > On Aug 31, 10:09 pm, Dave wrote: > > > > > > > > > @Ashima: Scan all but the first row and the first column. If

[algogeeks] Re: microsoft interview

2011-08-31 Thread siva viknesh
dave s algo is nice :) On Aug 31, 10:09 pm, Dave wrote: > @Ashima: Scan all but the first row and the first column. If there is > a 1 in a row, set the first element of that row to 1. If there is a 1 > in a column, set the first element of that column to zero. Now, set > any element in all but th

[algogeeks] Re: microsoft interview

2011-08-31 Thread Dave
@Ashima: Scan all but the first row and the first column. If there is a 1 in a row, set the first element of that row to 1. If there is a 1 in a column, set the first element of that column to zero. Now, set any element in all but the first row and the first column of the matrix that has a 1 it the

Re: [algogeeks] Re: microsoft interview

2011-08-31 Thread Ashima .
@dave wats d logic behind ur code Ashima M.Sc.(Tech)Information Systems 4th year BITS Pilani Rajasthan On Wed, Aug 31, 2011 at 9:05 AM, Dave wrote: > @Manish: > > for( i = 1 ; i < n ; ++i ) >for( j = 1 ; j < m ; ++j ) >if( a[i][j] != 0 ) >a[i][0] = a[0][j] = 1; > for(

[algogeeks] Re: microsoft interview

2011-08-31 Thread Dave
@Manish: for( i = 1 ; i < n ; ++i ) for( j = 1 ; j < m ; ++j ) if( a[i][j] != 0 ) a[i][0] = a[0][j] = 1; for( i = 1 ; i < n ; ++i ) for( j = 1 ; j < m ; ++j ) if( a[i][0] + a[0][j] != 0 ) a[i][j] = 1; Dave On Aug 31, 8:40 am, manish kapur wrote: >

[algogeeks] Re: Microsoft Interview Qn

2011-07-17 Thread Dumanshu
@Ashish: if i got ur algo correct, contrary to all the above examples, u r forming a linked list of level order traversal of the tree. m i right? On Jul 17, 8:49 pm, Ashish Goel wrote: > 1. PUSH ROOT IN Q > 2. PUSH DUMMY NODE IN Q, DEFINE PREVIOUS NODE AS NULL > 3. WHILE Q IS NOT EMPTY > 3A. POP

Re: [algogeeks] Re: Microsoft Interview Qn

2011-07-17 Thread naveen ms
im a bit confused with child-sibling term, this expects output for input: A /\ B C / \ / \ DE F G output: A / B C / / DE FG -- You received this message because you are subscribed to the Google Gro

Re: [algogeeks] Re: Microsoft Interview Qn

2011-07-17 Thread sagar pareek
mine solution will give sample o/p 2. On Sun, Jul 17, 2011 at 9:08 PM, naveen ms wrote: > im a bit confused with child-sibling term, this expects output for > > input: > A > /\ > B C > / \ / \ > DE F G > > > output: > A > / > B--

[algogeeks] Re: Microsoft Interview Qn

2011-07-17 Thread Dumanshu
plz give some example..sry but what do you mean by child sibling version?? On Jul 16, 3:46 pm, Reynald wrote: > Given a Parent -Child binary tree ,build the child -sibling version of > it? > Minimize the space requirements wherever possible. -- You received this message because you are subscri

Re: [algogeeks] Re: Microsoft Interview Qn

2011-07-17 Thread sagar pareek
This can be done using single array too... :) :) Do anybody wants the code? On Sun, Jul 17, 2011 at 3:04 PM, sagar pareek wrote: > This can be done like this > > 1. find out the height of the tree > 2. make the number of arrays(node* pointers)=height of tree > 3. traverse the tree from root as

Re: [algogeeks] Re: Microsoft Interview Qn

2011-07-17 Thread sagar pareek
This can be done like this 1. find out the height of the tree 2. make the number of arrays(node* pointers)=height of tree 3. traverse the tree from root as arr0[0]=root; arr1[0]=root->left; arr1[1]=root->right arr2[0]=arr1[0]->left arr2[1]=arr1[1]->right . . . and so on not

Re: [algogeeks] Re: Microsoft Interview Qn

2011-07-16 Thread naveen ms
in this recursive code...the right link node will point to its sibling to the right (if it has) or else it will be null. the left link of the node will point to its child(if it has) or else it will be null. regards, Naveen CSE R.V.C.E, Bangalore. -- You received this message because you are sub

Re: [algogeeks] Re: Microsoft Interview Qn

2011-07-16 Thread surender sanke
im a bit confused with child-sibling term, this expects output for A /\ B C / \ / \ DE F G 1 A / B C / / DE FG 2 A / B-- C / DEFG is output expected 1 or 2 sure

[algogeeks] Re: Microsoft Interview Qn

2011-07-16 Thread DK
void convert(Node * root, Node* sibling) { if(root == NULL) return; convert(root->left, root->right); convert(root->right, NULL); root->right = sibling; } convert(root, NULL); -- DK http://twitter.com/divyekapoor http://www.divye.in -- You received this message because you are

Re: [algogeeks] Re: Microsoft interview question

2011-02-07 Thread Ashish Goel
I would assume that in addition to functional testing through automation(combination of various fonts,sizes etc) the tenets like reliability, accessibility, interoperability, security(fuzz testing), different architectures(amd, intel 32 bit, 64 bit etc), stress(extremely long file reaching space co

[algogeeks] Re: Microsoft interview question

2011-02-01 Thread Gene
Well, this is a white box test. In a wbt, you look for edge and corner cases. Edge cases in this scenario are the largest and smallest point sizes. The fonts with largest kerning values. Largest ascenders and descenders. Largest number of printable characters. You'd probably concentrate on

Re: [algogeeks] Re: Microsoft interview question

2010-12-12 Thread Amir hossein Shahriari
use suffix tree it's much faster than simple trie with ukkonen's method you can build it in O(size of document) and then searching in it is practically O(1) http://en.wikipedia.org/wiki/Suffix_tree http://www.cs.helsinki.fi/u/ukkonen/SuffixT1withFigs.pdf On Fri, Dec 10, 2010 at 7:54 PM, ADITYA KUM

Re: [algogeeks] Re: Microsoft interview question

2010-12-10 Thread ADITYA KUMAR
@ligerdave agree with u :) > -- Regards Aditya Kumar B-tech 3rd year Computer Science & Engg. MNNIT, Allahabad. -- 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 unsubscri

[algogeeks] Re: Microsoft interview question

2010-12-10 Thread ligerdave
@aditya there is always trade-off. for what it's asking, TRIE is probably the fastest. the problem already stated, using "data structure", which to me, means, you index a document. indexing is expensive, but it's overhead process and it has nothing to do w/ finding an existing word in a doc. On De

[algogeeks] Re: Microsoft interview question

2010-12-07 Thread Dave
It sets the rightmost bit to 0. Could also be done with q = len & ~1; Dave On Dec 7, 12:50 am, ritesh wrote: >  q = (len >> 1) << 1; > > what this line is accomplishing? > > On Dec 4, 12:38 pm, Abioy Sun wrote: > > > > > Hello, > > > 2010/12/4 siva viknesh : > > > >  Modified 2 color sort probl

Re: [algogeeks] Re: Microsoft interview question

2010-12-07 Thread Abioy Sun
2010/12/7 ritesh : >  q = (len >> 1) << 1; > what this line is accomplishing? q = len & 0xFFFE; -- 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 gro

[algogeeks] Re: Microsoft interview question

2010-12-06 Thread ritesh
q = (len >> 1) << 1; what this line is accomplishing? On Dec 4, 12:38 pm, Abioy Sun wrote: > Hello, > > 2010/12/4 siva viknesh : > > >  Modified 2 color sort problem i.e. you are given an array of integers > > containing only 0s and 1s.You have to place all the 0s in even > > position and 1s i

[algogeeks] Re: Microsoft interview question

2010-09-26 Thread dreamer .....................
@ ashita and vrinda can u please write ur ms written and interview questions.. i ll be really thankful to both of u as ms is going to visit my campus soon.. so plz help... On Sep 26, 1:58 pm, ashita dadlani wrote: > @Mohit: > I dont think it really matters here.We just have to validate the snaps

Re: [algogeeks] Re: Microsoft interview question

2010-09-26 Thread ashita dadlani
@Mohit: I dont think it really matters here.We just have to validate the snapshot of the game board.Number of players should not have any relevance here. On Sat, Sep 25, 2010 at 2:46 PM, mohit ranjan wrote: > @Ashita, > > Your logic is fine for one vs one game, but as per question it's "one vs >

Re: [algogeeks] Re: Microsoft interview question

2010-09-25 Thread mohit ranjan
@Ashita, Your logic is fine for one vs one game, but as per question it's "one vs many game" Any idea what is that ? Mohit On Sat, Sep 25, 2010 at 1:18 PM, ashita dadlani wrote: > 1.The soldiers are initially placed at row 2 or row 7th(each-one of white > and either of black).Also let white o

Re: [algogeeks] Re: Microsoft interview question

2010-09-24 Thread ashita dadlani
1.The soldiers are initially placed at row 2 or row 7th(each-one of white and either of black).Also let white ones be at row 2.So they can never be at row 1st.Incase it is so in the game,its not a valid game. 2.There are Bishops.Each color has one of its Bishop which moves diagonally on all white s

[algogeeks] Re: Microsoft interview question

2010-09-24 Thread Gene
Valid must mean that you can get from an initial board to the the current game state by a series of legal moves. This is a classic branch and bound game tree search problem. You could search either from a starting configuration and try to "find" the current game state. Or start from the current

Re: [algogeeks] Re: Microsoft interview question

2010-08-30 Thread Abhishek Shrivastav
its an infinite loop. Beware. On Mon, Aug 23, 2010 at 5:32 AM, Gene wrote: > This doesn't work on "abb" for example. > > On Aug 22, 9:28 am, Ashish Goel wrote: > > use a array > > arr[char]=count char represent say a-z > > count is # of occurances > > > > while (*s!='\0') > > { > > arr[*s-'a']+

[algogeeks] Re: Microsoft interview question

2010-08-22 Thread Gene
This doesn't work on "abb" for example. On Aug 22, 9:28 am, Ashish Goel wrote: > use a array > arr[char]=count char represent say a-z > count is # of occurances > > while (*s!='\0') > { > arr[*s-'a']++; > if (arr[*s-'a']==1) lastchar=*s; > > } > > lastchar is the last non repeating char > > Best

Re: [algogeeks] Re: Microsoft interview question

2010-08-22 Thread Ashish Goel
optimization, use bitmap instead of array... char can be unicode, char may take 1 or 2 bytes, that can be written, big deal.. Best Regards Ashish Goel "Think positive and find fuel in failure" +919985813081 +919966006652 On Sun, Aug 22, 2010 at 7:59 PM, Saikat Debnath wrote: > This is the answe

Re: [algogeeks] Re: Microsoft interview question

2010-08-22 Thread nipun batra
Maybe to reduce the memory usage and to include all types of characters we could create a one to one mapping between the character and the number of occurrences.And while retrieving start from reverse checking the mapping value,print if it's one. On Sun, Aug 22, 2010 at 7:59 PM, Saikat Debnath wro

[algogeeks] Re: Microsoft interview question

2010-08-22 Thread Saikat Debnath
This is the answer i have given and interviewer said, "Optimise it further in terms of memory and character need not be ASCII" On Aug 22, 6:28 pm, Ashish Goel wrote: > use a array > arr[char]=count char represent say a-z > count is # of occurances > > while (*s!='\0') > { > arr[*s-'a']++; > if (a

[algogeeks] Re: microsoft interview(numbers)

2010-07-10 Thread aejeet
@Luciano Your method seems very vague. Can you elaborate ? The input can have elements larger than 9. So will you keep count of those elements with a numeric array of size 10. Also, your second step is not clear. Pls elaborate On Jul 8, 8:17 pm, jalaj jaiswal wrote: > @ above > the