6 kyu

Hollow array

315 of 749aweleshetu

Description:

An array is said to be hollow if it contains 3 or more 0s in the middle that are preceded and followed by the same number of non-zero elements. Furthermore, all the zeroes in the array must be in the middle of the array.

Write a function that accepts an integer array and returns true if it is a hollow array, else false.

Examples

[2, 3, 0, 0, 0, 5, 6] --> true
[2, 0, 0, 0, 5, 6] --> false // 1 nonzero to the left but 2 to the right
[2, 3, 0, 0, 5, 6] --> false // less than 3 zeroes in the middle
[0, 2, 0, 0, 0, 5, 6] --> false // 1 zero not in the middle
[0, 0, 0, 0, 0] --> true // 0 nonzero elements at both ends
[] --> false
Arrays
Fundamentals

Stats:

CreatedSep 11, 2017
PublishedSep 12, 2017
Warriors Trained1920
Total Skips75
Total Code Submissions11800
Total Times Completed749
JavaScript Completions315
TypeScript Completions76
C# Completions63
Python Completions324
C Completions21
Total Stars30
% of votes with a positive feedback rating87% of 244
Total "Very Satisfied" Votes194
Total "Somewhat Satisfied" Votes38
Total "Not Satisfied" Votes12
Total Rank Assessments11
Average Assessed Rank
6 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • aweleshetu Avatar
  • Blind4Basics Avatar
  • Voile Avatar
  • Souzooka Avatar
  • hobovsky Avatar
  • trashy_incel Avatar
  • akar-0 Avatar
Ad