As reported: Microsoft (2025), coding question on a given Java skeleton:
PhoneRegister.NextPhone()returns the next stored string and finallynull;maincallsNextLine()until it returnsnulland prints each result. OnlyNextLine()may be changed, without adding parameters, and it must get its data fromPhoneRegister.NextPhone(). Print every phone number separately.
A phone register gives out its contents one entry at a time through PhoneRegister.nextPhone(), which returns the next entry string, or nothing once the register is exhausted. Taken together, the entries form one stream of digits in which -- separates phone numbers — and a number may be cut across two or more consecutive entries.
Implement nextLine(): each call returns the next complete phone number, or nothing when no numbers are left. main calls it repeatedly and prints the numbers.
Example
entries: "324324--232", "4324--1223", "12--32432--", "12324332", "--23343254--",
"313123--221", "234234--213123", ""
nextLine() calls return:
324324, 2324324, 122312, 32432, 12324332, 23343254, 313123, 221234234, 213123, then nothing
232 at the end of the first entry continues with 4324 from the second: 2324324. 12324332 has no -- around it inside its entry, but the previous entry ended with -- and the next starts with one.
Example 2
entries: "555--1", "2", "3--", "--77" -> 555, 123, 77
Clarifications
- Empty pieces are skipped:
----between numbers, or--at the very start, produces no empty number. - When the register is exhausted, whatever digits are pending form the last number.
- A
--separator is never split between two entries. Entries may be empty strings. - Get entries only through
nextPhone(), as you need them — don't assume the register fits in memory.
Constraints: up to 3 · 10^4 entries; entries hold digits and -; up to 2 · 10^5 characters in total.
Code runner format: one line: the register's entries as a JSON array. The harness serves them through PhoneRegister.nextPhone() (Python/JavaScript/Java: returns None/null at the end; C++: PhoneRegister::nextPhone(string& s) returns false; Go: NextPhone() (string, bool)), calls your nextLine() on one Solution object until it reports the end (C++: bool nextLine(string& out); Go: NextLine() (string, bool)), and prints the list of numbers.