Re: [algogeeks] Microsoft Interview Question

2012-10-17 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 mak

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 Pa

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 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-15 Thread atul anand
http://www.geeksforgeeks.org/archives/13376 On Tue, Oct 16, 2012 at 8:56 AM, atul anand 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 DP solution for

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

[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-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 gr

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 wrote: > void make_group( int a[], int size) { > int j = 0; > > for ( int i = 0; i < size; i++ ) { > if ( a[i] < 0

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 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 wrote: > void change(int a[],int n) > { > int i,j; > i=0; > j=1; > > while(i { > if(j j=i+1; > else if(a[j]<0&&a[i]>0) >

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(i0) { swap(a,j,i); } else { if(a[j]>0) j++; else i++; } } } -- You received this message because you are subscribed to th

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 wrote: > @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 s

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 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 wrote: > Check this out, it works in O(n); > > int i = 0; > int j = n-1; > > while

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((i= 0)&&(i0 && a[j]<0) { swap(a[i],a[j]); i++; j--; } else { if(a[i]<0)

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 cou

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 wrote: > your so

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 wrote: > @shiv relate the ashish solution with quick sort then you will understand > easily > > > On Thu, Jun 14, 2012

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 wrote: > +1 Ashish solution > > > > -- > Thanks & Regards > Saurabh Yadav > > -- Thanks & Regards Saurabh Yadav -- You received this message because you are subscr

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 algogeeks+unsubscr...@goo

Re: [algogeeks] Microsoft Interview Question

2012-06-13 Thread Ashish Goel
int i=0; int j=n-1; while (i0) j--; if (iwrote: > 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). > > -

[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 t

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-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 wrote: > given 2 unsorted integer arrays a and b of

Re: [algogeeks] Microsoft interview question

2012-05-20 Thread GAURAV CHAWLA
we can do it bitwise... i can set the corresponding bit by 1 of any int ... lets take int ia,ib=0; and set the a[i]th bit of ia as 1 , and similar for bth array and ib ... and finally check.. if(ia==ib){permutation of each other} hope this will work.. On Sun, May 20, 2012 at 1:39 AM, malay

Re: [algogeeks] Microsoft interview question

2012-05-20 Thread DINESH KUKREJA
Agree .. u can hardcode primes no upto certain value . primes method works in case of permutation of alphabets . else u can ALSO use the below method .. find the n^2+n of each number in the array . and check for the same in the other array . -- You received this message because you are subscribe

Re: [algogeeks] Microsoft interview question

2012-05-20 Thread Dave
@Atul007: It looks like you have three equations in n unknowns. How would you _prove_ that these conditions are sufficient to determine whether the arrays are permutations? My guess is that a computer search with n = 8 or so would find a counterexample in short order. Dave On Sunday, May 20,

Re: [algogeeks] Microsoft interview question

2012-05-20 Thread atul anand
test case : - arr[]=1 1 2 2 arr[]=0 3 0 3 without 1st condition given test case will give wrong output. On Sun, May 20, 2012 at 1:35 PM, Darpan Baweja wrote: > @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 wrot

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 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 elements of arr1 an

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 wrote: > given 2 un

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" wrote: > @malay --- we can do it by precomputing the prime arrays > > > On Sun, May 20, 2012 at 1:10 AM, malay chakrabarti wrote: > >> method is ryt but to find ith prime u cannot to it in c

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 wrote: > method is ryt but to find ith prime u cannot to it in constant time. > On May 19, 2012 7:30 PM, "HARSHIT PAHUJA" > wrote: > >> given 2 unsorted integer arra

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" 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 help me with my s

[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 prime

Re: [algogeeks] Microsoft Interview Question

2012-03-12 Thread atul anand
i guess they were talking abt spanning tree , so you can use prism or kruskal algo to do the same. On Mon, Mar 12, 2012 at 3:05 PM, Umer Farooq wrote: > Hello friends, > > I recently had an onsite MS interview. One of the questions that they > asked was: > > >- Given a directed graph, write

[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 function

Re: [algogeeks] Microsoft interview question

2011-02-01 Thread Sarma Tangirala
@guys What's the right answer? Sent from my BlackBerry -Original Message- From: "HARISH S.C" Sender: algogeeks@googlegroups.com Date: Wed, 2 Feb 2011 13:01:59 To: Reply-To: algogeeks@googlegroups.com Subject: Re: [algogeeks] Microsoft interview question @Sarma : He

Re: [algogeeks] Microsoft interview question

2011-02-01 Thread HARISH S.C
> What were your test cases? > > Sent from my BlackBerry > -- > *From: * "HARISH S.C" > *Sender: * algogeeks@googlegroups.com > *Date: *Wed, 2 Feb 2011 01:14:00 +0530 > *To: * > *ReplyTo: * algogeeks@googlegroups.com > *Subject: *[

Re: [algogeeks] Microsoft interview question

2011-02-01 Thread Sarma Tangirala
- From: "HARISH S.C" Sender: algogeeks@googlegroups.com Date: Wed, 2 Feb 2011 01:14:00 To: 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 fonts like arial,calib

[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

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+unsubscr...@goo

Re: [algogeeks] microsoft interview question

2010-12-17 Thread DIPANKAR DUTTA
see careercup.com On Sat, Dec 18, 2010 at 1:49 AM, anujbhambhani wrote: > 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

[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 algoge

[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 { HashTable 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 }

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 at

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 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, Dec 10, 2010 at

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 wrote: > Help me in solving this problem... Define a data struct for the search > engine which will represent

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, GOB

[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-04 Thread Abioy Sun
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 in odd position. And if suppose, no. of 0s exceed no. > of 1s or vice versa then keep them untouched. Do that

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$ wrote: > @shreyas VA > you are using O(n) extra space... > > > On Sat, Dec 4, 2010 at 8:46 PM, Shreyas VA wrote: > >> Given the size of the input array, >> construct array1 = {0, 1, 0, 1} till n e

Re: [algogeeks] Microsoft interview question

2010-12-04 Thread coolfrog$
@shreyas VA you are using O(n) extra space... On Sat, Dec 4, 2010 at 8:46 PM, Shreyas VA wrote: > 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 a

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 wrote: > Modified 2 color sort p

Re: [algogeeks] Microsoft interview question

2010-12-04 Thread coolfrog$
here base index is 1 and total no. of elements are n. k=1; i=1; while(i wrote: > I hope the following approach will work. > Let 'a' be the input array with size n. > > int i = 0, j = 1; > > while( true) > { > while( i < n && a[i] == 0) i += 2; > while( j < n && a[j] ==

Re: [algogeeks] Microsoft interview question

2010-12-04 Thread Senthilnathan Maadasamy
I hope the following approach will work. Let 'a' be the input array with size n. int i = 0, j = 1; while( true) { while( i < n && a[i] == 0) i += 2; while( j < n && a[j] == 1) j += 2; if ( i < n && j < n ) swap(a[i], a[j]); if ( i > n && j < n ) {

[algogeeks] Microsoft interview question

2010-12-03 Thread 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 in odd position. And if suppose, no. of 0s exceed no. of 1s or vice versa then keep them untouched. Do that in ONE PASS and without taking extra memo

[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

Re: [algogeeks] Microsoft interview question

2010-08-22 Thread Ashish Goel
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 Regards Ashish Goel "Think positive and find fuel in failure" +919985813081 +919966006652 On Sun, Aug

[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 unsubs