├── 10240_ShorterSuperSum ├── ShorterSuperSum.html ├── ShorterSuperSum.json ├── ShorterSuperSum.py └── __init__.py ├── 10241_SequenceSums ├── SequenceSums.html ├── SequenceSums.json ├── SequenceSums.py └── __init__.py ├── 10243_BirdsCounting ├── BirdsCounting.html ├── BirdsCounting.json ├── BirdsCounting.py └── __init__.py ├── 10251_LinearPolyominoCovering ├── LinearPolyominoCovering.html ├── LinearPolyominoCovering.json ├── LinearPolyominoCovering.py └── __init__.py ├── 10254_SubwayTrip ├── SubwayTrip.html ├── SubwayTrip.json ├── SubwayTrip.py └── __init__.py ├── 10255_WizardsAppointments ├── WizardsAppointments.html ├── WizardsAppointments.json ├── WizardsAppointments.py └── __init__.py ├── 10256_YetAnotherStonesGame ├── YetAnotherStonesGame.html ├── YetAnotherStonesGame.json ├── YetAnotherStonesGame.py └── __init__.py ├── 10257_SumAndProduct ├── SumAndProduct.html ├── SumAndProduct.json ├── SumAndProduct.py └── __init__.py ├── 10258_LaserShooting ├── LaserShooting.html ├── LaserShooting.json ├── LaserShooting.py └── __init__.py ├── 10259_MegaCoolNumbers ├── MegaCoolNumbers.html ├── MegaCoolNumbers.json ├── MegaCoolNumbers.py └── __init__.py ├── 10261_FallingPoints ├── FallingPoints.html ├── FallingPoints.json ├── FallingPoints.py └── __init__.py ├── 10265_IncreasingLists ├── IncreasingLists.html ├── IncreasingLists.json ├── IncreasingLists.py └── __init__.py ├── 10266_HexatridecimalSum ├── HexatridecimalSum.html ├── HexatridecimalSum.json ├── HexatridecimalSum.py └── __init__.py ├── 10267_LeastMajorityMultiple ├── LeastMajorityMultiple.html ├── LeastMajorityMultiple.json ├── LeastMajorityMultiple.py └── __init__.py ├── 10274_Underprimes ├── Underprimes.html ├── Underprimes.json ├── Underprimes.py └── __init__.py ├── 10275_CellRemoval ├── CellRemoval.html ├── CellRemoval.json ├── CellRemoval.py └── __init__.py ├── 10279_ThePresents ├── ThePresents.html ├── ThePresents.json ├── ThePresents.py └── __init__.py ├── 10280_TheLongWay ├── TheLongWay.html ├── TheLongWay.json ├── TheLongWay.py └── __init__.py ├── 10281_MegaCoolNumbersEasy ├── MegaCoolNumbersEasy.html ├── MegaCoolNumbersEasy.json ├── MegaCoolNumbersEasy.py └── __init__.py ├── 10282_TheGarland ├── TheGarland.html ├── TheGarland.json ├── TheGarland.py └── __init__.py ├── 10284_Parallelograms ├── Parallelograms.html ├── Parallelograms.json ├── Parallelograms.py └── __init__.py ├── 10285_AnotherCoinProblem ├── AnotherCoinProblem.html ├── AnotherCoinProblem.json ├── AnotherCoinProblem.py └── __init__.py ├── 10286_DiamondMining ├── DiamondMining.html ├── DiamondMining.json ├── DiamondMining.py └── __init__.py ├── 10288_MazeWanderingEasy ├── MazeWanderingEasy.html ├── MazeWanderingEasy.json ├── MazeWanderingEasy.py └── __init__.py ├── 10289_WickedTeacher ├── WickedTeacher.html ├── WickedTeacher.json ├── WickedTeacher.py └── __init__.py ├── 10294_SkiFriction ├── SkiFriction.html ├── SkiFriction.json ├── SkiFriction.py └── __init__.py ├── 10295_GroupedWordChecker ├── GroupedWordChecker.html ├── GroupedWordChecker.json ├── GroupedWordChecker.py └── __init__.py ├── 10297_CirclesCountry ├── CirclesCountry.html ├── CirclesCountry.json ├── CirclesCountry.py └── __init__.py ├── 10298_TheSquareDivOne ├── TheSquareDivOne.html ├── TheSquareDivOne.json ├── TheSquareDivOne.py └── __init__.py ├── 10299_TheSquareDivTwo ├── TheSquareDivTwo.html ├── TheSquareDivTwo.json ├── TheSquareDivTwo.py └── __init__.py ├── 10308_Deposit ├── Deposit.html ├── Deposit.json ├── Deposit.py └── __init__.py ├── 10309_IncredibleMachineEasy ├── IncredibleMachineEasy.html ├── IncredibleMachineEasy.json ├── IncredibleMachineEasy.py └── __init__.py ├── 10310_IncredibleMachine ├── IncredibleMachine.html ├── IncredibleMachine.json ├── IncredibleMachine.py └── __init__.py ├── 10314_PawnsAndKings ├── PawnsAndKings.html ├── PawnsAndKings.json ├── PawnsAndKings.py └── __init__.py ├── 10317_Unicorn ├── Unicorn.html ├── Unicorn.json ├── Unicorn.py └── __init__.py ├── 10319_NumberGraph ├── NumberGraph.html ├── NumberGraph.json ├── NumberGraph.py └── __init__.py ├── 10324_DigitalCounter ├── DigitalCounter.html ├── DigitalCounter.json ├── DigitalCounter.py └── __init__.py ├── 10325_ConnectingAirports ├── ConnectingAirports.html ├── ConnectingAirports.json ├── ConnectingAirports.py └── __init__.py ├── 10326_MismatchedStrings ├── MismatchedStrings.html ├── MismatchedStrings.json ├── MismatchedStrings.py └── __init__.py ├── 10329_PageNumbers ├── PageNumbers.html ├── PageNumbers.json ├── PageNumbers.py └── __init__.py ├── 10331_BidirectionalQueue ├── BidirectionalQueue.html ├── BidirectionalQueue.json ├── BidirectionalQueue.py └── __init__.py ├── 10333_PlaneFractal ├── PlaneFractal.html ├── PlaneFractal.json ├── PlaneFractal.py └── __init__.py ├── 10335_KthProbableElement ├── KthProbableElement.html ├── KthProbableElement.json ├── KthProbableElement.py └── __init__.py ├── 10336_CircularShifts ├── CircularShifts.html ├── CircularShifts.json ├── CircularShifts.py └── __init__.py ├── 10337_DoNotTurn ├── DoNotTurn.html ├── DoNotTurn.json ├── DoNotTurn.py └── __init__.py ├── 10341_BestView ├── BestView.html ├── BestView.json ├── BestView.py └── __init__.py ├── 10342_DigitsSwap ├── DigitsSwap.html ├── DigitsSwap.json ├── DigitsSwap.py └── __init__.py ├── 10343_FriendScore ├── FriendScore.html ├── FriendScore.json ├── FriendScore.py └── __init__.py ├── 10355_EndlessStringMachine ├── EndlessStringMachine.html ├── EndlessStringMachine.json ├── EndlessStringMachine.py └── __init__.py ├── 10356_UnluckyIntervals ├── UnluckyIntervals.html ├── UnluckyIntervals.json ├── UnluckyIntervals.py └── __init__.py ├── 10360_FeudaliasBattle ├── FeudaliasBattle.html ├── FeudaliasBattle.json ├── FeudaliasBattle.py └── __init__.py ├── 10361_SaveTheTrees ├── SaveTheTrees.html ├── SaveTheTrees.json ├── SaveTheTrees.py └── __init__.py ├── 10369_TheSwap ├── TheSwap.html ├── TheSwap.json ├── TheSwap.py └── __init__.py ├── 10370_ChuckContest ├── ChuckContest.html ├── ChuckContest.json ├── ChuckContest.py └── __init__.py ├── 10375_StrangeCountry ├── StrangeCountry.html ├── StrangeCountry.json ├── StrangeCountry.py └── __init__.py ├── 10376_DifferentStrings ├── DifferentStrings.html ├── DifferentStrings.json ├── DifferentStrings.py └── __init__.py ├── 10377_ErdosNumber ├── ErdosNumber.html ├── ErdosNumber.json ├── ErdosNumber.py └── __init__.py ├── 10380_PalindromeFactory ├── PalindromeFactory.html ├── PalindromeFactory.json ├── PalindromeFactory.py └── __init__.py ├── 10382_PalindromePhrases ├── PalindromePhrases.html ├── PalindromePhrases.json ├── PalindromePhrases.py └── __init__.py ├── 10384_KingdomMap ├── KingdomMap.html ├── KingdomMap.json ├── KingdomMap.py └── __init__.py ├── 10386_SquareFreeSets ├── SquareFreeSets.html ├── SquareFreeSets.json ├── SquareFreeSets.py └── __init__.py ├── 10387_BinaryFlips ├── BinaryFlips.html ├── BinaryFlips.json ├── BinaryFlips.py └── __init__.py ├── 10389_StrongEconomy ├── StrongEconomy.html ├── StrongEconomy.json ├── StrongEconomy.py └── __init__.py ├── 10391_RotatingTriangles ├── RotatingTriangles.html ├── RotatingTriangles.json ├── RotatingTriangles.py └── __init__.py ├── 10395_SquareOfDigits ├── SquareOfDigits.html ├── SquareOfDigits.json ├── SquareOfDigits.py └── __init__.py ├── 10396_UnluckyNumbers ├── UnluckyNumbers.html ├── UnluckyNumbers.json ├── UnluckyNumbers.py └── __init__.py ├── 10401_Automaton ├── Automaton.html ├── Automaton.json ├── Automaton.py └── __init__.py ├── 10408_PouringWater ├── PouringWater.html ├── PouringWater.json ├── PouringWater.py └── __init__.py ├── 10412_PlanarGraphShop ├── PlanarGraphShop.html ├── PlanarGraphShop.json ├── PlanarGraphShop.py └── __init__.py ├── 10413_SequenceSum ├── SequenceSum.html ├── SequenceSum.json ├── SequenceSum.py └── __init__.py ├── 11777_BuildingReorganization ├── BuildingReorganization.html ├── BuildingReorganization.json ├── BuildingReorganization.py └── __init__.py ├── 6208_MislabeledWeights ├── MislabeledWeights.html ├── MislabeledWeights.json ├── MislabeledWeights.py └── __init__.py ├── 6226_OrderParser ├── OrderParser.html ├── OrderParser.json ├── OrderParser.py └── __init__.py ├── 8202_KeysInBoxes ├── KeysInBoxes.html ├── KeysInBoxes.json ├── KeysInBoxes.py └── __init__.py ├── 8211_Barracks ├── Barracks.html ├── Barracks.json ├── Barracks.py └── __init__.py ├── 8215_RevealTriangle ├── RevealTriangle.html ├── RevealTriangle.json ├── RevealTriangle.py └── __init__.py ├── 8216_ReadingBooks ├── ReadingBooks.html ├── ReadingBooks.json ├── ReadingBooks.py └── __init__.py ├── 8291_Transformation ├── Transformation.html ├── Transformation.json ├── Transformation.py └── __init__.py ├── 8302_ConsecutiveNumbers ├── ConsecutiveNumbers.html ├── ConsecutiveNumbers.json ├── ConsecutiveNumbers.py └── __init__.py ├── 8310_WordAbbreviation ├── WordAbbreviation.html ├── WordAbbreviation.json ├── WordAbbreviation.py └── __init__.py ├── 8314_DreamingAboutCarrots ├── DreamingAboutCarrots.html ├── DreamingAboutCarrots.json ├── DreamingAboutCarrots.py └── __init__.py ├── 8315_ParticleCollision ├── ParticleCollision.html ├── ParticleCollision.json ├── ParticleCollision.py └── __init__.py ├── 8320_NCool ├── NCool.html ├── NCool.json ├── NCool.py └── __init__.py ├── 8525_SuperWatch ├── SuperWatch.html ├── SuperWatch.json ├── SuperWatch.py └── __init__.py ├── 8734_MountainWalk ├── MountainWalk.html ├── MountainWalk.json ├── MountainWalk.py └── __init__.py └── README.md /10240_ShorterSuperSum/ShorterSuperSum.html: -------------------------------------------------------------------------------- 1 | 10240. ShorterSuperSum

10240. ShorterSuperSum

Problem

SuperSum is a function defined as:
2 |

6 |

Given k and n, return the value for SuperSum(k , n).

7 |

Definition

Filename

ShorterSuperSum.py

Signature

int calculate(int k, int n)

Constraints

Examples

-------------------------------------------------------------------------------- /10240_ShorterSuperSum/ShorterSuperSum.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | def calculate(k, n): 4 | pass 5 | 6 | -------------------------------------------------------------------------------- /10240_ShorterSuperSum/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codersasha/TopCoder-Python-Problems/506ba498597e24cbb131e3a359452ea2192ff844/10240_ShorterSuperSum/__init__.py -------------------------------------------------------------------------------- /10241_SequenceSums/SequenceSums.html: -------------------------------------------------------------------------------- 1 | 10241. SequenceSums

10241. SequenceSums

Problem

2 | Given a number N and a length L, find the shortest list of at least L consecutive non-negative integers whose sum is N. 3 | If the length of that list is 100 or smaller, return the sequence as a int[] in ascending order. 4 | If there is no such sequence or its length is larger than 100, return { }. 5 |

Definition

Filename

SequenceSums.py

Signature

int[] sequence(int N, int L)

Constraints

Examples

-------------------------------------------------------------------------------- /10241_SequenceSums/SequenceSums.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | def sequence(N, L): 4 | pass 5 | 6 | -------------------------------------------------------------------------------- /10241_SequenceSums/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codersasha/TopCoder-Python-Problems/506ba498597e24cbb131e3a359452ea2192ff844/10241_SequenceSums/__init__.py -------------------------------------------------------------------------------- /10243_BirdsCounting/BirdsCounting.html: -------------------------------------------------------------------------------- 1 | 10243. BirdsCounting

10243. BirdsCounting

Problem

In ecology, there are several ways of estimating the size of a population in a given area. We are interested in estimating the size of a population of birds. To do this, we will use the following procedure.
2 |
3 | First, there will be a data collection phase that lasts exactly daysNumber days. Initially, all the birds are unmarked. During each day of data collection, we will catch exactly caughtPerDay birds. At the end of each day, we will examine each of the birds we have caught. If a bird is unmarked, we will mark it. If a bird is already marked, we will leave it alone (and it will remain marked). We will then release all of them back into the wild before the next day begins.
4 |
5 | After the data collection phase is complete, we can use the number of unmarked birds caught each day to estimate the size of the population.
6 |
7 | To help our fellow ecologists in analyzing the collected data, we must compute the probability that after daysNumber days of data collection, there will be exactly birdsMarked marked birds assuming that there are birdsNumber birds in this area. Assume that the probability of being caught is exactly the same for every bird on every day.

Definition

Filename

BirdsCounting.py

Signature

