Juspay | OA | Nearest Meeting Cell
Anonymous User
81735

Hi,
I recently appeared for Juspay OA, for SDE - 1. The round consisted of 3 Problems to be solved in the span of 90 mins. This one of the questions that I wasn't able to solve.

Problem Description :

You are given a maze with N cells. Each cell may have multiple entry points but not more than one exit (i.e. entry/exit points are unidirectional doors like valves). The cells are named with an integer from 0 to N-1.

You have to find :

Nearest meeting cell : Given any two cells - C1, C2, find the closest cell Cm that can be reached from both C1 and C2.

INPUT FORMAT :

  1. The first line contains the number of cells N.
  2. The second line has a list of N values of the edge[ ] array, where edge[i] conatins the cell number that can be reached from cell 'i' in one step. edge[i] is -1 if the ith doesn't have an exit.
  3. Third line for each testcase contains two cell numbers whose nearest meeting cell needs to be found. (return -1 if there is no meeting cell from two given cells)

OUTPUT FORMAT :
Output a single line that denotes the nearest meeting cell (NMC).

Sample Input :
23
4 4 1 4 13 8 8 8 0 8 14 9 15 11 -1 10 15 22 22 22 22 22 21
9 2

Sample Output :
4

image

The other 2 questions can be found here - https://leetcode.com/discuss/interview-question/2032859/Juspay-or-OA-or-Maximum-Weight-Node
https://leetcode.com/discuss/interview-question/1186405/largest-sum-cycle (Not My post).

Kindly upvote if you found this helpful.

Comments (22)