{
  "slug": "palindrome-check",
  "title": "Palindrome Check",
  "category": "Strings",
  "difficulty": "easy",
  "complexity": {
    "time": "O(n)",
    "space": "O(1)"
  },
  "idea": "A palindrome reads the same forwards and backwards. Compare the first and last characters, then step inward. A single mismatch means it is not a palindrome.",
  "code": [
    "lo = 0; hi = n-1",
    "while lo < hi:",
    "    if s[lo] != s[hi]: return false",
    "    lo++; hi--",
    "return true"
  ],
  "example": {
    "array": [],
    "text": "racecar"
  },
  "invariant": "Each step is the real data structure at that step — the picture is a pure function of it.",
  "stepCount": 5,
  "steps": [
    {
      "i": 0,
      "op": "say",
      "caption": "Check whether \"racecar\" is a palindrome.",
      "note": null,
      "codeLine": 1,
      "stats": null,
      "array": [
        114,
        97,
        99,
        101,
        99,
        97,
        114
      ],
      "focus": [
        null,
        null,
        null,
        null,
        null,
        null,
        null
      ],
      "labels": [
        "r",
        "a",
        "c",
        "e",
        "c",
        "a",
        "r"
      ],
      "markers": [],
      "regions": []
    },
    {
      "i": 1,
      "op": "compare",
      "caption": "'r' = 'r' — matches. Step inward.",
      "note": null,
      "codeLine": 2,
      "stats": null,
      "array": [
        114,
        97,
        99,
        101,
        99,
        97,
        114
      ],
      "focus": [
        "compare",
        null,
        null,
        null,
        null,
        null,
        "compare"
      ],
      "labels": [
        "r",
        "a",
        "c",
        "e",
        "c",
        "a",
        "r"
      ],
      "markers": [
        {
          "name": "lo",
          "index": 0,
          "tone": "bound"
        },
        {
          "name": "hi",
          "index": 6,
          "tone": "bound"
        }
      ],
      "regions": []
    },
    {
      "i": 2,
      "op": "compare",
      "caption": "'a' = 'a' — matches. Step inward.",
      "note": null,
      "codeLine": 2,
      "stats": null,
      "array": [
        114,
        97,
        99,
        101,
        99,
        97,
        114
      ],
      "focus": [
        null,
        "compare",
        null,
        null,
        null,
        "compare",
        null
      ],
      "labels": [
        "r",
        "a",
        "c",
        "e",
        "c",
        "a",
        "r"
      ],
      "markers": [
        {
          "name": "lo",
          "index": 1,
          "tone": "bound"
        },
        {
          "name": "hi",
          "index": 5,
          "tone": "bound"
        }
      ],
      "regions": []
    },
    {
      "i": 3,
      "op": "compare",
      "caption": "'c' = 'c' — matches. Step inward.",
      "note": null,
      "codeLine": 2,
      "stats": null,
      "array": [
        114,
        97,
        99,
        101,
        99,
        97,
        114
      ],
      "focus": [
        null,
        null,
        "compare",
        null,
        "compare",
        null,
        null
      ],
      "labels": [
        "r",
        "a",
        "c",
        "e",
        "c",
        "a",
        "r"
      ],
      "markers": [
        {
          "name": "lo",
          "index": 2,
          "tone": "bound"
        },
        {
          "name": "hi",
          "index": 4,
          "tone": "bound"
        }
      ],
      "regions": []
    },
    {
      "i": 4,
      "op": "settle",
      "caption": "Every pair matched — \"racecar\" is a palindrome.",
      "note": null,
      "codeLine": 5,
      "stats": null,
      "array": [
        114,
        97,
        99,
        101,
        99,
        97,
        114
      ],
      "focus": [
        "settled",
        "settled",
        "settled",
        "settled",
        "settled",
        "settled",
        "settled"
      ],
      "labels": [
        "r",
        "a",
        "c",
        "e",
        "c",
        "a",
        "r"
      ],
      "markers": [],
      "regions": []
    }
  ]
}