Re: [algogeeks] Need an optimized solution.

2013-10-20 Thread Saurabh Paliwal
I submitted the solution on hackerrank and got Accepted. There is a change
though, there may be more terms like Term (r+1)
but this can also be done using O(1).

Term (r+2) : (2*n+1 - (r+2)*k)/2 and so forth until numerator becomes zero.
You can use the same technique to get this sum as well.

Sorry for the inconvenience.

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.


[algogeeks] Word breaking problem

2013-10-20 Thread kumar raja
I came across the word breaking problem in  geeks for geeks.
http://www.geeksforgeeks.org/dynamic-programming-set-32-word-break-problem/

If the problem statement is to count and print all the possible ways to
segment/partitaion a string
 based on dictionary of words. how to solve this problem?


The recurrence relation i have thought is


table[i,j] =  0  if i>j

 =  contains(dict,str[i])  if i==j

  =  contains(dict,str[i..j])+ sum(table[i[k]*table[k+1][j])
for i<=k