CODEVITA-2020 Round 1 questions

Hello everyone! I'm sharing the questions which I came across while giving Codevita Round 1. Overall I felt the questions were not easy, atleast in my set. While on the surface they did appear to me , solvable. But as I kept messing with my code and tescases, later did i realise how bad trap i fell into.
There were few questions, which felt as of i was just a step away from completely getting accepted. But boy I was wrong, The harder i tried, the longer i kept wasting time on those pitty questions.
Anyways, time finished off and i couldnt get myself accept a single solution. Neverthless there were some nice tough questions which i wish I had read them earlier in the competition. We humans are quite complicated. and majority of those complications arise from not managing emotions properly. I wish I had left those easy dusguised touture questions, so that i couldve have atleast come across the remaining.

Anyways feel free to have a look at the questions guys . I would love to see/learn how our leetcode community approaches them Cheers!

(note : the questions are kept in random order)

Question 1

    - Hedger

Problem Description
A hedger is an investor who takes steps to reduce the risks of investment by doing appropriate research and analysis of stocks. Assume that you are a hedger.

Now you have been given some parameters based on which you have to analyze and pick the correct stocks. You have been assigned a fund that you have to manage in such a way that it should give maximum returns.

According to your research you have a list of stocks for which you know the corresponding profit percentages that you can earn within a certain horizon. Being a hedger you don't want to put all your eggs in one basket. That's why you have decided the upper limit in terms of quantity that you will buy.

Given number of stocks, the upper limit on quantity, the amount to be invested, the list of stock prices and list of profit percentages, calculate the maximum profit you can make.

Note: All computation should be up to two digits after the decimal point.

Constraints
0 <= A <= 10^6

1 <= K <= 100

1 <= N <= 10^4

Input
First line contains three space separated integers N K A where N is number of stocks in Market, K is maximum quantity of any particular stock you can buy and A is capital amount you have.

Second line contains N space separated decimals denoting the prices of stocks.

Third line contains N space separated decimals denoting the profit percentages corresponding to the index of stock prices.

Output
Print the maximum profit that can be earned from the given amount, rounded to the nearest integer.

Time Limit
1

Examples
Example 1

Input

4 2 100

20 10 30 40

5 10 30 20

Output

26

Explanation

Here, we can select only two stocks of any stocks that we choose to buy. We choose to buy stocks which are priced at 30 and 40 respectively. Before we exhaust our capital maximum profit that can be earned

Profit=2*((3030)/100) +1((40*20)/100)=26

Example 2

Input

5 3 200

90 25.5 15.5 30.8 18.8

5 10 20 5.5 2.5

Output

20

Explanation

Here, we can select only three stocks of any stocks that we choose to buy. We choose to buy stocks which are priced at 25.5, 15.5 and 30.8 respectively. Before we exhaust our capital maximum profit that can be earned

Profit=3*((25.510)/100) +3((15.520)/100)+2((30.8*5.5)/100)=20.34 Hence, output is 20.


Question-2

    - Faulty Keyboard

Problem Description
Mr. Wick has a faulty keyboard. Some of the keys of the keyboard don't work. So he has copied all those characters corresponding to the faulty keys on a clipboard. Whenever those characters need to be typed he pastes it from the clipboard. In typing whatever is required he needs to make use of paste, backspace and cursor traversal operations. Help him in minimize the number of operations he needs to do to complete his typing assignment. Each operation has one unit weightage.

Constraints
1 <= S <= 16

1 <= T<= 10^4

String T and S will only be comprised of letters a-z and digits 0-9

Input
First line contains text T to be typed Second line contains string S of all the faulty keys pasted on clipboard

Output
Print the minimum number of operations required for typing the text T

Time Limit
1

Examples
Example 1

Input

experience was ultimate

ew

Output

14

Explanation

experience =(2+2+2+2) =[ {p+b} + {p+b} +{p+b} +{p+b} ]

was=(4)=[ p+m+b+m]

ultimate=(2)=[ p+b ]

where p=paste, b=backspace ,m= move cursor

Example 2

Input

supreme court is the highest judicial court

su

Output

17

Explanation

supreme =(1) =[ p]

court=(4)=[ p+m+b+m]

is=(2)=[ p+b ]

the=(0)

highest=(2)=[p+b]

judicial=(4)=[p+m+b+m]

court=(4)=[p+m+b+m]


Question-3

    - Signal Connection

Problem Description
You have been given longitude and latitude of locations from where the channels are going to be broadcasted. You also get the height of tower from which these channels are broadcasted. Moreover, you have been given the location of your friend Jason. You have to calculate how many connections he can make to the towers. Take Radius of earth= 6371 KM.

All the computation has to be accurate up to 6 digits after the decimal point.

Constraints
1 <= N < 10^5

Input
First line contains integer N denoting the number of locations from where the channel is going to be broadcasted

Second line contains N space-separated decimal values denoting latitudes

Third line contains N space-separated decimal values denoting longitudes

Fourth line contains N space-separated integer values denoting the height of tower from which channels are broadcasted

Fifth Line contains two space-separated decimal values denoting latitude, longitude of Jason's location

Output
Print the number of channels Jason can connect with

Time Limit
1

Examples
Example 1

Input

2

19.076090 17.387140

72.877426 78.491684

2 1

18.516726 73.856255

Output

1

Explanation

First latitude and longitude is Mumbai and second is for Hyderabad from where the channel signals are broadcasted. Jason is in Pune. According to signal strength Jason will only be able to connect Mumbai tower.

Example 2

Input

2

28.644800 22.572645

77.216721 88.363892

5 7

48.864716 2.349014

Output

0

Explanation

First latitude and longitude is Delhi and second is for Kolkata from where the channel signals are broadcasted. Jason is in Paris. According to signal strength Jason will not be able to connect any tower.


