Zum Hauptinhalt springen
Echtzeit-Radar & Feeds
Alle RSS Feeds ➔
👥 Community & Social
••
IT NachrichtenMicrosoft puts Brad Smith in charge of communications(25.09.2026 um 00:08 Uhr)
••
IT Nachrichten25. September(25.09.2026 um 00:05 Uhr)
•
IT NachrichtenCI-Solution GmbH von Crossware übernommen(25.09.2026 um 00:01 Uhr)
•
IT NachrichtenInsta360 GO Ultra erhält KI-Sprachassistenten mit Gemini(24.09.2026 um 21:30 Uhr)
••
AI & KI NachrichtenMaryland Governor Draws New Boundaries for Data Centers(25.09.2026 um 00:04 Uhr)
••••
IT NachrichtenMicrosoft puts Brad Smith in charge of communications(25.09.2026 um 00:08 Uhr)
••
IT Nachrichten25. September(25.09.2026 um 00:05 Uhr)
•
IT NachrichtenCI-Solution GmbH von Crossware übernommen(25.09.2026 um 00:01 Uhr)
•
IT NachrichtenInsta360 GO Ultra erhält KI-Sprachassistenten mit Gemini(24.09.2026 um 21:30 Uhr)
••
AI & KI NachrichtenMaryland Governor Draws New Boundaries for Data Centers(25.09.2026 um 00:04 Uhr)
••
Intelligence View
⚡ tsecurity.de Intelligence

3318. Find X-Sum of All K-Long Subarrays I

3318. Find X-Sum of All K-Long Subarrays I Difficulty: Easy Topics: Array, Hash Table, Sliding Window, Heap (Priority Queue), Weekly Contest 419 You are given an array nums of n integers and two integers k and x. The x-sum of an array…

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

3318. Find X-Sum of All K-Long Subarrays I



Difficulty: Easy



Topics: Array, Hash Table, Sliding Window, Heap (Priority Queue), Weekly Contest 419



You are given an array nums of n integers and two integers k and x.



The x-sum of an array is calculated by the following procedure:




  • Count the occurrences of all elements in the array.

  • Keep only the occurrences of the top x most frequent elements. If two elements have the same number of occurrences, the element with the bigger value is considered more frequent.

  • Calculate the sum of the resulting array.



Note that if an array has less than x distinct elements, its x-sum is the sum of the array.



Return an integer array answer of length n - k + 1 where answer[i] is the x-sum of the subarray1 nums[i..i + k - 1].



Example 1:





  • Input: nums = [1,1,2,2,3,4,2,3], k = 6, x = 2


  • Output: [6,10,12]


  • Explanation:


    • For subarray [1, 1, 2, 2, 3, 4], only elements 1 and 2 will be kept in the resulting array. Hence, answer[0] = 1 + 1 + 2 + 2.

    • For subarray [1, 2, 2, 3, 4, 2], only elements 2 and 4 will be kept in the resulting array. Hence, answer[1] = 2 + 2 + 2 + 4. Note that 4 is kept in the array since it is bigger than 3 and 1 which occur the same number of times.

    • For subarray [2, 2, 3, 4, 2, 3], only elements 2 and 3 are kept in the resulting array. Hence, answer[2] = 2 + 2 + 2 + 3 + 3.








Example 2:





  • Input: nums = [3,8,7,8,7,5], k = 2, x = 2


  • Output: [11,15,15,15,12]


  • Explanation: Since k == x, answer[i] is equal to the sum of the subarray nums[i..i + k - 1].



Constraints:




  • 1 <= n == nums.length <= 50

  • 1 <= nums[i] <= 50

  • 1 <= x <= k <= nums.length



Hint:




  1. Implement the x-sum function. Then, run x-sum on every subarray of nums of size k.



Solution:



We need to calculate the x-sum for every contiguous subarray of length k in the given array nums. The x-sum of an array is defined as the sum of all elements that belong to the top x most frequent elements. If there are ties in frequency, the element with the larger value is considered more frequent. If there are fewer than x distinct elements, the x-sum is simply the sum of all elements in the subarray.






Approach





  1. Sliding Window Technique: We use a sliding window of size k to iterate through all possible subarrays of length k in nums.


  2. Frequency Counting: For each window, we count the frequency of each element using a hash map.


  3. Sorting by Frequency and Value: We sort the distinct elements in the window based on their frequencies (descending) and their values (descending) to determine the top x elements.


  4. Calculate x-sum: We compute the sum of all elements in the window that are among the top x elements identified in the previous step.



Let's implement this solution in PHP: 3318. Find X-Sum of All K-Long Subarrays I




<?php
/**
* @param Integer[] $nums
* @param Integer $k
* @param Integer $x
* @return Integer[]
*/

