{"size": 1084, "ext": "js", "max_stars_repo_path": "string/0.6/1189-maximum-number-of-balloons/index.js", "max_stars_repo_name": "0x00000024/leetcode-javascript", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "string/0.6/1189-maximum-number-of-balloons/index.js", "max_issues_repo_name": "0x00000024/leetcode-javascript", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "string/0.6/1189-maximum-number-of-balloons/index.js", "max_forks_repo_name": "0x00000024/leetcode-javascript", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 25.8095238095, "max_line_length": 120, "alphanum_fraction": 0.6715867159}
/*
Given a string text, you want to use the characters of text to form as many instances of the word "balloon" as possible.

You can use each character in text at most once. Return the maximum number of instances that can be formed.

Example 1:
  Input: text = "nlaebolko"
  Output: 1

Example 2:
  Input: text = "loonbalxballpoon"
  Output: 2

Example 3:
  Input: text = "leetcode"
  Output: 0

Constraints:
  1 <= text.length <= 10^4
  text consists of lower case English letters only.
*/
/*
 * @param {string} text
 * @return {number}
 */
const maxNumberOfBalloons = function(text) {
  const chars = new Array(26).fill(0);
  for (let i = 0; i < text.length; ++i) {
    ++chars[text[i].charCodeAt(0) - 'a'.charCodeAt()];
  }
  let min = chars[1];
  min = Math.min(min, chars[0]);
  min = Math.min(min, Math.floor(chars[11] / 2));
  min = Math.min(min, Math.floor(chars[14] / 2));
  min = Math.min(min, chars[13]);
  return min;
};

// console.log(maxNumberOfBalloons('nlaebolko'));
// console.log(maxNumberOfBalloons('loonbalxballpoon'));
console.log(maxNumberOfBalloons('balon'));
