Re: [algogeeks] Microsoft Interview Question

2012-10-18 Thread Navin Kumar
@rahul: I got my fault. I didn't thought about that test case. I am thinking about applying DFS traversal algorithm for graph here. It may work here. On Wed, Oct 17, 2012 at 9:01 AM, Rahul Kumar Patle patlerahulku...@gmail.com wrote: @navin: still i am not getting your solution.. can you make

Re: [algogeeks] Microsoft Interview Question

2012-10-16 Thread Rahul Kumar Patle
@atul: in your solution object only can move down or right direction. but in my problem object is free to move in any direction and hence there are ch ances of cycle.. how to memoize cycle. if there is cycle then your approach will give infinite solution. consider this maze 1 1 0 0 0 1 1 0

Re: [algogeeks] Microsoft Interview Question

2012-10-16 Thread Navin Kumar
@Rahul: Loop won't occur because when you are visiting any matrix element then you are marking 1 in visited matrix. So second time it will be seen as a already visited element and it will choose another element (or path if exist) or will blocked. On Tue, Oct 16, 2012 at 9:31 AM, Rahul Kumar Patle

Re: [algogeeks] Microsoft Interview Question

2012-10-16 Thread atul anand
@Rahul : yes i know and actually i posted this query on geeksforgeeks. you can find my solution in comments , search for atul007 in the provided link.It will work for all cases. now to find all path you need to do small modification on the same code. On Tue, Oct 16, 2012 at 9:31 AM, Rahul Kumar

[algogeeks] Microsoft Interview Question

2012-10-15 Thread Rahul Kumar Patle
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 all the possible paths from a starting point to dest point in a maze(2-D array). ex: 1 0 1 0 1 1 1 1 0 1 0 1

Re: [algogeeks] Microsoft Interview Question

2012-10-15 Thread atul anand
can be done simply by backtracking . 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

Re: [algogeeks] Microsoft Interview Question

2012-10-15 Thread atul anand
http://www.geeksforgeeks.org/archives/13376 On Tue, Oct 16, 2012 at 8:56 AM, atul anand atul.87fri...@gmail.com wrote: can be done simply by backtracking . 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

Re: [algogeeks] Microsoft Interview Question

