Description
Solutions
Check Path Presence
πŸ”₯ FULLTIME

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 Description

Complete the function checkPathPresence in the editor.

checkPathPresence has the following parameters:

  1. 1. N: an integer, the number of vertices
  2. 2. int A[]: an array of integers representing one end of the edges
  3. 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)

Example 1:

Input:  N = 4, A = [1, 2, 4, 4, 3], B = [2, 3, 1, 3, 1]
Output: 1
Explanation:
There is a path 1-2-3-4 using the edges (1,2), (2,3), and (4,3).
Constraints:
    🍏🍏
Thumbnail 0
Testcase

Result
Case 1

input:

output: