We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 4c50285 commit 522ff5eCopy full SHA for 522ff5e
1177-can-make-palindrome-from-substring.js
@@ -0,0 +1,26 @@
1
+/**
2
+ * @param {string} s
3
+ * @param {number[][]} queries
4
+ * @return {boolean[]}
5
+ */
6
+const canMakePaliQueries = function(s, queries) {
7
+ const code = ch => ch.charCodeAt(0) - 'a'.charCodeAt(0)
8
+ const preCount = [...s].reduce(
9
+ (a, c) => {
10
+ let nc = a[a.length - 1]
11
+ nc ^= 1 << code(c) //NOT on one bit
12
+ a.push(nc)
13
+ return a
14
+ },
15
+ [0]
16
+ )
17
+ return queries.map(q => {
18
+ let subCount = preCount[q[1] + 1] ^ preCount[q[0]]
19
+ let oddChs = 0
20
+ while (subCount > 0) {
21
+ oddChs += subCount & 1
22
+ subCount >>= 1
23
+ }
24
+ return Math.floor(oddChs / 2) <= q[2]
25
+ })
26
+}
0 commit comments