Home > Backend Development > PHP Tutorial > Some interview questions for Jumei today

Some interview questions for Jumei today

WBOY
Release: 2016-08-08 09:23:56
Original
1107 people have browsed it

1. Write a function to randomly place 1,2,3,4,5,6 into an array. 3 cannot be in the third position, and 5 and 6 cannot be next to each other.

function sort_test($array)
{
    while(true) {
        shuffle($array);
        $temp = array_flip($array);
        if ($array[2] != 3 && 1 != abs($temp[5] - $temp[6])) {
            return $array;
        }
    }
}
$array = array(1,2,3,4,5,6);
print_r(sort_test($array));
Copy after login

2. Write a function to implement the first letter that appears once in the string $str="asdfasflasdfopafdsa".
function get_target_letter($str)
{
    $i = 0;
    $array = array();
    while(isset($str[$i])) {
        $array[$str[$i]] = isset($array[$str[$i]]) ? $array[$str[$i]] + 1 : 1;
        $i ++;
    }
    foreach($array as $key=>$val) {
        if ($val == 1) {
            return $key;
        }
    }
    return false;
}
echo get_target_letter('asdfastflasdfopafdsa');
Copy after login
3. There are two tables:
CREATE TABLE products (
  product_id INT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
  product_name VARCHAR(64) NOT NULL
);
CREATE TABLE orders (
  product_id INT UNSIGNED NOT NULL ,
  create_at INT UNSIGNED NOT NULL,
  num INT UNSIGNED NOT NULL 
);
Copy after login
Copy after login

Please write a SQL statement to query the product name and total sales volume during the t1-t2 time period and sort them from high to low according to the total sales volume.

My approach:

SELECT
  products.product_name,
  number.num
FROM ((SELECT
         product_id,
         sum(num) AS num
       FROM orders
         WHERE orders.create_at BETWEEN {$t1} AND {$t2}
       GROUP BY product_id) AS number) INNER JOIN products ON products.product_id = number.product_id
ORDER BY number.num DESC;
Copy after login
These three questions are more impressive. I can’t remember the others. The answers are written according to my own approach. Please correct me if I’m wrong

The above introduces several interview questions at Jumei today, including relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template