# LeetCode: Change Minimum Characters To Satisfy One Of Three Conditions Solution

```.css-ds3kc{display:table-row;}.css-1t8atru{display:table-cell;opacity:0.5;padding-right:var(--chakra-space-6);-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;text-align:right;}1.css-2qghsv{display:table-cell;}var minCharacters = function (a, b) {2  const convertToArrayOfCharCode = str =>3    str.split("").map((_, i) => str.charCodeAt(i) - 97)4
5  // min step for a < b6  const sol1 = (a, b) => {7    let res = Infinity8
9    // tricky part to make it strictly "<"10    for (let i = 1; i < 26; i++) {11      let count = 012      for (const ai of a) count += i <= ai13      for (const bi of b) count += i > bi14      res = Math.min(res, count)15    }16    return res17  }18
19  // min step to make a = b20  const sol3 = (a, b) => {21    let res = Infinity22
23    for (let i = 0; i < 26; i++) {24      let count = 025      for (const ai of a) count += i !== ai26      for (const bi of b) count += i !== bi27      res = Math.min(res, count)28    }29    return res30  }31
32  a = convertToArrayOfCharCode(a)33  b = convertToArrayOfCharCode(b)34  return Math.min(sol1(a, b), sol1(b, a), sol3(a, b))35}```

leetcode

## Next Post

LeetCode: Latest Time By Replacing Hidden Digits

Jan 24, 2021

Search Posts