# # maxOfBiggestVal

```javascript
// numbers = ［5,2,5,3,1]
// q = [1,5,3,4,5]
// return [2,1,1,1,1]

//1 [5,2,5,3,1]  return 2 因為 5 出現兩次
//5 [1] 1
//3 [5,3,1] 1
//4 [3,1] 1
//5 [1] 1
function maxOfBiggestVal (numbers, q) {}
```

### 怎麼解

先不要管 q，先從 numbers 開始找規則，發現從後面算的話，算到前面可以繼續利用．一開始一定是 return 1 因為最後一個只有有一個值，然後創一個 lookup 把寄過得值存起來

```javascript
function maxOfBiggestVal (numbers, q) {
  const len = numbers.length
  let maxNum = numbers[len-1]
  let lookup = new Map()
  let result= new Array(len)
   // [2,1,1,1,1]
  
  for(let i=len-1; i>=0; i--){
      if(!lookup.has(numbers[i])){
        lookup.set(numbers[i], 1)
      } else {
        lookup.set(numbers[i], lookup.get(numbers[i]) + 1)
      }
      maxNum = Math.max(numbers[i], maxNum)
      result[i] = lookup.get(maxNum)
  }
  

  return  q.map((query) => result[query-1] )
}
```

8/13

```javascript
function getBiggestValueCount(nums){
  if(nums.length == 0 ) return null
  if(nums.length < 2) return 1
  
  let map = new Map()
  let maxVal = nums[0]
  
  for(let num of nums){
    map.set(num, (map.get(num) || 0) + 1 )
    maxVal = Math.max(maxVal, num)
  }

  return map.get(maxVal)
}

function maxOfBiggestVal (numbers, q) {
  return q.map(query => 
    getBiggestValueCount(numbers.slice(query - 1))
  )
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://hannahpun.gitbook.io/leetcode-note/array/maxofbiggestval.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
