HackerRank - Slice an Array

April - 25/2025

Problem:

Given a list of countries, each on a new line, your task is to read them into an array. Then slice the array and display only the elements lying between positions 3 and 7, both inclusive. Indexing starts from from 0.

# Input

# Output

# Solution

            
    mapfile -t array
    echo "${array[@]:3:5}"
    

# Solution_01

              
    array=() 
    while read i ; do
        array+=("$i")
    done
    
    echo "${array[@]:3:5}"
  

Post: