Solution (source code)

= Solution
{c}

If $0<B<K$, every surviving terminal price is already below the strike, so this is a <barrier digital put> paying one at expiry exactly when the upper barrier has been avoided. To use the <Black-Scholes reflection symmetry>, cap the free digital-put strike at $B$, rather than continuing to use $K$:
$$
\boxed{H(S,t)=D_B(S,t)-(S/B)^\gamma D_B(B^2/S,t),\qquad0<S<B<K.}
$$
Indeed, $D_B$ has terminal payoff one throughout the alive region, while its reflected argument exceeds $B$ and hence has zero terminal payoff. The barrier values again cancel. Using $D_K$ in both terms would generally leave an unwanted reflected terminal payoff near the barrier.

Writing $b=r-\sigma^2/2$ makes the discounted survival <probability> explicit:
$$
\boxed{H(S,t)=e^{-r\tau}\left[
\Phi\!\left(\frac{\log(B/S)-b\tau}{\sigma\sqrt\tau}\right)
-(S/B)^\gamma\Phi\!\left(\frac{\log(S/B)-b\tau}{\sigma\sqrt\tau}\right)
\right].}
$$
The price is independent of $K$ in this case. Both cases combine by replacing the free strike with $\min(K,B)$ in the <up-and-out digital put> formula.