2012-06-21 Thread Abhishek Sharma
find the element nearest to zero.make it pivot element.then apply one pass of quicksort over the array.this is O(n) On Thu, Jun 21, 2012 at 12:27 AM, Akshat Sapra sapraaks...@gmail.comwrote: void make_group( int a[], int size) { int j = 0; for ( int i = 0; i size; i++ ) {

Re: [algogeeks] Microsoft Interview Question

2012-06-21 Thread Rishabh Agarwal
@Abhi: if you apply quick sort then again the order will will not be intact -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/ic2CXJXSGuoJ. To post to this

Re: [algogeeks] Microsoft Interview Question

2012-06-20 Thread Akshat Sapra
void make_group( int a[], int size) { int j = 0; for ( int i = 0; i size; i++ ) { if ( a[i] 0 ) { swap(a[i],a[j]); j++; } } } -- Akshat Sapra Under Graduation(B.Tech) IIIT-Allahabad(Amethi Campus)

Re: [algogeeks] Microsoft Interview Question

2012-06-15 Thread Guneesh Paul Singh
void change(int a[],int n) { int i,j; i=0; j=1; while(injn) { if(ji) j=i+1; else if(a[j]0a[i]0) { swap(a,j,i); } else { if(a[j]0) j++; else i++; }

Re: [algogeeks] Microsoft Interview Question

2012-06-15 Thread Shubham Sandeep
@guneesh your code fails to keep order b/w 3 and 4 in the above example On Fri, Jun 15, 2012 at 2:40 PM, Guneesh Paul Singh gunees...@gmail.comwrote: void change(int a[],int n) { int i,j; i=0; j=1; while(injn) { if(ji) j=i+1; else

Re: [algogeeks] Microsoft Interview Question

2012-06-14 Thread Mad Coder
As nothing is written about space complexity, I am assuming that we can take extra space. Take a temporary array of length n. 1. Maintain a counter for the length of temporary array filled till now. 2. Traverse the given array. If value contained is negative insert it in new array and update

Re: [algogeeks] Microsoft Interview Question

2012-06-14 Thread Manikanta Babu
Check this out, it works in O(n); int i = 0; int j = n-1; while((in j= 0)(ij)) { if(a[i]0 a[j]0) { swap(a[i],a[j]); i++; j--; } else {

Re: [algogeeks] Microsoft Interview Question

2012-06-14 Thread saurabh singh
Order may not be maintained necessarily by this solution Saurabh Singh B.Tech (Computer Science) MNNIT blog:geekinessthecoolway.blogspot.com On Thu, Jun 14, 2012 at 1:47 PM, Manikanta Babu manikantabab...@gmail.comwrote: Check this out, it works in O(n); int i = 0; int j =

Re: [algogeeks] Microsoft Interview Question

2012-06-14 Thread utsav sharma
@all :- by segregating 0 and 1 or by taking quicksort approach we have to swap no.s resulting which array becomes unordered. my approach is start from right and if a negative no. occurs insert it into another array temp[] this will shift all positive no.s to right and in 2nd pass start from left

Re: [algogeeks] Microsoft Interview Question

2012-06-14 Thread nadeem khan
how to do it in space comp- O(1) . I mean without using additional arrays. Could it be done ? On Thu, Jun 14, 2012 at 3:46 PM, utsav sharma utsav.sharm...@gmail.comwrote: @all :- by segregating 0 and 1 or by taking quicksort approach we have to swap no.s resulting which array becomes

[algogeeks] Microsoft Interview Question

2012-06-13 Thread Krishna Kishore
Given a array of integers both positive and negative and you need to shift positive numbers to one side and negative numbers to other side with the order intact. ex. {-1,5,3,-8,4,-6,9} to {-1,-8,-6,5,3,4,9}. This should be done in O(n). -- You received this message because you are subscribed

Re: [algogeeks] Microsoft Interview Question

2012-06-13 Thread Ashish Goel
int i=0; int j=n-1; while (ij) { while (ij) (a[i]=0) i++; while (ij) (a[j0) j--; if (ij) swap(a[i],a[j]); else break; i++; j--; } Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 On Wed, Jun 13, 2012 at 9:49 PM, Krishna Kishore

Re: [algogeeks] Microsoft Interview Question

2012-06-13 Thread Saurabh Yadav
+1 Ashish solution -- Thanks Regards Saurabh Yadav -- 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

Re: [algogeeks] Microsoft Interview Question

2012-06-13 Thread Saurabh Yadav
@shiv relate the ashish solution with quick sort then you will understand easily On Thu, Jun 14, 2012 at 2:06 AM, Saurabh Yadav saurabh...@gmail.com wrote: +1 Ashish solution -- Thanks Regards Saurabh Yadav -- Thanks Regards Saurabh Yadav -- You received this message because you

Re: [algogeeks] Microsoft Interview Question

2012-06-13 Thread Piyush Kapoor
@Ashish @Saurabh , Recheck your solutions , order won't be maintained in your solutions. Its output will be = {-1 -6 -8 3 4 5 9 } On Thu, Jun 14, 2012 at 2:08 AM, Saurabh Yadav saurabh...@gmail.com wrote: @shiv relate the ashish solution with quick sort then you will understand easily On

Re: [algogeeks] Microsoft Interview Question

2012-06-13 Thread saurabh singh
Think of the +ve numbers as 0 negative numbers as 1.Now the problem reduces to http://stackoverflow.com/questions/682171/arrange-0s-1s-in-a-array Saurabh Singh B.Tech (Computer Science) MNNIT blog:geekinessthecoolway.blogspot.com On Thu, Jun 14, 2012 at 3:00 AM, Piyush Kapoor

Re: [algogeeks] Microsoft interview question

2012-05-21 Thread Mithun Kumar
By doing Ex-OR we can find if b is permutation of A suppose a -- 3 5 4 b -- 4 3 5 if A ^ B = 0 then both are permutation or else not shout loud if this has flaws :P -mithun On Sun, May 20, 2012 at 12:59 AM, HARSHIT PAHUJA hpahuja.mn...@gmail.comwrote: given 2 unsorted

Re: [algogeeks] Microsoft interview question

2012-05-21 Thread monish001
@mithun: Try A = 1, 6 B = 4, 3 A ^ B = 0. Alone Ex-OR cant solve this in O(n) time. On Monday, 21 May 2012 21:48:30 UTC+5:30, mithun wrote: By doing Ex-OR we can find if b is permutation of A suppose a -- 3 5 4 b -- 4 3 5 if A ^ B = 0 then both are permutation or else

Re: [algogeeks] Microsoft interview question

2012-05-20 Thread atul anand
it can be done by doing set of operation on the data. 1) check sum of the square of arr1 = arr2 2) sum of elements of arr1=arr2 3) xoring elements of arr1 and arr2 == 0 if all 3 condition are successful then..permutation found. On Sun, May 20, 2012 at 12:59 AM, HARSHIT PAHUJA

Re: [algogeeks] Microsoft interview question

2012-05-20 Thread Darpan Baweja
@atul:- why we require 1st condition(check sum of the square of arr1 = arr2) ?? On Sun, May 20, 2012 at 1:10 PM, atul anand atul.87fri...@gmail.com wrote: it can be done by doing set of operation on the data. 1) check sum of the square of arr1 = arr2 2) sum of elements of arr1=arr2 3) xoring

[algogeeks] Microsoft interview question

2012-05-19 Thread HARSHIT PAHUJA
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(n) time and O(1) space ? please help me with my solution suppose a -- 3 5 4 b -- 4 3 5 now we replace a[i] with a[i]..th prime number and b with b[i] .. th

Re: [algogeeks] Microsoft interview question

2012-05-19 Thread malay chakrabarti
method is ryt but to find ith prime u cannot to it in constant time. On May 19, 2012 7:30 PM, HARSHIT PAHUJA hpahuja.mn...@gmail.com 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(n) time and O(1) space ? please

Re: [algogeeks] Microsoft interview question

2012-05-19 Thread HARSHIT PAHUJA
@malay --- we can do it by precomputing the prime arrays On Sun, May 20, 2012 at 1:10 AM, malay chakrabarti m1234...@gmail.comwrote: method is ryt but to find ith prime u cannot to it in constant time. On May 19, 2012 7:30 PM, HARSHIT PAHUJA hpahuja.mn...@gmail.com

Re: [algogeeks] Microsoft interview question

2012-05-19 Thread malay chakrabarti
dat defeats the o(1) space constraint. :-) On May 19, 2012 8:05 PM, HARSHIT PAHUJA hpahuja.mn...@gmail.com wrote: @malay --- we can do it by precomputing the prime arrays On Sun, May 20, 2012 at 1:10 AM, malay chakrabarti m1234...@gmail.comwrote: method is ryt but to

[algogeeks] Microsoft Interview Question

2012-03-12 Thread Umer Farooq
Hello friends, I recently had an onsite MS interview. One of the questions that they asked was: - Given a directed graph, write a program that takes root of the graph and returns root of a tree which comprises of all the nodes of the graph in the same way as they appeared in the graph

[algogeeks] MicroSoft Interview Question-9 February 2011

2011-02-09 Thread Divesh Dixit
1. write a function to convert a decimal no. to Roman no. (10 marks) 2. Design a elevators system for 50 storied hotel. condition are... at least one left should be available on ground flore. Min. time is expected ot reach the any floore... (5 marks) 3. Design all the test case for

[algogeeks] Microsoft interview question

2011-02-01 Thread HARISH S.C
We have a text editor application where we can choose 1)between 100s of different fonts like arial,calibri,etc.. 2)different text sizes 3) different formatting such as bold, Italics,regular,etc.. Imagine that the application is similar to word(there we will have these options). Now give different

