Re: [algogeeks] Re: sqrt function...

2011-09-24 Thread keyan karthi
binary search!!! :) On Sat, Sep 24, 2011 at 11:38 PM, sunny agrawal sunny816.i...@gmail.comwrote: let x be the number initialize ans to some value like x or x/2 now repeatedly do the following ans = (ans + x/ans)/2 each time you perform this operation you will move closer to the sqrt

Re: [algogeeks] All valid dictionary words must be found and printed.

2011-09-19 Thread keyan karthi
construct a trie.. then a simple recursion on the trie ll do ... :) any standard tutorial on tries ll help u build one ... then the recursion part should look something like this, start scanning from root of tire. if(end of word is found) { take is as a word, start searching from root of a

Re: [algogeeks] All valid dictionary words must be found and printed.

2011-09-19 Thread keyan karthi
didnt read the question properly ... ignore ma post !! :/ On Mon, Sep 19, 2011 at 8:44 PM, Yogesh Yadav medu...@gmail.com wrote: i=0; char *str; while(a[i]!=NULL) { j=0; while(j!=i) { for(k=j;k=i;k++) { l=0; str[l]=a[j]; }

Re: [algogeeks] spoj coin tossing

2011-08-24 Thread keyan karthi
thanks *Shashi* !!! http://deepblue.lib.umich.edu/bitstream/2027.42/24435/1/708.pdf this one is good to :) On Wed, Aug 24, 2011 at 5:32 PM, shashi kant shashiski...@gmail.com wrote: http://www.se.cuhk.edu.hk/~seem3570/12-pattern.pdf here is the solution to this On Wed, Aug 24,

Re: [algogeeks] spoj coin tossing

2011-08-24 Thread keyan karthi
^typo On Wed, Aug 24, 2011 at 6:46 PM, keyan karthi keyankarthi1...@gmail.comwrote: thanks *Shashi* !!! http://deepblue.lib.umich.edu/bitstream/2027.42/24435/1/708.pdf this one is good to :) On Wed, Aug 24, 2011 at 5:32 PM, shashi kant shashiski...@gmail.comwrote: http

[algogeeks] spoj- coin tossing

2011-08-23 Thread keyan karthi
http://www.spoj.pl/problems/MAIN8_D/ i tried solving this problem any ideas...?? for second test case 'htht' the states i considered are 1 T - (1/2) * x+1 2 HH - (1/4) * x+2 3 HTT - (1/8) * x+3 4 HTHH - (1/16) * x+4 5 HTHT - (1/16)(final state) x is the expected no

Re: [algogeeks] priority_queue

2011-08-14 Thread keyan karthi
priority_queueobject, vector of object, greaterobject On 8/15/11, Zack sandeep.masum4...@gmail.com wrote: how i use STL,s prority_queue as a min heap..? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to

Re: [algogeeks] priority_queue

2011-08-14 Thread keyan karthi
priority_queuepairint,int, vectorpairint,int , greater pair int, int here pair. First is used for comparing If you replace greater with lower , you get max heap If you use some structure... You have to define a bool function in tat case.. On 8/15/11, sandeep pandey

Re: [algogeeks] Design .. how to attack ???

2011-08-12 Thread keyan karthi
First thing tat should come to your mind s ' requirements ' ask him wat de requirements are. He will expect tat.. On 8/12/11, MAC macatad...@gmail.com wrote: Hi guys , Can anyone help me in understanding what is expected when some some one asks you design a car rental system . Exactly

Re: [algogeeks] MS question

2011-08-10 Thread keyan karthi
May be this way We dont display de title of a movie as a thumbnail So may be the first frame which has a wide distribution of colours , assuring it has some other part of de clip other than de title.. Ignore this if it sounds funny...!! On 8/9/11, *$* gopi.komand...@gmail.com wrote:

Re: [algogeeks] Duplicates in a string

2011-08-05 Thread keyan karthi
u can use a bool array size- 26 and do char[i]-'A' = 1 , check it to decide the first instance of the character. this can be done in O(n). u can even use bit mask to make ur code look better ( ;) ) On 8/5/11, priya v pria@gmail.com wrote: If an additional storage is used to store the

Re: [algogeeks] Re: latest google interview questions

2011-08-03 Thread keyan karthi
:D :D r u serious dude ?? On 8/3/11, Puneet Gautam puneet.nsi...@gmail.com wrote: @Utkarsh: How did u get the intern...? it cant be ...!!! Who is the moderator of this group..? I want this thread be removed immediately from this group...!!! pls do it... On 8/3/11, kaustubh

Re: [algogeeks] Tug of War

2011-07-30 Thread keyan karthi
if it is spoj -tug , then the problem gets reduced to knapsack dp which is used for subset sum calculation :) since u just have to print yes or no break once the sum count becomes '2' for some sum. On 7/30/11, Amol Sharma amolsharm...@gmail.com wrote: @saurabh- your algo has very high

Re: [algogeeks] Amazon Question

2011-07-26 Thread keyan karthi
@kavitha: u can use back tracking to print all the substring for a string .. pseudo code should look some thing like this: void next_perm(string st,int pos) { if(pos==length) { coutst; return; } for(int i=pos;ilength;i++) { swap(st,i,pos); next_perm(st,i+1);

Re: [algogeeks] Amazon Question

2011-07-26 Thread keyan karthi
oops .. permutation pardon me guys !!! On 7/26/11, keyan karthi keyankarthi1...@gmail.com wrote: @kavitha: u can use back tracking to print all the substring for a string .. pseudo code should look some thing like this: void next_perm(string st,int pos) { if(pos==length

Re: [algogeeks] Unique characters in a string

2011-07-23 Thread keyan karthi
yup tat should work fine :) :) On Sat, Jul 23, 2011 at 10:03 AM, rajeev bharshetty rajeevr...@gmail.comwrote: Use Quick sort to sort the characters of a string (qsort is inplace sorting ) then check for consecutive characters in the array, if they are same then the string is not unique else

Re: [algogeeks] Sorting in O(n)

2011-07-22 Thread keyan karthi
counting sort ll help to some extent... find the min and max element O(n) now u just need an array of size max-min to store the values then just traverse the list and while updating u do value+min... still it is not suitable if the magnitude is high. On Sat, Jul 23, 2011 at 9:45 AM,

Re: [algogeeks] Unique characters in a string

2011-07-22 Thread keyan karthi
u can use an integer as a bit mask to do this... by setting the alphabet-'a' th bit, and checking the same.. On Sat, Jul 23, 2011 at 9:52 AM, Reynald reynaldsus...@gmail.com wrote: Implement an algorithm to determine if a string has all unique characters. What if you can not use

Re: [algogeeks] c aps can some one explain this pls :)

2011-07-18 Thread keyan karthi
.unpredictable behaviour !! -- Amol Sharma Third Year Student Computer Science and Engineering MNNIT Allahabad On Mon, Jul 18, 2011 at 2:36 PM, keyan karthi keyankarthi1...@gmail.comwrote: #includeiostream using namespace std; int main() { int p=1; printf(%d %d %d %d,++p,p++,p

Re: [algogeeks] c aps can some one explain this pls :)

2011-07-18 Thread keyan karthi
thanks ppl :) On Mon, Jul 18, 2011 at 3:59 PM, schrodinger 6fae1ce6347...@gmail.comwrote: AFAIK, official answer is due to undefined behavior. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit

