# 李 interview
## Q1.
取出工作經歷(employmentHistory)中,任職最久的一份工作
```php=
<?php
$payload = '{
"employmentHistory": [
{
"employer": "JKL Inc.",
"position": "Web Developer",
"startDate": "2008-01-01",
"endDate": "2009-12-31"
},
{
"employer": "ABC Inc.",
"position": "Software Engineer",
"startDate": "2010-01-01",
"endDate": "2012-06-30"
},
{
"employer": "MNO Corp.",
"position": "Software Engineer",
"startDate": "2010-01-01",
"endDate": "2011-12-31"
},
{
"employer": "XYZ Corp.",
"position": "Senior Software Engineer",
"startDate": "2012-07-01",
"endDate": "2013-12-31"
},
{
"employer": "UVW Inc.",
"position": "Senior Software Engineer",
"startDate": "2012-01-01",
"endDate": "2014-12-31"
},
{
"employer": "Acme Corp.",
"position": "Lead Software Engineer",
"startDate": "2014-01-01",
"endDate": "2015-12-31"
},
{
"employer": "DEF Inc.",
"position": "Software Developer",
"startDate": "2016-01-01",
"endDate": "2017-12-31"
},
{
"employer": "GHI Corp.",
"position": "Systems Analyst",
"startDate": "2018-01-01",
"endDate": "2019-12-31"
},
{
"employer": "LMN Inc.",
"position": "Senior Systems Analyst",
"startDate": "2020-01-01",
"endDate": "2021-06-30"
},
{
"employer": "PQR Corp.",
"position": "Software Engineer",
"startDate": "2021-07-01",
"endDate": null
}
]
}';
$maxDuration = array(date(0), -1);
for($p as $payload["employmentHistory"]){
$diff = date($p["endate"]) - date($p["startDate"]);
if($diff > $maxDuartion[0]){
$maxDuration[1] = $p;
}
}
return $maxDuration[1];
```
## Q2.
Valid Parentheses
Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.
An input string is valid if:
Open brackets must be closed by the same type of brackets.
Open brackets must be closed in the correct order.
Every close bracket has a corresponding open bracket of the same type.
```php=
<? php
function isValid($s) {
}
/**
Example 1:
Input: s = "()"
Output: true
Example 2:
Input: s = "()[]{}"
Output: true
Example 3:
Input: s = "(]"
Output: false
Example 4:
Input: s = "{[({})]}"
Output: true
**/
```
stack<char> S;
for(auto c: s){
if(c == '(' || c == '[' || c == '{'){
S.push(c);
}
else if(c == ')'){
if(S.empty() || S.top() != '('){
return false;
}
S.pop();
}
else if(c == ']'){
if(S.empty() || S.top() != '['){
return false;
}
S.pop();
}
else if(c == '}'){
if(S.empty() || S.top() != '{'){
return false;
}
S.pop();
}
}
return S.empty();