Pycode Prelims Finals
Pycode Prelims Finals
Easy Abbreviations
The abbreviations should be as follows: Write the first letter of the word in
Uppercase followed by the number of Vowels and Consonants between
the first and last letter. Lastly we write the last letter of the word to finish
the abbreviation.
You are suggested to automatize the process of changing the words with
abbreviations. At that all too long words should be replaced by the
abbreviation and the words that are not too long should not undergo any
changes.
Constraints:
Any word longer than 10 characters should be converted to an abbreviation else
left unchanged.
Input
The first line contains an integer n (1 ≤ n ≤ 100). Each of the following n lines
contains one word. All the words consist of lowercase Latin letters and possess the
lengths of from 1 to 100 characters.
Output
Print n lines. The i-th line should contain the result of replacing of the i-th word
from the input data.
Example Cases:
Input:
4
word
localization
internationalization
Pneumonoultramicroscopicsilicovolcanoconiosis
Output:
word
L64n
I99n
p11S
Fuel Trouble
Rakshit is going on a journey and needs your help. He is on a circular route with n
gas stations.Each station i has a specific amount of gas, represented by the list
gas[i]. It requires cost[i] units of gas to travel from station i to the next station (i +
1), with the stations arranged in a loop. You start your journey with an empty gas
tank at one of the stations, and your car's tank has no capacity limits.
The task is to determine the starting station index that allows you to complete a
full loop around the route in a clockwise direction. If it is possible to make the
complete trip, return the starting station index. If not, return -1. If a valid solution
exists, it is guaranteed to be unique.
Example 1:
Input:
gas = [1,2,3,4,5]
cost = [3,4,5,1,2]
Output:
3
Explanation:
Start at station 3 (index 3) with 4 units of gas:
● Your tank = 0 + 4 = 4
● Travel to station 4: Your tank = 4 - 1 + 5 = 8
● Travel to station 0: Your tank = 8 - 2 + 1 = 7
● Travel to station 1: Your tank = 7 - 3 + 2 = 6
● Travel to station 2: Your tank = 6 - 4 + 3 = 5
● Travel back to station 3: Your tank is enough to complete the loop.
Thus, station 3 is the valid starting point.
Constraints:
● The number of gas stations, n, is the same for both
● gas and cost list.
AP Sequencing
Example
Input
[1, 3, 5, 7, 9, 11]
Output
8
Explanation
All subsequences of size greater than 1 which form an AP are [1, 3], [3, 5],
[5, 7], [7, 11], [1, 3, 5], [3, 5, 7], [3, 7, 11] (jumping over one element) and [1, 3,
5, 7]
Palindrome Re-ordering
Given a string, your task is to reorder its letters in such a way that it becomes a palindrome
(i.e., it reads the same forwards and backwards).
Input
Output
Print a palindrome consisting of the characters of the original string. You may print any valid
solution. If there are no solutions, print "NO SOLUTION".
Example
Input:
AAAACACBA
Output:
AACABACAA
Tower of Hanoi
The Tower of Hanoi game consists of three stacks (left, middle and right) and nnn round
disks of different sizes. Initially, the left stack has all the disks, in increasing order of size
from top to bottom.
The goal is to move all the disks to the right stack using the middle stack. On each move you
can move the uppermost disk from a stack to another stack. In addition, it is not allowed to
place a larger disk on a smaller disk.
Your task is to find a solution that minimizes the number of moves.
Input
Integer n stating the number of discs
Output
Constraints
● 1≤n≤10
Example
Input:
2
Output:
3
12
13
23
Eating Queries
Timur has n candies, each with a sugar content of aᵢ. For each of
the q queries, you need to find the minimum number of candies
required to consume at least xⱼ sugar, or print -1 if it's not
possible.
Input
The sum of n and q over all test cases does not exceed 1.5⋅10⁵.
Output
Input
2
41
1234
3
12
5
4
6
Output
1
1
-1
Explanation:
Timur wants to reach at least 4 units of sugar. He has one candy with 5 units of sugar.
Since eating this candy provides 5 units of sugar, which is greater than 4, he only needs to
eat 1 candy.
Then Timur wants to reach at least 6 units of sugar. He has only one candy with 5 units of
sugar. Since 5 is less than 6, it is not possible for Timur to reach the desired quantity of
sugar with the candies he has.