Re: [algogeeks] Given a BST containing integers, and a value K. You have to find two nodes that give sum = K.

2011-07-16 Thread keyan karthi
can be done in NlogN take a node, say 'a' check if k-a exists in the tree(logN) On Sat, Jul 16, 2011 at 7:58 PM, sourabh jakhar sourabhjak...@gmail.comwrote: convert into doubly linked list and than apply simple algo of finding two element with a sum On Sat, Jul 16, 2011 at 7:54 PM, saurabh

Re: [algogeeks] help..

2011-07-02 Thread keyan karthi
yup :) On Sat, Jul 2, 2011 at 1:38 PM, Shalini Sah shalinisah.luv4cod...@gmail.com wrote: i guess the no. of 1s in the binary representation of the number is the answer..for 6 its 2... On Sat, Jul 2, 2011 at 1:32 PM, cegprakash cegprak...@gmail.com wrote: the length of the rope is l

Re: [algogeeks] Sum to K problem

2011-07-02 Thread keyan karthi
http://en.wikipedia.org/wiki/Subset_sum_problem http://en.wikipedia.org/wiki/Subset_sum_problem this should help u :) knapsack like dp :) On Mon, Jun 20, 2011 at 11:55 AM, Navneet Gupta navneetn...@gmail.comwrote: Given a set of integers , find a set of numbers such that they sum to a given

Re: [algogeeks] Re: Find an element which is not present?

2011-06-21 Thread keyan karthi
one way might be... find min element, max element declare a array buffer[max-min] memset this to -1 for( i=0 to size ) buffer[input[i]-min elemet]=1 now check in O(n) the first position that has a -1 in array buffer, this position + min element is the answer but this uses lotta extra

Re: [algogeeks] Re: spoj problem chairs

2011-06-21 Thread keyan karthi
dp(int chair,int person,bool previous) if(previous) dp(chair-1,person,0) else dp(chair-1,person-1,1)+dp(chair-1,person,0) with basic conditions as it is a circle.. if person is placed in first chair u cant place a person in last chair On Tue, Jun 21, 2011 at 7:38 PM,

Re: [algogeeks] Re: find output.

2011-06-16 Thread keyan karthi
hi friends is a string literal.. ie the string hi friends is stored somewhere and a pointer to its base address is returned to pointer p at the time of initialization... u can always make use of this pointer to traverse / access the literal but u cant alter tat in the code, u r trying to do a ++

Re: [algogeeks] MSFT Q

2011-06-15 Thread keyan karthi
we can even add word completion :) On Wed, Jun 15, 2011 at 5:25 PM, immanuel kingston kingston.imman...@gmail.com wrote: Use a trie data structure and pre-load it with all the words of a dictionary. Thanks, Immanuel On Wed, Jun 15, 2011 at 3:06 PM, Piyush Sinha

Re: [algogeeks] Please explain this problem

2011-06-12 Thread keyan karthi
upper_bound and lower_bound does a binary search to get count of alike terms.. which u tend to sum of to get the ans.. out of the two arrays, u need to sort one array.. this will be teh vector in which u do the binary search wit every element of un sorted array.. this is the approach i used... :)

Re: [algogeeks] Please explain this problem

2011-06-12 Thread keyan karthi
assuming bsearch is returning a pointer to the first found element. On Sun, Jun 12, 2011 at 12:41 PM, keyan karthi keyankarthi1...@gmail.comwrote: upper_bound and lower_bound does a binary search to get count of alike terms.. which u tend to sum of to get the ans.. out of the two arrays, u

Re: [algogeeks] Please explain this problem

2011-06-12 Thread keyan karthi
...@gmail.comwrote: @keyan..your advice was really very helpful...the time limit has come under control ...1.4s but now i am getting WA though my code is giving right ans for the test cases...can you plz help me in figuring out where it fails .. On Sun, Jun 12, 2011 at 12:59 AM, keyan karthi

Re: [algogeeks] Re: SPOJ THRBL

2011-06-11 Thread keyan karthi
k=query(x,y-1) if(k==x) count++ with this change ur code ACs :) On Sat, Jun 11, 2011 at 1:24 PM, Radhika Renganathan radi.coo...@gmail.comwrote: i did the same prob wit range maximum query.. but im repeatedly getting wrong answer.. im stuck with this prob for a long time.. pls help.. my

Re: [algogeeks] SPOJ THRBL

2011-06-10 Thread keyan karthi
u construct a tree nlogn , every node answers a query.. (or u get ans with a recursion) in log(n) , so when u r doing a lot of query RMQ proves to be very fast On Fri, Jun 10, 2011 at 6:28 PM, nicks crazy.logic.k...@gmail.com wrote: ya i saw that in the comments on spoj someone suggested to use

Re: [algogeeks] Please explain this problem

2011-06-09 Thread keyan karthi
the nos can repeat :) ie the valid set may contain multiple instance of a same number.. hope this helps :) On Fri, Jun 10, 2011 at 9:31 AM, saurabh singh saurab...@gmail.com wrote: Problem link- ABCDEF https://www.spoj.pl/problems/ABCDEF/ Can someone please explain this problem.The problem

Re: [algogeeks] repeted element

2011-06-08 Thread keyan karthi
abba as goel pointed out.. is the answer 'b' or 'a' .. ie does the order in which u encounter the character matters.. 'a' comes before 'b' here... if it is 'b' then a normal buf[txt[i]-'a']++ should do.. :) On Wed, Jun 8, 2011 at 8:48 AM, Shivaji Varma shivaji...@gmail.com wrote: This problem

Re: [algogeeks] Re: get rid of sohail panzer spam

2011-06-08 Thread keyan karthi
:D :D On Wed, Jun 8, 2011 at 2:25 PM, Kunal Patil kp101...@gmail.com wrote: Automatic deletion will solve the trouble only for you not for the group as such messages are not reported spam.. [?] What i do is: When i login just type in search box 'panzer'...mark all...report spam and then

Re: [algogeeks] SPOJ ETF

2011-06-05 Thread keyan karthi
dude.. u code says pi(3) =3 as its a prime... but pi(3) is 2 in the same way pi(2)=2 as per ur code.. but ans is 1... mend ur code for this... :) On Sun, Jun 5, 2011 at 9:20 PM, kartik sachan kartik.sac...@gmail.comwrote: @keyan then also it is given time limit exceed i

Re: [algogeeks] SPOJ ETF

2011-06-05 Thread keyan karthi
also tc page tat arun said says as follows... 1. If *p* is prime, then φ (*p*) = *p* - 1 and φ (*pa*) = *p** a* * (1 - 1/*p*) for any *a*. 2. If *m* and *n* are coprime, then φ (*m* * *n*) = φ (*m*) * φ (*n*). 3. If *n* = , then Euler function can be found using formula: φ (*n*) =

Re: [algogeeks] SPOJ ETF

2011-06-04 Thread keyan karthi
first time when i pre processed, my code timed out :P on calling it for every loop iteration my code passed !! may be tats the problem... On Sun, Jun 5, 2011 at 1:56 AM, kartik sachan kartik.sac...@gmail.comwrote: @arun.i got nothing from this link becoz i have made the program

Re: [algogeeks] spoj problem acode

2011-06-01 Thread keyan karthi
even if the left over string length is 1 so that the recursion can be fun(s,current_position-2), u still have the option for choosing a single character... do u get it?? thats where u go wrong... :) the rec call should be return fun(cur_length-1)+fun(cur_len-2) ... On Wed, Jun 1, 2011 at 3:34

Re: [algogeeks] spoj problem acode

2011-06-01 Thread keyan karthi
oops.. :P that an if didnt notice tat :D On Wed, Jun 1, 2011 at 8:34 PM, keyan karthi keyankarthi1...@gmail.comwrote: even if the left over string length is 1 so that the recursion can be fun(s,current_position-2), u still have the option for choosing a single character... do u get

Re: [algogeeks] SPoj maximum sum subseuence

2011-03-14 Thread keyan karthi
i used the following code.. getting wa #includeiostream #includealgorithm #includevector #includelimits.h #includemap using namespace std; typedef unsigned long long int ull; int main() { int t; cint; while(t--) { int n,sm=0; scanf(%d,n); vectorint v(n); mapint,int mp; for(int i=0;in;i++)