Skip to main content

2825.js

/** ------------------------------------------------------------------------------
*
* 2825. Make String a Subsequence Using Cyclic Increments
* Topics: Two Pointers
* https://leetcode.com/problems/make-string-a-subsequence-using-cyclic-increments/?envType=daily-question&envId=2024-12-04
*
------------------------------------------------------------------------------ */
/**
* @param {string} str1
* @param {string} str2
* @return {boolean}
*/
var canMakeSubsequence = function (str1, str2) {
let i = 0,
j = 0

while (i < str1.length && j < str2.length) {
if (str1[i] === str2[j] || str1[i] === cyclic(str2[j])) {
j++
}
i++
}

return j == str2.length
}

const cyclic = (char) => {
if (char == "a") return "z"
return String.fromCharCode(char.charCodeAt(0) - 1)
}