ExpertRating - Online Certification and Employment Testing ExpertRating - Online Certification and Employment Testing ExpertRating - Online Certification and Employment Testing

 
Result Sheet (PHP Programming Skills Test)
 


  Below are the details of the problems encountered in the test along with the code submitted by the test taker. 4 example problems have been shown below, in the actual test, all 10 problems will be shown.
Problem No: 1
Problem Text:

Write a function GeneratePassword which accepts two arguments, an integer and a character string consisting of letters (a-z) and digits (0-9).

When GeneratePassword(5,'abc0123') is called, it should return a random string of 5 characters taken from 'abc0123'.



For Example : GeneratePassword(7,'abczxc012394') could return any of the following outputs :
2c00acb
2c23z93
030b2a4

Time taken to solve this problem:03:28 (mm:ss)
Pass rate for this question:35% (35% of the people who attempted this question could get it right)
Average time for solving this problem:3 mins
Result:Wrong Answer (Wrong Answer)
Code submitted:
function GeneratePassword($length, $characters)

      {

      if ($characters == '')

      {

      return '';

      }

      $chars_length = strlen($characters)-1;

      while(strlen($pwd) <= $length)

      {

      $rand_char = mt_rand(0, $chars_length);

      $pwd .= $characters[$rand_char];

      }

      return $pwd;

      }
Problem No: 2
Problem Text:

Create a function named 'sortsalary' which will accept an XML string as input. The XML string contains the data related to employees of the company. The following is the structure of the XML string.

<employees><employee empid="1" empname="Rock" empsalary="345" /><employee empid="2" empname="Jim" empsalary="500" /><employee empid="3" empname="Rick" empsalary="600" /></employees>

You are required to sort the employee's salary in decreasing order and display the name along with the salary in pairs separated by a hyphen (-). All records must be comma separated.

Here is an example. Suppose the above mentioned XML string is passed to the function 'sortsalary' in the following manner:

$a = '<employees><employee empid="1" empname="Rock" empsalary="345" /><employee empid="2" empname="Jim" empsalary="500" /><employee empid="3" empname="Rick" empsalary="600" /></employees>';

sortsalary($a);

Then the function should display the following output:

Rick-600,Jim-500,Rock-345

Time taken to solve this problem:05:23 (mm:ss)
Pass rate for this question:42% (42% of the people who attempted this question could get it right)
Average time for solving this problem:9 mins
Result:Accepted Solution (Accepted Solution)
Code submitted:
function sortsalary($a)
{
	$xmlstr=$a;
	$xml = simplexml_load_string($xmlstr);
	$recordcount = count($xml->employee);
	$salary = array();
	$str_output="";
	for ($i=0; $i<$recordcount; $i++)
	{
		$salary[] =$xml->employee[$i]["empsalary"];
	}
	rsort($salary,SORT_NUMERIC);
	$arraycount  = count($salary);
for($j=0;$j<$arraycount;$j++)
{
for ($i=0; $i<$recordcount; $i++)
{
	if ($xml->employee[$i]["empsalary"]==$salary[$j])
	{
		if ($str_output=="")
		{
			$str_output = 
			$xml->employee[$i]["empname"]."-".$salary[$j];
		}
		else
		{
			$str_output = $str_output.","
			.$xml->employee[$i]["empname"]."-".$salary[$j];
		}
		
	}
}	
		
	}
	
	echo $str_output;
}
Problem No: 3
Problem Text:

Create a function Permutation_st() which will accept a word and then return the various combinations of characters present in the word. The function should return the words in the form of an alphabetically sorted array.

Suppose we take the example of the word 'cat'. The function Permutation_st()should return an array containing the following words (in alphabetical order).

act,atc,cat,cta,tac,tca

One thing to keep in mind is that if a character is repeated in the word, the array returned should not contain duplicate elements. For example, if the word 'yyy' is sent to the function, Permutation_st("yyy") should return 'yyy' only.

Time taken to solve this problem:05:23 (mm:ss)
Pass rate for this question:55% (55% of the people who attempted this question could get it right)
Average time for solving this problem:6 mins
Result:Accepted Solution (Accepted Solution)
Code submitted:
function Permutation_st($str) 
{
	if (strlen($str) < 2) 
	{
		return array($str);
	}
	
	$permutations = array();
	 
	$tail = substr($str, 1);
	
	foreach (Permutation_st($tail) as $permutation) 
	{
		$length = strlen($permutation);
		for ($i = 0; $i <= $length; $i++) 
		{
			$permutations[] = substr($permutation, 0, $i) 
			. $str[0] . substr($permutation, $i);
		}
	}
	 
	return $permutations;
}
Problem No: 4
Problem Text:

Consider a database with one table called "students" having two fields:

"id" (type: INTEGER, PRIMARY KEY)
"studentname" (type: VARCHAR(32))

Write a standard SQL query which retrieves the second lowest value of "id" from the "students" table. The value returned should be represented using the column name "id".

Time taken to solve this problem:05:23 (mm:ss)
Pass rate for this question:72% (72% of the people who attempted this question could get it right)
Average time for solving this problem:6 mins
Result:Accepted Solution (Accepted Solution)
Code submitted:
SELECT MIN(id) as id FROM students where id>(SELECT MIN(id) FROM students)