<?php class Matrix{ /** •@param 2D array $matrix • •Prints distinct elements common to all rows of the matrix */ public static function getDistinctElementsCommonToAllRows($matrix){ // A hash map to store count of elements $hashmap = array(); $selectedHash = array(); $rows = count($matrix); $cols = count($matrix[0]); for ($i = 0; $i < $rows; $i++) { // Increment the count of first // element of the row if(array_key_exists($matrix[$i][0],$hashmap)){ $hashmap[$matrix[$i][0]] = $i+1; } // Starting from the second element // of the current row for ($j = 1; $j < $cols; $j++) { // If current ele
<?php class Node { public $value; public $next = null; // next node public $prev = null; // previous node public function __construct($value) { $this->value = $value; } } class Palindrome { /** •@param string $word •@return bool */ public static function isPalindrome($head, $tail){ if ($head == null) return true; while ($head != $tail){ if ($head->value != $tail->value) return false; $head = $head->next; $tail = $tail->prev; } return true; } } $head = new Node(1); $firstNode = new Node(2); $secondNode = new Node(3); $tail = new Node(4); $head->next = $firstNode; $firstNode->prev = $head; $firstNode->next = $secondNode; $secondNo