Re: [algogeeks] Re: search in O(logn)

2012-06-09 Thread partha sarathi Mohanty
smthng like this...


*if*(arr[mid]  arr[mid + 1])
 return mid;
   if(arr[low]  arr[mid])
 return findPoint(arr, low, mid-1);
   else
 return findPoint(arr, mid + 1, high);

On Sat, Jun 9, 2012 at 12:36 AM, Hassan Monfared hmonfa...@gmail.comwrote:

 Hi pharta :
  find the point where it is rotated to get 14-1 O(log(n))  how can
 you find rotation point in log(n) ?


 On Fri, Jun 8, 2012 at 6:57 PM, partha sarathi Mohanty 
 partha.mohanty2...@gmail.com wrote:

 It is easy.. find the point where it is rotated to get 14-1 O(log(n))
 since 214 that means u have to find it in subarray [123].. do a binary
 search here o(long(n))
 final 2*O(log(n))...


 On Fri, Jun 8, 2012 at 7:44 PM, Dave dave_and_da...@juno.com wrote:

 @Hassan: This is not possible without additional conditions. E.g., you
 cannot find the 1 in the array {0,0,0,...,0,1,0,0,...,0} in less than O(n)
 time.

 But with the condition that the elements of the array are pairwise
 distinct, you can use a binary search to find k such that a[k-1]  a[0] and
 a[k]  a[0]. Then if x  a[k], do a binary search to find x in {a[k] ...
 a[n-1]}; otherwise do a binary search to find x in {a[0] ... a[k]}.

 Dave

 On Friday, June 8, 2012 8:41:47 AM UTC-5, Hassan Monfared wrote:

 A sorted array of integers is rotated unknown times. find an item in
 O(logn) time and O(1) space complexity.
 for example : 1,2,3,7,10,14 ---rotated 3 times-- 7,10,14,1,2,3
 find 2 in O(logn) time in O(1) space complexity

 Regards
 Hassan H. Monfared

  --
 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/-/KD9Hz01ZIJ8J.

 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
 http://groups.google.com/group/algogeeks?hl=en.


  --
 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
 http://groups.google.com/group/algogeeks?hl=en.


  --
 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
 http://groups.google.com/group/algogeeks?hl=en.


-- 
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 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] first Repeating character in a string

2012-06-08 Thread partha sarathi Mohanty
@saurabh: why would u count all??? just see while counting if the bitmap is
set.. then return the char.

On Fri, Jun 8, 2012 at 4:33 PM, Saurabh Yadav saurabh...@gmail.com wrote:

 order of hashing and counting is important
 eg. abba
 if we do hashing by characters 'a' is stored before 'b'
 and count of both is 2 at the end and when we process this we give result
 'a' (because 'a' comes before 'b' )which is wrong
 because 'b' is the first repeated character.


 Thanks  Regards
 Saurabh

  --
 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
 http://groups.google.com/group/algogeeks?hl=en.


-- 
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 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: search in O(logn)

2012-06-08 Thread partha sarathi Mohanty
It is easy.. find the point where it is rotated to get 14-1 O(log(n))
since 214 that means u have to find it in subarray [123].. do a binary
search here o(long(n))
final 2*O(log(n))...


On Fri, Jun 8, 2012 at 7:44 PM, Dave dave_and_da...@juno.com wrote:

 @Hassan: This is not possible without additional conditions. E.g., you
 cannot find the 1 in the array {0,0,0,...,0,1,0,0,...,0} in less than O(n)
 time.

 But with the condition that the elements of the array are pairwise
 distinct, you can use a binary search to find k such that a[k-1]  a[0] and
 a[k]  a[0]. Then if x  a[k], do a binary search to find x in {a[k] ...
 a[n-1]}; otherwise do a binary search to find x in {a[0] ... a[k]}.

 Dave

 On Friday, June 8, 2012 8:41:47 AM UTC-5, Hassan Monfared wrote:

 A sorted array of integers is rotated unknown times. find an item in
 O(logn) time and O(1) space complexity.
 for example : 1,2,3,7,10,14 ---rotated 3 times-- 7,10,14,1,2,3
 find 2 in O(logn) time in O(1) space complexity

 Regards
 Hassan H. Monfared

  --
 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/-/KD9Hz01ZIJ8J.

 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
 http://groups.google.com/group/algogeeks?hl=en.


-- 
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 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: interview HARD problem

