A request logger records the error code of every failed request in codes, sorted ascending. To keep the log short, it keeps at most two entries for each code and drops the rest.
Write keepTwo(codes) that does this in place: each code appears at most twice, in ascending order, and the array is shortened to the kept items. Don't create a second array. The tests check codes after your function runs.
Input: codes = [404,404,404,500,503,503,503,503] Output: [404,404,500,503,503]
404 and 503 are cut down to two entries each.
Input: codes = [400,401,401] Output: [400,401,401]
No code appears more than twice.
0 <= codes.length <= 100000codes is sorted ascending.0 <= codes[i] <= 999Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #109 Keep Two of Each Retry. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.