There is 1 candidate who is to be interviewed by the n interviewers, so a total of n consecutive slots are needed for the same, for example The table below illustrates the availability of four interviewers (I1, I2, I3, I4) at four time slots (S1, S2, S3, S4). A 1 in the table indicates that the corresponding interviewer is available at the corresponding time slot.
For example, the first interviewer, I1, is available at time slots S1 and S2.
Each interviewer may only take one interview and all four slots should follow sequentially, like S1->S2->S3->S4
Find all the possible combinations for interviewers at each slot. This is one such example in figure,
ALGORITHM
Lets take for three sets (dig and algo are diff)
s1 = array("I1","I2","I3")
s2 = array("I1","I2")
s3 = array("I2","I3")
interviewr_slot = array('slot1'=>s1,'slot2'=>s2,'slot3'=>s3,'slot4'=>null)
count = 3 //it can be any
stack = array()
possibility = array()
traced = array();
myoutput = rec_function(interviewr_slot)
function rec_func($interviewr_slot){
static slot = 0;
slot++;
possibility = interviewr_slot['slot']
if(possibility != null)
{
push(stack,traced)
reset(our_input);
our_input = array();
for( i = slot; i<= n+1, i++)
{
our_input[sloti] = si;
}
foreach(possibility as k=>v)
{
if(!in_array(v, trace))
{
array_push(traced, v)
rec_func(our_output)
}
}
}
else
{
push(output_array,traced)
}
slot--
traced = pop(stack)
our_output = json.stringify(output_array)
return our_output
}
Using PHP Loop the final array and track each array elemet in reverse order to get the result
<?php
$s1 = array("I1","I2","I3");
$s2 = array("I1","I2","I3");
$s3 = array("I1","I2","I3");
$interviewr_slot = array('1'=>$s1,'2'=>$s2,'3'=>$s3);
$flag = 0;
$len = count($interviewr_slot);
for($i = $len; $i>= 1; $i--){
if($flag == 0){
foreach ($interviewr_slot[$i] as $key => $value) {
$myarray[$key] = array($value);
}
$flag = 1;
}else{
$checkarray = $myarray;
unset($myarray);
$myarray = array();
foreach ($interviewr_slot[$i] as $key => $value) {
foreach($checkarray as $k=>$v){
if(!in_array($value, $v)){
array_push($v, $value);
array_push($myarray, $v);
}
}
}
}
}
var_dump($myarray);
?>
output:
array (size=6)
0 =>
array (size=3)
0 => string 'I3' (length=2)
1 => string 'I2' (length=2)
2 => string 'I1' (length=2)
1 =>
array (size=3)
0 => string 'I2' (length=2)
1 => string 'I3' (length=2)
2 => string 'I1' (length=2)
2 =>
array (size=3)
0 => string 'I3' (length=2)
1 => string 'I1' (length=2)
2 => string 'I2' (length=2)
3 =>
array (size=3)
0 => string 'I1' (length=2)
1 => string 'I3' (length=2)
2 => string 'I2' (length=2)
4 =>
array (size=3)
0 => string 'I2' (length=2)
1 => string 'I1' (length=2)
2 => string 'I3' (length=2)
5 =>
array (size=3)
0 => string 'I1' (length=2)
1 => string 'I2' (length=2)
2 => string 'I3' (length=2)