Traffic movers
EasyOnline Assessment
Compare the page visits of two weeks and report which pages moved the most.
Each report is a list of strings "<path> <count>". A path may appear several times in the same report; its visits are the sum of its counts. A path that is missing from a report has 0 visits in it.
For every path whose visits differ between before and after, produce a line:
- If it had 0 visits before and has some now:
"<path> new". - If it had visits before and has 0 now:
"<path> gone". - Otherwise
"<path> <change>%", where the change is(after - before) / before * 100rounded to the nearest whole number, with halves rounded away from zero (+0.5 becomes +1, -0.5 becomes -1). Write a+before positive changes and a-before negative ones. If the rounded change is0, write0%without a sign (the line is still reported, because the visits did differ).
Paths with the same visits in both reports, including 0 in both, are not reported.
Input: before and after, lists of strings in the format above.
Output: the lines as a list of strings. Order them by the absolute difference in visits |after - before|, largest first; paths with the same difference are ordered by path in plain ascending (character code) order. If nothing changed, return [].
Example 1
- Input:
- [["/home 120","/pricing 80","/blog 40"],["/home 150","/pricing 40","/docs 30","/blog 40"]]
- Output:
- ["/pricing -50%","/docs new","/home +25%"]
- Explanation
- /home went from 120 to 150 visits (+25%) and /pricing from 80 to 40 (-50%). /docs has no visits in the before report, so it is new. /blog did not change and is left out. The biggest absolute changes come first: /pricing moved by 40, then /docs and /home both by 30, where the path name decides.
Example 2
- Input:
- [["/a 5","/a 5","/b 0","/c 7","/d 0"],["/b 3","/a 10","/d 0"]]
- Output:
- ["/c gone","/b new"]
- Explanation
- /a appears twice in the first report, so its count is 5 + 5 = 10; it is unchanged and left out. /b is listed with 0 visits before, which means no visits, so it is new. /c disappeared and is gone. /d has 0 in both reports and says nothing.
Example 3
- Input:
- [["/x 200","/y 200","/z 3","/w 1000","/q 1000"],["/x 201","/y 199","/z 4","/w 1001","/q 997"]]
- Output:
- ["/q 0%","/w 0%","/x +1%","/y -1%","/z +33%"]
- Explanation
- The percentages are rounded to the nearest whole number with halves away from zero: 200 to 201 is exactly +0.5%, which is +1%, and 200 to 199 is -1%. 3 to 4 is +33.33%, so +33%. A change of 0.1% rounds to 0% but the visits did change, so it is still listed, written 0% without a sign.
Constraints
0 <= before.length, after.length <= 300- Every entry is
"<path> <count>":pathhas no spaces and0 <= count <= 1000000