Re: [algogeeks] Microsoft interview question

2011-02-01 Thread Sarma Tangirala
: HARISH S.C s.c.har...@gmail.com Sender: algogeeks@googlegroups.com Date: Wed, 2 Feb 2011 01:14:00 To: algogeeks@googlegroups.com Reply-To: algogeeks@googlegroups.com Subject: [algogeeks] Microsoft interview question We have a text editor application where we can choose 1)between 100s of different

Re: [algogeeks] Microsoft interview question

2011-02-01 Thread HARISH S.C
from my BlackBerry -- *From: * HARISH S.C s.c.har...@gmail.com *Sender: * algogeeks@googlegroups.com *Date: *Wed, 2 Feb 2011 01:14:00 +0530 *To: *algogeeks@googlegroups.com *ReplyTo: * algogeeks@googlegroups.com *Subject: *[algogeeks] Microsoft interview question We

Re: [algogeeks] Microsoft interview question

2011-02-01 Thread Sarma Tangirala
? Sent from my BlackBerry -- *From: * HARISH S.C s.c.har...@gmail.com *Sender: * algogeeks@googlegroups.com *Date: *Wed, 2 Feb 2011 01:14:00 +0530 *To: *algogeeks@googlegroups.com *ReplyTo: * algogeeks@googlegroups.com *Subject: *[algogeeks] Microsoft interview

