Nothing in navigation signal processing is as simple as most descriptions make it sound. Signal detection theory is essentially probabilistic, so algorithms make their best guesses at the likeliest thing that might have happened, but there's always an error rate. Solving for the integer offsets can be done, if you are sufficiently careful and clever in defining an optimization procedure, as investigated in this thesis and this paper by Sandra Verhagen and Peter Teunissen. However, there isn't one common offset: each PRN code carries its own ambiguity. There are also lots of possible tradeoffs between efficiency and accuracy, brute force and clever trickery, memory requirements and processor requirements, etc. To understand any of them in detail, however, needs some background in digital signal processing, which I am not able to provide here, though I will allude to some of it in passing.
There are many possible ways to modify or break the ambiguity. The two algorithms I'll describe are just the ones I find easiest to think in, which says little to nothing about their accuracy or efficiency. It may be helpful to you to read these MIT lecture notes on GPS processing to give an introduction to other various things that have been tried for code tracking, and some comments on making comparisons between them.
Note: Ludo's question regards integer ambiguity in tracking the C/A code. This is not the same as most things you will find if you search on "GPS (or GNSS) integer ambiguity", which talk about tracking the phase of the signal. That's a different problem, that I won't get into here.
Algorithm One: Just Use a Longer Sample
One tradeoff in this case is that the longer the sample you use, the less ambiguous it becomes. Practical fast-response filters involve fancy tricks with multiple comparison voting schemes using many different lag shifts simultaneously to track a peak, as in Chapter 7 of this book, but you can get away with much simpler processing if you use a much longer input sequence. Yes, the C/A code repeats every millisecond, but that's not the only modulation present: the signal also contains the navigation message, which has a bit transition every 20 C/A repeats. Having just one or two bits of a nav message tells you very little, but if you use, for example, a full second of data, that's 50 bits of the nav message. That signal, of C/A and nav together, repeats exactly at most once per subframe, and in longer sequences might never repeat at all. When you autocorrelate this, you'll see a peak every 20 ms from just edge-detecting the nav message clock signal, but when you plot them all in a row you'll see the highest spike at the correct lag, with the incorrect ambiguous peaks sloping down away in both directions.
If the bit sequence in the sample you happened to snip out never repeats, there is no more ambiguity: equal length sections with different bit patterns won't correlate as strongly, so you can span the whole space of possible pseudoranges and pick the one best answer. If the bit sequence does repeat, then you have changed the ambiguity by the same amount you changed how long it takes the full C/A times Nav sequence to repeat, which should be the sampling interval (unless the bit pattern itself consists of a short repeating sequence). If you use a full second sample, the remaining ambiguity is not 300 kilometers, but 300 thousand kilometers, which is 3/4 of the way to the moon. You should have no difficulty picking which of those ambiguities might possibly make sense for a near-Earth object.
I do not recommend this as a practical approach! Its only requirement is to be easily explained. It is grossly inefficient, and its accuracy is limited by a basic physics effect you really ought to include in any GNSS processing, which complicates things but also helps break the ambiguity just by proper treatment. That is, since the satellites are in motion, and the receiver motion is not the same, there will be a Doppler shift. The receiver may be assumed to be stationary on the rotating Earth, or have its velocity estimated as part of the overall solution, or assumed to have its velocity known by other means and provided as an auxiliary input. There are errors and clever tricks and all that stuff for each of these, too.
Algorithm Two: Solve Simultaneously for the Doppler Shift
The importance of the Doppler shift to code acquisition is that the C/A code frequency is itself Doppler shifted, so its chip rate and its repeat rate are both increased or decreased by the same fractional amount that the carrier radio frequency is increased or decreased. If you correlate the received signal against your locally-generated C/A code, the Doppler shift will cause yours to misalign with the received signal, and give low scores for all lags, unless you somehow guess the right Doppler shift, and use it to modify your locally-generated code so it properly aligns with the actual bit rate received. This means what you really need to do is run the same correlation procedure against multiple different copies of the code that have their bit lengths altered by a range of possible observed Doppler shifts, then pick the pair of time delay and frequency offset which together give you the best fit. This is done by computing the Complex (or Cross) Ambiguity Function (CAF), and picking the highest CAF peak in two dimensions.
By this method of processing, in which you solve for both the time offset (pseudorange) and the frequency offset (Doppler shift) simultaneously, it is usually possible to get a better answer for each than you would have if you solved for the two offsets separately. It hopefully, but not necessarily, breaks the ambiguity by allowing you to look for inconsistencies, like plausible on their own time delays which CAF to infeasible Doppler shifts, or vice versa.
There is a large body of literature on CAF processing, to which Stein (1981) is the standard extremely condensed introduction. I won't get into any of the gory details, except for one little complication that catches my interest as a physicist: the Doppler shift is proportional to range rate. Therefore, since any number calculated by signal processing must be based on at least some number of samples of the signal, and each of those samples corresponds to some amount of time, the true pseudorange will be different at the beginning of the sample than at the end. It varies continuously in between, so any calculated pseudorange must be some kind of weighted average that represents all the values the instantaneous theoretical pseudorange takes in the time interval of the sample. Therefore, there is technically not just one correct answer to what pseudorange ought to be deduced from a sample. The same thing holds true of the Doppler shift itself! It has one value at the beginning of the interval, and a different one at the end, but the CAF attempts to encapsulate all of that variation into a single best-fit number.
These effects together mean that since although, for signal processing in general, textbook treatments get more accurate and SNR grows as you provide longer samples, taking longer samples naturally turns CAF peaks from nice sharp spikes into low, broad lumps with ill-defined centers, because just one number for pseudorange and Doppler don't do it justice anymore. The faster the range and the range-rate are changing, the less time you can profitably use in computing a single CAF.
 Sandra Verhagen. The GNSS integer ambiguities: Estimation and validation. Doctoral thesis, Technische Universiteit Delft, 2005. ISBN 90-804-1474-3
 Peter J. G. Teunissen and Sandra Verhagen. GNSS Ambiguity Resolution: When and How to Fix or not to Fix? Symposium on Theoretical and Computational Geodesy 6 (143-148), 2008. DOI 10.1007/978-3-540-74584-6_22
 Thomas Herring. Principles of the Global Positioning System, lecture 7. MIT Open Course Ware, https://ocw.mit.edu/courses/earth-atmospheric-and-planetary-sciences/12-540-principles-of-the-global-positioning-system-spring-2012/lecture-notes/MIT12_540S12_lec7.pdf
 Kai Borre, Dennis M. Akos, Nicolaj Bertelsen, Peter Rinder, and Søren Holdt Jensen. A Software-Defined GPS and Galileo Receiver: A Single-Frequency Approach. Springer-Verlag, 2007. ISBN 978-0-8176-4540-3
 Seymour Stein. Algorithms for ambiguity function processing. IEEE Transactions on Acoustics, Speech, and Signal Processing 29.3 (588-599), 1981. DOI 10.1109/TASSP.1981.1163621