Skip to content
Programming101
Programmingoneonone
  • Home
  • CS Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
  • 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
Programming101
Programmingoneonone

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

Pages

  • About US
  • Contact US
  • Privacy Policy

Programing Practice

  • C Programs
  • java Programs

HackerRank Solutions

  • C
  • C++
  • Java
  • Python
  • Algorithm

Other

  • Leetcode Solutions
  • Interview Preparation

Programming Tutorials

  • DSA
  • C

CS Subjects

  • Digital Communication
  • Human Values
  • Internet Of Things
  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2025 Programmingoneonone | WordPress Theme by SuperbThemes