awelgorithms

Print the window contents at a candidate

Updated

When the window is valid and you consider recording it, write the actual slice a[L..R] or s[L..R] plus the metric. Bounds without contents hide off-by-one.

What to focus on

Print only candidates (valid windows), or label INVALID if you also dump failing states. The contents must match indices L..R inclusive.

Worked examples

unique candidates

s = "abca"
  1. (0,2) "abc" len 3
  2. (1,3) "bca" len 3

Result: print "abc" and "bca"

cover candidate

s = "ADOBECODEBANC", t = "ABC", L=9 R=12
  1. s[9..12] = B,A,N,C
  2. missing==0

Result: print "BANC"

sum candidates

a = [4, 1, 9, 1], sum ≤ 10
  1. [0,1] [4,1] sum 5
  2. [1,2] [1,9] sum 10
  3. [2,3] [9,1] sum 10
  4. skip [0,2]

Result: print the three valid slices

Try it

Write printCandidate(s, L, R). s is a string, or a is an array of integers. L is the left index. R is the right index. The window includes s[L..R]. Print the slice, not only (L, R). At each RECORD print the slice text or array. Return nothing. On "abca" unique, ADOBECODEBANC vs ABC, and [4, 1, 9, 1] sum≤10.

a (or s) is nonempty. s contains a covering of t. All array values are positive.