let 10 digit phone number stored in array a[]
take a array b[10] and initialise its elements with 0
int gp2[][2]; // group with 2 elements will store here
int gp3[][3]; // group with 3 elements will store here
int l=0,r=0,count=0;
int m[],n; //l,m,n is global
for(i=0;i10;i++)
*I made a mistake everywhere in if else ... mistake is in bold*
if(b[i]==3 count==0)
{
gp3[r][0]=gp3[r][1]=gp3[r][2]=
b[i];
r++;
}
elseif*(b[i]==3 count!=0)*
{
gp2[l][0]=gp2[l][1]=b[i];
l++;
gp2[l][0]=b[i];
gp2[l][1]=m[n];
l++;
So, I think first check for excellent groups then good and then usual to
increase the quality.
So to get excellent groups scan the string and keep a count of the
contagious repeating elements ,if count==3 or count==2,then put in one
group
The same procedure for good and usual accord to constraints
@Rajeev...check ur logic for 4
On 7/8/11, rajeev bharshetty rajeevr...@gmail.com wrote:
So, I think first check for excellent groups then good and then usual to
increase the quality.
So to get excellent groups scan the string and keep a count of the
contagious repeating elements ,if
It scans 555 count=3(excellent group) it will put in one group than 54
since the count is one puts that in usual group quality =2*1 =2 ,
On Fri, Jul 8, 2011 at 1:28 AM, Piyush Sinha ecstasy.piy...@gmail.comwrote:
@Rajeev...check ur logic for 4
On 7/8/11, rajeev bharshetty
i think DP has answer to this question
initialy compute the quality value of all the substrings of length 1,2,3
Ans[i][j] =
max(ans[i,j-2]+ans[j-1][j],ans[i,j-3]+ans[j-2][j],ans[i,i+1]+ans[i+2][j],ans[i,i+2]+ans[i+3][j])
something like that.
On Fri, Jul 8, 2011 at 1:31 AM, rajeev bharshetty
@Rajeev..there is the fault.for 4, there can be 2 excellent groups..
55
55
54
therefore, quality = 2*2 = 4
which is highest...
On 7/8/11, rajeev bharshetty rajeevr...@gmail.com wrote:
It scans 555 count=3(excellent group) it will put in one group than 54
since the count is one puts
sorry a typing mistake...lst line contains only 4
On 7/8/11, Piyush Sinha ecstasy.piy...@gmail.com wrote:
@Rajeev..there is the fault.for 4, there can be 2 excellent
groups..
55
55
54
therefore, quality = 2*2 = 4
which is highest...
On 7/8/11, rajeev bharshetty
@Rajeev...ignore my previous two posts.
the grouping can be done as
55
554
quality is 2*1+1 = 3 which is the highest
On 7/8/11, Piyush Sinha ecstasy.piy...@gmail.com wrote:
sorry a typing mistake...lst line contains only 4
On 7/8/11, Piyush Sinha ecstasy.piy...@gmail.com wrote:
@sunny , yep it looks DP. more of MCM.
solve for substrings of length 1,2,3.
and then apply DP[i][j]=max score for a substring from i to j.
=max(DP[i][k]+DP[k][j]) where ki kj .
The complexity this approach renders would be O(n^3).
with O(n^2) space complexity.
anyone anything better ?
@Sunny...can u post a definite algo for it??
On 7/8/11, Ravi Shukla shuklaravi...@gmail.com wrote:
@sunny , yep it looks DP. more of MCM.
solve for substrings of length 1,2,3.
and then apply DP[i][j]=max score for a substring from i to j.
=max(DP[i][k]+DP[k][j]) where ki kj .
The
http://ideone.com/xv73J
On Fri, Jul 8, 2011 at 2:16 AM, Piyush Sinha ecstasy.piy...@gmail.comwrote:
@Sunny...can u post a definite algo for it??
On 7/8/11, Ravi Shukla shuklaravi...@gmail.com wrote:
@sunny , yep it looks DP. more of MCM.
solve for substrings of length 1,2,3.
and then
Can u explain ur algo too??
On 7/8/11, Piyush Sinha ecstasy.piy...@gmail.com wrote:
@Sunny...nice solution but ur solution works if there can 1 to 3
groups of digits..but in the question its mentioned the group should
contain exactly 2 or 3 digits...
but anyways nice solution...:)
On
Nopes solution is for only groups of size 2 and 3.
solution is like a general DP
for string of length i to j
there can be only 4 possibilities
substring of length 2 from start + remaining string
substring of length 3 from start + remaining string
string except last 2 + value of last 2
string
14 matches
Mail list logo