Triangle- Leetcode 120 [Medium]

Pruthvik Reddy
Jun 21, 2021

--

Problem Link:

https://leetcode.com/problems/triangle/

Given a triangle array, return the minimum path sum from top to bottom.

For each step, you may move to an adjacent number of the row below. More formally, if you are on index i on the current row, you may move to either index i or index i + 1 on the next row.

Solution

If you are at an index “i” in a row, you can move to index “i” or index “i+1” in the next row. So, the minimum value for an index “i” in a row can be obtained by considering index “i-1” or index “i” from the previous row. So, the original triangle matrix is modified top down considering the minimum values from the previous row. Finally, we return the minimum value from the last row.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Pruthvik Reddy
Pruthvik Reddy

Written by Pruthvik Reddy

Purdue CS Student. Looking for opportunities in software development.

No responses yet

Write a response