Zum Hauptinhalt springen
Echtzeit-Radar & Feeds
Alle RSS Feeds ➔
👥 Community & Social
Windows Tipps & SecurityGrafikkarte vor Überhitzung schützen: So geht’s(25.09.2026 um 08:00 Uhr)
••••••••••
Windows Tipps & SecurityGrafikkarte vor Überhitzung schützen: So geht’s(25.09.2026 um 08:00 Uhr)
••••••••••
Intelligence View
⚡ tsecurity.de Intelligence

2825. Make String a Subsequence Using Cyclic Increments

2825. Make String a Subsequence Using Cyclic Increments Difficulty: Medium Topics: Two Pointers, String You are given two 0-indexed strings str1 and str2. In an operation, you select a set of indices in str1, and for each index i in…

0
↗ Quelle (dev.to)
Reagiere als Erste:r — dein Feedback zählt!

2825. Make String a Subsequence Using Cyclic Increments



Difficulty: Medium



Topics: Two Pointers, String



You are given two 0-indexed strings str1 and str2.



In an operation, you select a set of indices in str1, and for each index i in the set, increment str1[i] to the next character cyclically. That is 'a' becomes 'b', 'b' becomes 'c', and so on, and 'z' becomes 'a'.



Return true if it is possible to make str2 a subsequence of str1 by performing the operation at most once, and false otherwise.



Note: A subsequence of a string is a new string that is formed from the original string by deleting some (possibly none) of the characters without disturbing the relative positions of the remaining characters.



Example 1:





  • Input: str1 = "abc", str2 = "ad"


  • Output: true


  • Explanation: Select index 2 in str1.


    • Increment str1[2] to become 'd'.

    • Hence, str1 becomes "abd" and str2 is now a subsequence. Therefore, true is returned.








Example 2:





  • Input: str1 = "zc", str2 = "ad"


  • Output: true


  • Explanation: Select indices 0 and 1 in str1.


    • Increment str1[0] to become 'a'.

    • Increment str1[1] to become 'd'.

    • Hence, str1 becomes "ad" and str2 is now a subsequence. Therefore, true is returned.








Example 3:





  • Input: str1 = "ab", str2 = "d"


  • Output: false


  • Explanation: In this example, it can be shown that it is impossible to make str2 a subsequence of str1 using the operation at most once.


    • Therefore, false is returned.








Constraints:




  • 1 <= str1.length <= 105

  • 1 <= str2.length <= 105


  • str1 and str2 consist of only lowercase English letters.



Hint:




  1. Consider the indices we will increment separately.

  2. We can maintain two pointers: pointer i for str1 and pointer j for str2, while ensuring they remain within the bounds of the strings.

  3. If both str1[i] and str2[j] match, or if incrementing str1[i] matches str2[j], we increase both pointers; otherwise, we increment only pointer i.

  4. It is possible to make str2 a subsequence of str1 if j is at the end of str2, after we can no longer find a match.



Solution:



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
/**
* @param String $str1
* @param String $str2
* @return Boolean
*/

function canMakeSubsequence($str1, $str2) {
...
...
...
/**
* go to ./solution.php
*/

}

// Example Usage
$str1 = "abc";
$str2 = "ad";
echo canMakeSubsequence($str1, $str2) ? 'true' : 'false'; // Output: true

$str1 = "zc";
$str2 = "ad";
echo canMakeSubsequence($str1, $str2) ? 'true' : 'false'; // Output: true

$str1 = "ab";
$str2 = "d";
echo canMakeSubsequence($str1, $str2) ? 'true' : 'false'; // Output: false
?>









Explanation:





  1. Two Pointers: i and j are initialized to the start of str1 and str2, respectively.


  2. Matching Logic: Inside the loop, we check if the characters at str1[i] and str2[j] are the same or if we can increment str1[i] to match str2[j] cyclically.


    • The cyclic increment condition is handled using (ord($str1[$i]) + 1 - ord('a')) % 26 which checks if str1[i] can be incremented to match str2[j].




  3. Subsequence Check: If we have iterated through str2 completely (i.e., j == m), it means str2 is a subsequence of str1. Otherwise, it's not.






Time Complexity:




  • The algorithm iterates through str1 once, and each character in str2 is checked only once, so the time complexity is O(n), where n is the length of str1.






Space Complexity:




  • The space complexity is O(1) since we only use a few pointers and do not need extra space dependent on the input size.



This solution efficiently checks if it's possible to make str2 a subsequence of str1 with at most one cyclic increment operation.



Contact Links



If you found this series helpful, please consider giving the repository a star on GitHub or sharing the post on your favorite social networks 😍. Your support would mean a lot to me!



If you want more helpful content like this, feel free to follow me:



1. Sofort-Triage & Abwehrmaßnahmen

SOC Incident Playbook: Vulnerability Remediation & Verification
Syntax validiert (0 Fehler)
title: Detect Exploitation - 2825. Make String a Subsequence Using Cyclic Increments
id: 208b6ac0-fd3b-43d7-a057-74dc8ebc30ac
status: experimental
description: Automatisch generierte SIEM-Erkennungsregel basierend auf CTI Intelligence
references:
  - https://tsecurity.de/
author: iShareStuff CTI Automated Detection Engine
date: 2026-09-27
logsource:
  category: network_connection
  product: any
detection:
  selection:
      CommandLine|contains:
        - 'exploit'
  condition: selection
falsepositives:
  - Legitime administrative Zugriffe oder Penetrationstests
level: high
tags:
  - attack.initial_access
Syntax validiert (0 Fehler)
rule CTI_Threat_Indicator {
    meta:
        author = "iShareStuff CTI Automated Detection Engine"
        date = "2026-09-27"
        description = "YARA Signature for "
    strings:
        $str = "2825. Make String a Subsequenc" ascii wide
    condition:
        any of them
}
Syntax validiert (0 Fehler)
index=security sourcetype IN ("cisco:asa", "pan:traffic", "zeek_conn", "suricata", "WinEventLog:Security")
("2825 Make String a Subsequence Using Cyc")
| stats count earliest(_time) as first_seen latest(_time) as last_seen by src_ip, dest_ip, dest_host, signature
| eval first_seen=strftime(first_seen, "%Y-%m-%d %H:%M:%S"), last_seen=strftime(last_seen, "%Y-%m-%d %H:%M:%S")
| sort - count
Syntax validiert (0 Fehler)
message: "*2825 Make String a Subsequence Using Cyc*"
Syntax validiert (0 Fehler)
CommonSecurityLog
| where Message has "2825 Make String a Subsequence Using Cyc"
| summarize EventCount = count(), FirstSeen = min(TimeGenerated), LastSeen = max(TimeGenerated) by SourceIP, DestinationIP, DestinationPort, Activity
| extend DetectionRule = "iShareStuff-CTI-Compiled"
| sort by EventCount desc

2. Cyber Threat Intelligence & Forensik

🎯
MITRE ATT&CK Matrix Navigator 14 Taktiken
Reconnaissance
-
Resource Development
-
Initial Access
Execution
Persistence
-
Privilege Escalation
Defense Evasion
Credential Access
-
Discovery
-
Lateral Movement
-
Collection
-
Command and Control
Exfiltration
-
Impact
tsecurity.de Cognitive Threat RAG
Fokus-Vektor:

Analyse für identifizierte Bedrohung auf Basis von Live-CTI (ENISA EUVD): CVSS 0.0 · EPSS 0.0% · CISA KEV: nein. Handlungsableitung aus den verlinkten Hersteller-Quellen.

🛡️ Angriffsfläche & Exposure

Netzwerk/Remote-Zugriff ohne Vorauthentifizierung möglich.

⚡ Empfohlene Sofortmaßnahmen
  • 1. Perimeter-Inspektion: Relevante Portfreigaben und exponierte Endpunkte unverzüglich scannen.
  • 2. Patch-Applikation: Hersteller-Hotfix einspielen oder betroffene Daemons in isolierte DMZ-Segmente überführen.
  • 3. Telemetrie & EDR-Alerts: Prozessaufrufe und Child-Processes auf anomale Shell-Spawns überwachen.
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten 2825. Make String a Subsequence Using Cyclic Increments

Thematisch verwandte Begriffe: 2825, Make, String, Subsequence · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

💬 Kommentare werden geladen…
Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-100739 | A vulnerability was detected in mathurvishal CloudClassroom-PHP-Project…
Advisory →
tsecurity.de Icon
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag