The production of Λ baryons and KS0 mesons (V0 particles) was measured in p–Pb collisions at sNN=5.02 TeV and pp collisions at s=7 TeV with ALICE at the LHC. The production of these strange particles is studied separately for particles associated with hard scatterings and the underlying event to shed light on the baryon-to-meson ratio enhancement observed at intermediate transverse momentum (pT) in high multiplicity pp and p–Pb collisions. Hard scatterings are selected on an event-by-event basis with jets reconstructed with the anti-kT algorithm using charged particles. The production of strange particles associated with jets pT,jetch>10 and pT,jetch>20 GeV/c in p–Pb collisions, and with jet pT,jetch>10 GeV/c in pp collisions is reported as a function of pT. Its dependence on angular distance from the jet axis, R(V0,jet), for jets with pT,jetch>10 GeV/c in p–Pb collisions is reported as well. The pT-differential production spectra of strange particles associated with jets are found to be harder compared to that in the underlying event and both differ from the inclusive measurements. In events containing a jet, the density of the V0 particles in the underlying event is found to be larger than the density in the minimum bias events. The Λ/KS0 ratio associated with jets in p–Pb collisions is consistent with the ratio in pp collisions and follows the expectation of jets fragmenting in vacuum. On the other hand, this ratio within jets is consistently lower than the one obtained in the underlying event and it does not show the characteristic enhancement of baryons at intermediate pT often referred to as “baryon anomaly” in the inclusive measurements.