---
# System prepended metadata

title: Challenges 1

---

## 1. Max Sum Consecutive Elements

### **Problem Statement:**

You are given an array of integers **`arr`** and an integer **`k`**. Your task is to find the maximum sum of any **`k`** consecutive elements in the array.

Write a C++ function **`maxSumOfKConsecutiveElements()`** that takes two parameters:

- **`arr`**: a vector of integers
- **`k`**: an integer representing the number of consecutive elements

The function should return an integer representing the maximum sum of any **`k`** consecutive elements in the array.

### **Requirements:**

- The function should handle the case where the length of the input array is less than **`k`**.
- The function should return **`0`** if the input array is empty.
- Your solution should have a time complexity of O(n).
- Your solution should not use any external libraries, such as the Standard Template Library (STL) or Boost.


### Example:

```j=C++
arr = {1, 3, 2, 5, 7, 2}
k = 3
maxSumOfKConsecutiveElements(arr, k) => 14
```

In this example, the maximum sum of any 3 consecutive elements in the array is **`5 + 7 + 2 = 14`**.

### Unit Test:

Here is a sample unit test you can use to test the function:

```=C++

void testMaxSumOfKConsecutiveElements() {
    vector<int> arr1 = {1, 3, 2, 5, 7, 2};
    int k1 = 3;
    assert(maxSumOfKConsecutiveElements(arr1, k1) == 14);

    vector<int> arr2 = {1, 2, 3, 4, 5};
    int k2 = 2;
    assert(maxSumOfKConsecutiveElements(arr2, k2) == 9);

    vector<int> arr3 = {1, 2, 3, 4, 5};
    int k3 = 5;
    assert(maxSumOfKConsecutiveElements(arr3, k3) == 15);

    vector<int> arr5 = {};
    int k5 = 3;
    assert(maxSumOfKConsecutiveElements(arr5, k5) == 0);
}
```

## 2. Palindrome Check

### **Problem Statement:**
Write a function that takes a string as input and checks if it is a palindrome. A palindrome is a word, phrase, number, or other sequence of characters that reads the same forward and backward, ignoring spaces, punctuation, and capitalization.

### Example:
Input: "A man, a plan, a canal, Panama"
Output: true

Input: "Hello, world!"
Output: false

### Unit Test:

```=cpp

#include <cassert>
#include <string>

bool isPalindrome(const std::string& str);

void testPalindromeCheck() {
    // Palindrome input
    assert(isPalindrome("A man, a plan, a canal, Panama") == true);
    assert(isPalindrome("racecar") == true);
    assert(isPalindrome("madam") == true);
    assert(isPalindrome("level") == true);

    // Non-palindrome input
    assert(isPalindrome("Hello, world!") == false);
    assert(isPalindrome("OpenAI") == false);
    assert(isPalindrome("coding") == false);
    assert(isPalindrome("challenge") == false);
}

int main() {
    testPalindromeCheck();
    return 0;
}

```


