Skip to main content
All Questions

Find the path from bottom-left to top-right, moving only north or east, collecting the most rocks.

Unlock detailed company stats for this questionUpgrade

You are a rock collector in southern California planning a cross-country road trip to New York, with rare rocks available in cities along the way. Given a grid of numbers representing the rare rocks in each city, find the optimal path from So_Cal (start, bottom-left) to New_York (finish, top-right) that accumulates the most rocks. You can only travel north (up) or east (right). Implement optimalPath() and consider adding tests in doTestsPass(). Example: {{0,0,0,0,5},{0,1,1,1,0},{2,0,0,0,0}} gives 10 (2+0+1+1+1+0+5). Time and space complexity were also asked.

Expect follow-ups like

  • What are the time and space complexities?

Format · Goldman Sachs CoderPad round, second of two questions.

Community answers

No answers contributed by the community yet.

Related courses

Course

Software Engineering Interview Prep

Land your dream software engineering role at Google, Amazon, Microsoft, Meta, Apple, and other top companies. Learn from mock interviews, frameworks, and advice from senior candidates—practice data structures, algorithms, system design, people management, behavioral interviews, and more.

Course

System Design Interviews

Learn how to answer the latest system design questions across product, infrastructure, and AI domains. Features in-depth video examples, written breakdowns, and helpful reference patterns. Watch senior engineers and managers answer these questions in mock interview videos.