Re: [algogeeks] Infinite stream , identify distinct k kintegers

2013-06-05 Thread sourabh singh
for each num instream inserting num to stl::set() if size of set == k break O(nlogk) On Sun, Jun 2, 2013 at 10:49 AM, MAC macatad...@gmail.com wrote: Given an infinite stream of integers with only k distinct integers, find those distinct integers. How would you modify your

[algogeeks] spoj problem EASYMATH

2012-06-24 Thread Sourabh Singh
please suggest something : Problem : http://www.spoj.pl/problems/EASYMATH/ C++ code : http://ideone.com/r2OSb was getting wrong ans due to over flow i think in LCM() for big prime's i guess. thin tried in python . Now getting NZEC for python code which mean's high level or recurrsion some

Re: [algogeeks] Re: Question asked in Amazon online test

2012-06-23 Thread Sourabh Singh
@deepika yes, it's giving number of swaps. still Linear time solution would be better :-) On Fri, Jun 22, 2012 at 11:38 PM, deepikaanand swinyanand...@gmail.com wrote: will bubble sort give number of swaps?? I tried the (bubble sort) code of 1,0,0,1,1,0,1 swapcount = 5 and for the array

Re: [algogeeks] Re: Question asked in Amazon online test

2012-06-23 Thread Sourabh Singh
, Sourabh Singh singhsourab...@gmail.com wrote: @deepika yes, it's giving number of swaps. still Linear time solution would be better :-) On Fri, Jun 22, 2012 at 11:38 PM, deepikaanand swinyanand...@gmail.com wrote: will bubble sort give number of swaps?? I tried the (bubble sort) code

Re: [algogeeks] Re: Question asked in Amazon online test

2012-06-23 Thread Sourabh Singh
@deepika anand solution given by me is for getting number of swap's in O(n) as far as sorting goes any O(n lgn) algo can be used . if count sort is allowed then O(n) for sorting also.[constant extra space.. ] On Sat, Jun 23, 2012 at 12:49 AM, ashish jain ashishjainco...@gmail.com wrote: @all

Re: [algogeeks] 4Sum

2012-06-23 Thread Sourabh Singh
@ALL O(n^2 lg(n^2)) http://www.spoj.pl/problems/SUMFOUR/ my code : http://ideone.com/kAPNB plz. suggest some test case's : On Sat, Jun 23, 2012 at 6:59 AM, Amol Sharma amolsharm...@gmail.com wrote: @bhaskar,rammar: I don't think your algo willn not work for the following test case --

Re: [algogeeks] Find peak element in log(n)

2012-06-23 Thread Sourabh Singh
@adarsh kumar are u sure it's worst case will be O (log n) ?? i think iff array is fully sorted O(n) will be required to say NO such element present On Sat, Jun 23, 2012 at 1:11 PM, adarsh kumar algog...@gmail.com wrote: This is a variation of binary search, the difference being that we have to

Re: [algogeeks] 4Sum

2012-06-23 Thread Sourabh Singh
://gplus.to/amolsharma99 http://twitter.com/amolsharma99http://in.linkedin.com/pub/amol-sharma/21/79b/507http://www.simplyamol.blogspot.com/http://facebook.com/amolsharma99 On Sun, Jun 24, 2012 at 1:22 AM, Sourabh Singh singhsourab...@gmail.comwrote: @ALL O(n^2 lg(n^2)) http

Re: [algogeeks] Find peak element in log(n)

2012-06-23 Thread Sourabh Singh
...@gmail.com wrote: just found a good resource for 1d and 2D version : http://courses.csail.mit.edu/6.006/spring11/lectures/lec02.pdf On Sun, Jun 24, 2012 at 3:31 AM, sengar.mahi sengar.m...@gmail.com wrote: @adarsh :its nt dat easy as u see it.. On Sun, Jun 24, 2012 at 1:45 AM, Sourabh Singh

Re: [algogeeks] Reverse Queue

2012-06-22 Thread Sourabh Singh
@ALL this shud work :-) #includeiostream #includequeue using namespace std; queueint Q; void rev() { if(!Q.empty()) { int x=Q.front(); Q.pop(); rev(); Q.push(x); } } main() { for(int i=1;i12;i++) Q.push(i); rev(); while(!Q.empty()) { int x=Q.front();