2012-06-05 Thread partha sarathi Mohanty
no
if ta/om/to/am/ba/batot/amoma are words then it should be the one. no
5*2  3*3

On Tue, Jun 5, 2012 at 7:45 PM, Gene gene.ress...@gmail.com wrote:

 Does this sufficae?

 Suppose you were using a dictionary from the frapplewonk language,
 which has only 5 words:

 tab
 oma
 to
 am
 ba

 Then the biggest rectangle is clearly

 tab
 oma



 On Jun 4, 10:39 pm, Ashish Goel ashg...@gmail.com wrote:
  preparing a sample itself is a great problem here, that is why i called
 it
  hard
 
  all words in the rectangle horizontally as well as vertically needs to be
  valid dictionary words
 
  Ashish
  Hassan
 
  say this rectangle AH,SA,HS,IS,SA,HN should also be valid dictonary
 words,
  indeed they are not..
 
  definitely we will need a multimap to have words of same length forming a
  bucket..not able to think beyond this
 
  Best Regards
  Ashish Goel
  Think positive and find fuel in failure
  +919985813081
  +919966006652
 
 
 
  On Mon, Jun 4, 2012 at 6:38 PM, Hassan Monfared hmonfa...@gmail.com
 wrote:
   Give a sample please
 
   On Mon, Jun 4, 2012 at 5:34 PM, Ashish Goel ashg...@gmail.com wrote:
 
   Given a dictionary of millions of words, give an algorithm to find the
   largest possible rectangle of letter that every row forms a
 word(reading
   left to right) and every column forms a word(reading from top to
 bottom).
 
   Best Regards
   Ashish Goel
   Think positive and find fuel in failure
   +919985813081
   +919966006652
 
   --
   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
  http://groups.google.com/group/algogeeks?hl=en.
 
--
   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
  http://groups.google.com/group/algogeeks?hl=en.

 --
 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
 http://groups.google.com/group/algogeeks?hl=en.



-- 
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 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Google Q : all anagrams next to each other

2012-05-23 Thread partha sarathi Mohanty
@ashish : couldnt get u.. can u give an example??

On Tue, May 22, 2012 at 5:45 PM, Prem Krishna Chettri hprem...@gmail.comwrote:

 What I Could possibly think of is

  For each string S1 that is an anagram of some string S, use Map and Store
 the Key Value as (S1,S). Now there is a trick here abt how to reduce Time
 Complexity here...

  Now its easy to put all string which has correspondence S next to each
 other. This is Simple one.

 Inplace.. Hv to think abt .. I doubt, as we need some space to get the
 anagrams Dude..

 Prem

 On Tue, May 22, 2012 at 5:18 PM, Ashish Goel ashg...@gmail.com wrote:

 Write a method to sort an array of strings so that all the anagrams are
 next to each other.

 What i could think of is preparing a multi linked list( multimap) whereby
 the key for each string is the sorted representation of the string(eg if
 string is gac, its sorted representation is acg). Walk of all lists of this
 multimap to give all anagrams.

 Is there any other better solution for this problem?
 Can this be done *inplace*?

 Best Regards
 Ashish Goel
 Think positive and find fuel in failure
 +919985813081
 +919966006652

 --
 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
 http://groups.google.com/group/algogeeks?hl=en.


  --
 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
 http://groups.google.com/group/algogeeks?hl=en.


-- 
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 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] amazon

2012-05-23 Thread partha sarathi Mohanty
Java has something call treeMap. it stores strings lexographically.. u can
always do permutations and store them in a treeMap. and get the rank
then... just the idea.. will post the solution once i am done.. what do u
guys think.abt the idea???

