Skip to content

Commit c1befce

Browse files
committed
Add Maximum Sum of Non-Adjacent Elements Algorithm
1 parent 88b79b5 commit c1befce

File tree

1 file changed

+0
-21
lines changed

1 file changed

+0
-21
lines changed

src/main/java/com/thealgorithms/dynamicprogramming/MaxSumNonAdjacent.java

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package com.thealgorithms.dynamicprogramming;
22

3-
import java.util.*;
4-
53
/*
64
What would you like to Propose?
75
I would like to propose adding an implementation of the Maximum Sum of Non-Adjacent Elements
@@ -57,23 +55,4 @@ static int solve(int n, int[] arr) {
5755
// Call the recursive solver for the last index (n-1).
5856
return solveUtil(n - 1, arr, dp);
5957
}
60-
61-
public static void main(String[] args) {
62-
Scanner sc = new Scanner(System.in);
63-
64-
// Input array size and elements.
65-
System.out.print("Enter the size of the array: ");
66-
int n = sc.nextInt();
67-
int[] nums = new int[n];
68-
System.out.print("Enter the elements of the array: ");
69-
for (int i = 0; i < n; i++) { nums[i] = sc.nextInt(); }
70-
71-
// Call the solve function to find the maximum possible sum.
72-
int ans = solve(n, nums);
73-
74-
// Print the result.
75-
System.out.println("Maximum sum of non-adjacent elements: " + ans);
76-
77-
sc.close(); // Close the scanner to prevent resource leakage.
78-
}
7958
}

0 commit comments

Comments
 (0)