MCPcopy Create free account
hub / github.com/Tiwarishashwat/InterviewCodes / backTrack

Method backTrack

AllPathsSourceToEndGraph.java:3–17  ·  view source on GitHub ↗
(int graph[][], int element, List<List<Integer>> list,List<Integer> sublist)

Source from the content-addressed store, hash-verified

1class Solution {
2
3 public static void backTrack(int graph[][], int element, List<List<Integer>> list,List<Integer> sublist){
4 // Base Case
5 if(element==graph.length-1)
6 {
7 list.add(new ArrayList<>(sublist));
8 return;
9 }
10
11 for(int i=0;i<graph[element].length;i++)
12 {
13 sublist.add(graph[element][i]);
14 backTrack(graph,graph[element][i],list,sublist);
15 sublist.remove(sublist.size()-1);
16 }
17 }
18
19 public List<List<Integer>> allPathsSourceTarget(int[][] graph) {
20 List<Integer> sublist = new ArrayList<Integer>();

Callers 1

allPathsSourceTargetMethod · 0.95

Calls 1

addMethod · 0.45

Tested by

no test coverage detected