SkillAgentSearch skills...

CodeFights

Solutions for challenges proposed on CodeFights.com/arcade

Install / Use

/learn @DataSutures/CodeFights
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

CodeFights

Solutions for challenges proposed on CodeFights.com

Arcade

Intro
Databases
The Core
Python
Graphs

Intro

  1. add
  2. centuryFromYear
  3. checkPalindrome
  4. adjacentElementsProduct
  5. shapeArea
  6. makeArrayConsecutive2
  7. almostIncreasingSequence
  8. matrixElementsSum
  9. allLongestStrings
  10. commonCharacterCount
  11. isLucky
  12. sortByHeight
  13. reverseParentheses
  14. alternatingSums
  15. addBorder
  16. areSimilar
  17. arrayChange
  18. palindromeRearranging
  19. areEquallyStrong
  20. arrayMaximalAdjacentDifference
  21. isIPv4Address
  22. avoidObstacles
  23. boxBlur
  24. minesweeper
  25. arrayReplace
  26. evenDigitsOnly
  27. variableName
  28. alphabeticShift
  29. chessBoardCellColor
  30. circleOfNumbers
  31. depositProfit
  32. absoluteValuesSumMinimization
  33. stringsRearrangement
  34. extractEachKth
  35. firstDigit
  36. differentSymbolsNaive
  37. arrayMaxConsecutiveSum
  38. growingPlant
  39. knapsackLight
  40. longestDigitsPrefix
  41. digitDegree
  42. bishopAndPawn
  43. isBeautifulString
  44. findEmailDomain
  45. buildPalindrome
  46. electionsWinners
  47. isMAC48Address
  48. lineEncoding
  49. chessKnight
  50. deleteDigit
  51. longestWord
  52. validTime
  53. sumUpNumbers
  54. differentSquares
  55. digitsProduct
  56. fileNaming

Databases

  1. projectList
  2. countriesSelection
  3. monthlyScholarships
  4. projectsTeam
  5. automaticNotifications
  6. volleyballResults
  7. mostExpensive
  8. contestLeaderboard
  9. gradeDistribution
  10. mischievousNephews

The Core

  1. addTwoDigits
  2. largestNumber
  3. candies
  4. seatsInTheater
  5. maxMultiple
  6. circleOfNumbers
  7. lateRide
  8. phoneCall
  9. reachNextLevel
  10. knapsackLight
  11. extraNumber
  12. isInfiniteProcess
  13. arithmeticExpression
  14. tennisSet
  15. willYou
  16. metroCard

Python

Graphs

add

Description

Write a function that returns the sum of two numbers.

Example:

param1 = 1
param2 = 2
add(param1, param2) = 3.

Input/Output

  • [time limit] 3000ms (java)

  • [input] integer param1

    Guaranteed constraints:

-100 ≤ param1 ≤ 1000
  • [input] integer param2

    Guaranteed constraints:

-100 ≤ param2 ≤ 1000
  • [output] integer
    The sum of the two inputs.

centuryFromYear

Description

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

//Example 1
year = 1905
centuryFromYear(year) = 20

//Example 2
year = 1700
centuryFromYear(year) = 17

Input/Output

  • [time limit] 3000ms (java)

  • [input] integer year

    A positive integer, designating the year.

    Guaranteed constraints:

1 ≤ year ≤ 2005.
  • [output] integer

    The number of the century the year is in.

checkPalindrome

Description

Given a string, check if it is a palindrome.

Example

// Example 1
inputString = "aabaa"
checkPalindrome(inputString) = true;
// Example 2
inputString = "abac"
checkPalindrome(inputString) = false;
// Example 3
inputString = "a"
checkPalindrome(inputString) = true;

Input/Output

  • [time limit] 3000ms (java)

  • [input] string inputString

    A non-empty string consisting of lowercase characters.

    Guaranteed constraints:

1 ≤ inputString.length ≤ 10^5
  • [output] boolean

    true if inputString is a palindrome, false otherwise.

adjacentElementsProduct

Description

Given an array of integers, find the pair of adjacent elements that has the largest product and return that product.ding the year 100, the second - from the year 101 up to and including the year 200, etc.

Example

inputArray = [3, 6, -2, -5, 7, 3]
adjacentElementsProduct(inputArray) = 21
// 7 and 3 produce the largest product.