On Tue, May 22, 2012 at 9:46 AM, atul anand atul.87fri...@gmail.com wrote:

 actually we can think of above approach as follows :-

 input : cabd

 sort(input) = abcd

 find first element of the input i.e 'c' in the sorted form i.e abcd

 'c' is at found_index=3 ( index starting from 1 )

 so permutaion stating from 'c' will come after temp_rank=(found_index -
 start_index) * (total_lentgh - 1) !

 now after temp_rank we know that permutation starting with 'c' will come.

 so to find out the exact index sort(input-1)  i.e removing 1st character
 ('c') from the input(cadb) we will get abd

 now permute string abd and compare with input - 1 character i.e (abd).

 and keep inc the counter , if match is found then you have to add this
 counter to temp_rank.

 so for the input = cabd

 temp_rank = (3 - 1) * (4-1) !
 =  2 * 3!
 =  12

 counter found c = 1;
 rank = 12 + c = 13

 but i dont think this would be good solution as be have to permute string
 and then compare at last...yes we did some optimization.
 i was wondering if instead of permuting at the end , we can calculate
 minimum number of swaps required to convert input - 1 to sorted input -1
 (removing 1st character )using edit distance ...will this work?? .


 On Mon, May 21, 2012 at 11:33 PM, atul anand atul.87fri...@gmail.comwrote:

 consider string input = cabd
 now sort this string = abcd

 now search 1st character from original string(cabd) in  sorted string
 abcd... index found = 3 (index starting from 1 )

 now you can arrange left elements from found index i.e index-1 elements
 in (index-1) ! and right elements from found index in (lastIndex - index)!
 before character 'c' occurs at index 0. similarly find for other characters
 and at the end subtract it from n! (n = length of the string ) to find rank


 On Mon, May 21, 2012 at 11:02 PM, rahul venkat rahul911...@gmail.comwrote:

 Given a string. Tell its rank among all its permutations sorted
 lexicographically.

 --
 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
 http://groups.google.com/group/algogeeks?hl=en.



  --
 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
 http://groups.google.com/group/algogeeks?hl=en.


-- 
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 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] symmetric binary tree

2012-05-23 Thread partha sarathi Mohanty
recurse on left and right will do it and keep comparing the values

On Tue, May 22, 2012 at 2:50 PM, atul anand atul.87fri...@gmail.com wrote:

 no need of creating another mirror tree
 you just need to call the function func(root-left,root-right);
 now left sub tree and right sub tree will be considered as if you are
 checking 2 different trees
 same code to check if 2 tree are structurally similar will work.

 On Tue, May 22, 2012 at 10:50 AM, algogeek 
 dayanidhi.haris...@gmail.comwrote:

 How to check if a given binary tree is  structurally symmetric ie. the
 left sub tree should be mirror image of right sub tree and vice-versa.

 --
 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
 http://groups.google.com/group/algogeeks?hl=en.


  --
 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
 http://groups.google.com/group/algogeeks?hl=en.


-- 
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 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] amazon

2012-05-23 Thread partha sarathi Mohanty
sorry it was treeset Here is the code..

public class asd1 {


public static TreeSetString t = new TreeSetString();
public static int j = 0;
public static void main(String args[]) {




String s= edcba;
permute(, s);
System.out.println(t.toString());
int length=t.size();
String[] arr=(String[]) t.toArray(new String[length]);
for(int i =0;ilength;i++)
{
System.out.println(arr[i]);
if(arr[i].equals(s)){
System.out.println(i+1);
break;
}
}
}

public static void permute(String st, String chars) {
if (chars.length() = 1)
t.add(st+chars);
else
for (int i = 0; i  chars.length(); i++) {
try {
String newString = chars.substring(0, i)
+ chars.substring(i + 1);
permute(st + chars.charAt(i), newString);
} catch (Exception e) {
e.printStackTrace();
}
}

}
}

On Tue, May 22, 2012 at 2:19 PM, partha sarathi Mohanty 
partha.mohanty2...@gmail.com wrote:

 Java has something call treeMap. it stores strings lexographically.. u can
 always do permutations and store them in a treeMap. and get the rank
 then... just the idea.. will post the solution once i am done.. what do u
 guys think.abt the idea???


 On Tue, May 22, 2012 at 9:46 AM, atul anand atul.87fri...@gmail.comwrote:

 actually we can think of above approach as follows :-

 input : cabd

 sort(input) = abcd

 find first element of the input i.e 'c' in the sorted form i.e abcd

 'c' is at found_index=3 ( index starting from 1 )

 so permutaion stating from 'c' will come after temp_rank=(found_index -
 start_index) * (total_lentgh - 1) !

 now after temp_rank we know that permutation starting with 'c' will come.

 so to find out the exact index sort(input-1)  i.e removing 1st character
 ('c') from the input(cadb) we will get abd

 now permute string abd and compare with input - 1 character i.e (abd).

 and keep inc the counter , if match is found then you have to add this
 counter to temp_rank.

 so for the input = cabd

 temp_rank = (3 - 1) * (4-1) !
 =  2 * 3!
 =  12

 counter found c = 1;
 rank = 12 + c = 13

 but i dont think this would be good solution as be have to permute string
 and then compare at last...yes we did some optimization.
 i was wondering if instead of permuting at the end , we can calculate
 minimum number of swaps required to convert input - 1 to sorted input -1
 (removing 1st character )using edit distance ...will this work?? .


 On Mon, May 21, 2012 at 11:33 PM, atul anand atul.87fri...@gmail.comwrote:

 consider string input = cabd
 now sort this string = abcd

 now search 1st character from original string(cabd) in  sorted string
 abcd... index found = 3 (index starting from 1 )

 now you can arrange left elements from found index i.e index-1 elements
 in (index-1) ! and right elements from found index in (lastIndex - index)!
 before character 'c' occurs at index 0. similarly find for other characters
 and at the end subtract it from n! (n = length of the string ) to find rank


 On Mon, May 21, 2012 at 11:02 PM, rahul venkat rahul911...@gmail.comwrote:

 Given a string. Tell its rank among all its permutations sorted
 lexicographically.

 --
 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
 http://groups.google.com/group/algogeeks?hl=en.



  --
 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
 http://groups.google.com/group/algogeeks?hl=en.




