Skip to content
Programmingoneonone
Programmingoneonone
  • Engineering Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
    • 100+ C++ Programs
  • Solutions
    • HackerRank
      • Algorithms Solutions
      • C solutions
      • C++ solutions
      • Java solutions
      • Python solutions
    • Leetcode Solutions
    • HackerEarth Solutions
  • Work with US
Programmingoneonone
Programmingoneonone

HackerRank Remove the First Capital Letter from Each Element problem solution

YASH PAL, 31 July 20246 February 2026

In this HackerRank Remove the First Capital Letter from Each Element problem solution In this challenge, we practice reading and transforming arrays.

Task

You are given a list of countries, each on a new line. Your task is to read them into an array and then transform them in the following way:

The first capital letter (if present) in each element of the array should be replaced with a dot (‘.’). Then, display the entire array with a space between each country’s names.

Input Format

The input format consists of a list of country names each on a separate line. The only characters present in the country names will be upper or lower-case characters and hyphens.

Output Format

Transform the names as described and display the entire array of country names with a space between each of them.

HackerRank Remove the First Capital Letter from Each Element problem solution

Problem solution.

a=(`cat $@`)
echo ${a[@]/[A-Z]/.}

Second solution.

n=0
while read c;
do 
    if [ "$c" != "" ]; then
        Country[$n]=$c
        ((n++))
    fi
done
for i in ${!Country[@]}; do
    Country[$i]=".${Country[$i]:1}"
done
echo "${Country[@]}"

Third solution.

i=0
while read line
do
    ary[i]=`echo "${line}" | sed -r 's/^[A-Z]+/./g'`
    ((i++))
done

echo ${ary[@]}

Fourth solution.

ar=()

while read input
do
    ar=("${ar[@]}" "$input")
done
declare -a pattern=( ${ar[@]/[A-Z]/.} )
echo ${pattern[@]}

coding problems solutions Hackerrank Problems Solutions linux shell HackerRankLinux shell

Post navigation

Previous post
Next post

Programmingoneonone

We at Programmingoneonone, also known as Programming101 is a learning hub of programming and other related stuff. We provide free learning tutorials/articles related to programming and other technical stuff to people who are eager to learn about it.

Pages

  • About US
  • Contact US
  • Privacy Policy

Practice

  • Java
  • C++
  • C

Follow US

  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2026 Programmingoneonone | WordPress Theme by SuperbThemes