Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- **TABLE SUM PSEUDOCODE**
- let N = number of elements
- let A = array of elements
- R0 = array that will hold A + (1 to N) in the 0th rotation
- for i in (0 to N-1)
- R0[i] = A[i] + (i+1)
- pre = prefix max array of length N
- pre[0] = R0[0]
- for i in (1 to N-1)
- pre[i] = max(pre[i-1], R0[i])
- suf = suffix max array of length N
- suf[N-1] = R0[N-1]
- for i in (N-2 to 0)
- suf[i] = max(suf[i+1], R0[i])
- print suf[0] as output for 0th rotation
- for r in (1 to N-1)
- maxbeforesplit = r + pre[N-r-1]
- maxaftersplit = r-N + suf[N-r]
- maxoverall = max(maxbeforesplit, maxaftersplit)
- print maxoverall as output for rth rotation
Add Comment
Please, Sign In to add comment