Check Path Presence
Learn this problemProblem statement
You are given an undirected graph consisting of N vertices, numbered from 1 to N, and M edges. The graph is described by two arrays, A and B, both of length M. A pair (A[K], B[K]) for K from 0 to M-1 describes an edge between vertex A[K] and vertex B[K]. Your task is to check whether the given graph contains a path from vertex 1 to vertex N going through all the vertices one by one in increasing order of their numbers. All connections on the path should be direct.
Function
checkPathPresence(N: int, A: int[], B: int[]) → int
Complete the function checkPathPresence in the editor.
checkPathPresence has the following parameters:
- 1.
N: an integer, the number of vertices - 2.
int A[]: an array of integers representing one end of the edges - 3.
int B[]: an array of integers representing the other end of the edges
Returns
int: 1 if true there is a path from vertex 1 to vertex N going through all the vertices in increasing order, otherwise 0 (false)
Examples
Example 1
N = 4A = [1, 2, 4, 4, 3]B = [2, 3, 1, 3, 1]return = 1Constraints
🍏🍏More Microsoft problems
- Maximum Pipeline ThroughputOA · Seen Jul 2026
- Maximum Strong Team SubarrayOA · Seen Jul 2026
- Minimum Cost K-Capable ModelsOA · Seen Jul 2026
- Alphabetically Smallest PalindromeOA · Seen Jul 2026
- Maximum Reward PointsOA · Seen Jul 2026
- Maximum Strength of Every NeuronOA · Seen Jul 2026
- Neural Network Subnetwork StrengthOA · Seen Jul 2026
- XOR MultiplicationOA · Seen Jul 2026