HackerRank Python Solution - Regex and Parsing - Validating Roman Numerals

  • You are given a string, and you have to validate whether it's a valid Roman numeral. If it is valid, print True. Otherwise, print False. Try to create a regular expression for a valid Roman numeral.

HackerRank Python Solution - Regex and Parsing - Group(), Groups() & Groupdict()

group():
  • A group() expression returns one or more subgroups of the match.
>>> import re
>>> m = re.match(r'(\w+)@(\w+)\.(\w+)','username@hackerrank.com')
>>> m.group(0)       # The entire match 
'username@hackerrank.com'
>>> m.group(1)       # The first parenthesized subgroup.
'username'
>>> m.group(2)       # The second parenthesized subgroup.
'hackerrank'
>>> m.group(3)       # The third parenthesized subgroup.
'com'
>>> m.group(1,2,3)   # Multiple arguments give us a tuple.
('username', 'hackerrank', 'com')

HackerRank Python Solution - Regex and Parsing - Re.start() & Re.end()

start() & end():
  • These expressions return the indices of the start and end of the substring matched by the group.
>>> import re
>>> m = re.search(r'\d+','1234')
>>> m.end()
4
>>> m.start()
0

HackerRank Python Solution - Regex and Parsing - Re.findall() & Re.finditer()

re.findall():
  • The expression re.findall() returns all the non-overlapping matches of patterns in a string as a list of strings.
>>> import re
>>> re.findall(r'\w','http://www.hackerrank.com/')
['h', 't', 't', 'p', 'w', 'w', 'w', 'h', 'a', 'c', 'k', 'e', 'r', 'r', 'a', 'n', 'k', 'c', 'o', 'm']

CodeChef - Python Practice Solution - Mahasena

Problem:
  • Kattapa, as you all know was one of the greatest warriors of his time. The kingdom of Maahishmati had never lost a battle under him (as army chief), and the reason for that was their mighty army, also called as Mahasena.
  • Kattapa was known to be a very superstitious person. He believed that a soldier is "lucky" if the soldier is holding an even number of weapons, and "unlucky" otherwise. He considered the army as "READY FOR BATTLE" if the count of "lucky" soldiers is strictly greater than the count of "unlucky" soldiers, and "NOT READY" otherwise.

HackerRank SQL Solution - Advanced Select - The PADS

Generate the following two result sets:
  • Query an alphabetically ordered list of all names in OCCUPATIONS, immediately followed by the first letter of each profession as a parenthetical (i.e.: enclosed in parentheses). For example: AnActorName(A), ADoctorName(D), AProfessorName(P), and ASingerName(S).
  • Query the number of occurrences of each occupation in OCCUPATIONS. Sort the occurrences in ascending order, and output them in the following format:
There are a total of [occupation_count] [occupation]s.
  • where [occupation_count] is the number of occurrences of occupation in OCCUPATIONS and [occupation] is the lowercase occupation name. If more than one Occupation has the same [occupation_count], they should be ordered alphabetically.

HackerRank SQL Solution - Advanced Select - Type of Triangle

  • Write a query identifying the type of each record in the TRIANGLES table using its three side lengths. Output one of the following statements for each record in the table:
    • Equilateral: It's a triangle with 3 sides of equal length.
    • Isosceles: It's a triangle with 2 sides of equal length.
    • Scalene: It's a triangle with 3 sides of differing lengths.
    • Not A Triangle: The given values of A, B, and C don't form a triangle.

HackerRank SQL Solution - Basic Select - Employee Salaries

  • Write a query that prints a list of employee names (i.e.: the name attribute) for employees in Employees having a salary greater than $2000 per month who have been employees for less than 10 months. Sort your result by ascending employee_id.
Input Format:
  • The Employee table containing employee data for a company is described as follows:

HackerRank SQL Solution - Basic Select - Employee Names

  • Write a query that prints a list of employee names (i.e.: the name attribute) from the Employee table in alphabetical order.
Input Format:
  • The Employee table containing employee data for a company is described as follows:

HackerRank SQL Solution - Basic Select - Higher Than 75 Marks

  • Query the Name of any student in STUDENTS who scored higher than 75 Marks. Order your output by the last three characters of each name. If two or more students both have names ending in the same last three characters (i.e.: Bobby, Robby, etc.), secondary sort them by ascending ID.
Input Format:
  • The STUDENTS table is described as follows:

You might also like

Deploy your Django web app to Azure Web App using App Service - F1 free plan

In this post, we will look at how we can deploy our Django app using the Microsoft Azure app service - a free plan. You need an Azure accoun...