Top-Funded Villages and Projects
Updated
Problem statement
You are given three finite relations encoded as string matrices:
- Each
villagesrow is[villageId, villageName]. - Each
projectsrow is[projectId, villageId, projectName]. - Each
fundsrow is[projectId, date, amount], wheredateusesYYYY-MM-DDformat andamountis a nonnegative decimal integer.
Only funding rows whose date is in calendar year 2024 contribute. A project's funding is the sum of its contributing rows, and a project with no contributing row has funding 0. A village's total funding is the sum of the funding for all of its listed projects.
Consider every village that has at least one listed project. Keep every village tied for the maximum total funding. Within each selected village, keep every project tied for that village's maximum project funding.
Return one row [villageName, projectName, projectFunding] for every retained project. Encode projectFunding as a base-10 string. Sort the rows by village name, then project name, then village ID, then project ID, all in ascending lexicographic order. Return an empty matrix when there are no villages or no projects.
Function
topFundedVillageProjects(villages: String[][], projects: String[][], funds: String[][]) → String[][]Examples
Example 1
villages = [["v1","Maple"],["v2","River"],["v3","Hill"]]projects = [["p1","v1","Clinic"],["p2","v1","Library"],["p3","v2","Bridge"],["p4","v2","School"],["p5","v3","Well"]]funds = [["p1","2024-01-10","50"],["p2","2024-05-20","50"],["p3","2024-02-01","60"],["p3","2024-12-15","40"],["p4","2023-08-01","200"],["p5","2024-04-12","80"]]return = [["Maple","Clinic","50"],["Maple","Library","50"],["River","Bridge","100"]]Maple and River each receive a village total of 100, so both survive the first tie. Maple's two projects tie at 50; River's Bridge project has 100 while School has 0. Hill's total of 80 is not maximal.
Example 2
villages = [["v2","Beta"],["v1","Alpha"]]projects = [["p2","v2","Orchard"],["p1","v1","Garden"]]funds = [["p1","2023-12-31","90"],["p2","2025-01-01","90"]]return = [["Alpha","Garden","0"],["Beta","Orchard","0"]]Neither funding row belongs to 2024. Both village totals and both project totals are therefore 0, so both tie levels retain every listed project. Village-name ordering places Alpha first.
Example 3
villages = []projects = []funds = []return = []There is no village-project pair to rank, so the result is empty.
Constraints
0 <= villages.length, projects.length, funds.length <= 100000.- Village IDs are unique, project IDs are unique, and every project and funding row references an existing ID.
- IDs and names contain between
1and100printable ASCII characters. - Every date is a valid Gregorian date in
YYYY-MM-DDformat. 0 <= amount <= 10^9, and every project and village sum fits in a signed 64-bit integer.
More Adobe Online Assessment questions
- Base Unit ConversionsOA · Seen Nov 2026
- Rotate an Array In PlaceOA · PHONE SCREEN · Seen Aug 2026
- Count Parent Nodes With a Target SumOA · Seen Aug 2026
- Largest Binary Number by ConcatenationOA · Seen Aug 2026
- Count Events by CategoryOA · Seen Aug 2026
- Graph M-ColoringOA · Seen Aug 2026
- Hall of Shifting TilesOA · Seen Aug 2026
- K-th Ancestor Subtree Preorder QueryOA · Seen Aug 2026
- Maze ReachabilityOA · Seen Aug 2026
- Minimum Numeric Code TransformationOA · Seen Aug 2026
Similar questions at other companies
- Top K Frequent ElementsAmazon · OA · PHONE SCREEN
- Subscription and Usage-Based Billing CalculatorStripe · OA
- Count Servers With No Requests in a Time WindowIBM · OA
- Maximum Escape Game ScoreMicrosoft · OA
- Build Sessions from Unordered Events (Part 1)Scale AI · OA
- Minimum Distinct Prefix CostChubb · OA
- Decode Words with Anagram KeysCresta · OA
- Count Redundant File BackupsGoldman Sachs · OA
- Top Mutual-Friend RecommendationsVisa · OA
- Top Mutual-Friend RecommendationsSuperhuman · OA