double computeProbability(int birdsNumber, int caughtPerDay, int daysNumber, int birdsMarked)

Constraints

Examples

-------------------------------------------------------------------------------- /10243_BirdsCounting/BirdsCounting.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | def computeProbability(birdsNumber, caughtPerDay, daysNumber, birdsMarked): 4 | pass 5 | 6 | -------------------------------------------------------------------------------- /10243_BirdsCounting/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codersasha/TopCoder-Python-Problems/506ba498597e24cbb131e3a359452ea2192ff844/10243_BirdsCounting/__init__.py -------------------------------------------------------------------------------- /10251_LinearPolyominoCovering/LinearPolyominoCovering.html: -------------------------------------------------------------------------------- 1 | 10251. LinearPolyominoCovering

10251. LinearPolyominoCovering

Problem

You have an infinite number of the following two polyominoes: AAAA and BB.

2 |

You are given a String region, filled with characters '.' and 'X'. You need to cover (without overlapping) all the 'X' characters with the given polyominoes.

3 |

Return a String that contains the same region with cells marked '.' left untouched, and cells marked 'X' changed to 'A' or 'B', according to the polyomino that covers the cell.

4 |

If there is no solution, return the String "impossible" (quotes for clarity only).

5 |

If there are multiple solutions, return the lexicographically smallest one.

6 |

Definition

Filename

LinearPolyominoCovering.py

Signature

String findCovering(String region)

Constraints

Examples

-------------------------------------------------------------------------------- /10251_LinearPolyominoCovering/LinearPolyominoCovering.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | def findCovering(region): 4 | pass 5 | 6 | -------------------------------------------------------------------------------- /10251_LinearPolyominoCovering/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codersasha/TopCoder-Python-Problems/506ba498597e24cbb131e3a359452ea2192ff844/10251_LinearPolyominoCovering/__init__.py -------------------------------------------------------------------------------- /10254_SubwayTrip/SubwayTrip.html: -------------------------------------------------------------------------------- 1 | 10254. SubwayTrip

10254. SubwayTrip

Problem

You are walking down the escalator to catch a subway train. 2 | The escalator itself moves at a speed of Ve meters per minute. 3 | You can walk down the escalator at a relative speed of Vy meters per minute. 4 | The length of the escalator is L meters. 5 | Trains arrive T minutes apart. 6 |
7 | Let t be the time between your arrival to the station if you stand still on the escalator 8 | and the arrival of the last train before your arrival. 9 | Assume that t is a random variable uniformly distributed between 0 and T. 10 |
11 | Return the probability of catching an earlier train if you choose to walk down the escalator 12 | instead of standing still on it. 13 |

Definition

Filename

SubwayTrip.py

Signature

double earlierTrain(int Ve, int Vy, int L, int T)

Constraints

Examples

