Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

maximum sum of non-adjacent elements

public static void NumbersSumb(int[] arr)
{
    if(arr.Length <=2)
      	Console.WriteLine(arr.Max());

    arr[2] = arr[0] + Math.Max(0, arr[2]);

    for (int i = 3; i < arr.Length; i++)
      	arr[i] = Math.Max(arr[i - 2], arr[i - 3]) + Math.Max(0, arr[i]);

    Console.WriteLine(Math.Max(arr[arr.Length - 1], arr[arr.Length - 2]));
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: c# get first word of string 
Csharp :: c# convert string to datetime 
Csharp :: how to add a componet to a gameobject throgh code unity 
Csharp :: javas 
Csharp :: var c# 
Csharp :: c# loop array backwards 
Csharp :: loop c# 
Csharp :: c# exists in list 
Csharp :: convert array to list c# 
Csharp :: how to clear a dictionary in c# 
Csharp :: unity destroy gameobject with delay 
Csharp :: how to make a enemy in unity 
Csharp :: function on program stops unity 
Csharp :: c# web page show 2nd page of tiff on an image control 
Csharp :: razor: show editable list 
Csharp :: generate random string 
Html :: turn off autocomplete input html 
Html :: how to open link in a new tab 
Html :: flutter build web html renderer 
Html :: twitter share link html 
Html :: html long text three dots 
Html :: target _blank 
Html :: accepts audio html 
Html :: bootstrap div vertical center 
Html :: stop video javascript 
Html :: bootstrap height 100vh class 
Html :: tag input type float number html 
Html :: meta refresh url 
Html :: gradient on top of image css 
Html :: loop through htmlcollection 
ADD CONTENT
Topic
Content
Source link
Name
6+2 =