Re: [algogeeks] Re: Sorting using array of pointer

2012-06-22 Thread Sourabh Singh
Nice DCE vs NSIT On Fri, Jun 22, 2012 at 3:12 AM, deepikaanand swinyanand...@gmail.com wrote: @vindhya thanx .. -- 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

Re: [algogeeks] Programming Question

2012-06-22 Thread Sourabh Singh
u can use stl::map(string,vectorstring) idea is same bucket sort :-) On Fri, Jun 22, 2012 at 3:02 AM, Eshwar eshwaronl...@gmail.com wrote: Bucket sort algortihm Linkedlist based On Fri, Jun 22, 2012 at 3:31 PM, Gobind Kumar Hembram gobind@gmail.com wrote: I was asked this question in

Re: [algogeeks]

2012-06-21 Thread Sourabh Singh
at the other solution I proposed? I guess that solves the problem to some extent. On Tue, Jun 19, 2012 at 7:18 PM, Sourabh Singh singhsourab...@gmail.com wrote: @Umer and Navin : 1 is generated by (1,3) only. 2 is generated by (1,1) and (2,3). so given solution is wrong On Tue, Jun 19, 2012

Re: [algogeeks]

2012-06-21 Thread Sourabh Singh
, Sourabh Singh singhsourab...@gmail.com wrote: @Umer and Navin : 1 is generated by (1,3) only. 2 is generated by (1,1) and (2,3). so given solution is wrong On Tue, Jun 19, 2012 at 5:17 AM, Sourabh Singh singhsourab...@gmail.com wrote: @ ALL     please. post along with your method

Re: [algogeeks] Re: POSTAGE STAMP PROBLEM

2012-06-20 Thread Sourabh Singh
try this : similar problem http://www.spoj.pl/problems/NOCHANGE/ On Tue, Jun 19, 2012 at 1:32 PM, aditya gupta adityagupta...@gmail.com wrote: this can be solved in a manner similar to knapsack problem. u can take the weight of tha knapsack the be the the various amounts u need to make, 13

[algogeeks]

2012-06-19 Thread Sourabh Singh
@ALL Given a random number generator say r(5) generates number between 1-5 uniformly at random , use it to in r(7) which should generate a random number between 1-7 uniformly at random i have seen this on many site's but not a single correct solution. all solution's posted got rejected by

Re: [algogeeks]

2012-06-19 Thread Sourabh Singh
@ sry condition should be: if(20*prob = 500/7) :-) On Tue, Jun 19, 2012 at 12:26 AM, Sourabh Singh singhsourab...@gmail.comwrote: @ALL Given a random number generator say r(5) generates number between 1-5 uniformly at random , use it to in r(7) which should generate a random number between

Re: [algogeeks]

2012-06-19 Thread Sourabh Singh
better try this: rand(5) + (rand(5)%3). On Tue, Jun 19, 2012 at 2:45 PM, Umer Farooq the.um...@gmail.com wrote: rand(5) + (rand(5)%2); On Tue, Jun 19, 2012 at 12:30 PM, Sourabh Singh singhsourab...@gmail.com wrote: @ sry condition should be: if(20*prob = 500/7) :-) On Tue, Jun 19

Re: [algogeeks]

2012-06-19 Thread Sourabh Singh
@Umer and Navin : 1 is generated by (1,3) only. 2 is generated by (1,1) and (2,3). so given solution is wrong On Tue, Jun 19, 2012 at 5:17 AM, Sourabh Singh singhsourab...@gmail.comwrote: @ *ALL* please. post along with your method . proof than it make's equal distribution over

Re: [algogeeks] Find the Max from each sub-array of size k

2012-06-16 Thread Sourabh Singh
@ALL can be solved using segment tree . :-) On Fri, Sep 2, 2011 at 9:49 AM, Anup Ghatage ghat...@gmail.com wrote: I just checked Shashank's blog post. The Deque solution is awesome :) -- Anup Ghatage -- You received this message because you are subscribed to the Google Groups Algorithm

Re: [algogeeks] MS Question: Reverse stack using push, pop without any auxiliary data structure

