Re: [algogeeks] MS question

2011-06-02 Thread Senthil S
Output

Hello! how is this? super
That is C!

-- 
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: strings

2011-05-27 Thread Senthil S
@ sunny agrawal : I misinterpreted the question .. but im not clear about
how you define interleaving of two strings .. Should the two strings be
mixed up at constant intervals or they can be mixed up anywhere .. and
should the ordering of the characters in the original strings be preserved
while constructing the third string ??

-- 
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: strings

2011-05-26 Thread Senthil S
Can it be done this way ..Take count of each alphabet for all the three
strings and store separately.. Then for each alphabet in the third string,
check if its count is equal to the sum of the counts of the corresponding
alphabet in the first two strings .. If the counts match for all alphabets
then the third string is an interleaving of the first two ..

-- 
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 INTERVIEW QUESTION

2011-05-10 Thread Senthil S
Hello Anders Ma .. for inputs like "iiestseig" (just a random string) your
code will not produce the correct output .. cos the best possible way to
split these strings is {"i","iestsei","g"} .. But your code will produce
{"ii","este","i","g"} as output .. so when there are overlapping palindromes
your code wont produce the correct output .. please look into it ..

On Tue, May 10, 2011 at 8:03 AM, Anders Ma  wrote:

> #include 
> #include 
>
> int is_palindrome(char* string, int start, int end)
> {
>int i = start, j = end;
>
>while (start <= end) {
>if (string[start++] != string[end--])
>return 0;
>}
>
>/* print */
>printf("[%d,%d] ", i, j);
>while ( i <= j)
>printf("%c", string[i++]);
>printf("\n");
>
>return 1;
> }
>
> int main(int argc, char** argv)
> {
>int i, j, k;
> int len, rescan;
>char demo[] = "madamimadam";
> char *p;
>
>if (argc != 2) {
>printf("usage padin (string)\n");
>return 0;
>}
>p = argv[1];
>
> do {
>rescan = 0;
>len = strlen(p);
>for (i = 0; i < len && rescan == 0; i++) {
> for (j = i, k = len; j <= k; k--)
>if (is_palindrome(p, j, k)) {
>p += k - j + 1;
> rescan = 1;
>break;
>}
>}
>} while (rescan);
>
>return 0;
> }
> anders@ubuntu:~/c$ gcc palindrome.c -o palin
> anders@ubuntu:~/c$ ./palin helloworld
> [0,0] h
> [0,0] e
> [0,1] ll
> [0,2] owo
> [0,0] r
> [0,0] l
> [0,0] d
> anders@ubuntu:~/c$ ./palin madamimadam
> [0,10] madamimadam
> anders@ubuntu:~/c$ ./palin andersma
> [0,0] a
> [0,0] n
> [0,0] d
> [0,0] e
> [0,0] r
> [0,0] s
> [0,0] m
> [0,0] a
>
>
> On Tue, May 10, 2011 at 10:11 AM, oldman 
> wrote:
> > I agree with Anders Ma's point,but in my opinion, using goto is risky in
> a
> > import interview
> >
> > On Tue, May 10, 2011 at 9:52 AM, Anders Ma  wrote:
> >>
> >>  sometimes we need goto, goto is not so evil.
> >>
> >> On Tue, May 10, 2011 at 2:49 AM, Manjeet Chayel
> >>  wrote:
> >> > Dont use goto... its not good to have it.
> >> >
> >> > On Mon, May 9, 2011 at 2:44 PM, Anders Ma 
> wrote:
> >> >>
> >> >> #include 
> >> >> #include 
> >> >>
> >> >> int is_palindrome(char* string, int start, int end)
> >> >> {
> >> >>int i = start, j = end;
> >> >>
> >> >>while (start <= end) {
> >> >>if (string[start++] != string[end--])
> >> >>return 0;
> >> >>}
> >> >>
> >> >>/* print */
> >> >>printf("[%d,%d] ", i, j);
> >> >>while ( i <= j)
> >> >>printf("%c", string[i++]);
> >> >>printf("\n");
> >> >>
> >> >>return 1;
> >> >> }
> >> >>
> >> >> int main(int argc, char** argv)
> >> >> {
> >> >>int i, j, k;
> >> >>int len;
> >> >>char *p;
> >> >>
> >> >>if (argc != 2) {
> >> >>printf("usage padin (string)\n");
> >> >>return 0;
> >> >>}
> >> >>p = argv[1];
> >> >> BEGIN:
> >> >>
> >> >>len = strlen(p);
> >> >>for (i = 0; i < len; i++) {
> >> >>for (j = i, k = len; j <= k; k--)
> >> >>if (is_palindrome(p, j, k)) {
> >> >>p += k - j + 1;
> >> >>goto BEGIN;
> >> >>}
> >> >>}
> >> >>
> >> >>return 0;
> >> >> }
> >> >>
> >> >> anders@ubuntu:~/c$ ./palin helloworld
> >> >> [0,0] h
> >> >> [0,0] e
> >> >> [0,1] ll
> >> >> [0,2] owo
> >> >> [0,0] r
> >> >> [0,0] l
> >> >> [0,0] d
> >> >> anders@ubuntu:~/c$ ./palin madamamadam
> >> >> [0,10] madamamadam
> >> >> anders@ubuntu:~/c$
> >> >>
> >> >>
> >> >>
> >> >> On Fri, May 6, 2011 at 8:58 PM, sourabh jakhar
> >> >> 
> >> >> wrote:
> >> >> >
> >> >> >
> >> >> > On Fri, May 6, 2011 at 4:23 PM, sourabh jakhar
> >> >> > 
> >> >> > wrote:
> >> >> >>
> >> >> >> You are given a large string. You need to cut the string into
> chunks
> >> >> >> such
> >> >> >> that each substring that you get is a palindrome. Remember that
> each
> >> >> >> 1
> >> >> >> length string is always a palindrome. You need to find the minimum
> >> >> >> number of
> >> >> >> cuts that you need to make such that each substring is a
> palindrome.
> >> >> >>
> >> >> >> --
> >> >> >> SOURABH JAKHAR,(CSE)(3 year)
> >> >> >> ROOM NO 167 ,
> >> >> >> TILAK,HOSTEL
> >> >> >> 'MNNIT ALLAHABAD
> >> >> >>
> >> >> >> The Law of Win says, "Let's not do it your way or my way; let's do
> >> >> >> it
> >> >> >> the
> >> >> >> best way."
> >> >> >>
> >> >> >> --
> >> >> >> You received this message because you are subscribed to the Google
> >> >> >> Gr

Re: [algogeeks] maximum difference in an array

2011-03-30 Thread Senthil S
Sorting takes O (N logN) .. You can find the minimum and the maximum in a
single traversal i.e O(N) time and return the difference of the two ..
To find minimum and maximum you can do the following :
i) Assign min = max = first element in the array.
ii)Then traverse the array .. for each element in the array .. if it is
greater than max , update max = that element .. else if it is lesser than
min, update min as that element ..

After finding min and max return the difference of the two


On Wed, Mar 30, 2011 at 12:43 PM, UTKARSH SRIVASTAV  wrote:

> Problem
> Can anyone give me the efficient algo to know the the maximum difference of
> two numbers in an arrayplease only tell the algo not code
> -
> *UTKARSH SRIVATAV*
> *CSE-3
> B-Tech 2nd Year
> @MNNIT ALLAHABAD*
>
>  --
> 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.