7 kyu

Simple Fun #22: Is Smooth?

176 of 1,217myjinxin2015

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 array arr

    The given array.

    Constraints:

    • 2length(arr)1032 \leq \text{length}(arr) \leq 10^3
    • 103arri103-10^3 \leq arr_i \leq 10^3
  • [output] a boolean value

    true if arr is smooth, false otherwise.

Puzzles

Stats:

CreatedJan 24, 2017
PublishedJan 24, 2017
Warriors Trained1722
Total Skips22
Total Code Submissions3669
Total Times Completed1217
JavaScript Completions403
C# Completions107
Python Completions440
PHP Completions101
Ruby Completions64
C++ Completions176
Haskell Completions9
Total Stars22
% of votes with a positive feedback rating93% of 317
Total "Very Satisfied" Votes278
Total "Somewhat Satisfied" Votes32
Total "Not Satisfied" Votes7
Total Rank Assessments9
Average Assessed Rank
7 kyu
Highest Assessed Rank
7 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • myjinxin2015 Avatar
  • GiacomoSorbi Avatar
  • donaldsebleung Avatar
  • kazk Avatar
  • JohanWiltink Avatar
  • FArekkusu Avatar
  • hobovsky Avatar
  • tobeannouncd Avatar
  • Just4FunCoder Avatar
  • saudiGuy Avatar
Ad