// Cpp program to Find Minimum Sum Path // in a Triangle using Recursion #include…
- User
// Cpp program to Find Minimum Sum Path
// in a Triangle using Recursion #include <bits/stdc++.h> using namespace std;// Helper function to find minimum sum for a path int helper(vector<vector>& mat, int i, int j) {
// Base Case if(i == mat.size() ){ return 0 ; } int mn ; // Add current to the minimum of the next paths mn = mat[i][j] + min(helper(mat, i+1,j), helper(mat,i+1, j+1)) ; //return minimum return mn ;}
int minSumPath(vector<vector>& mat) { return helper(mat,0, 0) ; }
int main() { vector<vector > mat{ { 2 }, { 3, 9 }, { 1, 6, 7 } }; cout << minSumPath(mat); return 0; }
Give me code in Python, Java, C#, JavaScript
Remember like Cpp is for C++ and at start replace Cpp with language name and then comment
without changing variable name and also do not change comments
have one line space after code when comment is written.
don’t use class if needed then name it GfG
don’t use public if not needed.
and In C program don’t use #define and malloc and calloc instead use simple array
- Assistant