-- 
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 
http://groups.google.com/group/algogeeks?hl=en.



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 ashg...@gmail.com 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 particular key. If some char
 not there in HT, return false, else return true.
 Best Regards
 Ashish Goel
 Think positive and find fuel in failure
 +919985813081
 +919966006652



 On Mon, May 21, 2012 at 6:14 PM, Dave dave_and_da...@juno.com wrote:

 @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

 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 then these 2 arrays are permutations
 of each other.

 Space = O(1)
 Time=O(n)

 I think this should work. Please correct me if you find mistakes.

 On 5/20/12, anuj agarwal coolbuddy...@gmail.com wrote:
  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= [ 3,5,4 ]
  diff=0;
  for (i=0; in;i++)
  { diff= diff+a[i]-b[i];
  }
  if diff == 0
   print: permutation
  else
   print: not permutation
 
 
 
 
 
  On 20 May 2012 07:2 0, Dave dave_and_da...@juno.com 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 -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
  data types?
 
  Dave
 
  On Saturday, May 19, 2012 2:29:52 PM UTC-5, 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 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 number
 
now array  a becomes  5 11 7
   array  b becomes  7 5 11
 
  now we take product of elements of array a and do the same with
 array  b
  elements
  if product is equal  then b is a permutation of a
 
   --
  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/-/WEW0M5VUUVEJhttps://groups.google.com/d/msg/algogeeks/-/WEW0M5VUUVEJ.

 
  To post to this group, send email to algogeeks@googlegroups.com.
  To unsubscribe from this group, send email to
  algogeeks+unsubscribe@**googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com.

  For more options, visit this group at
  http://groups.google.com/**group/algogeeks?hl=enhttp://groups.google.com/group/algogeeks?hl=en.

 
 
 
 
  --
  *Piyush Khandelwal***
  Mobile No: 91-8447229204
   91-9808479765
 
 
   --
  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+unsubscribe@**googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com.

  For more options, visit this group at
  http://groups.google.com/**group/algogeeks?hl=enhttp://groups.google.com/group/algogeeks?hl=en.

 
 
  --
  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+unsubscribe@**googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com.

  For more options, visit this group at
  http://groups.google.com/**group/algogeeks?hl=enhttp://groups.google.com/group/algogeeks?hl=en.

 
 


 --
 *
 *

 *Kalyanasundaram N*

 *BE 2nd year, CSE*

 *College of Engineering Guindy,*

 *Chennai-600025*
 *
 *

  --
 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/-/i-WLn7rdzDYJ.

 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
 http://groups.google.com/group/algogeeks?hl=en.


  --
 You received this message because you are 

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.. if both are
equal they are pormutations
 if i am missing any corner cases related to 0 or -e numbers u can keep a
track of them while traversalO(N) and constant space



On Mon, May 21, 2012 at 6:40 PM, karthikeya s karthikeya.a...@gmail.comwrote:

 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 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 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
  number
 
now array  a becomes  5 11 7
   array  b becomes  7 5 11
 
  now we take product of elements of array a and do the same with array  b
  elements
  if product is equal  then b is a permutation of a

 --
 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
 http://groups.google.com/group/algogeeks?hl=en.



-- 
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 
http://groups.google.com/group/algogeeks?hl=en.