[Javascript] Binary Search
Solution: Binary Search\n\nBinary search for minimum maximum nums[i].\nTo check whether it is possible to take k non-adjacent houses with maximum score of nums[
**Solution: Binary Search**\n\nBinary search for minimum maximum `nums[i]`.\nTo check whether it is possible to take `k` non-adjacent houses with maximum score of `nums[i]`,\n*   Greedily take `k` houses with `nums[i] <= max`.\n*   When we find `nums[i] <= max`, take the house and skip to `nums[i + 2]` (It is optimal to take a house earlier than later).\n\n`n = length of nums`, `m = max(nums[i])`\nTime Complexity: `O(n log(m))`\nSpace Complexity: `O(1)`\n```\nvar minCapability = function(nums, k) {\n  let min = nums[0], max = nums[0];\n  let n = nums.length;\n  for (let i = 0; i < n; i++) {\n    min = Math.min(min, nums[i]);\n    max = Math.max(max, nums[i]);\n  }\n  let low = min, high = max;\n  while (low < high) {\n    let mid = Math.floor((low + high) / 2);\n    if (isEnough(mid)) high = mid;\n    else low = mid + 1;\n  }\n  return low;\n  \n  function isEnough(max) { // greedily take k houses with nums[i] <= max\n    let houses = 0;\n    for (let i = 0; i < n; i++) {\n      if (nums[i] <= max) {\n        houses++;\n        i++;\n      }\n      if (houses === k) return true;\n    }\n    return false;\n  }\n};\n```
['JavaScript']