Input/Output

  • [time limit] 3000ms (java)

  • [input] array.integer inputArray

    An array of integers containing at least two elements.

    Guaranteed constraints:

2 ≤ inputArray.length ≤ 10
-1000 ≤ inputArray[i] ≤ 1000
  • [output] integer

    The largest product of adjacent elements.

shapeArea

Description

Below we will define an n-interesting polygon. Your task is to find the area of a polygon for a given n.

A 1-interesting polygon is just a square with a side of length 1. An n-interesting polygon is obtained by taking the n - 1-interesting polygon and appending 1-interesting polygons to its rim, side by side. You can see the 1-, 2-, 3- and 4-interesting polygons in the picture below. shapeArea

Example

// Example 1
n = 2
shapeArea(n) = 5
// Example 2
n = 3
shapeArea(n) = 13

Input/Output

  • [time limit] 3000ms (java)

  • [input] integer n

    Guaranteed constraints:

1 ≤ n < 10^4
  • [output] integer
    The area of the n-interesting polygon.

makeArrayConsecutive2

Description

Ratiorg got statues of different sizes as a present from CodeMaster for his birthday, each statue having an non-negative integer size. Since he likes to make things perfect, he wants to arrange them from smallest to largest so that each statue will be bigger than the previous one exactly by 1. He may need some additional statues to be able to accomplish that. Help him figure out the minimum number of additional statues needed.

Example

statues = [6, 2, 3, 8]
makeArrayConsecutive2(statues) = 3

Input/Output

  • [time limit] 3000ms (java)

  • [input] array.integer statues

    An array of distinct non-negative integers.

    Guaranteed constraints:

1 ≤ statues.length ≤ 10
0 ≤ statues[i] ≤ 20
  • [output] integer

    The minimal number of statues that need to be added to existing statues such that it contains every integer size from an interval [L, R] (for some L, R) and no other sizes.

almostIncreasingSequence

Description

Given a sequence of integers as an array, determine whether it is possible to obtain a strictly increasing sequence by removing no more than one element from the array.

Example

// Example 1
sequence = [1, 3, 2, 1]
almostIncreasingSequence(sequence) = false
// There is no one element in this array that can be removed in order to get a strictly increasing
// sequence.

// Example 2
sequence = [1, 3, 2]
almostIncreasingSequence(sequence) = true
// You can remove 3 from the array to get the strictly increasing sequence [1, 2]. Alternately, you
// can remove 2 to get the strictly increasing sequence [1, 3].

Input/Output

  • [time limit] 3000ms (java)

  • [input] array.integer sequence

    Guaranteed constraints:

2 ≤ sequence.length ≤ 10^5
-105 ≤ sequence[i] ≤ 10^5
  • [output] boolean

    Return true if it is possible to remove one element from the array in order to get a strictly increasing sequence, otherwise return false.

matrixElementsSum

Description

After becoming famous, CodeBots decided to move to a new building and live together. The building is represented by a rectangular matrix of rooms, each cell containing an integer - the price of the room. Some rooms are free (their cost is 0), but that's probably because they are haunted, so all the bots are afraid of them. That is why any room that is free or is located anywhere below a free room in the same column is not considered suitable for the bots.

Help the bots calculate the total price of all the rooms that are suitable for them.

Example

matrix = [[0, 1, 1, 2],
[0, 5, 0, 0],
[2, 0, 3, 3]]
matrixElementsSum(matrix) = 9

Here's the rooms matrix with unsuitable rooms marked with 'x':

[[x, 1, 1, 2],
[x, 5, x, x],
[x, x, x, x]]

Thus, the answer is: 1 + 5 + 1 + 2 = 9.

Input/Output

  • [time limit] 3000ms (java)

  • [input] array.array.integer matrix
    2-dimensional array of integers representing a rectangular matrix of the building.

    Guaranteed constraints:

1 ≤ matrix.length ≤ 5
1 ≤ matrix[i].length ≤ 5
0 ≤ matrix[i][j] ≤ 10
View on GitHub
GitHub Stars5
CategoryDevelopment
Updated1y ago
Forks4

Languages

Java

Security Score

55/100

Audited on Oct 26, 2024

No findings