[algogeeks] Re: strings

2011-05-19 Thread Don
bool interleaved(char *s1, char *s2, char *s3) { // Base case, all strings are empty return (!s1[0] && !s2[0] && !s3[0]) || // First character of s1 is next in s3 (s1[0] && (s1[0] == s3[0]) && interleaved(s1+1,s2,s3+1)) || // First character of s2 is next in s3 (s2[0] && (s2[0] == s3[

[algogeeks] Re: strings

2011-05-19 Thread Don
bool interleaved(char *s1, char *s2, char *s3) { return (!*s1 && !*s2 && !*s3) || // Base case, all strings are empty (*s1 && (*s1 == *s3) && interleaved(s1+1,s2,s3+1)) || // First character of s1 is next in s3 (*s2 && (*s2 == *s3) && interleaved(s1,s2+1,s3+1));// First character of s2

[algogeeks] Setnja Wrong Answer [ Haskell Code ]

2011-05-19 Thread mukesh tiwari
Hello all , i am trying to solve this problem https://www.spoj.pl/problems/SETNJA/ but getting WA. Could some one please tell me what is wrong with algorithm. import qualified Data.ByteString.Char8 as BS import Data.List as L solve :: BS.ByteString -> Integer solve xs = solverHelp xs 1 where

Re: [algogeeks] Array problem

2011-05-19 Thread Kunal Patil
@ Piyush: Excellent Solution...It appears both Correct and O(n)...Good work !![?] Just a minor correction in your algo.[?] * while(B[i]http://groups.google.com/group/algogeeks?hl=en. <<363.gif>><<360.gif>>

[algogeeks] strings

2011-05-19 Thread Piyush Sinha
Design an algorithm to find whether a given string is formed by the interleaving of two given strings or not. e.g. s1= aabccabc s2= dbbabc s3= aabdbbccababcc Given s1,s2,s3 design an efficient algorithm to find whether s3 is formed from the interleaving of s1 and s2 -- *Piyush Sinha* *IIIT, Allah

Re: [algogeeks] Re: GOOGLE Q

2011-05-19 Thread pacific :-)
If we were given two strings and asked to check if they have the same characters (anagrams) : @ gene : you are sorting them both ,and trying to match. cost : sort the first string + sort the second string + compare i.e k * k + k * k + k .. k is the length of the string. I presume that bubble sort

[algogeeks] counting palindromes CODECHEF

2011-05-19 Thread ila
My code using dp takes leeser amount of time than a few submitted solutions still submission says TLE .. Kindly help!! #include #include #include #include using namespace std; int A[1001][1001]; bool if_palindrome( string s, int i, int j ) { if( s[i] == s[j] ){

[algogeeks] Re: nearest neighbour

2011-05-19 Thread Dave
@Sravanreddy001: You are to find _each_ person's friends. Can you do that in O(n)? Dave On May 19, 8:59 am, sravanreddy001 wrote: > Also, I think there is no need for sorting the number, its still okey if the > 3rd person is standing 1st and has the lowest number line value. > > And, finding the

[algogeeks] Re: nearest neighbour

2011-05-19 Thread Dave
@Puneet: It didn't say integer. -- Dave On May 19, 8:43 am, Puneet Ginoria wrote: > I guess the sorting in this case is not O(nlogn) > If the nos. we are associating with each person from the number line , it > can be sorted in O(n) time, if those nos. are in from {1,2,..n}. > Correct me if I am

Re: [algogeeks] Re: nearest neighbour

2011-05-19 Thread sravanreddy001
Also, I think there is no need for sorting the number, its still okey if the 3rd person is standing 1st and has the lowest number line value. And, finding the closest 3 number takes, 3*n time.. so.. its O(n) running time.. @Dave.. good catch.. :) -- You received this message because you ar

Re: [algogeeks] Re: nearest neighbour

2011-05-19 Thread Puneet Ginoria
I guess the sorting in this case is not O(nlogn) If the nos. we are associating with each person from the number line , it can be sorted in O(n) time, if those nos. are in from {1,2,..n}. Correct me if I am Wrong -- You received this message because you are subscribed to the Google Groups "Algor

Re: [algogeeks] [brain teaser ] Is This Maths Riddle 19 may

2011-05-19 Thread sourabh jakhar
10=3 because ten = three characters in it On Thu, May 19, 2011 at 1:51 PM, ps.raghuchan...@gmail.com < ps.raghuchan...@gmail.com> wrote: > cuz 10=3 > > > On Thu, May 19, 2011 at 12:57 PM, Lavesh Rawat wrote: > >> *Is This Maths Riddle >> * * *** >> * >> * >> ** >> *If >> 12=6 >> and >> 6=3 >> th

Re: [algogeeks] [brain teaser ] Is This Maths Riddle 19 may

2011-05-19 Thread ps.raghuchan...@gmail.com
cuz 10=3 On Thu, May 19, 2011 at 12:57 PM, Lavesh Rawat wrote: > *Is This Maths Riddle > * * *** > * > * > ** > *If > 12=6 > and > 6=3 > then why doesn't > 10=5? > (and what does 10 equal?) > * > [brain teaser ] Is This Maths Riddle 19 may > > *Update Your Answers at* : Click > Here

[algogeeks] [brain teaser ] Is This Maths Riddle 19 may

2011-05-19 Thread Lavesh Rawat
*Is This Maths Riddle * * * ** *If 12=6 and 6=3 then why doesn't 10=5? (and what does 10 equal?) * [brain teaser ] Is This Maths Riddle 19 may *Update Your Answers at* : Click Here Solution: Will be upd