×

# Dynamic Programming (Hackerrank WalmartLabs-codesprint)

 0 Can someone please explain the dynamic programing solution to this problem. asked 04 Nov '16, 13:11 4★akchamp 124●1●9 accept rate: 20%

 0 This problem can be solved by knowledge of 'Catalan Number'. You can read on this: http://www.geeksforgeeks.org/applications-of-catalan-numbers/ and https://en.wikipedia.org/wiki/Catalan_number . Here is dynamic solution to find n'th catalan number: long long int catalan[4002]; void precalc() { catalan[0] = 1; for(int i=1;i<=4001;i++) { if(i==1) catalan[i] = 1; else { long long int sum =0,left,right; for(int k=0;k
 2 You could also check out this article on catalan numbers.As catalan numbers are defined recursively it can be easily converted into itarative dp(similar to fibonacci).Just undestand how we arrive at the series coding this into dp is quite intutive. for solution you may refer to geeksforgeeks. answered 04 Nov '16, 14:07 537●1●8 accept rate: 27%
 0 This was the function I used in Java: static long[] catalanDP(int n) { long[] f = new long[n+1]; f[0] = f[1] = 1; for(int i=2;i<=n;i++) { for(int j=0;j
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×2,172

question asked: 04 Nov '16, 13:11

question was seen: 1,119 times

last updated: 04 Nov '16, 20:45