[algogeeks] microsoft interview question

2010-12-17 Thread anujbhambhani
write a recursive function to convert a BST into sorted doubly linked list. -- 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

Re: [algogeeks] microsoft interview question

2010-12-17 Thread DIPANKAR DUTTA
see careercup.com On Sat, Dec 18, 2010 at 1:49 AM, anujbhambhani anuj.bhambh...@gmail.comwrote: write a recursive function to convert a BST into sorted doubly linked list. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this

Re: [algogeeks] microsoft interview question

2010-12-17 Thread Saurabh Koar
http://cslibrary.stanford.edu/109/TreeListRecursion.html -- 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

[algogeeks] Microsoft interview question

2010-12-12 Thread ebrima saye
I can only think of one way off the top of my head: class IndexedDocument { HashTableString, int index; String contents; /// Build an index of words and their position in the document void buildIndex() { for each word in document { add word, position to index

[algogeeks] Microsoft interview question

2010-12-10 Thread GOBIND KUMAR
Help me in solving this problem... Define a data struct for the search engine which will represent whether given word is there in the document or not .It should be fast. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this

Re: [algogeeks] Microsoft interview question

2010-12-10 Thread ankit sablok
just search for the word in the document using an efficient string matching algorithm use Knuth Morris Pratt algorithm as it runs in O(m) time. or use a data structure called TRIE where u can search for the word in O(1) time any suggestions are always welcomed On Fri, Dec 10, 2010 at 3:13 PM,

Re: [algogeeks] Microsoft interview question

2010-12-10 Thread ADITYA KUMAR
@ankit u can'nt use TRIE becoz , input will be given in form of text so generating the TRIE will be much expensive than linear search On Fri, Dec 10, 2010 at 3:13 PM, GOBIND KUMAR gobind@gmail.com wrote: Help me in solving this problem... Define a data struct for the search engine

Re: [algogeeks] Microsoft interview question

2010-12-10 Thread manoj lalavat
it will give you an idea. http://en.wikipedia.org/wiki/Full_text_search On Fri, Dec 10, 2010 at 4:03 PM, ADITYA KUMAR aditya...@gmail.com wrote: @ankit u can'nt use TRIE becoz , input will be given in form of text so generating the TRIE will be much expensive than linear search On Fri,

Re: [algogeeks] Microsoft interview question

2010-12-10 Thread ankit sablok
then u can just use or build a dynamic dictionary of words as done in LZW coding such that if the word is there in the dictionary it just gives u the indx of the word and if its not it just adds that word to the dictionary any suggestions are always welcomed thnx in advance On Fri, Dec 10, 2010

Re: [algogeeks] Microsoft interview question

2010-12-04 Thread Shreyas VA
Given the size of the input array, construct array1 = {0, 1, 0, 1} till n elements traverse through input array checking sum of 1's n 0's. at the end if both sums are equal return array1 else return input array. On Sat, Dec 4, 2010 at 12:06 AM, siva viknesh sivavikne...@gmail.comwrote:

Re: [algogeeks] Microsoft interview question

2010-12-04 Thread Shreyas VA
My bad, did not see the in-place memory requirement On Sat, Dec 4, 2010 at 8:49 PM, coolfrog$ dixit.coolfrog.div...@gmail.comwrote: @shreyas VA you are using O(n) extra space... On Sat, Dec 4, 2010 at 8:46 PM, Shreyas VA v.a.shre...@gmail.com wrote: Given the size of the input array,

Re: [algogeeks] Microsoft interview question

2010-12-04 Thread Abioy Sun
Hello, 2010/12/4 siva viknesh sivavikne...@gmail.com:  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 in odd position. And if suppose, no. of 0s exceed no. of 1s or vice versa then keep them

[algogeeks] Microsoft interview question

2010-09-24 Thread vrinda vasishth
Asked in microsoft interview Given a snapshot of an ongoing chess game, which probably is a one vs many game, identify whether it is a valid game or not. It would be great if someone would clarify on what conditions does validity of the game depend.. --Vrinda -- You received this message

[algogeeks] Microsoft interview question

2010-08-22 Thread Saikat Debnath
How to find last unique character in a given string. Unique character means non-repeated number. Give an optimized way. -- 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