Skip to content
Programmingoneonone
Programmingoneonone

Learn everything about programming

  • Home
  • CS Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
    • Cybersecurity
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programmingoneonone
Programmingoneonone

Learn everything about programming

HackerRank Grep – B problem solution

YASH PAL, 31 July 2024

In this HackerRank Grep – B problem solution we have given an input file, with N credit card numbers, each in a new line, your task is to grep out and output only those credit card numbers which have two or more consecutive occurrences of the same digit (which may be separated by a space, if they are in different segments). Assume that the credit card numbers will have 4 space-separated segments with 4 digits each.

If the credit card number is 1434 5678 9101 1234, there are two consecutive instances of 1 (though) as highlighted in box brackets: 1434 5678 910[1] [1]234

Here are some credit card numbers where consecutively repeated digits have been highlighted in box brackets. The last case does not have any repeated digits: 1234 5678 910[1] [1]234

2[9][9][9] 5178 9101 [2][2]34

[9][9][9][9] 5628 920[1] [1]232

8482 3678 9102 1232

Input Format

N credit card numbers. Assume that the credit card numbers will have 4 space-separated segments with 4 digits each.

Constraints

1<=N<=20

However, the value of N does not matter while writing your command.

Output Format

Display the required lines after filtering with grep, without any changes to their relative ordering in the input file.

HackerRank Grep - B problem solution

Problem solution.

grep "([0-9]) *1"

Second solution.

#grep -E '([[:digit:]])1'

grep -E -e '([[:digit:]])[[:space:]]1' -e '([[:digit:]])1'

Third solution.

grep -E -e "0(s)?0|1(s)?1|2(s)?2|3(s)?3|4(s)?4|5(s)?5|6(s)?6|7(s)?7|8(s)?8|9(s)?9"

Fourth solution.

grep '00|11|22|33|44|55|66|77|88|99|0 0|1 1|2 2|3 3|4 4|5 5|6 6|7 7|8 8|9 9'

coding problems solutions linux shell

Post navigation

Previous post
Next post

Are you a student and stuck with your career or worried about real-time things, and don't know how to manage your learning phase? Which profession to choose? and how to learn new things according to your goal, and land a dream job. Then this might help to you.

Hi My name is YASH PAL, founder of this Blog and a Senior Software engineer with 5+ years of Industry experience. I personally helped 40+ students to make a clear goal in their professional lives. Just book a one-on-one personal call with me for 30 minutes for 300 Rupees. Ask all your doubts and questions related to your career to set a clear roadmap for your professional life.

Book session - https://wa.me/qr/JQ2LAS7AASE2M1

Pages

  • About US
  • Contact US
  • Privacy Policy

Follow US

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