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 :: page refresh on button click in c# 
Csharp :: string methods in c# 
Csharp :: .net 6 get appsettings value 
Csharp :: c# only only 2 digits after decimal number double 
Csharp :: string stringbuilder c# 
Csharp :: c# loop backwards 
Csharp :: c# winforms input 
Csharp :: c# get folder of full ilepath 
Csharp :: c# use enum in class 
Csharp :: how to print a variable in c# 
Csharp :: devexpress objectspace to session 
Csharp :: c# movement script 
Csharp :: c# array inst working 
Csharp :: Responsive Bootstrap 4 Admin Dashboard icon cdn 
Csharp :: forces the user to enter his password before submitting the form asp.net core 
Csharp :: c# switch statement 
Html :: fa fa email 
Html :: how to open link in new tab 
Html :: html input regex only numbers 
Html :: remove border in ion item 
Html :: success green color code 
Html :: taka html code 
Html :: accepts only audio file in html 
Html :: input type="file" and display image 
Html :: NavBar Bootstrap v4 Fix 
Html :: google web fonts open sans 
Html :: how to link external css to html 
Html :: html preselected radio button 
Html :: linear gradient with image 
Html :: html indice 
ADD CONTENT
Topic
Content
Source link
Name
5+8 =