2012-06-14 Thread Sourabh Singh
@ Navin Kumar Nice . Solution. But your function also make a stack only. so you are using a stack[internal] here. but may be this one is allowed:-) On Thu, Jun 14, 2012 at 5:23 AM, Navin Kumar algorithm.i...@gmail.comwrote: void Reverse(struct Stack *S) { int data;

Re: [algogeeks] Re: spoj problem

2012-06-13 Thread Sourabh Singh
@ saurabh singh : what algorithm can be used ?? coz.. i did it by simple observation. 1) just take any sequence of numbers. 2) write it's first 5-6 xor round's. 3) now luk for some pattern. u'll get the answer : ) On Wed, Jun 13, 2012 at 9:46 PM, saurabh singh saurab...@gmail.com

Re: [algogeeks] Matrix Minimum Path Sum

2012-06-06 Thread Sourabh Singh
Basic Dijikstra problem . :-) On Wed, Jun 6, 2012 at 6:13 AM, Dheeraj Jain dheerajj...@gmail.com wrote: http://www.geeksforgeeks.org/archives/14943 On Mon, Jun 4, 2012 at 7:57 PM, Decipher ankurseth...@gmail.com wrote: @Victor - Someone had asked this question from me !! He told me its

Re: [algogeeks] Maximum size square sub-matrix with all 1s

2012-03-15 Thread Sourabh Singh
is O(1). On Thu, Mar 15, 2012 at 12:26 AM, Sourabh Singh singhsourab...@gmail.comwrote: @atul 1) it won't work for large dimention's coz their is a limit to size of array we can declare on stack. ( which is typically 10^6 as far as i know :-) ). 2) the algo i m trying to find would

Re: [algogeeks] Maximum size square sub-matrix with all 1s

2012-03-14 Thread Sourabh Singh
@atul Also the histogram algo and algo given by you can't work on very very big dimentions. say 10^5 x 10^5 matrix. but if we can find a DP then we just need to keep 2 row's at a time. :-) On Tue, Mar 13, 2012 at 1:03 PM, Sourabh Singh singhsourab...@gmail.comwrote: @atul read

Re: [algogeeks] Maximum size square sub-matrix with all 1s

2012-03-14 Thread Sourabh Singh
it first tym...it executes...but explain plz.. On Wed, Mar 14, 2012 at 6:56 PM, Sourabh Singh singhsourab...@gmail.comwrote: @atul Also the histogram algo and algo given by you can't work on very very big dimentions. say 10^5 x 10^5 matrix. but if we can find a DP then we just need to keep 2

Re: [algogeeks] Maximum size square sub-matrix with all 1s

2012-03-14 Thread Sourabh Singh
++) {printf( %d,a[i][j]); } printf(\n); } printf(\n\n\n\n\n); for(i=0;i6;i++) { for(j=0;j6;j++) {printf( %d,b[i][j]); } printf(\n); } getch(); return 0; } On Wed, Mar 14, 2012 at 11:56 AM, Sourabh Singh

Re: [algogeeks] Maximum size square sub-matrix with all 1s

2012-03-13 Thread Sourabh Singh
@ ALL finding square matrix is quite a standard question and nw an easy one as everyone knows the reccussence atul has given. but i wanted to find max rectangle.. i know there is a DP for it. in O(n^2). for nxn matrix..don't know the whole approach .but here is what i remember.. 1. aproach

Re: [algogeeks] Maximum size square sub-matrix with all 1s

2012-03-13 Thread Sourabh Singh
: check solution i have posted in below link http://groups.google.com/group/algogeeks/browse_thread/thread/91a17f7c78c2319e/991d1c2625a62ff0?hl=enlnk=gstq=rectangle+of+max+sum+MS+Q#991d1c2625a62ff0 On Tue, Mar 13, 2012 at 10:26 PM, Sourabh Singh singhsourab...@gmail.comwrote: @ ALL finding

[algogeeks]

2012-01-27 Thread Sourabh Singh
@ALL //Imagine that you write down all numbers between A and B in 2's complement representation using 32 bits. How many 1's will you write down in all ? wat's wrong with this code working fine for all cases i tested but on http://www.spoj.pl/problems/CODESPTA/ wrong answer.. plz.. point

Re: [algogeeks] Re: sort 2D array

