Inspired by this StackOverflow post.
Bob's job is to create spreadsheets and organize them. The way he organizes them is known to very few except for Bob, but he creates a list of each of the spreadsheets that fall under the same group. There's a bunch of data in the spreadsheet he creates, but there's only one piece of data that we're looking at right now: The number of days between the day he started this job and the day he made the spreadsheet. The first day he created two spreadsheets, noted them both as
0 and sorted them in to their proper locations.
Now, his boss is asking for a review of what kinds of spreadsheet happened each day, and it's your job to write some code that will figure that out for Bob; he has far too many spreadsheets to do it by hand.
Bob's info that he gives you comes in the form of a (0-or-1 indexed) jagged array where each datum is of the form
x = a[i][j].
a is what I'm calling the jagged array itself,
i is the type of spreadsheet, and
x is the date the array was created.
j is unimportant.
Given a jagged array of spreadsheet creation days organized by their type, return a jagged array of spreadsheet types organized by spreadsheet creation day.
Bob isn't going to just leave you with this abstract data. He's given me a subset of some of his spreadsheets to help you out with figuring out what everything is supposed to be.
Example input (0-indexed):
a = [ [3,2,5,0], # Bob doesn't necessarily sort his lists [1,3], [2,1,0,4], [4,5,3], [6,6] ]
Example output (with commentary, which of course is not required):
output = [ [0,2] # On day 0, Bob made one type 0 and one type 2 spreadsheet [1,2] # On day 1, Bob made one type 1 and one type 2 spreadsheet [0,2] # On day 2, Bob made one type 0 and one type 2 spreadsheet [0,1,3] # On day 3, Bob made one type 0, one type 1, and one type 3 spreadsheet [2,3] # On day 4, Bob made one type 2 and one type 3 spreadsheet [0,3] # On day 5, Bob made one type 0 and one type 3 spreadsheet [4,4] # On day 6, Bob made two type 4 spreadsheets ]
Note that Bob doesn't always make two spreadsheets every day, and so the output may be jagged as well. But he always makes at least one spreadsheet every day, so the output will never need to contain empty arrays - although if your output has empty arrays at the end, you don't need to remove them.
More test cases:
[[3,5,6,2],[0,0,0],[1,0,3,4]] -> [[1,1,1,2],,,[0,2],,,] [[-1]] -> Undefined behavior, as all input numbers will be non-negative integers. [,,,] -> [[0,1,3]]
The output's inner lists do not need to be sorted.
As always, no standard loopholes, and of course shortest code wins.
(As this is my first question, please let me know of anything I can do to improve it.)