跳到正文
DEV Community· Ayush S Pangaonkar·· 3 天前AI 評分37

錯過 HackerRank Orchestrate 截止期限後,作者分享未提交的 Ghost Data 解法

I missed the HackerRank Orchestrate deadline, so here is the Ghost Data solution I never submitted

AI 導讀

作者錯過 HackerRank Orchestrate 截止期限,仍完成 Ghost Data 專案,但只在本機執行,沒有提交或放上 GitHub。解法在 32 個公開參考案例中答對 29 個狀態(90.6%),但只有 4 個案例的步驟次序完全正確(12.5%)。程式為全部 518 個請求輸出有效的 output.csv,但這些請求沒有標籤,因此作者沒有聲稱其準確度。

正文

 I missed the HackerRank Orchestrate deadline, so I never submitted. I finished the project anyway, and this is what I built.

The challenge

Ghost Data Still Exists. A fictional company, Northstar Shop, lost $2.4M after a "deleted" customer came back. Every dashboard said Complete, yet the email still couldn't re-register. The data was sitting in search indexes, support attachments, analytics exports, logs and backups.

For each deletion request, the agent must say whether the data is really gone, and if not, what to do. The output is a status (COMPLETE, INCOMPLETE or NOT_APPLICABLE) plus ordered steps in three phases: finding, remediation, verification.

I built and ran this on my local machine only. It isn't on GitHub.

What I built and would defend

1. Negation gets checked first. 8 patterns for "this is not a deletion request", 9 for "this is one". The negations run first, because "Do not close the account" would otherwise match "close ... account". Deletion patterns also cover Spanish, French, German and Japanese. Tested on six requests, including a marketing opt-out.

def request_authorizes_deletion(text: str) -> bool:
    normalized = " ".join(text.casefold().split())
    if any(re.search(pattern, normalized) for pattern in NON_DELETION_PATTERNS):
        return False
    return any(re.search(pattern, normalized) for pattern in DELETION_PATTERNS)

2. Identity comes from two places. I match the request email against the current identity table and against old and new values in the audit log's email changes, only up to the request's audit time. If that resolves to zero users or more than one, the code raises an error instead of guessing.

3. Phone numbers match across formats. I join the digits with \D* so the same number matches with spaces, dashes or a country code:

phone_pattern = r"\D*".join(re.escape(digit) for digit in digits)

4. Evidence comes in many shapes: JSON, SQL dumps, JSON-line, syslog and pipe-delimited logs, cloud-runtime logs (joined by trace and request ID), PDFs and OCR'd images. Table names map to services, so customer_profiles_failover_replica counts as the account service. Easy to forget in a real system.

5. Linking is deliberately strict. A record counts only if it matches the user's id, email, hash, name or phone, or shares a (system, resource, category) key with a record that does. Nearby activity is not proof of ownership. This is the filter, trimmed:

# Ignore time-nearby system activity as a substitute for subject ownership.
# A resource is only relevant when it is directly linked to the request via
# the resolved identities or grounded evidence, not by proximity alone.
matching = [
    record
    for record in records
    if (
        record.source_path != "system_activity.csv"
        or record.values.get("event_type") == "LINK_RESOURCE_IDENTITY"
    )
    and time_leq(record.captured_at, cutoff)
    and (
        record in identity_matches
        or (record.system_id, record.resource_id, record.category) in linked_keys
    )
]

6. Unknown means present. If a record shows no sign of being deleted, redacted or anonymized, record_state falls through to PRESENT. I'd rather report something that might be gone than call it clean.

7. No sample answers are hard-coded into the prediction logic.

Results on the 32 public reference cases

Metric Result
Status correct 29/32 (90.6%)
Exact ordered step sequence 4/32 (12.5%)
Fields matched 809/1,372 (59.0%)
No evidence could be linked 3 cases, counted as wrong

It writes a valid output.csv for all 518 requests. I have no labels for those, so I claim no accuracy on them.

Where it's weak

  • The policy function branches on the English wording of the condition column in deletion_rules.csv ("legal hold", "retention period"). It would break if the wording changed.
  • Support messages, analytics records and backups have the most special-case code, and that's where my treatments go wrong most often.
  • Status is usually right and the plan usually isn't: 29 correct statuses, only 4 fully correct sequences.

Problem statement and dataset: hackerrank-orchestrate-october26.

來源:DEV Community · dev.to