1

I have to calculate number of sliding window in a string.

If the sample string is "CHECKIT" and window size is 2 then

  1. CH
  2. HE
  3. EC
  4. CK
  5. KI
  6. IT

Window size may vary for the string.

Rustyn
  • 8,407

1 Answers1

3

For a word with $n$ alphabets, for eg. ALPHABETS has 9 alphabets. Of this, window size is $k$. Total possible ways will be:

$$P = n - k + 1 = 9 - k + 1 = 10 - k$$


$ k = 2 $

  1. AL
  2. LP
  3. PH
  4. HA
  5. AB
  6. BE
  7. ET
  8. TS

$k = 4$

  1. ALPH
  2. LPHA
  3. PHAB
  4. HABE
  5. ABET
  6. BETS

and so on...

hjpotter92
  • 3,049