@Anand: it depends on how you think of i
i thought of it as the starting digit of a group but you're thinking of it
as it's last
however both views are correct here since you're talking about my solution
minus 2!
you need to initialize the dp to 0 (and a bit change in IFs so that you
don't refer to
@amir: you for loop start from the end of the string so I think it should be
a[i], a[i-1], a[i-2];
On Mon, Jul 12, 2010 at 5:15 PM, Amir hossein Shahriari <
amir.hossein.shahri...@gmail.com> wrote:
> @ashish: i think u meant amir! anyway...
>
> profit for an excellent group is 2 and for a good gr
@ashish: i think u meant amir! anyway...
profit for an excellent group is 2 and for a good group it's 1
dp[i] is the max profit for memorizing a[i], a[i+1], ... , a[n]
dp is initialized to 0
so for example if a[i]==a[i+1]==a[i+2] it means that we can group a[i] &
a[i+1] & a[i+2] together in an e
@amit..can you little explain this
On Mon, Jul 12, 2010 at 4:50 PM, Amir hossein Shahriari <
amir.hossein.shahri...@gmail.com> wrote:
> this can be done in O(n) using DP:
>
> for (i=n-1;i>=0;i--){
>
> dp[i]=max(dp[i+2],dp[i+3]); // usual
> if (a[i]==a[i+1]) // excellent size 2
>
> dp[i]=ma
this can be done in O(n) using DP:
for (i=n-1;i>=0;i--){
dp[i]=max(dp[i+2],dp[i+3]); // usual
if (a[i]==a[i+1]) // excellent size 2
dp[i]=max(dp[i],2+dp[i+2]);
if (a[i]==a[i+1] && a[i+1]==a[i+2])//excellent size 3
dp[i]=max(dp[i],2+dp[i+3]);
if (a[i]==a[i+1] || a[i]==a[i+2] || a[i+
You are given a String number containing the digits of a phone number
(the number of digits, n, can be any positive integer) . To help you
memorize the number, you want to divide it into groups of contiguous
digits. Each group must contain exactly 2 or 3 digits. There are three
kinds of groups:
• E
3.You have 50,000 html files, some of which contain phone numbers. How would
you create a list of all the files which contain phone numbers?
Solutions should be optimal
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups