Skip to content

2825. Make String a Subsequence Using Cyclic Increments #912

Answered by mah-shamim
mah-shamim asked this question in Q&A
Discussion options

You must be logged in to vote

We need to check if we can make str2 a subsequence of str1 by performing at most one cyclic increment operation on any characters in str1:

Explanation:

  • We will use two pointers, i for str1 and j for str2.
  • If the character at str1[i] matches str2[j], we move both pointers forward.
  • If str1[i] can be incremented to match str2[j] (cyclically), we try to match them and then move both pointers.
  • If neither of the above conditions holds, we only move the pointer i for str1.
  • Finally, if we can match all characters of str2, then it is possible to make str2 a subsequence of str1, otherwise not.

Let's implement this solution in PHP: 2825. Make String a Subsequence Using Cyclic Increments

<?php
/**

Replies: 1 comment 2 replies

Comment options

mah-shamim
Dec 4, 2024
Maintainer Author

You must be logged in to vote
2 replies
@topugit
Comment options

topugit Dec 4, 2024
Collaborator

@mah-shamim
Comment options

mah-shamim Dec 4, 2024
Maintainer Author

Answer selected by topugit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested medium Difficulty
2 participants