Re: [algogeeks] Re: wrong output of C program

2012-06-08 Thread sengar.mahi
@naveen :read the his doubt properly...he was expecting 5 10 15 but was getting 8 32 96...and dats the correction required which i made On Fri, Jun 8, 2012 at 8:08 AM, Navin Kumar algorithm.i...@gmail.comwrote: @Mahendra: for ur above code with t=(a2)+a o/p will be 5,10, 15 as i explained

Re: [algogeeks] Re: Power(n^n)

2012-06-08 Thread Abhishek Sharma
You don't need to use BigNum or long int for this program. Both n k should be less than 1000. Since there is no restriction on k,you don't need Bignum Since both n,k are restricted,you don't need bignum. if n5, simply reject the input and return false On Fri, Jun 8, 2012 at 11:01 AM, Dave

Re: [algogeeks] Re: Power(n^n)

2012-06-08 Thread Abhishek Sharma
Ignore the last post. Updated: You don't need to use BigNum or long int for this program. Both n k should be less than 1000. you need bignum only if there would be no restriction on k. Since both n,k are restricted, you don't need bignum. if n5( 5^5 1000), simply reject the input and return

Re: [algogeeks] MS Q: how to test a driverless car?

2012-06-08 Thread Ashish Goel
Things like sensor data coming from CAN/MoST from the car is collected and analysed in real time to avoid collisions, off-lane movement, distance maintenance, auto parking(including parallel), slippage on road/snow, GPS integration for perfect location and location specific data (like

Re: [algogeeks] Re: MS question : string compression

2012-06-08 Thread Ashish Goel
#include stdafx.h #include iostream using namespace std; const int len = 20; const int maxCount = 127; int rle(char* pStr, int length, char* pNew) { if (!pStr) return -1; if (length 3) return -1; int i = 0; int k = 0; char p1 = pStr[i++]; char p2 = pStr[i++]; char p3 = pStr[i++]; int pos=0;

Re: [algogeeks] Re: wrong output of C program

2012-06-08 Thread Navin Kumar
@sengar: sorry dude...i got his doubt.Though my explanation was correct. I think now everybody's doubt is clear.By the way thanx for correcting me. On Fri, Jun 8, 2012 at 11:48 AM, sengar.mahi sengar.m...@gmail.com wrote: @naveen :read the his doubt properly...he was expecting 5 10 15 but was

[algogeeks] Book Feedback needed for book from Narasimha Karumanchi

2012-06-08 Thread Ashish Goel
Hi, I came across Data Structures and Algorithms Made Easy: Data Structure and Algorithmic Puzzles Request for feedback if it is worth purchase. Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 -- You received this message because you are subscribed

Re: [algogeeks] Book Feedback needed for book from Narasimha Karumanchi

2012-06-08 Thread rajesh singarapu
Its a book worth have. On Fri, Jun 8, 2012 at 1:44 PM, Ashish Goel ashg...@gmail.com wrote: Hi, I came across Data Structures and Algorithms Made Easy: Data Structure and Algorithmic Puzzles Request for feedback if it is worth purchase. Best Regards Ashish Goel Think positive and

[algogeeks] first Repeating character in a string

2012-06-08 Thread himanshu kansal
how can we find 1st repeating character in string??? e.g. if the string is abba it should return 'b' and not 'a'. note: hashing will give the answer as 'a' -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send

Re: [algogeeks] first Repeating character in a string

2012-06-08 Thread Anika Jain
you will have to note time for of occurence of a character for all chars On Fri, Jun 8, 2012 at 2:15 PM, himanshu kansal himanshukansal...@gmail.com wrote: how can we find 1st repeating character in string??? e.g. if the string is abba it should return 'b' and not 'a'. note: hashing

Re: [algogeeks] first Repeating character in a string

2012-06-08 Thread atul anand
howcome hashing will result in wrong output..?? if(isHashed(str[i]) { character found. break. } else hash(str[i]); On Fri, Jun 8, 2012 at 2:15 PM, himanshu kansal himanshukansal...@gmail.com wrote: how can we find 1st repeating character in string??? e.g. if the string is abba

[algogeeks] Re: Book Feedback needed for book from Narasimha Karumanchi

2012-06-08 Thread Ramindar Singh
anybody having the ebook ? On Friday, 8 June 2012 13:44:18 UTC+5:30, ashgoel wrote: Hi, I came across Data Structures and Algorithms Made Easy: Data Structure and Algorithmic Puzzles Request for feedback if it is worth purchase. Best Regards Ashish Goel Think positive and find fuel

Re: [algogeeks] first Repeating character in a string

2012-06-08 Thread Ashish Goel
This is MS Q and hasing will give the right answer. walk over the string, if it is present in hashTable, it is first repeated character. This is single pass. However, if you do another pass, your answer would be a which is first char that is repeated whereas b is first character to occur first

Re: [algogeeks] Re: MS question : string compression

2012-06-08 Thread Ashish Goel
Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 On Fri, Jun 8, 2012 at 12:54 PM, Ashish Goel ashg...@gmail.com wrote: #include stdafx.h #include iostream using namespace std; const int len = 20; const int maxCount = 127; int rle(char* pStr,

Re: [algogeeks] first Repeating character in a string

2012-06-08 Thread Ganesh M
But you can use unordered map something like what boost does .. http://boost.cowic.de/rc/pdf/unordered.pdf Cheers. On Friday, June 8, 2012 5:38:56 PM UTC+8, ashgoel wrote: This is MS Q and hasing will give the right answer. walk over the string, if it is present in hashTable, it is first

[algogeeks] Re: Differentiate the following declarations.

2012-06-08 Thread Navin Gupta
Using Spiral-Anderson rule, 1:- const char * a - a is a pointer to char const (character which is constant , the value pointed by the pointer is constant) 2:- char * const a - a is a const pointer to char (pointer is constant, it always point to same memory location) 3:- char const * a - a is a

Re: [algogeeks] Re: Book Feedback needed for book from Narasimha Karumanchi

2012-06-08 Thread ABHISHEK PRAJAPATI
Its one of the best book. If u r planning for some big jobs thn u should read this book SDE 1 Amazon India development Center On Fri, Jun 8, 2012 at 2:45 PM, Ramindar Singh ramin...@gmail.com wrote: anybody having the ebook ? On Friday, 8 June 2012 13:44:18 UTC+5:30, ashgoel wrote: Hi,

Re: [algogeeks] Re: wrong output of C program

2012-06-08 Thread s yogeesh
@mehender exactly bro. program --  #include stdio.h   #define PrintInt(expr) printf(%s : %d\n,#expr,(expr))   int FiveTimes(int a)   {       int t;       t = (a2) + a;    // change - added parenthesis.       return t;   }   int main()   {       int a = 1, b = 2,c = 3;      

Re: [algogeeks] first Repeating character in a string

2012-06-08 Thread Rathish Kannan
In a string try to loop through all character and count the occurances (incrementing by 1 whenever that character occurs)... store it in hash (initialize the hash to 0)... when the count of any char equals 2 break from the loop that char is first repeating char. -- RK :) On Fri, Jun 8, 2012 at

Re: [algogeeks] first Repeating character in a string

2012-06-08 Thread Praveen
Use the below function, that will return first repeated character of string or null; Note: blank space is also consider as character... you can add exception to avoid such case char firstRepeatChar(char *str) { int arr[256] = {0}; for(int i = 0; str[i] != '\0'; i++) { arr[str[i]] +=1;

Re: [algogeeks] first Repeating character in a string

2012-06-08 Thread Nishant Pandey
the output will be correct it will not be incorrect in hashing case . On Fri, Jun 8, 2012 at 2:38 PM, atul anand atul.87fri...@gmail.com wrote: howcome hashing will result in wrong output..?? if(isHashed(str[i]) { character found. break. } else hash(str[i]); On Fri, Jun

Re: [algogeeks] first Repeating character in a string

2012-06-08 Thread Mahesh Thakur
lets say we have an array COUNT[256] which is initialized to zero. 1) traverse the string S from 0 to length-1 2) if COUNT[S[i] - '0'] == 0 , increment COUNT[S[i] - '0'] = 1; 3) else print the first repeating character. -Mahesh On Fri, Jun 8, 2012 at 2:26 PM, Anika Jain

Re: [algogeeks] Book Feedback needed for book from Narasimha Karumanchi

2012-06-08 Thread dvs kiran
Hi, I have been reading this book these days Book have very nice collection of problems which are very much needed for interview preparation. This is for not for those who is expecting to learn basics. On Fri, Jun 8, 2012 at 1:46 PM, rajesh singarapu rajesh0...@gmail.comwrote: Its a book

Re: [algogeeks] first Repeating character in a string

2012-06-08 Thread Nishant Pandey
you may use look up table for each character like this : int table[255]={0}; for(int i=0;str[i];i++) { if( table[str[i]] ) return true; else { table[str[i]]=1; } } return false; On Fri, Jun 8, 2012 at 2:26 PM, Anika Jain anika.jai...@gmail.com wrote: you will have to note

[algogeeks] Finding largest zigzag subsequence

2012-06-08 Thread Ratan
Given a list of integers n, we have to find the length of largest zigazg subsequence in the list i.e,zigzag subsequence is defined as if the first number is increasing then the 2nd one should be decreasing or vice versa.. for eg : if list[n]={1,10,5,9,8,12,20} then, largest zigzag

Re: [algogeeks] first Repeating character in a string

2012-06-08 Thread saurabh singh
The key doesn't lies in the way it will be solved.It is how efficiently you implement the hash table.do we really need an integer array ( 4*256 bytes) just to record the first occurrence of a character? Saurabh Singh B.Tech (Computer Science) MNNIT blog:geekinessthecoolway.blogspot.com On Fri,

Re: [algogeeks] first Repeating character in a string

2012-06-08 Thread Ashish Goel
no hashtable needed , a bitmap is sufficient Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 On Fri, Jun 8, 2012 at 4:04 PM, saurabh singh saurab...@gmail.com wrote: The key doesn't lies in the way it will be solved.It is how efficiently you

Re: [algogeeks] Finding largest zigzag subsequence

2012-06-08 Thread Ashish Goel
O(n) is straight forward bool increase = true; int j = 0; result[j++]=a[0]; for (int i=1;in;i++) { if ((increase) { if (result[j-1]a[i])) { result[j++] = a[i]; increase = false; } } else { if (result[j-1] a[i])) { result[j++] = a[i]; increase =

Re: [algogeeks] Finding largest zigzag subsequence

2012-06-08 Thread Ratan
Thats what the question is about to find the maximum subsequence. i too tried your code with the sample 10,4,12,4,1,43,21,4,1,5,7,23,9 ur code gave the result 10 12 4 43 21 23; but the correct optimized o/p should have been with length 7 as 4,12,1,43,21,23,9 On

Re: [algogeeks] Finding largest zigzag subsequence

2012-06-08 Thread srikanth reddy malipatel
we should use dp On Fri, Jun 8, 2012 at 5:39 PM, Ratan success.rata...@gmail.com wrote: Thats what the question is about to find the maximum subsequence. i too tried your code with the sample 10,4,12,4,1,43,21,4,1,5,7,23,9 ur code gave the result 10 12 4 43 21

Re: [algogeeks] Finding largest zigzag subsequence

2012-06-08 Thread srikanth reddy malipatel
#includestdio.h int main() { int Seq[100],i,j,n,Max,tmp; int zzlen[100][2]; scanf(%d,n); for(i = 0 ; i n ; i++) { scanf(%d,Seq[i]); zzlen[i][0] = 1;zzlen[i][1] = 0;} Max = 1; for(i = 1 ; i n ; i++) { for(j = i-1 ; j = 0 ; j--) { if(Seq[i]

Re: [algogeeks] first Repeating character in a string

2012-06-08 Thread Saurabh Yadav
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

Re: [algogeeks] Finding largest zigzag subsequence

2012-06-08 Thread Ratan
@srikanth: can u frame out the recursive function for the solution proposed in DP . i was actually finding difficulty in this.. On Fri, Jun 8, 2012 at 5:40 PM, srikanth reddy malipatel srikk...@gmail.com wrote: #includestdio.h int main() {     int Seq[100],i,j,n,Max,tmp;     int

Re: [algogeeks] Re: Book Feedback needed for book from Narasimha Karumanchi

2012-06-08 Thread Decipher
Does anybody has its ebook ? Please upload it -- 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/-/AETPnqJps7AJ. To post to this group, send email to

[algogeeks] search in O(logn)

2012-06-08 Thread Hassan Monfared
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

[algogeeks] Re: search in O(logn)

2012-06-08 Thread Dave
@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]

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

2012-06-08 Thread Hassan Monfared
Yes, Thanks Dave. for non-distinct items It's not possible. On Fri, Jun 8, 2012 at 6: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

Re: [algogeeks] first Repeating character in a string

2012-06-08 Thread himanshu kansal
@all: my bad...i ws confused while posting the ques. hashing can gv either a or bonly thing tht matters is hw u implement hashing and counting thanx i hv got the soln On Fri, Jun 8, 2012 at 4:33 PM, Saurabh Yadav saurabh...@gmail.com wrote: order of hashing and counting is

[algogeeks] override struct definition in c ????

2012-06-08 Thread HARSHIT PAHUJA
is it possible to override struct definition in c in header.h header file i have eg typedef struct a { int ab ; } nw in .c file i have included header.h typedef struct a { char c ; int b; } and giving following def i m getting an error ... *'struct type redefinition'* So anyways in c

Re: [algogeeks] Re: Algorithm page

2012-06-08 Thread Wladimir Tavares
More post: http://marathoncode.blogspot.com.br/2012/06/qual-e-o-melhor-comentario-no-codigo.html http://marathoncode.blogspot.com.br/2012/06/importancia-de-algoritmos-eficientes.html http://marathoncode.blogspot.com.br/2012/06/um-professor-em-minha-vida.html

[algogeeks] Re: override struct definition in c ????

2012-06-08 Thread Gene
No. In C++ you can't either. You can declare a new class that _extends_ a previous one, but you can't change a declaration once it's complete. On Jun 8, 11:38 am, HARSHIT PAHUJA hpahuja.mn...@gmail.com wrote: is it possible to override struct definition in c in header.h header file i

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

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

Re: [algogeeks] first Repeating character in a string

2012-06-08 Thread Karunakar Reddy
ya...hashing is rt method but, we have to implement it by using self referential structure i think ..stilll we can solve this problem by using arrayslike int arr[256]={0}; int main() { char str[]=abba; . . for(i=0;str[i]!=NULL;i++) { if(arr[(str[i]-'0')]==1) { printf(first

Re: [algogeeks] Re: interview HARD problem

2012-06-08 Thread muthulakshmi..63
is it like this : Ex: rose open send end this is a rectangle having valid words.and available in dictionary tooo... On Wed, Jun 6, 2012 at 11:46 AM, Ashish Goel ashg...@gmail.com wrote: Gene, you are right, the rectangle is valid if rotated by 90 degrees too. Best Regards Ashish

Re: [algogeeks] first Repeating character in a string

2012-06-08 Thread Saurabh Yadav
i was explaining the general idea which we generally use with hashing i.e. hashing and counting the all the char and then find which is the repeated character yes u r correct , for the correct solution we should return when we found bitmap set , which is the actual solution :) On Fri, Jun 8,

[algogeeks] Basics--- Advanced

2012-06-08 Thread vickywiz
If one wants to start with basics of Data Structures and Algorithms and then move to advanced, how should one start with. I mean, which books to read first so that one gets basics clear. And then to move to advanced level, what more to do(like books to read,training in USACO, practice in