Re: [algogeeks] Amazon interview Question

2013-02-13 Thread Pralay Biswas
@Rashmi: I did not get your approach. I do not get emails from the group just in case you have posted a solution :( What do you mean by keeping a count? Also, are you using a hashmap? If yes, whats ur K,V? #Pralay On Tue, Feb 12, 2013 at 10:00 AM, rashmi i rash...@gmail.com wrote: Hey Pralay,

Re: [algogeeks] Amazon interview Question

2013-02-12 Thread Pralay Biswas
Guys, Why can't we simply use a hashset for both the questions. hash the arr[i] and the frequencies in the hash map in the first pass. Then iterate over the array to find the first arr[i] whose freq is 1 in the hash map. For second part, keep a count and find the kth element in the array whose

Re: [algogeeks] Amazon interview Question

2013-02-07 Thread Pralay Biswas
I guess the part 1 can be solved in O(n) time and space both. Here is my approach. Assume: Array given is arr[] = {2,3,1,2,3,2,4,1,5,6} 1. Given an array, scan thru it, element by element and hash it on a hashmap with key as the arr[i] as the key and i+1 as the index. 2. There would be two cases

Re: [algogeeks] Amazon interview Question

2013-02-07 Thread Pralay Biswas
Also, for the part two of the question, you can simply go in for the *kth largest positive index *in the same hashmap (described earlier for part 1). That solves the part two of the problem :) Hth, *Pralay Biswas* *MS,Comp Sci, * *University of California, Irvine* On Tue, Feb 5, 2013 at 8:46 PM

Re: [algogeeks] reverse a string efficiently

2012-11-27 Thread Pralay Biswas
Technically linear! On Mon, Nov 26, 2012 at 9:47 PM, shady sinv...@gmail.com wrote: what is the time complexity of this? str_reverse(str){ if(isempty(str)) return str; else if(length(str) = even) then split str into str_1 and str_2; (of equal length) (Calculate mid =O(1), then

Re: [algogeeks] reverse a string efficiently

2012-11-27 Thread Pralay Biswas
Yes, my bad. I din notice the recursion at all! Thot it to be a flat mid-split followed by a reverse followed by a concat. Thanks. On Mon, Nov 26, 2012 at 11:18 PM, atul anand atul.87fri...@gmail.comwrote: considering '+' , here will take Cn time . Here '+' is for concatenate , now this

Re: [algogeeks] fastest sequential access

2012-11-23 Thread Pralay Biswas
for two way sequential access, good for insertions in the middle. Pralay Biswas MS-CS, University of California Irvine On Wed, Nov 21, 2012 at 6:51 AM, shady sinv...@gmail.com wrote: which data structure among the follow has fastest sequential access ? i) vector ii) Singly linked list iii

Re: [algogeeks] fastest sequential access

2012-11-23 Thread Pralay Biswas
I am sorry, vectors are synced and hence slow (concurrency overhead, arraylists are non synced). Rest remain the same, if your application demands frequent two way sequential scans, go for DLL. Pralay Biswas MS-CS, University of California Irvine On Wed, Nov 21, 2012 at 6:57 AM, Pralay Biswas

Re: [algogeeks] fastest sequential access

2012-11-23 Thread Pralay Biswas
Also, vectors are not contiguously memory slotted always. Its a expanding array where the resizing takes place on demand. There are times when the array backing the vector is resized and re-allocated, but even then the amortized cost of insertion stays linear (O(n)). Although it makes sense to

Re: [algogeeks] Re: time complexity of gcd euclid algo(recursive)

2012-11-23 Thread Pralay Biswas
@Dave: Could you please correct me if am wrong here. 1) So we are looking out for the worst case, and that happens when m and n are consecutive Fibo numbers, being mutually prime to reach other. 2) Its taking 5 iterations to reduce the number of digits in the smaller of m and n, by one. Assuming

Re: [algogeeks] BIG O

2012-10-28 Thread Pralay Biswas
is the significance of while loop in the above code? I understand that the for loop implies O(n),does the log n in the O(n log n) comes from the while loop? What if there where two while loops in the for loop separately? On Sat, Oct 27, 2012 at 3:26 AM, Pralay Biswas pralaybiswas2...@gmail.com wrote

Re: [algogeeks] BIG O

2012-10-27 Thread Pralay Biswas
Yes! On Fri, Oct 26, 2012 at 2:55 PM, rahul sharma rahul23111...@gmail.comwrote: for k=1 to n { j=k; while(j0) j=j/2; } the complexity is big o is o(nlogn) am i ryt -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to

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; in;i++)

Re: [algogeeks] Permutations of a string

2012-05-08 Thread Pralay Biswas
Nice solution Akshay. Here is my small attempt! [image: Inline image 1] #Pralay On Mon, May 7, 2012 at 1:03 AM, Akshay Rastogi akr...@gmail.com wrote: private static void swap(char[] str, int i,int j) { char temp = str[i]; str[i] = str[j]; str[j] = temp; }