Simple Fun #22: Is Smooth?
Description:
Task
We define the middle of the array arr
as follows:
if arr
contains an odd number of elements, its middle is the element whose index number is the same when counting from the beginning of the array and from its end;
if arr
contains an even number of elements, its middle is the sum of the two elements whose index numbers when counting from the beginning and from the end of the array differ by one.
An array is called smooth if its first and its last elements are equal to one another and to the middle. Given an array arr, determine if it is smooth or not.
Example
For arr = [7, 2, 2, 5, 10, 7], the output should be true
The first and the last elements of arr are equal to 7, and its middle also equals 2 + 5 = 7. Thus, the array is smooth and the output is true.
For arr = [-5, -5, 10], the output should be false
The first and middle elements are equal to -5, but the last element equals 10. Thus, arr is not smooth and the output is false.
Input/Output
[input]
integer arrayarr
The given array.
Constraints:
[output]
a boolean valuetrue
if arr is smooth,false
otherwise.
Similar Kata:
Stats:
Created | Jan 24, 2017 |
Published | Jan 24, 2017 |
Warriors Trained | 1722 |
Total Skips | 22 |
Total Code Submissions | 3669 |
Total Times Completed | 1217 |
JavaScript Completions | 403 |
C# Completions | 107 |
Python Completions | 440 |
PHP Completions | 101 |
Ruby Completions | 64 |
C++ Completions | 176 |
Haskell Completions | 9 |
Total Stars | 22 |
% of votes with a positive feedback rating | 93% of 317 |
Total "Very Satisfied" Votes | 278 |
Total "Somewhat Satisfied" Votes | 32 |
Total "Not Satisfied" Votes | 7 |
Total Rank Assessments | 9 |
Average Assessed Rank | 7 kyu |
Highest Assessed Rank | 7 kyu |
Lowest Assessed Rank | 7 kyu |