'〜か〜ないかのうちに': Barely Before Finishing ('Hardly Had... When...')
[Verb Dict Form] か [Verb Nai-form] かのうちに (Barely any perceptible interval)
'〜か〜ないかのうちに' indicates that before the first action had even fully finished concluding, the second action occurred almost simultaneously ('no sooner had... than...', 'hardly had... when...').
⚠ Note: Affirmative + negative verb: '終わるか終わらないかのうちに' (hardly before it even ended).
チャイムが鳴るか鳴らないかのうちに、生徒たちは教室を飛び出した。
No sooner had the chime started ringing than the students bolted out of the classroom.
布団に入るか入らないかのうちに、彼は深い眠りに落ちた。
Hardly had he slipped under the covers when he fell into a deep sleep.