Question- 4

image
image
image
image


Question-5

- Maximum Prize

Problem Description
Imagine you are a martial arts fighter fighting with fellow martial artists to win prize money. However unlike traditional competitions, here you have the opportunity to pick and choose your opponent to maximize your prize kitty. The rules of maximization of prize kitty are as follows

► You have a superpower bestowed upon you, that you will win against anyone you challenge

► You have to choose the right order because unfortunately the superpower does not ensure that your prize money is always the highest

► Every victory against an opponent that you challenge and win against, will translate into a certain winning sum

► Here begins the technical part that you need to know in order to maximize your winning prize money

All your opponents are standing in one line next to each other i.e. the order of opponents is fixed
Your first task is to choose a suitable opponent from this line
When you choose one opponent from that line, he steps out of the line and fights you.
After you beat him, you get to decide how your prize money for winning against him will be calculated
Essentially, if the opponent you have beaten has two neighbours, then you have the option to multiply the opponent number with any one of the two neighbours and add the other opponent number. That value becomes your prize money for that match
If your opponent has only one neighbor then your prize money for that match is product of current opponent number with neighbours' opponent number
When dealing with last opponent in the tournament, your prize money is equal to the value of the last opponent number
As the tournament proceeds, the opponent that you have beaten has to leave the tournament
Example: 2 5 6 7

This depicts that you have four opponents with numbers 2 5 6 and 7 respectively

  1. Suppose you choose to fight opponent number 5, then after winning, the max prize kitty you can win for that match is = 5*6+2 = 32

Question-6

Codu wants to create a shopping application. ^^The application would sell only SHIRT and SHOE and have a cost that can be modified based on market needs.^^ This application should allow users in two roles, viz. store manager(SM) and shopper(S).

Codu wants to test the app. He wants the application to execute a few commands and print the output.

Following is the list of allowed commands:

CMD SM ADD [ITEM NAME] [ITEM QTY] - adds the given quantity of the item to the inventory and prints(returns) the quantity added, otherwise prints -1 when there is any error or invalid input. Item qty can only be whole numbers > 0.

CMD SM REMOVE [ITEM NAME] - removes the item from the inventory, returns and prints -1 when there is an error, otherwise prints(returns) 1.

CMD SM GET_QTY [ITEM NAME] - returns and prints the currently available quantity for the item in the inventory, otherwise prints(returns) 0 in case the item is not found.

CMD SM INCR [ITEM NAME] [ITEM QTY] - adds the given quantity of the item to the inventory and prints(returns) the quantity added, otherwise prints(returns) -1 when there is any error or invalid input. item qty can only be whole numbers > 0.

CMD SM DCR [ITEM NAME] [ITEM QTY] - removes the given quantity of the item from the inventory and prints(returns) the quantity added, otherwise prints(returns) -1 when there is any error or invalid input. item qty can only be whole numbers > 0.

CMD SM SET_COST [ITEM NAME] [COST] - sets the cost of the item, returns the value, otherwise prints -1 in case of any errors or invalid input. Cost must be decimal.

CMD S ADD [ITEM NAME] [ITEM QTY] - adds the given quantity of the item to the shopping cart and prints(returns) the quantity added, otherwise prints -1 when there is any error or invalid input. Item qty can only be whole numbers > 0.

CMD S REMOVE [ITEM NAME] - removes the item from the shopping cart, returns and prints -1 when there is an error, otherwise prints(returns) 1.

CMD S INCR [ITEM NAME] [ITEM QTY] - adds the given quantity of the item to the shopping cart and prints(returns) the quantity added, otherwise prints(returns) -1 when there is any error or invalid input. item qty can only be whole numbers > 0.

CMD S DCR [ITEM NAME] [ITEM QTY] - removes the given quantity of the item from the shopping cart and prints(returns) the quantity added, otherwise prints(returns) -1 when there is any error or invalid input. item qty can only be whole numbers > 0.

CMD S GET_ORDER_AMOUNT - gets the total price of the items in the cart, returns the value, otherwise prints -1 in case of any error or invalid input. The total amount should be rounded and printed up to two decimal places.

^^NOTE- Increment and Decrement operations are only possible when the item is already in the inventory or cart. If increment or decrement is attempted on items that do not exist in the cart, then the command should return and print -1.^^

^^If an attempt is made to add an item that is already in the inventory or cart, such operations should result in an error and must return and print -1.
^^
^^If an item which is present in the cart of inventory is removed using remove command and an increment or decrement operation is performed on it, such operations should result in an error and must return and print -1.^^

^^If any item quantity after decrement becomes zero, the same is removed from the corresponding inventory or cart. Performing increment or decrement operation after such a previous decrement operation, should result in an error and return -1.^^

You need to think of other similar error conditions while implementing the solution.

Please note at the beginning of a test case or command set, both the inventory as well as the cart is empty.

Here,

SM= STORE MANAGER

S= SHOPPER

You are required to create the application for Codu to manage the shopping kiosk.

The first line of input T, gives the number of test cases.

Each test set is a set of commands, which ends with "END" string.

( incomplete test-case and i/o ahead!!)

Each command in a test case is on a new line
- testcase
-
- 1
CMD SM SET_COST SHOE 5
CMD SM SET_COST SHIRT 10
CMD SM ADD SHOE 5
CMD SM ADD SHIRT 10
CMD SM DCR SHIRT 5
CMD SM INCR SHOE 5
CMD SM GET_QTY SHIRT
CMD SM GET_QTY SHOE
CMD SM REMOVE SHIRT
CMD SM GET_QTY SHIRT
CMD S ADD SHOE 2
CMD S INCR SHOE 2
CMD S DCR SHOE 1
CMD S GET_ORDER_AMOUNT
END

Comments (3)