2012-01-27 Thread Sourabh Singh
@all I have come across this question earlier. it's a young's tableaus ( cormen pg. 167 ) can be treated as min heap. solution can be found in mit online study material. i'll post the link here as soon as i remember it. On 1/24/12, atul anand atul.87fri...@gmail.com wrote: @praveen : k way

Re: [algogeeks] Re: Amazon ques

2012-01-27 Thread Sourabh Singh
@all plz.. tell if this thing would work.. assume 2 in place of every 0 in array. ie 1 1 0 0 0 1 0 1 be 1 1 2 2 2 1 2 1 then find max sub array wid sum length/2 * 3. this can be done in O(n) but worst case would still be O(n lgn) . On 1/26/12, Sanjay Rajpal sanjay.raj...@live.in wrote: +1

[algogeeks]

2012-01-18 Thread Sourabh Singh
@ALL hi everyone m trying to make prime checker based on miller-rabin test . can some1 point out . wat's wrong with the code. thank's alot in advance... //prime checker based on miller-rabin test #includeiostream #includeconio.h #includemath.h int is_prime(int n) { if(n==2 | n==3)

Re: [algogeeks]

2012-01-18 Thread Sourabh Singh
@all output's to above code are just random.. some prime's. found correctly while some are not why i used certain primes to check ie.(2,3,31,73,61,7) coz.. its given n wiki for about 10^15 checking with these is enough.. On 1/18/12, Sourabh Singh singhsourab...@gmail.com wrote: @ALL hi everyone

Re: [algogeeks]

2012-01-18 Thread Sourabh Singh
) d=1; 2. the accuracy of pow is far from enough. you should implement your own pow-modulo-n method. 3. for big n, (exceed 32bit), x=(x*x)%n can be overflow also. you may need to implement your own multiply method in this case. On 2012-1-18 18:15, Sourabh Singh wrote: @all output's

Re: [algogeeks]

2012-01-18 Thread Sourabh Singh
) return 0; if(x==n-1) break; } if(x!=n-1) return 0; } return 1; } main() {for(int k=1;k20;k++) printf(%d is %d\n,k,is_prime(k)); getch();} On 1/18/12, Sourabh Singh

Re: [algogeeks]

2012-01-18 Thread Sourabh Singh
@gmail.com wrote: @Sourabh m=2^s***d primes[i]**n On 2012-1-18 19:39, Sourabh Singh wrote: @Terrence sry i didn't explain what s,d were they were also wrong i ws calculating for n not n-1 earlier n=2^s+d nw m=n-1; for odd n m=2^s+d; //suggested corrections made

Re: [algogeeks]

2012-01-18 Thread Sourabh Singh
@ Terence I belive nw its giving wrong answer for n41 onwards due to error's in pow and x*x over flow as u already stated... i guess algo is right nw.. ;-) thanx again.. On 1/18/12, Sourabh Singh singhsourab...@gmail.com wrote: @ thanx got it.. silly mistakes ;-) . missed thought it ws

Re: [algogeeks]

2012-01-18 Thread Sourabh Singh
, Terence technic@gmail.com wrote: error in pow. as long as n 2^31, x*x fits into int64_t, since xn. On 2012-1-18 20:51, Sourabh Singh wrote: @ Terence I belive nw its giving wrong answer for n41 onwards due to error's in pow and x*x over flow as u already stated... i guess algo is right nw

Re: [algogeeks]

2012-01-18 Thread Sourabh Singh
@all sorry .. 21 is prime :-) hw can above algo be well implemented to get mpow function... On 1/18/12, Sourabh Singh singhsourab...@gmail.com wrote: @All pow() mod is giving problem... found an algo .. is some1 intrested to discuss... Example: Take 3^21 (mod 7) 3^2= 9

Re: [algogeeks] Re: DP problems in SPOJ

2011-12-28 Thread sourabh singh
17592186044416 1413883960704 On Tue, Dec 27, 2011 at 11:20 PM, sourabh singh singhsourab...@gmail.comwrote: @all plz point out wat's wrong with this code. works for small numbers but fails for large number's #includeconio.h #includeiostream using namespace std; unsigned int

Re: [algogeeks] Re: DP problems in SPOJ

