Maximum Loot Problem
More details about the problem are mentioned at:
More details about the problem are mentioned at:
Input:
5 5 10 100 10 5
Output:
110
5 5 10 100 10 5
Output:
110
Input:
1 2 3
Output:
4
1 2 3
Output:
4
I found it difficult to find many data structures puzzles, questions and problem in 100s of websites, so thought of writing and consolidating in a single place. This would help me to refer it any time and others can also if they like it. I have contributed as well as referred code from various websites where other has contributed.
int[][] input1 = { {1, 2, 3, 4, 5}, {0, 5, 1, 5, 2}, {0, 0, 0, 1, 3}, {4, 1, 1, 0, 1}, {0, 0, 0, 0, 3}, };
Output: 3 4 5 5 0 1 3 Max Sum for input1 is: 21Input:
int[][] input2 = { {3, 0, 0, 5}, {2, 5, 5, 5}, {0, 0, 0, 1}, {4, 4, 0, 0}, {0, 0, 3, 0}, };Output:
2 5 5 0 4 4 0 Max Sum for input2 is: 20
Input:
int[][] input3 = { {-1, -1, 0, -9, -2, -2}, {-2, -1, -6, -8, -2, -5}, {-1, -1, -1, -2, -3, -4}, {-1, -9, -2, -4, -4, -5}, {-7, -3, -3, -2, -9, -9}, {-1, -3, -1, -2, -4, -5} };
Output:
-1 -1 0 -1 -1 -1 -1 Max Sum for input3 is: -6
Node node1 = new Node("1", 6, 4);
Node node1 = new Node("1", 6, 4); Node node2 = new Node("2", 3, 6); Node node3 = new Node("3", 7, 3);Output
Node node1 = new Node("1", 4, 6); Node node2 = new Node("2", 6, 5); Node node3 = new Node("3", 7, 3); Node node4 = new Node("4", 4, 5);