function findXSum($nums, $k, $x) {
...
...
...
/**
* go to ./solution.php
*/

}

// Test cases
// Example 1
$nums = array(1, 1, 2, 2, 3, 4, 2, 3);
$k = 6;
$x = 2;
print_r(findXSum($nums, $k, $x));
// Output: [6, 10, 12]

// Example 2
$nums = array(3, 8, 7, 8, 7, 5);
$k = 2;
$x = 2;
print_r(findXSum($nums, $k, $x));
// Output: [11, 15, 15, 15, 12]
?>









Explanation:





  1. Initialization: We initialize the result array to store the x-sum for each window.


  2. Sliding Window: For each starting index i from 0 to n - k, we extract the subarray of length k starting at i.


  3. Frequency Map: We count the occurrences of each element in the current window using a hash map.


  4. Sorting: We sort the distinct elements in the window first by their frequency in descending order, and then by their value in descending order to handle ties.


  5. Top x Elements: We select the top x elements from the sorted distinct elements.


  6. Sum Calculation: We iterate through the window and sum all elements that are in the top x elements.


  7. Store Result: The computed sum for the current window is stored in the result array.



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!

Buy Me A Coffee



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











  1. Subarray: A subarray is a contiguous non-empty sequence of elements within an array. ↩




CTI Threat Relationship Graph2 Knoten / 1 Relationen
CVE / Incident Software MITRE ATT&CK CWE Weakness IoC
SOC Incident Playbook: Vulnerability Remediation & Verification
Syntax validiert (0 Fehler)
title: Detect Exploitation - 3318. Find X-Sum of All K-Long Subarrays I
id: 8a460001-f833-4334-87e8-cedcdb729037
status: experimental
description: Automatisch generierte SIEM-Erkennungsregel basierend auf CTI Intelligence
references:
  - https://tsecurity.de/
author: iShareStuff CTI Automated Detection Engine
date: 2026-09-25
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-25"
        description = "YARA Signature for "
    strings:
        $str = "3318. Find X-Sum of All K-Long" ascii wide
    condition:
        any of them
}
Syntax validiert (0 Fehler)
index=security sourcetype IN ("cisco:asa", "pan:traffic", "zeek_conn", "suricata", "WinEventLog:Security")
("3318 Find X-Sum of All K-Long Subarrays ")
| 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: "*3318 Find X-Sum of All K-Long Subarrays *"
Syntax validiert (0 Fehler)
CommonSecurityLog
| where Message has "3318 Find X-Sum of All K-Long Subarrays "
| summarize EventCount = count(), FirstSeen = min(TimeGenerated), LastSeen = max(TimeGenerated) by SourceIP, DestinationIP, DestinationPort, Activity
| extend DetectionRule = "iShareStuff-CTI-Compiled"
| sort by EventCount desc
🎯
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:

Kognitive Analyse für identifizierte Bedrohung: Erhöhte Bedrohungslage im Bereich 3318. Find X-Sum of All K-Long Subarrays.... Basierend auf 368k Vektor-Korrelationen werden sofortige Isolationsmaßnahmen für betroffene Endpunkte empfohlen.

🛡️ 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.
🔗 Semantisch verwandte Zero-Days MariaDB 11.7 VEC
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten 3318. Find X-Sum of All K-Long Subarrays I

Thematisch verwandte Begriffe: 3318, Find, XSum, KLong · 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 ...

Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-82585 | The Botslab G980H dash camera firmware transmits sensitive information o…
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
Themen-Radar & Intelligence Matrix
Echtzeit-Taxonomie nach Angriffsvektoren & Plattformen

tsecurity.de Live Threat Radar

🔴 LIVE RADAR
MONITORING
AKTIV
CVE-DATENBANK
LIVE
🔍
Community Radar & Live Chat
Sentinel Bot online • Live-Stream
Dein Cluster: Security Explorer
Match:
lädt…
Verbindung zum Community-Stream wird aufgebaut...
Bearbeitungsmodus — Senden überschreibt deine Nachricht
Community-Puls — was gerade passiert
lädt…
Aktivitäten deiner Analysten
lädt…
Neues Thema oder Eilmeldung einreichen

Reiche interessante Links, Zero-Days oder Debatten ein. Die Community entscheidet per Upvote über die Veröffentlichung.

Heiß diskutierte Einreichungen
📂 Keine gespeicherten Artikel vorhanden.
Zurück Ziehen Vor
Links: vorheriger Artikel • Rechts: nächster Artikel • unten: schließen
News NIS-2 Frühwarnung Tier-1 Intel TTP ⏱️ 3 Min vor 10 Min
Artikeldaten werden geladen...
↗ Original-Quelle