2011-12-27 Thread sourabh singh
@All i was searching fr some better way for i/o . i came across this code and many similar examples on net. i think asm can provide a way to load .output directly nd take input directly from i/o registers . but due to me being new to asm these code's are giving me trouble. It's an ATT type asm

Re: [algogeeks] Re: DP problems in SPOJ

2011-12-27 Thread sourabh singh
@all plz point out wat's wrong with this code. works for small numbers but fails for large number's #includeconio.h #includeiostream using namespace std; unsigned int find_nCp(unsigned int n,unsigned int p) { unsigned int j=p; unsigned int num=1,den=1; for(;j;j--)

Re: [algogeeks] Re: doubt in spoj 8473 ways

2011-12-17 Thread sourabh singh
@anubhav i too didn't find it on google bt may be it is: f(n)= ((4n-2)/n)*f(n-1)n1 2 n=1 On Fri, Dec 16, 2011 at 8:07 AM, anubhav raj anubhaw@gmail.com wrote: @samm:i hv googled it several time bt by code no path r ways as a tag bt cudnt get ne

Re: [algogeeks] Re: doubt in spoj 8473 ways

2011-12-17 Thread sourabh singh
@all got AC 114 still i think without some other way to input/output it hard to get below 100. can some1 suggest some better (smaller ) way to i/o integers On Sat, Dec 17, 2011 at 1:31 AM, sourabh singh singhsourab...@gmail.comwrote: @anubhav i too didn't find it on google bt may

Re: [algogeeks] Re: doubt in spoj 8473 ways

2011-12-17 Thread sourabh singh
@anubhav No,i can't post an AC code here . takes all fun out of spoj problem solving thing. i can just hint that i used the function posted earlier and u don't need to make a function single for loop will do. that's it try harder. buddy :-) btw it got ac 111 later :-). On Sat, Dec 17, 2011

Re: [algogeeks] doubt in spoj 8473 ways

2011-12-16 Thread sourabh singh
limit is just v.smll can ny1 help me with this code: [ c code ] get it under 120 bytes . is there any way to take inputs. without using scanf ??? in c . m thinking about inputs getting into argc array directly.??? #define s(n) scanf(%d,n); f(int n){return n==1?1:(n*f(n-1));} main() { int

Re: [algogeeks] Re: Sub-array problem

2011-12-07 Thread sourabh singh
; } On Wed, Dec 7, 2011 at 4:58 AM, GIRIDHAR IS gigir...@gmail.com wrote: @sourabh can you explain me how it will work for this example a[]={2,7,3,4,5,8,10} On Dec 7, 12:17 am, sourabh singh singhsourab...@gmail.com wrote: @ sourabh :-) yep, got your point... it wont work for all cases

Re: [algogeeks] Re: Sub-array problem

2011-12-07 Thread sourabh singh
2 0299 0312 12 24712 2512 12 4613 13 On 12/7/11, sourabh singh singhsourab...@gmail.com wrote: @ giridhar IS assuming u wanted k=13 ( max sum =13) start : i,j points to 1st element keep a track of sum between

Re: [algogeeks] Re: Sub-array problem

2011-12-06 Thread sourabh singh
@ sourabh :-) yep, got your point... it wont work for all cases. but if we set initial max to a negative value . say max possible 64 bit -ve number.then ? point is though the code has limitations it will work fine mostly. On 12/5/11, sourabh sourabhd2...@gmail.com wrote: @sourabh singh.. Hey

Re: [algogeeks] Sub-array problem

2011-12-05 Thread sourabh singh
@ mohit my first post on here. this solution got ac in spoj main() { unsigned int n,m,sum,max,i,j; sum=0;max=1; n=in.ReadNextUInt(); m=in.ReadNextUInt(); unsigned int *a = new unsigned int[n]; unsigned

Re: [algogeeks] Re: Sub-array problem

2011-12-05 Thread sourabh singh
integers... On Dec 5, 4:25 pm, sourabh singh singhsourab...@gmail.com wrote: @ mohit my first post on here. this solution got ac  in spoj main() {            unsigned int n,m,sum,max,i,j;                 sum=0;max=1;                 n=in.ReadNextUInt();                 m=in.ReadNextUInt