Aggregate Investment Ownership from CSV
Problem statement
Each input row is a headerless CSV investment record: date,investorName,sharesPurchased,cashUsed.
Aggregate shares and cash by investor. Ownership is the investor's total shares divided by all purchased shares, reduced to a fraction. Return a canonical compact JSON array sorted by investor name, with each object using the field order investorName, sharesPurchased, cashUsed, ownership.
Function
aggregateOwnership(csvRows: String[]) → StringExamples
Example 1
csvRows = ["2025-01-01,Alice,100,500","2025-01-02,Bob,50,400","2025-01-03,Alice,50,300"]return = "[{\"investorName\":\"Alice\",\"sharesPurchased\":150,\"cashUsed\":800,\"ownership\":\"3/4\"},{\"investorName\":\"Bob\",\"sharesPurchased\":50,\"cashUsed\":400,\"ownership\":\"1/4\"}]"Alice owns 150 of 200 shares and Bob owns 50.
Example 2
csvRows = ["2025-01-01,Solo,7,21"]return = "[{\"investorName\":\"Solo\",\"sharesPurchased\":7,\"cashUsed\":21,\"ownership\":\"1/1\"}]"The only investor owns all shares.
Example 3
csvRows = ["2025-01-01,Zed,1,10","2025-01-02,Amy,2,30"]return = "[{\"investorName\":\"Amy\",\"sharesPurchased\":2,\"cashUsed\":30,\"ownership\":\"2/3\"},{\"investorName\":\"Zed\",\"sharesPurchased\":1,\"cashUsed\":10,\"ownership\":\"1/3\"}]"Output is sorted by investor, not input order.
Constraints
1 <= csvRows.length <= 100000.- Dates use
YYYY-MM-DD. Investor names contain ASCII letters, digits, spaces, underscores, or hyphens and contain no comma or quote. - Shares and cash are positive integers; all totals fit signed 64-bit integers.