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

Method backtrack

FlowerPlantingWithNoAdjacent.java:8–24  ·  view source on GitHub ↗
(int garden,int path[][], int output[],int n)

Source from the content-addressed store, hash-verified

6 }
7
8 public boolean backtrack(int garden,int path[][], int output[],int n)
9 {
10 if(garden == n)
11 return true;
12 for(int i=1;i<=4;i++)
13 {
14 if(isFeasible(garden,path,output,i))
15 {
16 output[garden-1]=i;
17 if(backtrack(garden+1,path,output,n))
18 {
19 return true;
20 }
21 }
22 }
23 return false;
24 }
25
26 public boolean isFeasible(int garden,int path[][],int output[],int color)
27 {

Callers 1

gardenNoAdjMethod · 0.95

Calls 1

isFeasibleMethod · 0.95

Tested by

no test coverage detected