LeetCode Solution - Problem Pow(x, n)

  • Implement pow(x, n), which calculates x raised to the power n (i.e., x^n).
Example 1:

Input: x = 2.00000, n = 10
Output: 1024.00000

LeetCode Solution - Problem Factorial Trailing Zeroes

  • Given an integer n, return the number of trailing zeroes in n!.
  • Note that n! = n * (n - 1) * (n - 2) * ... * 3 * 2 * 1.
Example 1:

Input: n = 3
Output: 0
Explanation: 3! = 6, no trailing zero.

LeetCode Solution - Problem Palindrome Number

  • Given an integer x, return true if x is a palindrome, and false otherwise. 
Example 1:

Input: x = 121
Output: true
Explanation: 121 reads as 121 from left to right and from right to left.

LeetCode Solution - Problem Reverse Integer

  • Given a signed 32-bit integer x, return x with its digits reversed. If reversing x causes the value to go outside the signed 32-bit integer range [-231, 231 - 1], then return 0.
  • Assume the environment does not allow you to store 64-bit integers (signed or unsigned).
Example 1:

Input: x = 123
Output: 321

LeetCode Solution - Problem Single Number

  • Given a non-empty array of integers nums, every element appears twice except for one. Find that single one.
  • You must implement a solution with a linear runtime complexity and use only constant extra space.
Example 1:

Input: nums = [2,2,1]
Output: 1

LeetCode Solution - Problem Fizz Buzz

Given an integer n, return a string array answer (1-indexed) where:
  • answer[i] == "FizzBuzz" if i is divisible by 3 and 5.
  • answer[i] == "Fizz" if i is divisible by 3.
  • answer[i] == "Buzz" if i is divisible by 5.
  • answer[i] == i (as a string) if none of the above conditions are true.
Example 1:

Input: n = 3
Output: ["1","2","Fizz"]

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()

  • 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 
>>> m.group(1)       # The first parenthesized subgroup.
>>> m.group(2)       # The second parenthesized subgroup.
>>> m.group(3)       # The third parenthesized subgroup.
>>> 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()
>>> m.start()

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

  • 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']

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...