Question: Uber OA | 2023
0
Entering edit mode

3 QUESTIONS | 90 MINUTES

Question 1

Lazy Swapnil is playing with 'Tower of Swapol'. Unfortunately, this is going to cost him energy which he doesn't want to waste. There are n towers with rings present on some towers. The sum of the number of rings in all towers is equal to n. Swapnil wants to make all towers contain only one single ring. In one single step, he can move as many rings from a particular tower to its either adjacent left or adjacent right tower(not on both sides). Since Swapnil is lazy, he wants to minimize his energy wastages. Find the minimum number of steps so that all the towers contain a single ring after doing these steps.

INPUTS

Integer n (n ≤ 100000)

Array A (0 ≤ A[i] ≤ 100000)

OUTPUT

An integer denoting the minimum number of steps.



 

Question 2

This is the year 2050, and humans have shifted to a planet Ceres. The humans have evolved into 2 supernatural species namely alpha and beta. The alpha members call themselves as Alph and the beta members as Bts. Yakohama is a huge kingdom build by late king Hiroshi of alpha group. Since then the entire place has been a lure for beta and have been attacked several times by them. This beautiful kingdom is situated in an island amidst forest and ocean.

An army of bts is going to attack the Kingdom of Yakohama at night through a secret path that comes all the way from the jungle to the kingdom. Akari being the king needs to protect his people at all costs. His kingdom is located at the top left corner of a forest, and there are several people from beta clan in the entire forest.

The forest is in a form of m'n grid, with either an active volcano or bts member in each grid (there won't be any grids that are empty). The volcano is marked as 1, and the rest of the values are 0. Akari thinks of a plan to go to the forest by himself and kill the maximum members of bts during the day only. As Akari is about to leave, he gets hurt and deeply wounded. Now, Akarl can only fight up to a given number of hours. He should return to his kingdom before this time, otherwise he will be defeated by the beta clan.

Whenever Akari moves over a cell, he will kill the opponent if any of the bts members was present in the cell (he won't do anything if the cell was empty). The only precaution that he needs to take is not enter a cell having volcano else he will be engulfed by the molten lava.

Akari takes 1 hour to execute a move (ie. go from a cell to another, including leaving the kingdomere the time taken to kill the opponent is assumed to be 0). Note that Akari can only move left, right, up and down. He cannot move diagonally

Write a function that returns the maximum number of bts killed by Akari when he reaches the kingdom.

Example

Input:

Forest Plan (grid)

000

010

000


Hour to survive

6

Output:

3

 

Here the king can take the following path: (0, 0)-> (0, 1)-> (0, 2) (0, 1)-> (0, 0). Here 3 bts ((0, 0), (0, 1), (0, 2)) are killed and Akari reaches back to (0, 0) before running out of hours.

Note that after (0, 2), if the king moves to (1, 2), he won't be able to reach the starting position before the allotted hours, so it cannot kill that bts. Also, here (0, 0)- (0, 1)-> (1, 1)-> (1, 0)-> (0, 0) is an invalid path because the king can't move on cell (1, 1) as it has a volcano.

Constraints:

1s forestPlan.length 10,

1 s forestPlan[i]s 10.

1s hours to survives 12,

Starting point won't have volcano

[input) array.array.boolean forest plan

Forest plan refers to the location of bts and volcanoes in the forest.

[output] integer

The maximum number of bts killed. Note that the king can't move on the cells having volcades and should return to the kingdom before hours_to_survive.



Question 3
 

Eastar Game Manufacturing recently launched a Magical Dice Game where there is a strip of T cells, of which some cells are empty while some cells are blocked. Being board game enthusiasts, Samuel decided to gift Tina the Magical Dice Game for her 16th birthday.

Tina and Samuel decide to play a betting game on this strip. The players take turns, with Tina going First.

The Rules of the Game are as follows, a player must choose:

1. First N contiguous empty cells, and place a disappearing banner on each of these cells

2. If a banner is placed on the empty cells on turn Y, the banner will automatically vanish just before the start of turn Y-X, L.e the cell will be considered empty again exactly X turns after the disappearing banner has been placed

The player who is unable to make a move eventually loses the game.

3. If no one is able to start the game, it automatically becomes a Tie

Given variables T, N, X, and which cells of the strip are initially blocked, who between Tina and Samuel will win this game? Or will the game go on infinitely(Tie)?

Input Format:

First line of input contains a string S of length T which signifies the initial state of the strip, where 0 denotes an empty cell and 1 denotes a blocked cell Contains the 3 required integers: T NX, as mentioned in the problem statement above

Output Format:

Return string value denoting the game winner: Should be either Tina, Samuel or Tie (incase the game goes on infinitely)

 

Sample Testcase:

Input:

010001110

9

4



Output:

Tina

 

Explanation:

Tina starts the game and places disappearing banner on 3rd and 4th cell

Samuel needs 2 consecutive empty cells to make a move, but no such cells are available.

Hence Tina wins the game

 

Testcase 2:

Input

011100010001003

25

3



Output:

Tie

 

Explanation:

 

Tina: Starts the game and needs 3 consecutive empty tiles, so Tina places the disappearing banner on tiles 5, 6 & 7

(these tiles will become empty after 1 move)

Samuel: Needs to find next 3 consecutive empty tiles, so places on tiles 9, 10 & 11

(these tiles will become empty after 1 move)

Tina: Needs to find next 3 consecutive empty tiles, now tiles 5,6 & 7 are empty again. So Tina will place the banner there. The way will go way go on infinitely, hence TIE

 

Constraints:

• 1<_N<_T200

• 1<_X<_20

•S is a binary string.

 

•[execution time limit] 0.5 seconds (cpp)

•[memory limit] 1 GB

•[input] string s

First line of input contains a string S of length T which signifies the initial state of the strip, where Q denotes an empty cell and 1 denotes a blocked cell
 

[memory limit] 1 GB

[input] string s

First line of input contains a string S of length T which signifies the initial state of the strip, where 0 denotes an empty cell and 1 denotes a blocked cell.

[input] integer t

Second Line contains the 3 required integers: TN X, as mentioned in the problem statement above

[input] integer n

[input] integer x

.

[output] string

Return string value denoting the game winner: Should be either Tina, Samuel or Tie (incase the game goes on infinitely)

 



 

 

ADD COMMENTlink 15 months ago PoGo 2.4k
0
Entering edit mode

It was for full time or intern and which role?

ADD COMMENTlink 13 months ago Vishal Sharma 20

Login before adding your answer.

Similar Posts
Loading Similar Posts