add

Write a function that returns the sum of two numbers.

Example
For param1 = 1 and param2 = 2, the output should be
add(param1, param2) = 3.
Input/Output

  • [execution time limit] 4 seconds (php)
  • [input] integer param1Guaranteed constraints:
    -1000 ≤ param1 ≤ 1000.
  • [input] integer param2Guaranteed constraints:
    -1000 ≤ param2 ≤ 1000.
  • [output] integer
    • The sum of the two inputs.
function add($param1, $param2) {
    return $param1 + $param2;
}

centuryFromYear

Given a year, return the century it is in. The first century spans from the year 1 up to and including the year 100, the second – from the year 101 up to and including the year 200, etc.

Example

  • For year = 1905, the output should be
    centuryFromYear(year) = 20;
  • For year = 1700, the output should be
    centuryFromYear(year) = 17.

Input/Output

  • [execution time limit] 4 seconds (php)
  • [input] integer yearA positive integer, designating the year.Guaranteed constraints:
    1 ≤ year ≤ 2005.
  • [output] integer
    • The number of the century the year is in.
function centuryFromYear($year) {
    return intdiv($year, 100) + ($year % 100 ? 1 : 0);
}

Explanation
intdiv with 100 will give us the first 2 digits of the year. If the last two digits are more than 00 than we are in the next century, so add 1.


checkPalindrome

Given the string, check if it is a palindrome.

Example

  • For inputString = "aabaa", the output should be
    checkPalindrome(inputString) = true;
  • For inputString = "abac", the output should be
    checkPalindrome(inputString) = false;
  • For inputString = "a", the output should be
    checkPalindrome(inputString) = true.

Input/Output

  • [execution time limit] 4 seconds (php)
  • [input] string inputStringA non-empty string consisting of lowercase characters.Guaranteed constraints:
    1 ≤ inputString.length ≤ 105.
  • [output] boolean
    • true if inputString is a palindrome, false otherwise.
function checkPalindrome($inputString) {
    return $inputString == strrev($inputString);
}
Home » The Journey Begins