Skip to content

Maximum Non-Adjacent Number Sum #249

Description

@drkennetz

Maximum Non-Adjacent Number Sum

Write a function that takes in an array of positive integers and returns the maximum sum of non-adjacent elements in the array.
If the input array is empty, the function should return 0.

Business Rules/Errata

  • The function takes in an array of integers
  • The array is one dimensional and is not sorted
  • if the array is empty, return 0
  • when considering the maximum sum, integers in the array MUST be non-adjacent
  • Optimal Space and Time Complexity: O(n) time | O(1) space - where n is the length of the input array

Examples

array = [75, 105, 120, 75, 90, 135]
MaxNonAdjacentSum(array) -> 330 // 75 + 120 + 135

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions