Physical Address

304 North Cardinal St.
Dorchester Center, MA 02124

Hex Color Code Hacker Rank Solution – Queslers

Problem : Hex Color Code Hacker Rank Solution

CSS colors are defined using a hexadecimal (HEX) notation for the combination of Red, Green, and Blue color values (RGB).
Specifications of HEX Color Code
■ It must start with a ‘#’ symbol.
■ It can have 3 or digits 6.
■ Each digit is in the range of 0 to F. ( 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, A, B, C, D, E and F).
■ A – F letters can be lower case. (a, b, c, d, e and f are also valid digits).

Example :

Valid Hex Color Codes
#FFF 
#025 
#F0A1FB 

Invalid Hex Color Codes
#fffabg
#abcf
#12365erff

You are given N lines of CSS code. Your task is to print all valid Hex Color Codes, in order of their occurrence from top to bottom.

CSS Code Pattern

Selector
{
	Property: Value;
}

Input Format :

The first line contains N, the number of code lines.
The next N lines contains CSS Codes.

Constraints :

  • 0 < N < 50

Output Format :

Output the color codes with ‘#’ symbols on separate lines.


Sample Input :

11
#BED
{
    color: #FfFdF8; background-color:#aef;
    font-size: 123px;
    background: -webkit-linear-gradient(top, #f9f9f9, #fff);
}
#Cab
{
    background-color: #ABC;
    border: 2px dashed #fff;
}   

Sample Output :

#FfFdF8
#aef
#f9f9f9
#fff
#ABC
#fff

Explanation :

#BED and #Cab satisfy the Hex Color Code criteria, but they are used as selectors and not as color codes in the given CSS.
Hence, the valid color codes are:
#FfFdF8
#aef
#f9f9f9
#fff
#ABC
#fff
Note: There are no comments ( // or /* */) in CSS Code.

Hex Color Code Hacker Rank Solution in python 2

import re
reg1="{[^}]*}"
reg2="""(#(?:[0-9A-Fa-f]){3}|#(?:[0-9A-Fa-f]){6})[^0-9a-fA-F]"""
n=input()
s=""
for i in range(n): s+=raw_input()
x=re.findall(reg1,s)
for l in x:
    y=re.findall(reg2,l)
    #print l
    for z in y: print z

Hex Color Code Hacker Rank Solution in python 3

# Enter your code here. Read input from STDIN. Print output to STDOUT
import re
N=int(input())

for i in range(0,N):
    s=input()

    x=s.split()

    if len(x)>1  and  '{' not in x:
        x=re.findall(r'#[a-fA-F0-9]{3,6}',s)
        [print(i) for  i in x]

Hex Color Code Hacker Rank Solution in pypy

import re, sys

N = int(raw_input())
for _ in range(N):
    line = raw_input().strip()
    codes = [j for j in re.findall('[\s:](#[a-f0-9]{6}|#[a-f0-9]{3})[\s:;,)]', line, re.I)]
    for code in codes:
        print code

Hex Color Code Hacker Rank Solution in pypy 3

# Enter your code here. Read input from STDIN. Print output to STDOUT

import re

in_block = False
for x in range(int(input())):
    line = input()
    if '{' in line:
        in_block = True
        continue
    if '}' in line:
        in_block = False
        continue
        
    if in_block == True:
        m = re.findall(r'(#[a-fA-F0-9]{3,6})', line)
        if m:
            print(*m, sep='\n')
Hex Color Code Hacker Rank Solution Review:

In our experience, we suggest you solve this Hex Color Code Hacker Rank Solution and gain some new skills from Professionals completely free and we assure you will be worth it.

Hex Color Code is available on Hacker Rank for Free, if you are stuck anywhere between compilation, just visit Queslers to get all Hacker Rank Solution

Hex Color Code Hacker Rank Solution Conclusion:

I hope this Hex Color Code Hacker Rank Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Hacker Rank, Leetcode, Codechef, Codeforce Solution.

This Problem is intended for audiences of all experiences who are interested in learning about Data Science in a business context; there are no prerequisites.

Keep Learning!

More Hacker Rank Problem & Solutions >>

Mini-Max Sum Hacker Rank Solution

String Validators Hacker Rank Solution

Text Alignment Hacker Rank solution

String validators Hacker Rank Solution

Staircase Hacker Rank Solution

Leave a Reply

Your email address will not be published. Required fields are marked *