-------------------------------------------------------------------------------- /10254_SubwayTrip/SubwayTrip.json: -------------------------------------------------------------------------------- 1 | { 2 | "definition": { 3 | "method": "earlierTrain", 4 | "names": { 5 | "input": [ 6 | "Ve", 7 | "Vy", 8 | "L", 9 | "T" 10 | ] 11 | }, 12 | "types": { 13 | "output": "double", 14 | "input": [ 15 | "int", 16 | "int", 17 | "int", 18 | "int" 19 | ] 20 | }, 21 | "class": "SubwayTrip" 22 | }, 23 | "tests": [], 24 | "name": "SubwayTrip", 25 | "statement": "You are walking down the escalator to catch a subway train. \nThe escalator itself moves at a speed of Ve meters per minute. \nYou can walk down the escalator at a relative speed of Vy meters per minute.\nThe length of the escalator is L meters.\nTrains arrive T minutes apart.\n
\nLet t be the time between your arrival to the station if you stand still on the escalator \nand the arrival of the last train before your arrival.\nAssume that t is a random variable uniformly distributed between 0 and T.\n
\nReturn the probability of catching an earlier train if you choose to walk down the escalator \ninstead of standing still on it.\n", 26 | "constraints": [ 27 | "Ve will be between 10 and 60, inclusive.", 28 | "Vy will be between 1 and 10, inclusive.", 29 | "L will be between 10 and 100, inclusive.", 30 | "T will be between 2 and 20, inclusive." 31 | ], 32 | "number": 10254, 33 | "examples": [ 34 | { 35 | "comment": "
If you stand still, it'll take you 20/10 = 2 minutes to reach the bottom of the escalator. If you choose to walk, it'll make you 20/(10+10) = 1 minute. In the second case you save 1 minute and in 50% of the cases it'll allow you to catch an earlier train.
", 36 | "input": [ 37 | 10, 38 | 10, 39 | 20, 40 | 2 41 | ], 42 | "output": 0 43 | }, 44 | { 45 | "comment": "", 46 | "input": [ 47 | 50, 48 | 5, 49 | 55, 50 | 20 51 | ], 52 | "output": 0 53 | }, 54 | { 55 | "comment": "", 56 | "input": [ 57 | 34, 58 | 3, 59 | 85, 60 | 7 61 | ], 62 | "output": 0 63 | }, 64 | { 65 | "comment": "
Here, if you choose to walk instead of stand still, you will save 5 minutes and you will certainly be guaranteed to catch an earlier train.
", 66 | "input": [ 67 | 10, 68 | 10, 69 | 100, 70 | 4 71 | ], 72 | "output": 1 73 | } 74 | ] 75 | } -------------------------------------------------------------------------------- /10254_SubwayTrip/SubwayTrip.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | def earlierTrain(Ve, Vy, L, T): 4 | pass 5 | 6 | -------------------------------------------------------------------------------- /10254_SubwayTrip/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codersasha/TopCoder-Python-Problems/506ba498597e24cbb131e3a359452ea2192ff844/10254_SubwayTrip/__init__.py -------------------------------------------------------------------------------- /10255_WizardsAppointments/WizardsAppointments.html: -------------------------------------------------------------------------------- 1 | 10255. WizardsAppointments

10255. WizardsAppointments

Problem

Several wizards have scheduled appointments to meet with non-wizards. Each wizard will have exactly one meeting with a non-wizard. Unfortunately, some of the wizards have just realized that they will not be able to arrive at their meetings on time. They will show up either too early or too late. 2 |
3 | In an attempt to minimize the total waiting time, the wizards have decided to reschedule all of the meetings by shifting each one by the same amount of time. The total waiting time includes the time spent by wizards waiting for non-wizards to show up and the time spent by non-wizards waiting for wizards to show up. The non-wizards will all arrive exactly on time to the rescheduled meetings. 4 |
5 | You are given int[]s scheduledTimes and arrivalTimes. The i-th element of scheduledTimes is the original scheduled starting time for the i-th wizard's meeting. The i-th element of arrivalTimes is the time when the i-th wizard will show up to his meeting. All times are given in hours. If you shift all the meetings by T hours, the total waiting time can be calculated as the sum of abs(scheduledTimes[i] + T - arrivalTimes[i]) over all the meetings. 6 | 7 | Return the number of distinct integer shifts which allow to minimize the total waiting time.

Definition

Filename

WizardsAppointments.py

Signature

int scheduleAdjustment(int[] scheduledTimes, int[] arrivalTimes)

Constraints

Examples

-------------------------------------------------------------------------------- /10255_WizardsAppointments/WizardsAppointments.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | def scheduleAdjustment(scheduledTimes, arrivalTimes): 4 | pass 5 | 6 | -------------------------------------------------------------------------------- /10255_WizardsAppointments/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codersasha/TopCoder-Python-Problems/506ba498597e24cbb131e3a359452ea2192ff844/10255_WizardsAppointments/__init__.py -------------------------------------------------------------------------------- /10256_YetAnotherStonesGame/YetAnotherStonesGame.html: -------------------------------------------------------------------------------- 1 | 10256. YetAnotherStonesGame

10256. YetAnotherStonesGame

Problem

Johnny is playing a simple game with a set of colored stones and a circular board with squares laid out in a track around the edge, some of which are marked. To start with, he places some stones of different colors on the board in different unmarked squares and marks the starting position of each stone. He then picks some number from allowedMoves and advances some stone that number of squares clockwise around the board. If the square that the stone lands in is unmarked, then he leaves the stone there and marks the square. If the square was the starting position of that particular stone, then he removes the stone from the board. Otherwise, if the square had previously been marked, the move is invalid and he returns the stone to its position before he moved it at the beginning of this turn. He then repeats this process. The board is considered complete once all the squares are marked and all the stones have been removed (having moved at least once, then returned to their starting positions). To make the game more interesting, some of the squares on the board are marked before he starts the game and these squares are given in a String markedSquares, in which a marked square is denoted 'X' and an unmarked square '.'. The squares are given in clockwise order. Note that since the board is circular, the first element of markedSquares is adjacent to the last element. Return the minimum number of stones that Johnny would need to place on the board in order to complete the game, or -1 if it is impossible to complete the board.

Definition

Filename

YetAnotherStonesGame.py

Signature

int fewestStones(int[] allowedMoves, String markedSquares)

Constraints

Examples

-------------------------------------------------------------------------------- /10256_YetAnotherStonesGame/YetAnotherStonesGame.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | def fewestStones(allowedMoves, markedSquares): 4 | pass 5 | 6 | -------------------------------------------------------------------------------- /10256_YetAnotherStonesGame/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codersasha/TopCoder-Python-Problems/506ba498597e24cbb131e3a359452ea2192ff844/10256_YetAnotherStonesGame/__init__.py -------------------------------------------------------------------------------- /10257_SumAndProduct/SumAndProduct.html: -------------------------------------------------------------------------------- 1 | 10257. SumAndProduct

10257. SumAndProduct

Problem

A list of non-negative numbers is called satisfactory if the sum of the numbers in the list is equal to S and the product of the numbers is equal to P. Find a satisfactory list with the least possible number of elements, and return its size. If no such list exists, return -1 instead. Please note that the list may contain non-integer numbers.

Definition

Filename

SumAndProduct.py

Signature

int smallestSet(int S, int P)

Constraints

Examples

-------------------------------------------------------------------------------- /10257_SumAndProduct/SumAndProduct.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | def smallestSet(S, P): 4 | pass 5 | 6 | -------------------------------------------------------------------------------- /10257_SumAndProduct/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codersasha/TopCoder-Python-Problems/506ba498597e24cbb131e3a359452ea2192ff844/10257_SumAndProduct/__init__.py -------------------------------------------------------------------------------- /10258_LaserShooting/LaserShooting.html: -------------------------------------------------------------------------------- 1 | 10258. LaserShooting

10258. LaserShooting

Problem

There is a laser cannon at coordinates (0, 0) on the cartesian plane. There are also several targets on the plane. Each target is a vertical line segment, and the endpoints of the i-th target are at coordinates (x[i], y1[i]) and (x[i], y2[i]). A random angle between -Pi/2 and Pi/2, inclusive, is chosen, and a single shot is fired. The angle -Pi/2 is straight down vertically, 0 is straight to the right horizontally, and Pi/2 is straight up vertically. A shot is a straight ray of infinite length starting from the point (0, 0). A shot hits a target if there is a common point between them. Return the expected number of targets that will be hit by the single shot. Hitting a target doesn't change the direction of the laser shot.

Definition

Filename

LaserShooting.py

Signature

double numberOfHits(int[] x, int[] y1, int[] y2)

Constraints

Examples

-------------------------------------------------------------------------------- /10258_LaserShooting/LaserShooting.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | def numberOfHits(x, y1, y2): 4 | pass 5 | 6 | -------------------------------------------------------------------------------- /10258_LaserShooting/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codersasha/TopCoder-Python-Problems/506ba498597e24cbb131e3a359452ea2192ff844/10258_LaserShooting/__init__.py -------------------------------------------------------------------------------- /10259_MegaCoolNumbers/MegaCoolNumbers.html: -------------------------------------------------------------------------------- 1 | 10259. MegaCoolNumbers

10259. MegaCoolNumbers

Problem

A positive integer is called a cool number of power A if it can be separated into exactly A groups of consecutive digits, where the digits in each group form an arithmetic progression. An arithmetic progression is a sequence of numbers in which the difference between any two consecutive numbers is the same. A positive integer is called a mega cool number of power A if it is a cool number of power A, not a cool number of power A-1, and all its digits are in non-decreasing order.
2 | 3 | Determine the number of mega cool numbers of power A that contain exactly N digits (with no leading zeroes). Return this number modulo 1,000,000,007.

Definition

Filename

MegaCoolNumbers.py

Signature

int count(int N, int A)

Constraints

Examples

-------------------------------------------------------------------------------- /10259_MegaCoolNumbers/MegaCoolNumbers.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | def count(N, A): 4 | pass 5 | 6 | -------------------------------------------------------------------------------- /10259_MegaCoolNumbers/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codersasha/TopCoder-Python-Problems/506ba498597e24cbb131e3a359452ea2192ff844/10259_MegaCoolNumbers/__init__.py -------------------------------------------------------------------------------- /10261_FallingPoints/FallingPoints.html: -------------------------------------------------------------------------------- 1 | 10261. FallingPoints

10261. FallingPoints

Problem

You are given a int[] X containing the x-coordinates of several points. Each point starts at an infinitely high y-coordinate. Starting with the first point, each point falls down until it is either a distance of R away from a previously fallen point or it reaches y = 0. Each point (after the first point) will start falling only when the previous one stops. Return a double[], where the i-th element is the final y-coordinate of the i-th point.

Definition

Filename

FallingPoints.py

Signature

double[] getHeights(int[] X, int R)

Constraints

Examples

-------------------------------------------------------------------------------- /10261_FallingPoints/FallingPoints.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | def getHeights(X, R): 4 | pass 5 | 6 | -------------------------------------------------------------------------------- /10261_FallingPoints/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codersasha/TopCoder-Python-Problems/506ba498597e24cbb131e3a359452ea2192ff844/10261_FallingPoints/__init__.py -------------------------------------------------------------------------------- /10265_IncreasingLists/IncreasingLists.html: -------------------------------------------------------------------------------- 1 | 10265. IncreasingLists

10265. IncreasingLists

Problem

A string is called an increasing list if it is a comma-separated list of increasing positive integers with no leading zeroes. For example, the strings "2,3,9", "30", and "1,100,1000000000000000000000" are increasing lists, while "5,6,6", "1,2,3,", "0" and "1,02" are not.

2 |

You're given a String mask consisting of digits, commas and question marks. 3 | Replace each question mark with a digit or a comma, so that the resulting string is an increasing list, and return the resulting string. 4 | If there are multiple possible resulting strings, return the lexicographically smallest one. 5 | If it is impossible to produce an increasing list, return the string "impossible" (quotes for clarity only).

Definition

Filename

IncreasingLists.py

Signature

String makeIncreasingList(String mask)

Constraints

Examples

-------------------------------------------------------------------------------- /10265_IncreasingLists/IncreasingLists.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | def makeIncreasingList(mask): 4 | pass 5 | 6 | -------------------------------------------------------------------------------- /10265_IncreasingLists/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codersasha/TopCoder-Python-Problems/506ba498597e24cbb131e3a359452ea2192ff844/10265_IncreasingLists/__init__.py -------------------------------------------------------------------------------- /10266_HexatridecimalSum/HexatridecimalSum.html: -------------------------------------------------------------------------------- 1 | 10266. HexatridecimalSum

10266. HexatridecimalSum

Problem

Hexatridecimal notation is base 36 notation. The digits are '0' to '9' (with values 0 to 9) and 'A' to 'Z' (with values 10 to 35).

2 |

You are given a String[] numbers, where each element represents a positive integer in hexatridecimal notation. You must select exactly k digits (from the set of all digits - '0' to '9' and 'A' to 'Z') and replace all of their occurrences in all of the numbers with 'Z'. Then, calculate the sum of all the numbers.

3 |

Return the maximal possible sum you can get. The return value must be in hexatridecimal format with no leading zeroes.

Definition

Filename

HexatridecimalSum.py

Signature

String maximizeSum(String[] numbers, int k)

Constraints

Examples

-------------------------------------------------------------------------------- /10266_HexatridecimalSum/HexatridecimalSum.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | def maximizeSum(numbers, k): 4 | pass 5 | 6 | -------------------------------------------------------------------------------- /10266_HexatridecimalSum/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codersasha/TopCoder-Python-Problems/506ba498597e24cbb131e3a359452ea2192ff844/10266_HexatridecimalSum/__init__.py -------------------------------------------------------------------------------- /10267_LeastMajorityMultiple/LeastMajorityMultiple.html: -------------------------------------------------------------------------------- 1 | 10267. LeastMajorityMultiple

10267. LeastMajorityMultiple

Problem

Given five positive integers, their least majority multiple is the smallest positive integer that is divisible by at least three of them.

2 |

Given distinct ints a, b, c, d and e, return their least majority multiple.

Definition

Filename

LeastMajorityMultiple.py

Signature

int leastMajorityMultiple(int a, int b, int c, int d, int e)

Constraints

Examples

-------------------------------------------------------------------------------- /10267_LeastMajorityMultiple/LeastMajorityMultiple.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | def leastMajorityMultiple(a, b, c, d, e): 4 | pass 5 | 6 | -------------------------------------------------------------------------------- /10267_LeastMajorityMultiple/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codersasha/TopCoder-Python-Problems/506ba498597e24cbb131e3a359452ea2192ff844/10267_LeastMajorityMultiple/__init__.py -------------------------------------------------------------------------------- /10274_Underprimes/Underprimes.html: -------------------------------------------------------------------------------- 1 | 10274. Underprimes

10274. Underprimes

Problem

The prime factorization of a number X is the list of prime numbers that multiply together to form X. For example, the prime factorization of 12 is 2 * 2 * 3. Note that 1 is not a prime number.

2 |

An underprime is a number whose prime factorization contains a prime number of elements. For example, 12 is an underprime because its prime factorization contains 3 elements, and 3 is a prime number. Given ints A and B, return the number of underprimes between A and B, inclusive.

Definition

Filename

Underprimes.py

Signature

int howMany(int A, int B)

Constraints

Examples

-------------------------------------------------------------------------------- /10274_Underprimes/Underprimes.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | def howMany(A, B): 4 | pass 5 | 6 | -------------------------------------------------------------------------------- /10274_Underprimes/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codersasha/TopCoder-Python-Problems/506ba498597e24cbb131e3a359452ea2192ff844/10274_Underprimes/__init__.py -------------------------------------------------------------------------------- /10275_CellRemoval/CellRemoval.html: -------------------------------------------------------------------------------- 1 | 10275. CellRemoval

10275. CellRemoval

Problem

In biology, organisms have the following property: Starting from the first cell (the zygote), each cell during an organism's development process either divides into 2 other cells or does not divide at all. An organism is mature when all of its cells will not divide any further.
2 |
3 | Let's assign a unique number to each cell in an organism's development process. For example, consider a species in which each organism starts with cell 0, which divides into cells 1 and 2. Cell 1 divides into cells 3 and 4. Cells 2, 3 and 4 do not divide. Every mature organism of this species will consist of exactly 3 cells - 2, 3 and 4.
4 | 5 |
6 | During the development process, if we kill a cell, it will be absent in the mature form of the organism. If that cell happens to be a cell that divides, then the mature organism will be missing all of the cell's descendants as well because the cell is killed before it has a chance to divide. For example, in the organism described above, if we kill cell 1 during the development process, the mature organism will contain only cell 2.
7 | 8 |
9 | 10 | You are given a int[] parentCell describing the development process of an organism. The i-th element of parentCell is the parent cell of cell i (where i is a 0-based index). The zygote's parent is -1. Return the number of cells the mature form of this organism would have if you killed cell deletedCell during the development process.

Definition

Filename

CellRemoval.py

Signature

int cellsLeft(int[] parent, int deletedCell)

Constraints

Examples

-------------------------------------------------------------------------------- /10275_CellRemoval/CellRemoval.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | def cellsLeft(parent, deletedCell): 4 | pass 5 | 6 | -------------------------------------------------------------------------------- /10275_CellRemoval/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codersasha/TopCoder-Python-Problems/506ba498597e24cbb131e3a359452ea2192ff844/10275_CellRemoval/__init__.py -------------------------------------------------------------------------------- /10279_ThePresents/ThePresents.html: -------------------------------------------------------------------------------- 1 | 10279. ThePresents

10279. ThePresents

Problem

2 | Santa Claus has n small boxes, all of equal size, containing presents for the children. Each box is a A x A x A cube. Santa wants to pack all of the small boxes into a large rectangular box with dimensions length x width x height. Each small box must be placed inside the big box with its sides parallel to the sides of the big box. 3 |

4 |

5 | Return the maximal possible value of A that will allow Santa Claus to fit all of the small boxes into the big one. Note that A is not necessarily an integer. 6 |

7 |

Definition

Filename

ThePresents.py

Signature

double find(int n, int length, int width, int height)

Constraints

Examples

-------------------------------------------------------------------------------- /10279_ThePresents/ThePresents.json: -------------------------------------------------------------------------------- 1 | { 2 | "definition": { 3 | "method": "find", 4 | "names": { 5 | "input": [ 6 | "n", 7 | "length", 8 | "width", 9 | "height" 10 | ] 11 | }, 12 | "types": { 13 | "output": "double", 14 | "input": [ 15 | "int", 16 | "int", 17 | "int", 18 | "int" 19 | ] 20 | }, 21 | "class": "ThePresents" 22 | }, 23 | "tests": [], 24 | "name": "ThePresents", 25 | "statement": "

\nSanta Claus has n small boxes, all of equal size, containing presents for the children. Each box is a A x A x A cube. Santa wants to pack all of the small boxes into a large rectangular box with dimensions length x width x height. Each small box must be placed inside the big box with its sides parallel to the sides of the big box.\n

\n

\nReturn the maximal possible value of A that will allow Santa Claus to fit all of the small boxes into the big one. Note that A is not necessarily an integer.\n

\n", 26 | "constraints": [ 27 | "n will be between 1 and 1,000,000,000, inclusive.", 28 | "length, width and height will be between 1 and 1,000,000,000, inclusive." 29 | ], 30 | "number": 10279, 31 | "examples": [ 32 | { 33 | "comment": "
There's room for eight 1x1x1 presents in the big box. However, if the presents are larger than 1x1x1, there is only room for one at most.\n
", 34 | "input": [ 35 | 2, 36 | 2, 37 | 2, 38 | 2 39 | ], 40 | "output": 1 41 | }, 42 | { 43 | "comment": "
Just one present.
", 44 | "input": [ 45 | 1, 46 | 12, 47 | 47, 48 | 5 49 | ], 50 | "output": 5 51 | }, 52 | { 53 | "comment": "
There will be no free space left in the big box.
", 54 | "input": [ 55 | 10, 56 | 4, 57 | 2, 58 | 10 59 | ], 60 | "output": 2 61 | }, 62 | { 63 | "comment": "", 64 | "input": [ 65 | 77, 66 | 146, 67 | 523, 68 | 229 69 | ], 70 | "output": 52 71 | } 72 | ] 73 | } -------------------------------------------------------------------------------- /10279_ThePresents/ThePresents.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | def find(n, length, width, height): 4 | pass 5 | 6 | -------------------------------------------------------------------------------- /10279_ThePresents/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codersasha/TopCoder-Python-Problems/506ba498597e24cbb131e3a359452ea2192ff844/10279_ThePresents/__init__.py -------------------------------------------------------------------------------- /10280_TheLongWay/TheLongWay.html: -------------------------------------------------------------------------------- 1 | 10280. TheLongWay

10280. TheLongWay

Problem

2 | When all the presents are packed, Santa Claus has to deliver them to the children. He will start by delivering to the children in his own city. 3 | The city is a rectangular grid containing square blocks of equal size. You are given a String[] cityMap, where the j-th character of the i-th element is the block at row i, column j. There are four types of city blocks: 4 |

5 | 11 |

12 | It takes Santa one minute to move one city block north, south, east or west. He can only move in those four directions, and he cannot leave the city. When he enters a block containing children, he will deliver presents to all of them. This happens instantaneously and does not take any additional time. Since he doesn't want anybody to see him, he must change his direction after each minute and can make no stops. This means he can never make two consecutive moves in the same direction. Return the minimal number of minutes required for Santa to deliver presents to all the children in the city. If it is impossible, return -1 instead. 13 |

14 |

Definition

Filename

TheLongWay.py

Signature

int minimalTime(String[] cityMap)

Constraints

Examples

-------------------------------------------------------------------------------- /10280_TheLongWay/TheLongWay.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | def minimalTime(cityMap): 4 | pass 5 | 6 | -------------------------------------------------------------------------------- /10280_TheLongWay/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codersasha/TopCoder-Python-Problems/506ba498597e24cbb131e3a359452ea2192ff844/10280_TheLongWay/__init__.py -------------------------------------------------------------------------------- /10281_MegaCoolNumbersEasy/MegaCoolNumbersEasy.html: -------------------------------------------------------------------------------- 1 | 10281. MegaCoolNumbersEasy

10281. MegaCoolNumbersEasy

Problem

A positive integer is called a mega cool number if its digits form an arithmetic progression. An arithmetic progression is a sequence of numbers in which the difference between any two consecutive numbers is the same. Return the number of mega cool numbers between 1 and N, inclusive. 2 |

Definition

Filename

MegaCoolNumbersEasy.py

Signature

int count(int N)

Constraints

Examples

-------------------------------------------------------------------------------- /10281_MegaCoolNumbersEasy/MegaCoolNumbersEasy.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | def count(N): 4 | pass 5 | 6 | -------------------------------------------------------------------------------- /10281_MegaCoolNumbersEasy/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codersasha/TopCoder-Python-Problems/506ba498597e24cbb131e3a359452ea2192ff844/10281_MegaCoolNumbersEasy/__init__.py -------------------------------------------------------------------------------- /10282_TheGarland/TheGarland.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | def find(lamps, n): 4 | pass 5 | 6 | -------------------------------------------------------------------------------- /10282_TheGarland/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codersasha/TopCoder-Python-Problems/506ba498597e24cbb131e3a359452ea2192ff844/10282_TheGarland/__init__.py -------------------------------------------------------------------------------- /10284_Parallelograms/Parallelograms.html: -------------------------------------------------------------------------------- 1 | 10284. Parallelograms

10284. Parallelograms

Problem

2 | A parallelogram is a quadrilateral with two sets of parallel sides. 3 |

4 |

5 | You are given three distinct points A(xA,yA), B(xB,yB) and C(xC,yC) in the plane. 6 |

7 |

8 | Consider all non-degenerate parallelograms such that A, B, and C are three of its vertices. 9 | Your method should return the difference between the largest and the smallest possible perimeter of such a parallelogram. 10 | If there is no such parallelogram, return -1 instead. 11 |

Definition

Filename

Parallelograms.py

Signature

double getDifference(int xA, int yA, int xB, int yB, int xC, int yC)

Constraints

Examples

-------------------------------------------------------------------------------- /10284_Parallelograms/Parallelograms.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | def getDifference(xA, yA, xB, yB, xC, yC): 4 | pass 5 | 6 | -------------------------------------------------------------------------------- /10284_Parallelograms/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codersasha/TopCoder-Python-Problems/506ba498597e24cbb131e3a359452ea2192ff844/10284_Parallelograms/__init__.py -------------------------------------------------------------------------------- /10285_AnotherCoinProblem/AnotherCoinProblem.html: -------------------------------------------------------------------------------- 1 | 10285. AnotherCoinProblem

10285. AnotherCoinProblem

Problem

2 | The monetary system in Absurdistan is really simple and systematic. The locals only use coins. The coins come in different values. 3 | The values used are: 4 |

5 |

6 | 1, 10, 25, 100, 1000, 2500, 10000, 100000, 250000, 1000000, ... 7 |

8 |

9 | Formally, for each K>=0 there are coins worth 10K, and coins worth 25*100K. 10 |

11 |

12 | You want to buy a new car. Its price is cost. Write a method that will return the smallest number of coins necessary to pay exactly the cost of the car (assuming 13 | you have a sufficient supply of coins of each of the types you will need). 14 |

Definition

Filename

AnotherCoinProblem.py

Signature

int minimumCoins(long cost)

Constraints

Examples

-------------------------------------------------------------------------------- /10285_AnotherCoinProblem/AnotherCoinProblem.json: -------------------------------------------------------------------------------- 1 | { 2 | "definition": { 3 | "method": "minimumCoins", 4 | "names": { 5 | "input": [ 6 | "cost" 7 | ] 8 | }, 9 | "types": { 10 | "output": "int", 11 | "input": [ 12 | "long" 13 | ] 14 | }, 15 | "class": "AnotherCoinProblem" 16 | }, 17 | "tests": [], 18 | "name": "AnotherCoinProblem", 19 | "statement": "

\nThe monetary system in Absurdistan is really simple and systematic. The locals only use coins. The coins come in different values.\nThe values used are:\n

\n

\n1, 10, 25, 100, 1000, 2500, 10000, 100000, 250000, 1000000, ...\n

\n

\nFormally, for each K>=0 there are coins worth 10K, and coins worth 25*100K.\n

\n

\nYou want to buy a new car. Its price is cost. Write a method that will return the smallest number of coins necessary to pay exactly the cost of the car (assuming \nyou have a sufficient supply of coins of each of the types you will need).\n

", 20 | "constraints": [ 21 | "cost will be between 1 and 10^15, inclusive." 22 | ], 23 | "number": 10285, 24 | "examples": [ 25 | { 26 | "comment": "
The best way to pay 47 is 25+10+10+1+1.
", 27 | "input": [ 28 | 47 29 | ], 30 | "output": 5 31 | }, 32 | { 33 | "comment": "
To pay 9, we can only use nine coins worth 1 each.
", 34 | "input": [ 35 | 9 36 | ], 37 | "output": 9 38 | }, 39 | { 40 | "comment": "", 41 | "input": [ 42 | 250111 43 | ], 44 | "output": 4 45 | }, 46 | { 47 | "comment": "
3*25,000,000 + 1*1,000,000 + 2*250,000 + 4*10,000 + 1*100 + 2*10 + 3*1 = 76,540,123\n
\n3 + 1 + 2 + 4 + 1 + 2 + 3 = 16
", 48 | "input": [ 49 | 76540123 50 | ], 51 | "output": 16 52 | } 53 | ] 54 | } -------------------------------------------------------------------------------- /10285_AnotherCoinProblem/AnotherCoinProblem.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | def minimumCoins(cost): 4 | pass 5 | 6 | -------------------------------------------------------------------------------- /10285_AnotherCoinProblem/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codersasha/TopCoder-Python-Problems/506ba498597e24cbb131e3a359452ea2192ff844/10285_AnotherCoinProblem/__init__.py -------------------------------------------------------------------------------- /10286_DiamondMining/DiamondMining.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | def largestDiamond(R, C, seed, threshold): 4 | pass 5 | 6 | -------------------------------------------------------------------------------- /10286_DiamondMining/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codersasha/TopCoder-Python-Problems/506ba498597e24cbb131e3a359452ea2192ff844/10286_DiamondMining/__init__.py -------------------------------------------------------------------------------- /10288_MazeWanderingEasy/MazeWanderingEasy.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | def decisions(maze): 4 | pass 5 | 6 | -------------------------------------------------------------------------------- /10288_MazeWanderingEasy/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codersasha/TopCoder-Python-Problems/506ba498597e24cbb131e3a359452ea2192ff844/10288_MazeWanderingEasy/__init__.py -------------------------------------------------------------------------------- /10289_WickedTeacher/WickedTeacher.html: -------------------------------------------------------------------------------- 1 | 10289. WickedTeacher

10289. WickedTeacher

Problem

A wicked teacher is trying to fail one of his students. He gives him the following problem:

2 | 3 | You are given a String[] numbers containing a set of distinct integers. You can concatenate some permutation of these integers to obtain one large integer. For example, the permutation {5221, 40, 1, 58, 9} can be concatenated to form 5221401589. Find a permutation of the given numbers such that its concatenation is divisible by the integer K.

4 | 5 | The student doesn't have a clue how to solve this problem, so he just answers with some random permutation. There may be multiple correct answers, and maybe the student has chosen one of them by chance. Return the probability that the student has chosen one of the correct answers and return it as a String in the form of an irreducible fraction "p/q" (quotes for clarity), where p is the fraction's numerator and q is its denominator. Assume that each permutation has the same probability of being chosen.

Definition

Filename

WickedTeacher.py

Signature

String cheatProbability(String[] numbers, int K)

Constraints

Examples

-------------------------------------------------------------------------------- /10289_WickedTeacher/WickedTeacher.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | def cheatProbability(numbers, K): 4 | pass 5 | 6 | -------------------------------------------------------------------------------- /10289_WickedTeacher/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codersasha/TopCoder-Python-Problems/506ba498597e24cbb131e3a359452ea2192ff844/10289_WickedTeacher/__init__.py -------------------------------------------------------------------------------- /10294_SkiFriction/SkiFriction.html: -------------------------------------------------------------------------------- 1 | 10294. SkiFriction

10294. SkiFriction

Problem

Kate is standing on a pair of skis at the beginning of a straight path. The path consists of n segments of equal length. You are given a String pathFriction representing the friction of the path. The i-th character of pathFriction is a digit between '1' and '9', inclusive, representing the friction of the i-th segment of the path. (All indices in this problem are 0-based.)
2 |
3 | In this problem, we will treat Kate's skis as one single ski. The ski consists of m segments of equal length. A ski segment has the same length as a path segment. The friction of the ski is given in the String skiFriction, where the i-th character is a digit between '1' and '9', inclusive, representing the friction of the i-th segment of the ski.
4 |
5 | Initially, Kate is standing in such a way that the i-th segment of her ski touches the i-th segment of the path. She will move forward one segment at a time until the (m-1)-th segment of her ski touches the (n-1)-th segment of the path. Each time she moves forward one segment, she moves at the speed of the slowest segment of her ski. The time required for a segment of her ski to move forward by one segment is equal to the friction of that ski segment plus the friction of the path segment it currently touches.
6 |
7 | Return the total time required for Kate to ski to the end of the path.

Definition

Filename

SkiFriction.py

Signature

int bestPosition(String skiFriction, String pathFriction)

Constraints

Examples

-------------------------------------------------------------------------------- /10294_SkiFriction/SkiFriction.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | def bestPosition(skiFriction, pathFriction): 4 | pass 5 | 6 | -------------------------------------------------------------------------------- /10294_SkiFriction/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codersasha/TopCoder-Python-Problems/506ba498597e24cbb131e3a359452ea2192ff844/10294_SkiFriction/__init__.py -------------------------------------------------------------------------------- /10295_GroupedWordChecker/GroupedWordChecker.html: -------------------------------------------------------------------------------- 1 | 10295. GroupedWordChecker

10295. GroupedWordChecker

Problem

A word is grouped if, for each letter in the word, all occurrences of that letter form exactly one consecutive sequence. In other words, no two equal letters are separated by one or more letters that are different. For example, the words "ccazzzzbb" and "code" are grouped, while "aabbbccb" and "topcoder" are not.

2 |
3 |

You are given several words as a String[]. Return how many of them are grouped.

4 |

Definition

Filename

GroupedWordChecker.py

Signature

int howMany(String[] words)

Constraints

Examples

-------------------------------------------------------------------------------- /10295_GroupedWordChecker/GroupedWordChecker.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | def howMany(words): 4 | pass 5 | 6 | -------------------------------------------------------------------------------- /10295_GroupedWordChecker/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codersasha/TopCoder-Python-Problems/506ba498597e24cbb131e3a359452ea2192ff844/10295_GroupedWordChecker/__init__.py -------------------------------------------------------------------------------- /10297_CirclesCountry/CirclesCountry.html: -------------------------------------------------------------------------------- 1 | 10297. CirclesCountry

10297. CirclesCountry

Problem

Circles Country is a country that contains several circular-shaped districts. Some districts may be situated inside other districts, but their borders do not intersect or touch. Qatam is a resident of Circles Country. When he travels between two locations, he always tries to cross the fewest number of district borders as possible because crossing borders is usually a laborious task. 2 |

3 | Imagine Circles Country as an infinite plane. You are given int[]s X, Y and R, where (X[i], Y[i]) are the coordinates of the i-th district's center and R[i] is its radius. Qatam is currently at point (x1,y1) and he needs to get to point (x2,y2). Neither of these points lies on a district border. Return the minimal number of district borders he must cross to get to his destination. 4 |

Definition

Filename

CirclesCountry.py

Signature

int leastBorders(int[] X, int[] Y, int[] R, int x1, int y1, int x2, int y2)

Constraints

Examples

-------------------------------------------------------------------------------- /10297_CirclesCountry/CirclesCountry.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | def leastBorders(X, Y, R, x1, y1, x2, y2): 4 | pass 5 | 6 | -------------------------------------------------------------------------------- /10297_CirclesCountry/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codersasha/TopCoder-Python-Problems/506ba498597e24cbb131e3a359452ea2192ff844/10297_CirclesCountry/__init__.py -------------------------------------------------------------------------------- /10298_TheSquareDivOne/TheSquareDivOne.html: -------------------------------------------------------------------------------- 1 | 10298. TheSquareDivOne

10298. TheSquareDivOne

Problem

John and Brus like puzzles. They have been playing a new game which involves placing checkers on a square board. The board is a grid containing the same number of columns and rows.
2 |
3 | The game begins with John placing checkers on specific cells of the board. Then, R[i] is calculated for each row i, where R[i] is the number of checkers in the i-th row. Brus must then move the checkers in such a way that for each column i in the final board, the number of checkers in that column is equal to R[i]. Note that R[i] is calculated for the initial placement of checkers and is not modified afterwards. In a single turn, Brus can move a checker up, down, left or right into an adjacent empty cell. He must use as few turns as possible to reach the goal.
4 |
5 | You are give a String[] board, where the j-th character of the i-th element is uppercase 'C' if the cell at row i, column j contains a checker and '.' otherwise. Return the final placement of checkers using the same format as the input. Since there may be many possible final placements, return the one that comes first lexicographically.

Definition

Filename

TheSquareDivOne.py

Signature

String[] solve(String[] board)

Constraints

Examples

-------------------------------------------------------------------------------- /10298_TheSquareDivOne/TheSquareDivOne.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | def solve(board): 4 | pass 5 | 6 | -------------------------------------------------------------------------------- /10298_TheSquareDivOne/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codersasha/TopCoder-Python-Problems/506ba498597e24cbb131e3a359452ea2192ff844/10298_TheSquareDivOne/__init__.py -------------------------------------------------------------------------------- /10299_TheSquareDivTwo/TheSquareDivTwo.html: -------------------------------------------------------------------------------- 1 | 10299. TheSquareDivTwo

10299. TheSquareDivTwo

Problem

John and Brus like puzzles. They have been playing a new game which involves placing checkers on a square board. The board is a grid containing the same number of columns and rows.
2 |
3 | The game begins with John placing checkers on specific cells of the board. Then, R[i] is calculated for each row i, where R[i] is the number of checkers in the i-th row. Brus must then move the checkers in such a way that for each column i in the final board, the number of checkers in that column is equal to R[i]. Note that R[i] is calculated for the initial placement of checkers and is not modified afterwards. In a single turn, Brus can move a checker up, down, left or right into an adjacent empty cell. He may use as many turns as necessary to reach the goal.
4 |
5 | You are given a String[] board, where the j-th character of the i-th element is uppercase 'C' if the cell at row i, column j contains a checker and '.' otherwise. Return the final placement of checkers using the same format as the input. Since there may be many possible final placements, return the one that comes first lexicographically.

Definition

Filename

TheSquareDivTwo.py

Signature

String[] solve(String[] board)

Constraints

Examples

-------------------------------------------------------------------------------- /10299_TheSquareDivTwo/TheSquareDivTwo.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | def solve(board): 4 | pass 5 | 6 | -------------------------------------------------------------------------------- /10299_TheSquareDivTwo/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codersasha/TopCoder-Python-Problems/506ba498597e24cbb131e3a359452ea2192ff844/10299_TheSquareDivTwo/__init__.py -------------------------------------------------------------------------------- /10308_Deposit/Deposit.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | def successProbability(siteX, siteY, depositX, depositY): 4 | pass 5 | 6 | -------------------------------------------------------------------------------- /10308_Deposit/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codersasha/TopCoder-Python-Problems/506ba498597e24cbb131e3a359452ea2192ff844/10308_Deposit/__init__.py -------------------------------------------------------------------------------- /10309_IncredibleMachineEasy/IncredibleMachineEasy.html: -------------------------------------------------------------------------------- 1 | 10309. IncredibleMachineEasy

10309. IncredibleMachineEasy

Problem

You may remember an old computer game called "The Incredible Machine". It was a game where you could simulate simple processes like balls falling, lasers shooting, or cats pursuing mice. Moreover, you were able to perform these observations with different values for gravitational acceleration.

2 | 3 | Imagine a system with some unknown acceleration of gravity. There are N balls, each fixed initially at some height above the ground. You are given a int[] height, where the i-th element is the height of the i-th ball above the ground. At time 0, the first ball is set loose and it starts falling. When it reaches the ground, the second ball is instantly set loose, and so on. This continues until the last ball reaches the ground at time T.

4 | 5 | Return the acceleration of gravity in this system. Neglect air resistance and any other resisting factors. The distance d travelled by an object falling for time t with no initial velocity in a system with gravitational acceleration g and no resisting factors is equal to d = 0.5 * g * t^2.

Definition

Filename

IncredibleMachineEasy.py

Signature

double gravitationalAcceleration(int[] height, int T)

Constraints

Examples

-------------------------------------------------------------------------------- /10309_IncredibleMachineEasy/IncredibleMachineEasy.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | def gravitationalAcceleration(height, T): 4 | pass 5 | 6 | -------------------------------------------------------------------------------- /10309_IncredibleMachineEasy/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codersasha/TopCoder-Python-Problems/506ba498597e24cbb131e3a359452ea2192ff844/10309_IncredibleMachineEasy/__init__.py -------------------------------------------------------------------------------- /10310_IncredibleMachine/IncredibleMachine.html: -------------------------------------------------------------------------------- 1 | 10310. IncredibleMachine

10310. IncredibleMachine

Problem

You may remember an old computer game called "The Incredible Machine". It was a game where you could simulate simple processes like balls falling, lasers shooting, or cats pursuing mice. Moreover, you were able to perform these observations with different values for gravitational acceleration.

2 | 3 | We are observing a system with some unknown acceleration of gravity. There is a slope which has the form of a polyline with N vertices. Each vertex of the polyline is positioned lower and to the right of the previous one. At time 0, a ball is placed at the first vertex. The ball is small enough to be considered a single point. Assume that there's no friction between the slope and the ball, the ball is absolutely nonelastic, and the direction of its velocity changes instantly at the polyline's vertices. Under these conditions, the ball will follow the polyline without ever losing contact with it. The ball reaches the final vertex at time T.

4 | 5 | You are given int[]s x and y, where (x[i], y[i]) are the coordinates of the i-th vertex. Return the gravitational acceleration in this system. A body rolling down an inclined plane of angle alpha (measured between the plane and horizontal direction) under gravitational acceleration g has a constant acceleration of a = g * sin(alpha). The distance d travelled by an object during time t moving with initial velocity v0 and with constant acceleration a is equal to d = v0 * t + 0.5 * a * t^2. The velocity v1 of the object after time t has passed is equal to v1 = v0 + a * t.

Definition

Filename

IncredibleMachine.py

Signature

double gravitationalAcceleration(int[] x, int[] y, int T)

Constraints

Examples

-------------------------------------------------------------------------------- /10310_IncredibleMachine/IncredibleMachine.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | def gravitationalAcceleration(x, y, T): 4 | pass 5 | 6 | -------------------------------------------------------------------------------- /10310_IncredibleMachine/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codersasha/TopCoder-Python-Problems/506ba498597e24cbb131e3a359452ea2192ff844/10310_IncredibleMachine/__init__.py -------------------------------------------------------------------------------- /10314_PawnsAndKings/PawnsAndKings.html: -------------------------------------------------------------------------------- 1 | 10314. PawnsAndKings

10314. PawnsAndKings

Problem

2 | You are given a String[] board representing a standard 8x8 chess board. 3 | The '.' character represents an empty cell, 'P' represents a cell occupied by a pawn, and 'K' 4 | represents a cell occupied by a king. 5 |

6 |

7 | In a single move, a king can move to any of its 8 neighboring cells. If you move a king 8 | into a cell occupied by a pawn, the king will capture that pawn. You can never move a 9 | king outside the board or into a cell already occupied by another king. 10 |

11 |

12 | Return the minimal number of moves required for the kings to capture all the pawns. 13 |

14 |

Definition

Filename

PawnsAndKings.py

Signature

int minNumberOfMoves(String[] board)

Constraints

Examples

-------------------------------------------------------------------------------- /10314_PawnsAndKings/PawnsAndKings.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | def minNumberOfMoves(board): 4 | pass 5 | 6 | -------------------------------------------------------------------------------- /10314_PawnsAndKings/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codersasha/TopCoder-Python-Problems/506ba498597e24cbb131e3a359452ea2192ff844/10314_PawnsAndKings/__init__.py -------------------------------------------------------------------------------- /10317_Unicorn/Unicorn.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | def countWays(R, C, L, seed, word): 4 | pass 5 | 6 | -------------------------------------------------------------------------------- /10317_Unicorn/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codersasha/TopCoder-Python-Problems/506ba498597e24cbb131e3a359452ea2192ff844/10317_Unicorn/__init__.py -------------------------------------------------------------------------------- /10319_NumberGraph/NumberGraph.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | def largestSet(graphSet, joiningSet): 4 | pass 5 | 6 | -------------------------------------------------------------------------------- /10319_NumberGraph/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codersasha/TopCoder-Python-Problems/506ba498597e24cbb131e3a359452ea2192ff844/10319_NumberGraph/__init__.py -------------------------------------------------------------------------------- /10324_DigitalCounter/DigitalCounter.html: -------------------------------------------------------------------------------- 1 | 10324. DigitalCounter

10324. DigitalCounter

Problem

2 | We have an N-digit digital counter that increments every second. The counter is cyclic: after it reaches 10^N - 1, it starts once again from zero. 3 |

4 |

5 | Each digit is shown using the standard seven-segment display. The exact forms of all the digits are shown in the ASCII art below. 6 |

7 |
 8 |     +   +---+   +---+   +   +   +---+
 9 |     |       |       |   |   |   |
10 |     +   +---+   +---+   +---+   +---+
11 |     |   |           |       |       |
12 |     +   +---+   +---+       +   +---+
13 | 
14 | +---+   +---+   +---+   +---+   +---+
15 | |           |   |   |   |   |   |   |
16 | +---+       +   +---+   +---+   +   +
17 | |   |       |   |   |       |   |   |
18 | +---+       +   +---+       +   +---+
19 | 
20 |

21 | Each line segment that connects two adjacent '+' symbols represents a single lit segment. For example, '1' contains two lit segments, and '9' contains five lit segments. 22 |

23 |

24 | You are given a String current that contains the current number shown by the counter. 25 |
26 | The number of characters in current is equal to the number N of displayed digits. 27 |

28 |

29 | Return the smallest positive number of seconds after which the counter will have the same total number of lit segments as it does now. 30 |

Definition

Filename

DigitalCounter.py

Signature

long nextEvent(String current)

Constraints

Examples

-------------------------------------------------------------------------------- /10324_DigitalCounter/DigitalCounter.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | def nextEvent(current): 4 | pass 5 | 6 | -------------------------------------------------------------------------------- /10324_DigitalCounter/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codersasha/TopCoder-Python-Problems/506ba498597e24cbb131e3a359452ea2192ff844/10324_DigitalCounter/__init__.py -------------------------------------------------------------------------------- /10325_ConnectingAirports/ConnectingAirports.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | def getSchedule(capacityA, capacityU): 4 | pass 5 | 6 | -------------------------------------------------------------------------------- /10325_ConnectingAirports/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codersasha/TopCoder-Python-Problems/506ba498597e24cbb131e3a359452ea2192ff844/10325_ConnectingAirports/__init__.py -------------------------------------------------------------------------------- /10326_MismatchedStrings/MismatchedStrings.html: -------------------------------------------------------------------------------- 1 | 10326. MismatchedStrings

10326. MismatchedStrings

Problem

2 | Well-parenthesized strings are defined using the following rules: 3 |

4 | 10 |

11 | In this problem we will deal with the complement of this set of strings: The strings that consist only of the characters '(' and ')', but are not well-parenthesized. We will call these strings mismatched. 12 |

13 |

14 | You are given an int N and a long K. All mismatched strings of length N can be ordered lexicographically, and numbered sequentially, starting with zero. Return the string that will get the number K in this order. If there is no such string, return the empty string instead. 15 |

16 |

Definition

Filename

MismatchedStrings.py

Signature

String getString(int N, long K)

Constraints

Examples

-------------------------------------------------------------------------------- /10326_MismatchedStrings/MismatchedStrings.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | def getString(N, K): 4 | pass 5 | 6 | -------------------------------------------------------------------------------- /10326_MismatchedStrings/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codersasha/TopCoder-Python-Problems/506ba498597e24cbb131e3a359452ea2192ff844/10326_MismatchedStrings/__init__.py -------------------------------------------------------------------------------- /10329_PageNumbers/PageNumbers.html: -------------------------------------------------------------------------------- 1 | 10329. PageNumbers

10329. PageNumbers

Problem

2 | We have a book with N pages, numbered 1 to N. 3 | How many times does each digit occur in the page numbers? 4 |

5 |

6 | You are given an int N. Return a int[] with 10 elements, where for all i between 0 and 9, inclusive, the element i will be the number of times digit i occurs when we write down all the numbers between 1 and N, inclusive. 7 |

Definition

Filename

PageNumbers.py

Signature

int[] getCounts(int N)

Constraints

Examples

-------------------------------------------------------------------------------- /10329_PageNumbers/PageNumbers.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | def getCounts(N): 4 | pass 5 | 6 | -------------------------------------------------------------------------------- /10329_PageNumbers/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codersasha/TopCoder-Python-Problems/506ba498597e24cbb131e3a359452ea2192ff844/10329_PageNumbers/__init__.py -------------------------------------------------------------------------------- /10331_BidirectionalQueue/BidirectionalQueue.html: -------------------------------------------------------------------------------- 1 | 10331. BidirectionalQueue

10331. BidirectionalQueue

Problem

You are given a bidirectional cyclical queue which contains N elements. You need to extract several elements from this queue. 2 |
3 | You can do 3 kinds of operations with this queue: 4 |

  1. 5 | Extract first element. After applying this operation, queue a1, ..., aK becomes a2, ..., aK. 6 |
  2. 7 | Shift queue elements left. After applying this operation, queue a1, ..., aK becomes a2, ..., aK, a1. 8 |
  3. 9 | Shift queue elements right. After applying this operation, queue a1, ..., aK becomes aK, a1, ..., aK-1. 10 |
11 | You are given the initial number of elements in the queue N and a int[] indices which contains the initial (1-based) positions of wanted elements in the queue. Return the minimal number of left and right shifts you'll have to perform to extract the wanted elements in the given order.

Definition

Filename

BidirectionalQueue.py

Signature

int extractElements(int N, int[] indices)

Constraints

Examples

-------------------------------------------------------------------------------- /10331_BidirectionalQueue/BidirectionalQueue.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | def extractElements(N, indices): 4 | pass 5 | 6 | -------------------------------------------------------------------------------- /10331_BidirectionalQueue/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codersasha/TopCoder-Python-Problems/506ba498597e24cbb131e3a359452ea2192ff844/10331_BidirectionalQueue/__init__.py -------------------------------------------------------------------------------- /10333_PlaneFractal/PlaneFractal.html: -------------------------------------------------------------------------------- 1 | 10333. PlaneFractal

10333. PlaneFractal

Problem

A plane fractal grows in the following way. At time 0, the fractal is a single white square. During each unit of time, each square in the fractal is divided into an NxN grid of equal subsquares. If the square was white, then the center KxK subsquares will become black (N and K will have the same parity). 2 |

3 | For example, if N = 3 and K = 1, then at time 1, there are 3x3 squares, the middle square is black and the rest are white. At time 2, there are 9x9 squares, 17 are black and the rest are white. 4 |

5 | 6 |

7 | Return a String[] representing the content of the fractal at time s between rows r1 and r2, inclusive, and columns c1 and c2, inclusive (all indices are 0-based). White squares should be represented by '0' (zero) and black squares should be represented by '1'.

Definition

Filename

PlaneFractal.py

Signature

String[] getPattern(int s, int N, int K, int r1, int r2, int c1, int c2)

Constraints

Examples

-------------------------------------------------------------------------------- /10333_PlaneFractal/PlaneFractal.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | def getPattern(s, N, K, r1, r2, c1, c2): 4 | pass 5 | 6 | -------------------------------------------------------------------------------- /10333_PlaneFractal/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codersasha/TopCoder-Python-Problems/506ba498597e24cbb131e3a359452ea2192ff844/10333_PlaneFractal/__init__.py -------------------------------------------------------------------------------- /10335_KthProbableElement/KthProbableElement.html: -------------------------------------------------------------------------------- 1 | 10335. KthProbableElement

10335. KthProbableElement

Problem

M integers are randomly independently chosen from the interval lowerBound...upperBound, inclusive. Return the probability that the K-th smallest element of the generated set is equal to N. K=1 refers to the smallest element, K=2 refers to the second smallest element, and so on. 2 |

Definition

Filename

KthProbableElement.py

Signature

double probability(int M, int lowerBound, int upperBound, int N, int K)

Constraints

Examples

-------------------------------------------------------------------------------- /10335_KthProbableElement/KthProbableElement.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | def probability(M, lowerBound, upperBound, N, K): 4 | pass 5 | 6 | -------------------------------------------------------------------------------- /10335_KthProbableElement/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codersasha/TopCoder-Python-Problems/506ba498597e24cbb131e3a359452ea2192ff844/10335_KthProbableElement/__init__.py -------------------------------------------------------------------------------- /10336_CircularShifts/CircularShifts.html: -------------------------------------------------------------------------------- 1 | 10336. CircularShifts

10336. CircularShifts

Problem

You have two lists of numbers, X and Y, each containing exactly N elements. You can optionally apply any number of circular shifts to each list. A circular shift means removing the last element from a list and re-inserting it before the first element. For example, {1, 2, 3} would become {3, 1, 2}, and {3, 1, 2} would become {2, 3, 1}. After you apply any circular shifts, the final score is calculated as:
2 | 3 | X[0]*Y[0] + X[1]*Y[1] + ... + X[N-1]*Y[N-1]
4 | 5 | You are given ints Z0, A, B and M. Generate a list Z of length 2*N, using the following recursive definition:
6 | 7 | Z[0] = Z0 MOD M
8 | Z[i] = (Z[i-1]*A+B) MOD M (note that Z[i-1]*A+B may overflow a 32-bit integer)
9 | 10 | Then, generate lists X and Y, each of length N, using the following definitions:
11 | 12 | X[i] = Z[i] MOD 100
13 | Y[i] = Z[i+N] MOD 100
14 | 15 | Return the maximal final score you can achieve. 16 | 17 | 18 |

Definition

Filename

CircularShifts.py

Signature

int maxScore(int N, int Z0, int A, int B, int M)

Constraints

Examples

-------------------------------------------------------------------------------- /10336_CircularShifts/CircularShifts.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | def maxScore(N, Z0, A, B, M): 4 | pass 5 | 6 | -------------------------------------------------------------------------------- /10336_CircularShifts/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codersasha/TopCoder-Python-Problems/506ba498597e24cbb131e3a359452ea2192ff844/10336_CircularShifts/__init__.py -------------------------------------------------------------------------------- /10337_DoNotTurn/DoNotTurn.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | def minimumTurns(N, X0, A, B, Y0, C, D, P, M): 4 | pass 5 | 6 | -------------------------------------------------------------------------------- /10337_DoNotTurn/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codersasha/TopCoder-Python-Problems/506ba498597e24cbb131e3a359452ea2192ff844/10337_DoNotTurn/__init__.py -------------------------------------------------------------------------------- /10341_BestView/BestView.html: -------------------------------------------------------------------------------- 1 | 10341. BestView

10341. BestView

Problem

There are several skyscrapers arranged in a row. You're interested in finding the one from which the maximal number of other skyscrapers can be seen. The i-th skyscraper can be represented as a line segment on a plane with endpoints (i, 0) and (i, heights[i]). A skyscraper can be seen from the roof of another skyscraper if a line segment connecting their roofs does not intersect with or touch any other skyscraper. Return the maximal number of other skyscrapers that can be seen from the roof of some skyscraper.

Definition

Filename

BestView.py

Signature

int numberOfBuildings(int[] heights)

Constraints

Examples

-------------------------------------------------------------------------------- /10341_BestView/BestView.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | def numberOfBuildings(heights): 4 | pass 5 | 6 | -------------------------------------------------------------------------------- /10341_BestView/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codersasha/TopCoder-Python-Problems/506ba498597e24cbb131e3a359452ea2192ff844/10341_BestView/__init__.py -------------------------------------------------------------------------------- /10342_DigitsSwap/DigitsSwap.html: -------------------------------------------------------------------------------- 1 | 10342. DigitsSwap

10342. DigitsSwap

Problem

You are given two positive integers, x and y, whose decimal representations contain the same number of digits. A digit-swap operation for an index i swaps the digits at the i-th positions in x and y. After exactly swaps digit-swap operations, what is the maximal possible value of x*y? Return the String representation of this maximal product with no leading zeroes.

Definition

Filename

DigitsSwap.py

Signature

String maximalProduct(String x, String y, int swaps)

Constraints

Examples

-------------------------------------------------------------------------------- /10342_DigitsSwap/DigitsSwap.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | def maximalProduct(x, y, swaps): 4 | pass 5 | 6 | -------------------------------------------------------------------------------- /10342_DigitsSwap/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codersasha/TopCoder-Python-Problems/506ba498597e24cbb131e3a359452ea2192ff844/10342_DigitsSwap/__init__.py -------------------------------------------------------------------------------- /10343_FriendScore/FriendScore.html: -------------------------------------------------------------------------------- 1 | 10343. FriendScore

10343. FriendScore

Problem

You want to determine the most popular person in a social network. To do this, you will count the number of "2-friends" that each person has. Person A is called a 2-friend of another person B if they are friends with each other or if there exists some person C who is a friend of both A and B. The most popular person is the person with the highest number of 2-friends. (There might be more than one if multiple people all have the maximal number of 2-friends.)
2 | 3 | You are given a String[] friends, where the j-th character of the i-th element is 'Y' if person i and person j are friends, and 'N' otherwise. Return the number of 2-friends of the most popular person in this social network.

Definition

Filename

FriendScore.py

Signature

int highestScore(String[] friends)

Constraints

Examples

-------------------------------------------------------------------------------- /10343_FriendScore/FriendScore.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | def highestScore(friends): 4 | pass 5 | 6 | -------------------------------------------------------------------------------- /10343_FriendScore/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codersasha/TopCoder-Python-Problems/506ba498597e24cbb131e3a359452ea2192ff844/10343_FriendScore/__init__.py -------------------------------------------------------------------------------- /10355_EndlessStringMachine/EndlessStringMachine.html: -------------------------------------------------------------------------------- 1 | 10355. EndlessStringMachine

10355. EndlessStringMachine

Problem

A certain theoretical machine works by executing a program exactly s times. The first time it is executed, the program is given the String input as its input. For each subsequent execution, the program uses the output of the previous execution as its input.

2 | 3 | The initial input is a string containing only lowercase letters. A program is defined as a string containing lowercase letters and '$' characters. The output of a program is simply this string with all instances of the '$' character replaced by the program's input. For example, if the input is "a" and the program is "$meric$", the first output would be "america". The second time it is executed, it will use "america" as its input, and its output will be "americamericamerica". This process is repeated s times, so for a large s, the output would be: "americamericamericamericamericamericamericamericamericamericamericamericamericamericamerica...".

4 | 5 | Given the input, the program and s, return the substring of the machine's final output starting at index min and ending at index max, where min and max are inclusive 1-based indices. If an index between min and max exceeds the bounds of the final output, put a placeholder '-' character in its place. 6 | 7 |

Definition

Filename

EndlessStringMachine.py

Signature

String getFragment(String input, String program, int s, int min, int max)

Constraints

Examples

-------------------------------------------------------------------------------- /10355_EndlessStringMachine/EndlessStringMachine.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | def getFragment(input, program, s, min, max): 4 | pass 5 | 6 | -------------------------------------------------------------------------------- /10355_EndlessStringMachine/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codersasha/TopCoder-Python-Problems/506ba498597e24cbb131e3a359452ea2192ff844/10355_EndlessStringMachine/__init__.py -------------------------------------------------------------------------------- /10356_UnluckyIntervals/UnluckyIntervals.html: -------------------------------------------------------------------------------- 1 | 10356. UnluckyIntervals

10356. UnluckyIntervals

Problem

You are given a set of integers called luckySet. An interval [A,B], where B is greater than A, and A and B are positive integers, is considered unlucky if none of the integers between A and B, inclusive, belongs to luckySet.

2 | 3 | An integer x is considered to be luckier than another integer y if the number of unlucky intervals that contain x is smaller than the number of unlucky intervals that contain y. In case both x and y belong to an equal number of unlucky intervals, or both belong to an infinite number of unlucky intervals, the smallest of them is considered to be luckier than the other.

4 | 5 | Given a int[] luckySet, return the top n luckiest positive integers sorted in descending order by luckiness (in other words, each element of the int[] must be luckier than the next element).

Definition

Filename

UnluckyIntervals.py

Signature

int[] getLuckiest(int[] luckySet, int n)

Constraints

Examples

-------------------------------------------------------------------------------- /10356_UnluckyIntervals/UnluckyIntervals.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | def getLuckiest(luckySet, n): 4 | pass 5 | 6 | -------------------------------------------------------------------------------- /10356_UnluckyIntervals/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codersasha/TopCoder-Python-Problems/506ba498597e24cbb131e3a359452ea2192ff844/10356_UnluckyIntervals/__init__.py -------------------------------------------------------------------------------- /10360_FeudaliasBattle/FeudaliasBattle.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | def getMinimumTime(baseX, baseY, siloX, siloY, takeOffTime, rechargeTime, missileSpeed): 4 | pass 5 | 6 | -------------------------------------------------------------------------------- /10360_FeudaliasBattle/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codersasha/TopCoder-Python-Problems/506ba498597e24cbb131e3a359452ea2192ff844/10360_FeudaliasBattle/__init__.py -------------------------------------------------------------------------------- /10361_SaveTheTrees/SaveTheTrees.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | def minimumCut(x, y, h): 4 | pass 5 | 6 | -------------------------------------------------------------------------------- /10361_SaveTheTrees/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codersasha/TopCoder-Python-Problems/506ba498597e24cbb131e3a359452ea2192ff844/10361_SaveTheTrees/__init__.py -------------------------------------------------------------------------------- /10369_TheSwap/TheSwap.html: -------------------------------------------------------------------------------- 1 | 10369. TheSwap

10369. TheSwap

Problem

2 | There is nothing more beautiful than just an integer number. 3 |

4 |

5 | You are given an integer n. Write down n in decimal notation with no leading zeroes, and let M be the number of written digits. Perform the following operation exactly k times: 6 |

9 |

10 |

11 | Return the maximal possible number you can get at the end of this procedure. If it's not possible to perform k operations, return -1 instead. 12 |

13 |

Definition

Filename

TheSwap.py

Signature

int findMax(int n, int k)

Constraints

Examples

-------------------------------------------------------------------------------- /10369_TheSwap/TheSwap.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | def findMax(n, k): 4 | pass 5 | 6 | -------------------------------------------------------------------------------- /10369_TheSwap/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codersasha/TopCoder-Python-Problems/506ba498597e24cbb131e3a359452ea2192ff844/10369_TheSwap/__init__.py -------------------------------------------------------------------------------- /10370_ChuckContest/ChuckContest.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | def chuckRules(numProblems, lowerBounds, upperBounds, partTimes): 4 | pass 5 | 6 | -------------------------------------------------------------------------------- /10370_ChuckContest/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codersasha/TopCoder-Python-Problems/506ba498597e24cbb131e3a359452ea2192ff844/10370_ChuckContest/__init__.py -------------------------------------------------------------------------------- /10375_StrangeCountry/StrangeCountry.html: -------------------------------------------------------------------------------- 1 | 10375. StrangeCountry

10375. StrangeCountry

Problem

There is a country with N cities, some of which are connected with bidirectional roads. Your task is to reconfigure the roads so that it is possible to get from each city to every other city. You must do this using the minimum possible number of transformations, where each transformation consists of the following steps: 2 | 3 |

    4 |
  1. Choose four different cities A, B, C and D, where roads (A, B) and (C, D) exist, but (A, C), (A, D), (B, C) and (B, D) do not exist.
  2. 5 |
  3. Destroy roads (A, B) and (C, D).
  4. 6 |
  5. Build two new roads - either (A, C) and (B, D), or (A, D) and (B, C).
  6. 7 |
8 | 9 | The following images show an example of this transformation. From the first situation you can get the second one or the third one:
10 |   

11 | 12 | You are given a String[] g, where the j-th character of the i-th element is 'Y' if there is a road between cities i and j, and 'N' otherwise. Return minimal number of transformations required to accomplish your task, or return -1 if it is impossible.

Definition

Filename

StrangeCountry.py

Signature

int transform(String[] g)

Constraints

Examples

-------------------------------------------------------------------------------- /10375_StrangeCountry/StrangeCountry.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | def transform(g): 4 | pass 5 | 6 | -------------------------------------------------------------------------------- /10375_StrangeCountry/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codersasha/TopCoder-Python-Problems/506ba498597e24cbb131e3a359452ea2192ff844/10375_StrangeCountry/__init__.py -------------------------------------------------------------------------------- /10376_DifferentStrings/DifferentStrings.html: -------------------------------------------------------------------------------- 1 | 10376. DifferentStrings

10376. DifferentStrings

Problem

If X and Y are two Strings of equal length N, then the difference between them is defined as the number of indices i where the i-th character of X and the i-th character of Y are different. For example, the difference between the words "ant" and "art" is 1.

2 | 3 | You are given two Strings, A and B, where the length of A is less than or equal to the length of B. You can apply an arbitrary number of operations to A, where each operation is one of the following: 4 | 5 |

9 | 10 | Apply the operations in such a way that A and B have the same length and the difference between them is as small as possible. Return this minimum possible difference.

Definition

Filename

DifferentStrings.py

Signature

int minimize(String A, String B)

Constraints

Examples

-------------------------------------------------------------------------------- /10376_DifferentStrings/DifferentStrings.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | def minimize(A, B): 4 | pass 5 | 6 | -------------------------------------------------------------------------------- /10376_DifferentStrings/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codersasha/TopCoder-Python-Problems/506ba498597e24cbb131e3a359452ea2192ff844/10376_DifferentStrings/__init__.py -------------------------------------------------------------------------------- /10377_ErdosNumber/ErdosNumber.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | def calculateNumbers(publications): 4 | pass 5 | 6 | -------------------------------------------------------------------------------- /10377_ErdosNumber/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codersasha/TopCoder-Python-Problems/506ba498597e24cbb131e3a359452ea2192ff844/10377_ErdosNumber/__init__.py -------------------------------------------------------------------------------- /10380_PalindromeFactory/PalindromeFactory.html: -------------------------------------------------------------------------------- 1 | 10380. PalindromeFactory

10380. PalindromeFactory

Problem

A palindrome is a string that reads the same forward and backward. Not all strings are palindromes and we are going to fix that.
2 | In this problem we consider four edit operations:
3 |

    4 |
  1. Insert a character at any position of a string (including the beginning and the end)
  2. 5 |
  3. Delete a character at any position of a string
  4. 6 |
  5. Change a character at any position of a string
  6. 7 |
  7. Swap any two different characters (not necessarily adjacent)
  8. 8 |
9 |
10 | You can apply the first three operations any number of times, but the last operation can be applied at most once.
11 |
12 | You are given a String initial. Return the minimal number of operations needed to make a palindrome from it.

Definition

Filename

PalindromeFactory.py

Signature

int getEditDistance(String initial)

Constraints

Examples

-------------------------------------------------------------------------------- /10380_PalindromeFactory/PalindromeFactory.json: -------------------------------------------------------------------------------- 1 | { 2 | "definition": { 3 | "method": "getEditDistance", 4 | "names": { 5 | "input": [ 6 | "initial" 7 | ] 8 | }, 9 | "types": { 10 | "output": "int", 11 | "input": [ 12 | "String" 13 | ] 14 | }, 15 | "class": "PalindromeFactory" 16 | }, 17 | "tests": [], 18 | "name": "PalindromeFactory", 19 | "statement": "A palindrome is a string that reads the same forward and backward. Not all strings are palindromes and we are going to fix that.
\nIn this problem we consider four edit operations:
\n
    \n
  1. Insert a character at any position of a string (including the beginning and the end)
  2. \n
  3. Delete a character at any position of a string
  4. \n
  5. Change a character at any position of a string
  6. \n
  7. Swap any two different characters (not necessarily adjacent)
  8. \n
\n
\nYou can apply the first three operations any number of times, but the last operation can be applied at most once.
\n
\nYou are given a String initial. Return the minimal number of operations needed to make a palindrome from it.", 20 | "constraints": [ 21 | "initial will contain between 1 and 50 lowercase letters ('a'-'z'), inclusive." 22 | ], 23 | "number": 10380, 24 | "examples": [ 25 | { 26 | "comment": "
The string is already a palindrome.
", 27 | "input": [ 28 | "abba" 29 | ], 30 | "output": 0 31 | }, 32 | { 33 | "comment": "
We can delete the first letter to make a palindrome.
", 34 | "input": [ 35 | "dabba" 36 | ], 37 | "output": 1 38 | }, 39 | { 40 | "comment": "
Delete\u00a0'v'\u00a0and\u00a0swap\u00a0the\u00a0first\u00a0two\u00a0characters.
", 41 | "input": [ 42 | "babacvabba" 43 | ], 44 | "output": 2 45 | }, 46 | { 47 | "comment": "
We can change 'c' to 'a' to get a palindrome in one operation.
", 48 | "input": [ 49 | "abc" 50 | ], 51 | "output": 1 52 | }, 53 | { 54 | "comment": "
Insert 'b' after the first character.
", 55 | "input": [ 56 | "acxcba" 57 | ], 58 | "output": 1 59 | }, 60 | { 61 | "comment": "
Swap 'd' with 'a' in the middle.
", 62 | "input": [ 63 | "abcacbd" 64 | ], 65 | "output": 1 66 | } 67 | ] 68 | } -------------------------------------------------------------------------------- /10380_PalindromeFactory/PalindromeFactory.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | def getEditDistance(initial): 4 | pass 5 | 6 | -------------------------------------------------------------------------------- /10380_PalindromeFactory/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codersasha/TopCoder-Python-Problems/506ba498597e24cbb131e3a359452ea2192ff844/10380_PalindromeFactory/__init__.py -------------------------------------------------------------------------------- /10382_PalindromePhrases/PalindromePhrases.html: -------------------------------------------------------------------------------- 1 | 10382. PalindromePhrases

10382. PalindromePhrases

Problem

One of your friends has given you several words and asked you how many palindromic phrases you can compose with those words. 2 | To save yourself some time, you've decided to write a program to answer this question. In this problem, a word is defined as a non-empty sequence 3 | of lowercase letters ('a'-'z'). A phrase is a non-empty sequence of words, where each pair of consecutive words is separated with exactly one space character. A phrase is palindromic if it reads the same forward and backward, ignoring space characters. 4 |

5 | You are given a String[] words. Return the number of different palindromic phrases that can be composed with the given words. Each word in words can be used at most once within each phrase. Two phrases are considered different if they are different strings, even if they read the same when ignoring spaces (for example, "a ba" and "ab a" are different phrases).

Definition

Filename

PalindromePhrases.py

Signature

long getAmount(String[] words)

Constraints

Examples

-------------------------------------------------------------------------------- /10382_PalindromePhrases/PalindromePhrases.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | def getAmount(words): 4 | pass 5 | 6 | -------------------------------------------------------------------------------- /10382_PalindromePhrases/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codersasha/TopCoder-Python-Problems/506ba498597e24cbb131e3a359452ea2192ff844/10382_PalindromePhrases/__init__.py -------------------------------------------------------------------------------- /10384_KingdomMap/KingdomMap.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | def getRoadsToRemove(n, roads): 4 | pass 5 | 6 | -------------------------------------------------------------------------------- /10384_KingdomMap/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codersasha/TopCoder-Python-Problems/506ba498597e24cbb131e3a359452ea2192ff844/10384_KingdomMap/__init__.py -------------------------------------------------------------------------------- /10386_SquareFreeSets/SquareFreeSets.html: -------------------------------------------------------------------------------- 1 | 10386. SquareFreeSets

10386. SquareFreeSets

Problem

A square-free number is an integer that is not divisible by the square of any integer except 1. A set containing only square-free numbers is called a square-free set. The product of such a set is the product of all its elements. If the product of a square-free set is a square-free number itself, that set is called a perfect set.

2 | 3 | You are given two ints N and K. Determine the number of perfect square-free sets that contain between 1 and K elements, inclusive, where each element is between 2 and N, inclusive. Return this number modulo 1,000,000,007.

Definition

Filename

SquareFreeSets.py

Signature

int countPerfect(int N, int K)

Constraints

Examples

-------------------------------------------------------------------------------- /10386_SquareFreeSets/SquareFreeSets.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | def countPerfect(N, K): 4 | pass 5 | 6 | -------------------------------------------------------------------------------- /10386_SquareFreeSets/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codersasha/TopCoder-Python-Problems/506ba498597e24cbb131e3a359452ea2192ff844/10386_SquareFreeSets/__init__.py -------------------------------------------------------------------------------- /10387_BinaryFlips/BinaryFlips.html: -------------------------------------------------------------------------------- 1 | 10387. BinaryFlips

10387. BinaryFlips

Problem

You are playing a game where you initially have A zeros and B ones. Your goal is to end up with all ones. In each move, you must choose exactly K of the numbers and flip their values (zeros change to ones, and vice-versa). You can choose any K numbers each time, regardless of their current values or whether you have flipped them before. Return the minimal number of moves required to win the game, or -1 if it is impossible. 2 |

Definition

Filename

BinaryFlips.py

Signature

int minimalMoves(int A, int B, int K)

Constraints

Examples

-------------------------------------------------------------------------------- /10387_BinaryFlips/BinaryFlips.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | def minimalMoves(A, B, K): 4 | pass 5 | 6 | -------------------------------------------------------------------------------- /10387_BinaryFlips/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codersasha/TopCoder-Python-Problems/506ba498597e24cbb131e3a359452ea2192ff844/10387_BinaryFlips/__init__.py -------------------------------------------------------------------------------- /10389_StrongEconomy/StrongEconomy.html: -------------------------------------------------------------------------------- 1 | 10389. StrongEconomy

10389. StrongEconomy

Problem

As a serious strategy-games player, you know how important it is for your country to have a strong economy. In order to make this happen, you've just built n factories and hired k specialists. Unfortunately, you now have no gold left, and you must figure out the fastest way to raise target units of gold.

2 | In a single round, you earn F*S units of gold, where F is the number of factories and S is the number of specialists you currently have. At the end of each round, you can build more factories and hire more specialists. Building one new factory or hiring one new specialist costs price units of gold. As long as you can afford them, there is no limit to the number of factories and specialists you have. Return the minimum number of rounds required to earn at least target units of gold.

Definition

Filename

StrongEconomy.py

Signature

long earn(long n, long k, long price, long target)

Constraints

Examples

-------------------------------------------------------------------------------- /10389_StrongEconomy/StrongEconomy.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | def earn(n, k, price, target): 4 | pass 5 | 6 | -------------------------------------------------------------------------------- /10389_StrongEconomy/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codersasha/TopCoder-Python-Problems/506ba498597e24cbb131e3a359452ea2192ff844/10389_StrongEconomy/__init__.py -------------------------------------------------------------------------------- /10391_RotatingTriangles/RotatingTriangles.html: -------------------------------------------------------------------------------- 1 | 10391. RotatingTriangles

10391. RotatingTriangles

Problem

NOTE: This problem statement contains images that may not display properly if viewed outside of the applet. 2 |
3 |
4 | You are given a white rectangular grid made up of square cells. Some cells contain black squares, and some contain black squares that have been folded in half to form right triangles. Each of these triangles can be rotated left or right by any multiple of 90 degrees. They can also be unfolded to become squares. However, black squares cannot be folded to become triangles.
5 |
6 | Your task is to generate proper black triangles in the grid using the aforementioned operations. A black triangle is considered proper within a grid configuration if no other black shape shares a line segment with it. However, black shapes may still share one or more points with the triangle.
7 |
8 | The grid will be given as a String[], where the j-th character of the i-th element represents the cell at row i, column j. '.' represents an empty cell, '#' represents a cell containing a black square, and '/' represents a cell containing a black triangle. Return the total number of distinct proper black triangles that can be formed in this grid. Two triangles are considered distinct if they differ in at least one vertex.
9 |
10 | For example, consider the following input grid:
11 |
12 |
13 |
14 | It is possible to generate 5 distinct proper black triangles:
15 |
16 |

 
17 |
 
18 |

Definition

Filename

RotatingTriangles.py

Signature

int count(String[] grid)

Constraints

Examples

-------------------------------------------------------------------------------- /10391_RotatingTriangles/RotatingTriangles.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | def count(grid): 4 | pass 5 | 6 | -------------------------------------------------------------------------------- /10391_RotatingTriangles/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codersasha/TopCoder-Python-Problems/506ba498597e24cbb131e3a359452ea2192ff844/10391_RotatingTriangles/__init__.py -------------------------------------------------------------------------------- /10395_SquareOfDigits/SquareOfDigits.html: -------------------------------------------------------------------------------- 1 | 10395. SquareOfDigits

10395. SquareOfDigits

Problem

You are given a String[] data representing a rectangular grid where each cell contains a digit. 2 | Find the largest square in this grid that contains the same digit in all of its corner cells. 3 | The sides of the square must be parallel to the sides of the grid. 4 | If there is more than one such largest square, pick any one of them. 5 |
6 | Return the number of cells in the square. Note that a single cell is also considered a square, so there will always be an answer.

Definition

Filename

SquareOfDigits.py

Signature

int getMax(String[] data)

Constraints

Examples

-------------------------------------------------------------------------------- /10395_SquareOfDigits/SquareOfDigits.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | def getMax(data): 4 | pass 5 | 6 | -------------------------------------------------------------------------------- /10395_SquareOfDigits/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codersasha/TopCoder-Python-Problems/506ba498597e24cbb131e3a359452ea2192ff844/10395_SquareOfDigits/__init__.py -------------------------------------------------------------------------------- /10396_UnluckyNumbers/UnluckyNumbers.html: -------------------------------------------------------------------------------- 1 | 10396. UnluckyNumbers

10396. UnluckyNumbers

Problem

You are given a set of integers called luckySet. An interval [A,B], where B is greater than A, and A and B are positive integers, is considered unlucky if none of the integers between A and B, inclusive, belongs to luckySet.

2 | 3 | Given a int[] luckySet and a int n that is not greater than the maximum element in luckySet. Return the total number of unlucky intervals that contain n.

Definition

Filename

UnluckyNumbers.py

Signature

int getCount(int[] luckySet, int n)

Constraints

Examples

-------------------------------------------------------------------------------- /10396_UnluckyNumbers/UnluckyNumbers.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | def getCount(luckySet, n): 4 | pass 5 | 6 | -------------------------------------------------------------------------------- /10396_UnluckyNumbers/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codersasha/TopCoder-Python-Problems/506ba498597e24cbb131e3a359452ea2192ff844/10396_UnluckyNumbers/__init__.py -------------------------------------------------------------------------------- /10401_Automaton/Automaton.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | def numberOfMatchings(transitions, stringLength, x0, xa, c0, ca, modifications): 4 | pass 5 | 6 | -------------------------------------------------------------------------------- /10401_Automaton/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codersasha/TopCoder-Python-Problems/506ba498597e24cbb131e3a359452ea2192ff844/10401_Automaton/__init__.py -------------------------------------------------------------------------------- /10408_PouringWater/PouringWater.html: -------------------------------------------------------------------------------- 1 | 10408. PouringWater

10408. PouringWater

Problem

You have N bottles, each with unlimited capacity. Initially, each bottle contains exactly 1 liter of water. You want to carry these bottles to another location, but you can only carry K bottles at a time. You don't want to waste any water and you don't want to make more than one trip, so you decide to redistribute the contents of the bottles until you end up with no more than K non-empty bottles. 2 |

3 | You are only allowed to redistribute your water using the following method. First, pick two bottles that contain an equal amount of water. Then, pour the entire content of one of those bottles into the other. Repeat this process as many times as necessary. 4 |

5 | Because of this restriction, it may be impossible to end up with no more than K non-empty bottles using only the N bottles that you have initially. Fortunately, you can also buy more bottles. Each bottle that you buy will contain exactly 1 liter of water and have unlimited capacity. For example, consider the case where N is 3 and K is 1. It's impossible to get from 3 bottles to 1. If you pour one bottle into another, you end up with one 2 liter bottle and one 1 liter bottle. At that point, you're stuck. However, if you then buy another bottle, you can pour that bottle into the 1 liter bottle, and pour the resulting 2 liter bottle into the other 2 liter bottle to end up with just one 4 liter bottle. 6 |

7 | Return the minimum number of additional bottles you must buy in order to achieve your goal. If it's impossible, return -1 instead.

Definition

Filename

PouringWater.py

Signature

int getMinBottles(int N, int K)

Constraints

Examples

-------------------------------------------------------------------------------- /10408_PouringWater/PouringWater.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | def getMinBottles(N, K): 4 | pass 5 | 6 | -------------------------------------------------------------------------------- /10408_PouringWater/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codersasha/TopCoder-Python-Problems/506ba498597e24cbb131e3a359452ea2192ff844/10408_PouringWater/__init__.py -------------------------------------------------------------------------------- /10412_PlanarGraphShop/PlanarGraphShop.html: -------------------------------------------------------------------------------- 1 | 10412. PlanarGraphShop

10412. PlanarGraphShop

Problem

2 | In the Kocurkovo village there is a shop that sells simple planar graphs. (See Notes for a definition.) 3 |

4 |

5 | The cost of any graph with X vertices and Y edges is (X^3 + Y^2) gold coins. 6 |

7 |

8 | Monika has N gold coins, and she wants to spend all of them on simple planar graphs. 9 |

10 |

11 | Write a method that gets the value N and computes the minimum number of simple planar graphs Monika has to buy in order to spend exactly N gold coins. 12 | She is allowed to buy multiple graphs of the same type. 13 |

Definition

Filename

PlanarGraphShop.py

Signature

int bestCount(int N)

Constraints

Examples

-------------------------------------------------------------------------------- /10412_PlanarGraphShop/PlanarGraphShop.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | def bestCount(N): 4 | pass 5 | 6 | -------------------------------------------------------------------------------- /10412_PlanarGraphShop/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codersasha/TopCoder-Python-Problems/506ba498597e24cbb131e3a359452ea2192ff844/10412_PlanarGraphShop/__init__.py -------------------------------------------------------------------------------- /10413_SequenceSum/SequenceSum.html: -------------------------------------------------------------------------------- 1 | 10413. SequenceSum

10413. SequenceSum

Problem

2 | Given two sequences X=(X[0], ..., X[N-1]) and Y=(Y[0], ..., Y[M-1]), their pairwise sum is the sequence: 3 |

4 |

5 | X@Y = (X[0]+Y[0], X[0]+Y[1], ..., X[0]+Y[M-1], X[1]+Y[0], X[1]+Y[1], ..., X[N-1]+Y[M-1]). 6 |

7 |

8 | For example, if X=(0,10) and Y=(0,2,1) then X@Y=(0,2,1,10,12,11). 9 |

10 |

11 | Formally, X@Y is a sequence of length NM, where for each i in {0,...,N-1} and for each j in {0,...,M-1} we have (X@Y)[i*M+j] = X[i]+Y[j]. Note that X@Y is not necessarily the same sequence as Y@X. 12 |

13 |

14 | You are given int[]s A, B, C, D, E, F, and a String[] Z. 15 | Concatenate the elements of Z to get a space-separated sequence of non-negative integers NEEDLE. Sequence HAYSTACK is defined as follows: 16 |

17 |

18 | HAYSTACK = ((((A @ B) @ C) @ D) @ E) @ F 19 |

20 |

21 | Write a method that will find and return the smallest non-negative integer X such that if we delete the first X elements of the sequence HAYSTACK, then the sequence HAYSTACK will start with the sequence NEEDLE. If there is no such X, return -1 instead. 22 |

Definition

Filename

SequenceSum.py

Signature

long findSubstring(int[] A, int[] B, int[] C, int[] D, int[] E, int[] F, String[] Z)

Constraints

Examples

-------------------------------------------------------------------------------- /10413_SequenceSum/SequenceSum.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | def findSubstring(A, B, C, D, E, F, Z): 4 | pass 5 | 6 | -------------------------------------------------------------------------------- /10413_SequenceSum/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codersasha/TopCoder-Python-Problems/506ba498597e24cbb131e3a359452ea2192ff844/10413_SequenceSum/__init__.py -------------------------------------------------------------------------------- /11777_BuildingReorganization/BuildingReorganization.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | def theMin(heights, A, B, cost): 4 | pass 5 | 6 | -------------------------------------------------------------------------------- /11777_BuildingReorganization/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codersasha/TopCoder-Python-Problems/506ba498597e24cbb131e3a359452ea2192ff844/11777_BuildingReorganization/__init__.py -------------------------------------------------------------------------------- /6208_MislabeledWeights/MislabeledWeights.html: -------------------------------------------------------------------------------- 1 | 6208. MislabeledWeights

6208. MislabeledWeights

Problem

You are given a balance scale to weigh some items. Unfortunately the weights you use as counterbalances are not accurate. Some of them may be marked incorrectly - either 1 gram too heavy or one gram too light. (Some may be marked correctly.)

2 |

You are given a int[] weights representing the set of weights you have. The i-th of your weights is marked by weights[i] grams. The subset of your weights is called good if it's possible that all the real weights in it sum exactly to testWeight. Find the good subset with the minimum possible number of weights and return the number of weights in it. If there is no good subset of weights, your method should return -1.

Definition

Filename

MislabeledWeights.py

Signature

int fewest(int[] weights, int testWeight)

Constraints

Examples

-------------------------------------------------------------------------------- /6208_MislabeledWeights/MislabeledWeights.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | def fewest(weights, testWeight): 4 | pass 5 | 6 | -------------------------------------------------------------------------------- /6208_MislabeledWeights/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codersasha/TopCoder-Python-Problems/506ba498597e24cbb131e3a359452ea2192ff844/6208_MislabeledWeights/__init__.py -------------------------------------------------------------------------------- /6226_OrderParser/OrderParser.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | def orderAmount(items, message): 4 | pass 5 | 6 | -------------------------------------------------------------------------------- /6226_OrderParser/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codersasha/TopCoder-Python-Problems/506ba498597e24cbb131e3a359452ea2192ff844/6226_OrderParser/__init__.py -------------------------------------------------------------------------------- /8202_KeysInBoxes/KeysInBoxes.html: -------------------------------------------------------------------------------- 1 | 8202. KeysInBoxes

8202. KeysInBoxes

Problem

There are N boxes numbered from 1 to N and N keys numbered from 1 to N. 2 | The i-th key can only be used to open the i-th box. 3 | Now, we randomly put exactly one key into each of the boxes. 4 | We assume that all configurations of keys in boxes occur with the same probability. Then we lock all the boxes. 5 | You have M bombs, each of which can be used to open one locked box. 6 | Once you open a locked box, you can get the key in it and perhaps open another locked box with that key. 7 | Your strategy is to select a box, open it with a bomb, take the key and open all the boxes you can and then repeat with another bomb.

8 |

9 | Return the probability that you can get all the keys. 10 | The return value must be a string formatted as "A/B" (quotes for clarity), representing the probability as a fraction. A and B must both be positive integers with no leading zeroes, and the greatest common divisor of A and B must be 1.

11 |

Definition

Filename

KeysInBoxes.py

Signature

String getAllKeys(int N, int M)

Constraints

Examples

-------------------------------------------------------------------------------- /8202_KeysInBoxes/KeysInBoxes.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | def getAllKeys(N, M): 4 | pass 5 | 6 | -------------------------------------------------------------------------------- /8202_KeysInBoxes/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codersasha/TopCoder-Python-Problems/506ba498597e24cbb131e3a359452ea2192ff844/8202_KeysInBoxes/__init__.py -------------------------------------------------------------------------------- /8211_Barracks/Barracks.html: -------------------------------------------------------------------------------- 1 | 8211. Barracks

8211. Barracks

Problem

As a serious strategy-games player, you decided to solve one of the most common problems - attacking your 2 | opponent's building (barracks), which constantly produces new soldiers.

3 | 4 | Before the attack, you've got myUnits soldiers. In a single round, each soldier can either kill one of your opponent's soldiers or inflict 1 hit point of damage to the barracks.
5 | 6 | Your opponent doesn't have any soldiers initially. However, his barracks has barHp hit points and produces unitsPerRound soldiers per round.

7 | 8 | The course of one round:
9 | 1. Each solider from your army either kills one of your opponent's soldiers or inflicts 1 hit point of damage to the barracks. Each soldier can choose to do something different. When the barracks loses all of its hit points, it is destroyed.
10 | 2. Your opponent attacks. He will kill k of your soldiers, where k is the number of remaining soldiers he has.
11 | 3. If the barracks are not yet destroyed, your opponent will produce unitsPerRound new soldiers.

12 | 13 | Your task is to destroy the barracks and kill all your opponent's soldiers. If it is possible, return the minimum number of rounds you need to do this. 14 | Otherwise return -1. 15 | 16 |

Definition

Filename

Barracks.py

Signature

int attack(int myUnits, int barHp, int unitsPerRound)

Constraints

Examples

-------------------------------------------------------------------------------- /8211_Barracks/Barracks.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | def attack(myUnits, barHp, unitsPerRound): 4 | pass 5 | 6 | -------------------------------------------------------------------------------- /8211_Barracks/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codersasha/TopCoder-Python-Problems/506ba498597e24cbb131e3a359452ea2192ff844/8211_Barracks/__init__.py -------------------------------------------------------------------------------- /8215_RevealTriangle/RevealTriangle.html: -------------------------------------------------------------------------------- 1 | 8215. RevealTriangle

8215. RevealTriangle

Problem

2 | Suppose there is a triangle of digits like the following: 3 |

4 |
74932
 5 | 1325
 6 | 457
 7 | 92
 8 | 1
9 |

10 | Each digit, with the exception of those in the top row, is equal to the last digit of the sum of 11 | its upper and upper-right neighboring digits. 12 |

13 |

14 | You will be given a String[] questionMarkTriangle containing a triangle where 15 | only one digit in each row is known and all others are represented by '?'s 16 | (see example 0 for clarification). 17 | Each element of questionMarkTriangle represents a row of the triangle, and the rows are given 18 | from top to bottom. Each element contains exactly one digit ('0'-'9') and 19 | the remaining characters are all '?'s. Restore the triangle and return it as a 20 | String[] without '?'s. 21 |

22 |

Definition

Filename

RevealTriangle.py

Signature

String[] calcTriangle(String[] questionMarkTriangle)

Constraints

Examples

-------------------------------------------------------------------------------- /8215_RevealTriangle/RevealTriangle.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | def calcTriangle(questionMarkTriangle): 4 | pass 5 | 6 | -------------------------------------------------------------------------------- /8215_RevealTriangle/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codersasha/TopCoder-Python-Problems/506ba498597e24cbb131e3a359452ea2192ff844/8215_RevealTriangle/__init__.py -------------------------------------------------------------------------------- /8216_ReadingBooks/ReadingBooks.html: -------------------------------------------------------------------------------- 1 | 8216. ReadingBooks

8216. ReadingBooks

Problem

2 | There are some books, each consisting of exactly three parts: introduction, story and edification. 3 | There is a reader who goes through the books and reads various parts. 4 | Each time he finishes reading a part, he adds the name of the part to the end of a list. 5 | He may read zero or more parts from each book, and he can read them in any order, but he cannot 6 | read each part more than once. 7 | Whenever he starts reading a new book, he can no longer go back and read any parts of books he has 8 | looked at previously. 9 |

10 |

11 | You are given a String[] readParts containing the list created by the reader. 12 | Each element of readParts is "introduction", "story" or "edification" (quotes for clarity). 13 | Return the maximum possible number of books for which the reader has read all three parts. 14 |

15 |

Definition

Filename

ReadingBooks.py

Signature

int countBooks(String[] readParts)

Constraints

Examples

-------------------------------------------------------------------------------- /8216_ReadingBooks/ReadingBooks.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | def countBooks(readParts): 4 | pass 5 | 6 | -------------------------------------------------------------------------------- /8216_ReadingBooks/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codersasha/TopCoder-Python-Problems/506ba498597e24cbb131e3a359452ea2192ff844/8216_ReadingBooks/__init__.py -------------------------------------------------------------------------------- /8291_Transformation/Transformation.html: -------------------------------------------------------------------------------- 1 | 8291. Transformation

8291. Transformation

Problem

You are to transform a positive integer vector (A1,A2,...,An) 2 | into another positive integer vector (B1,B2,...,Bn) of the same length. 3 | The transformation must satisfy the conditions below:
4 | 1) For 1 < = i < =n., Bi must evenly divide into Ai.
5 | 2) The least common multiple of all Ai should be equal to that of all Bi.

6 |

7 | 8 | You are given the original integer vector as a String[] A, where the i-th (1-based) element is a positive integer representing Ai. 9 | Return a String[] containing the transformed integer vector in the same format. 10 | 11 | Each element of the return String[] must be a positive integer with no leading zeroes. 12 | 13 | If there are multiple solutions, return the one where the first number is the smallest. If there are still multiple solutions, return the one with the smallest second number etc.

14 |

Definition

Filename

Transformation.py

Signature

String[] transform(String[] A)

Constraints

Examples

-------------------------------------------------------------------------------- /8291_Transformation/Transformation.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | def transform(A): 4 | pass 5 | 6 | -------------------------------------------------------------------------------- /8291_Transformation/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codersasha/TopCoder-Python-Problems/506ba498597e24cbb131e3a359452ea2192ff844/8291_Transformation/__init__.py -------------------------------------------------------------------------------- /8302_ConsecutiveNumbers/ConsecutiveNumbers.html: -------------------------------------------------------------------------------- 1 | 8302. ConsecutiveNumbers

8302. ConsecutiveNumbers

Problem

Your little son has written some consecutive positive integers on a piece of paper, in no particular order. Each integer was written exactly once. He then erased one of the integers and showed you the remaining ones. Do you know which number your son erased?

2 |

Formally, a list of positive integers is said to be consecutive if there are two positive integers a and b such that every integer between a and b, inclusive, appears in the list exactly once.

3 |

For example, if the remaining numbers are (10,7,12,8,11), the only possible missing number is 9. If the remaining numbers are (2,3), the missing number could be either 1 or 4. If the remaining numbers are (3,6), your son must have made a mistake.

4 |

You are given the remaining numbers in a int[] numbers. Return a int[] containing all the possible numbers your son might have erased. The numbers should be sorted in ascending order, and there should be no duplicates. If your son made a mistake, return an empty int[].

Definition

Filename

ConsecutiveNumbers.py

Signature

int[] missingNumber(int[] numbers)

Constraints

Examples

-------------------------------------------------------------------------------- /8302_ConsecutiveNumbers/ConsecutiveNumbers.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | def missingNumber(numbers): 4 | pass 5 | 6 | -------------------------------------------------------------------------------- /8302_ConsecutiveNumbers/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codersasha/TopCoder-Python-Problems/506ba498597e24cbb131e3a359452ea2192ff844/8302_ConsecutiveNumbers/__init__.py -------------------------------------------------------------------------------- /8310_WordAbbreviation/WordAbbreviation.html: -------------------------------------------------------------------------------- 1 | 8310. WordAbbreviation

8310. WordAbbreviation

Problem

You are given a String[] words, each element of which is a single word. Return a String[] where the i-th element is the abbrevation for the i-th word. The abbreviation for a word is its shortest non-empty prefix that is not a prefix of any other given word. The constraints will guarantee that it is possible to find an abbreviation for all the given words.

Definition

Filename

WordAbbreviation.py

Signature

String[] getAbbreviations(String[] words)

Constraints

Examples

-------------------------------------------------------------------------------- /8310_WordAbbreviation/WordAbbreviation.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | def getAbbreviations(words): 4 | pass 5 | 6 | -------------------------------------------------------------------------------- /8310_WordAbbreviation/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codersasha/TopCoder-Python-Problems/506ba498597e24cbb131e3a359452ea2192ff844/8310_WordAbbreviation/__init__.py -------------------------------------------------------------------------------- /8314_DreamingAboutCarrots/DreamingAboutCarrots.html: -------------------------------------------------------------------------------- 1 | 8314. DreamingAboutCarrots

8314. DreamingAboutCarrots

Problem

John works at a company called "FIELD-Tech", and today, he was so tired after work that he fell asleep as soon as he got home. Unfortunately, even in his sleep, he was unable to forget about his work. In one dream, he was asked to help a carrot producing company deal with the following question: how many carrots grow on a line segment connecting two given carrots? The endpoints of the segment (i.e., the two given carrots) should not be included. It's a rather strange question, and to make it even stranger, the company's representatives (guys who have carrots instead of heads) said that all the carrots grow on an infinite plane, and there is exactly one carrot at each point with integer coordinates. You must help tired John deal with this problem.

2 |

The coordinates of the two carrots are (x1, y1) and (x2, y2). Return the number of carrots that lie strictly on the line segment connecting these carrots.

Definition

Filename

DreamingAboutCarrots.py

Signature

int carrotsBetweenCarrots(int x1, int y1, int x2, int y2)

Constraints

Examples

-------------------------------------------------------------------------------- /8314_DreamingAboutCarrots/DreamingAboutCarrots.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | def carrotsBetweenCarrots(x1, y1, x2, y2): 4 | pass 5 | 6 | -------------------------------------------------------------------------------- /8314_DreamingAboutCarrots/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codersasha/TopCoder-Python-Problems/506ba498597e24cbb131e3a359452ea2192ff844/8314_DreamingAboutCarrots/__init__.py -------------------------------------------------------------------------------- /8315_ParticleCollision/ParticleCollision.html: -------------------------------------------------------------------------------- 1 | 8315. ParticleCollision

8315. ParticleCollision

Problem

Particles (which can be considered points in 3D-space for the purposes of the problem) can move in an electro-magnetic field. If a particle is charged, its trajectory can be described as spiral, and if it is uncharged, it is just a straight line. Given two particles (one charged and one uncharged) it should be determined whether they can possibly collide or not. Two particles can possibly collide if and only if their trajectories intersect.

2 |

Some steps have already been made by the physicist to simplify the problem, so the coordinates of the charged particle are represented as follows:

3 |

x1 = cos(PI * t)

4 |

y1 = sin(PI * t)

5 |

z1 = t

6 |

and for the uncharged particle:

7 |

x2 = vx * t + x0

8 |

y2 = vy * t + y0

9 |

z2 = vz * t + z0

10 |

Here t is a parameter which can be chosen arbitrarily and independently for both trajectories.

11 |

Your method will be given 6 integers - vx, vy, vz, x0, y0 and z0, describing the trajectory of the uncharged particle. It should determine whether the two given trajectories intersect or not. If they do, it should return a double[] containing exactly 3 elements x, y and z - the coordinates of the point where a collision can happen. If there is more than one such point, it should return a double[] containing exactly three zeroes. If collision of the two particles is impossible it should return an empty double[].

12 |

Definition

Filename

ParticleCollision.py

Signature

double[] collision(int vx, int vy, int vz, int x0, int y0, int z0)

Constraints

Examples

-------------------------------------------------------------------------------- /8315_ParticleCollision/ParticleCollision.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | def collision(vx, vy, vz, x0, y0, z0): 4 | pass 5 | 6 | -------------------------------------------------------------------------------- /8315_ParticleCollision/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codersasha/TopCoder-Python-Problems/506ba498597e24cbb131e3a359452ea2192ff844/8315_ParticleCollision/__init__.py -------------------------------------------------------------------------------- /8320_NCool/NCool.html: -------------------------------------------------------------------------------- 1 | 8320. NCool

8320. NCool

Problem

You are given a convex polygon and you must count the number of N-cool points. A point is N-cool if it is a lattice point covered by the polygon and also an endpoint of some N-cool segment. A line segment is N-cool if it contains at least N lattice points that are covered by the polygon. A point is considered covered by the polygon if it is inside or on the boundary of the polygon. Endpoints of a segment are considered to be inside of it. A lattice point is a point with integer coordinates.

2 |

Consider the example in the picture below. Here N is equal to 6, and there are 21 6-cool points, marked green. Also two 6-cool segments, which are colored red, are shown.

3 | 4 |

You are given int[]s x and y describing the vertices of the polygon (in no particular order). The coordinates of each vertex are specified by corresponding elements of x and y. Return the number of N-cool points.

5 |

Definition

Filename

NCool.py

Signature

int nCoolPoints(int[] x, int[] y, int n)

Constraints

Examples

-------------------------------------------------------------------------------- /8320_NCool/NCool.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | def nCoolPoints(x, y, n): 4 | pass 5 | 6 | -------------------------------------------------------------------------------- /8320_NCool/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codersasha/TopCoder-Python-Problems/506ba498597e24cbb131e3a359452ea2192ff844/8320_NCool/__init__.py -------------------------------------------------------------------------------- /8525_SuperWatch/SuperWatch.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | def smallestImprecision(times, zones): 4 | pass 5 | 6 | -------------------------------------------------------------------------------- /8525_SuperWatch/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codersasha/TopCoder-Python-Problems/506ba498597e24cbb131e3a359452ea2192ff844/8525_SuperWatch/__init__.py -------------------------------------------------------------------------------- /8734_MountainWalk/MountainWalk.html: -------------------------------------------------------------------------------- 1 | 8734. MountainWalk

8734. MountainWalk

Problem

You are in a mountainous area which is represented by a String[] areaMap. The j-th character of the i-th element of the areaMap is a digit '0'-'9' representing the height of cell (i, j). You perform a walk in the area according to the following rules: 2 |

7 | You must return the number of cells that you visit while performing your walk. You visit cell (i, j) if and only if you enter cell (i, j) at some point during your walk (the starting cell (0, 0) also counts as entered, i.e., you definitely visit (0, 0)). Note that you will visit each cell at most once since you never enter the same cell twice.

Definition

Filename

MountainWalk.py

Signature

int cellsVisited(String[] areaMap, int heightDifference)

Constraints

Examples

-------------------------------------------------------------------------------- /8734_MountainWalk/MountainWalk.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | def cellsVisited(areaMap, heightDifference): 4 | pass 5 | 6 | -------------------------------------------------------------------------------- /8734_MountainWalk/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codersasha/TopCoder-Python-Problems/506ba498597e24cbb131e3a359452ea2192ff844/8734_MountainWalk/__init__.py -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Introduction 2 | ------------ 3 | This repository is a collection of solutions to TopCoder problems, written in Python. 4 | 5 | Coupled with the TopCoder Scraper, these problems can be automatically timed and tested. 6 | 7 | Format 8 | ------ 9 | The problem format follows that of PyTopCoder: https://github.com/sbermeister/PyTopCoder 10 | These problems have been scraped using the scraper tool, and can be similarly tested using the testing tool. 11 | 12 | --------------------------------------------------------------------------------