TVS Credit E.P.I.C IT Challenge | Coding Round | D2C
Anonymous User
1789

The participants had to solve 2 coding challenges within a time period of 1 hour.

Question 1
You are standing at an infinite position axis grid and the starting position is (1,1).
The value in particaular position (i,j) in a grid is defined by the equation:
F( i , j )= i * j , where * denotes multiplication.

In one move , you can move from (i , j) to (i+1, j) or (i , j+1)
You are also given and integer N.
Now your task is to find the minimum number of moves needed to reach a position that contains the value N.

Input Format:
The first line contains an integer N.
where, 2<=N<=10^12

Output Format:
Print the minimum number of moves needed to reach a position that contains the value N.

  • Sample Test Case #0:
    Input: 10
    Output: 5

  • Sample Test Case #1:
    Input: 25
    Output: 8

Question 2
Given two arrays of length n
x = {x1, x2, x3,..., xn} and y = {y1, y2, y3,..., yn}

One operation consists of the following in order :

  • Choose i, where 1<=i<n
  • Swap x[i] with x[i+1]
  • X[i]=X[i] + 1
  • X[i+1]=X[i+1] - 1

Find the minimum number of operations to convert X to Y. If impossible, return -1.

Constrainsts:

  • 2<=n<=2*10^5
  • 0<=X[i], Y[i] <=10^9
    All input values are integers.

Input Format:
N
X[1] X[2].......X[N]
Y[1] Y[2]........Y[N]

Output Format:
Print the minimum number of operationsto make X equal to Y. If it is impossible return -1.

  • Sample Test Case #0:
    Input:
    3
    1 2 3
    1 2 3

  • Output: 0


Comments (1)