Consider a centred random walk in dimension one with a positive finite variance σ2, and let τB be the hitting time for a bounded Borel set B with a non-empty interior. We prove the asymptotic Px(τB>n)∼2/πσ−1VB(x)n−1/2 and provide an explicit formula for the limit VB as a function of the initial position x of the walk. We also give a functional limit theorem for the walk conditioned to avoid B by the time n. As a main application, we consider the case that B is an interval and study the size of the largest gap Gn (maximal spacing) within the range of the walk by the time n. We prove a limit theorem for Gn, which is shown to be of the constant order, and describe its limit distribution. In addition, we prove an analogous result for the number of non-visited sites within the range of an integer-valued random walk.