{"id":"find-first-and-last-position-of-element-in-sorted-array","title":"Find First and Last Position of Element in Sorted Array","difficulty":"medium","patterns":["binary-search"],"primaryConcept":"binary-search-modified","concepts":["binary-search-modified"],"problemForm":"core","companies":[],"category":"searching-sorting","compareMode":"exact","description":"Given a sorted array of integers `nums` and an integer `target`, return `[first, last]`, where `first` is the first index where `target` appears and `last` is the last index where it appears. If `target` does not appear, return `[-1, -1]`.\n\nRequirements:\n- `nums` is sorted in ascending order.\n- Duplicates may appear.\n- Your solution should run in O(log n) time.","requiredComplexity":[{"metric":"time","bound":"O(log n)","scope":"function","functions":["searchRange"],"case":"worst","enforcement":"hard","reason":"The prompt requires O(log n) time."}],"examples":[{"input":"nums = [5,7,7,8,8,10], target = 8","output":"[3,4]","explanation":"The target 8 starts at index 3 and ends at index 4."},{"input":"nums = [5,7,7,8,8,10], target = 6","output":"[-1,-1]","explanation":"6 is not present in the array."},{"input":"nums = [1,1,1,1,1,1,1], target = 1","output":"[0,6]","explanation":"Every value is the target, so the range covers the whole array."}],"constraints":[{"id":"0-len-nums-10-5","text":"0 <= len(nums) <= 10^5","check":{"kind":"sizeRange","target":"nums","measure":"arrayLength","min":0,"max":100000}},{"id":"10-9-nums-i-10-9","text":"-10^9 <= nums[i] <= 10^9"},{"id":"nums-is-sorted-in-ascending-order","text":"nums is sorted in ascending order.","check":{"kind":"ordering","target":"nums","order":"nondecreasing","selector":"items"}},{"id":"10-9-target-10-9","text":"-10^9 <= target <= 10^9"}],"starterCode":"class Solution:\n    def searchRange(self, nums: list[int], target: int) -> list[int]:\n        # Your code here\n        pass","functionName":"searchRange","testCases":[{"id":"1","input":{"nums":[5,7,7,8,8,10],"target":8},"expected":[3,4],"description":"Target appears in the middle."},{"id":"2","input":{"nums":[5,7,7,8,8,10],"target":6},"expected":[-1,-1],"description":"Target is absent."},{"id":"3","input":{"nums":[],"target":0},"expected":[-1,-1],"description":"Empty array."},{"id":"4","input":{"nums":[1],"target":1},"expected":[0,0],"description":"Single matching value."},{"id":"5","input":{"nums":[1,1,1,1,1,1,1],"target":1},"expected":[0,6],"description":"Imported all-target seed case."},{"id":"h1","input":{"nums":[2,2,2,3,4],"target":2},"expected":[0,2],"description":"A run of duplicates at the beginning."},{"id":"h2","input":{"nums":[1,2,3,4,4,4],"target":4},"expected":[3,5],"description":"A run of duplicates at the end."},{"id":"h3","input":{"nums":[5,5,5],"target":4},"expected":[-1,-1],"description":"An absent target in an all-equal array."},{"id":"h4","input":{"nums":[1],"target":2},"expected":[-1,-1],"description":"A single-element miss."},{"id":"h5","input":{"nums":[-3,-2,-2,-1],"target":-2},"expected":[1,2],"description":"Negative values with a duplicate target."},{"id":"topup-1","input":{"nums":[-5,-5,-5,-2,0,0,3],"target":-5},"expected":[0,2],"description":"Top-up case 1: the target run can start at index zero with negative values."},{"id":"topup-2","input":{"nums":[1,2,2,2,3,4,4,5],"target":4},"expected":[5,6],"description":"Top-up case 2: a duplicate target near the tail is found without including the final larger value."}],"hints":[{"level":1,"content":"Finding one occurrence is not enough. After a hit, keep searching toward the side whose boundary you need.","revealPattern":false},{"level":2,"content":"Use the same binary-search helper twice: once biased left, once biased right.","revealPattern":true},{"level":3,"content":"When `nums[mid] == target`, save `mid`; then move `right = mid - 1` for the first position or `left = mid + 1` for the last position.","revealPattern":true}],"guidedFlow":{"approachSelection":{"contract":"approach-selection-v1","question":"Which approach should we implement?","decisionPrompt":"Choose the approach whose state and complexity match the problem constraints.","approaches":[{"id":"hit-then-scan","name":"Find one hit, then scan outward","summary":"Use binary search for one target index, then expand left and right while values match.","decisionReason":"Finding one 8 is fast, but walking outward past every neighboring 8 is the part that scales with the run. On an array that is all 8s, that walk touches every index, so the whole call slips back to O(n).","complexity":{"time":"O(log n + k), worst-case O(n)","space":"O(1)"},"tradeoffs":["Runs in O(log n + k), worst-case O(n) time and uses O(1) space."],"isOptimal":false},{"id":"two-boundary-searches","name":"Two biased binary searches","summary":"Run one binary search for the left edge and one for the right edge.","decisionReason":"Each run is an ordinary binary search that never stops on the first 8. It records the hit and keeps halving toward the edge, so even a run of a million 8s costs two O(log n) passes.","complexity":{"time":"O(log n)","space":"O(1)"},"tradeoffs":["Runs in O(log n) time and uses O(1) space."],"isOptimal":true}]},"codingCheckpoints":[{"id":"bounds","title":"Initialize the helper search bounds","description":"Inside the boundary helper, set up a closed binary-search window.","validation":{"type":"semantic","validator":"familyFact","params":[{"family":"binary-search","fact":"initializes_search_bounds","scope":"init-pointers","readMode":"binary-search-value-query-v1"}]},"commonMistakes":["Using a past-the-end upper bound with closed-interval updates","Forgetting the helper should handle an empty array"],"hint":"Use the first and last valid indices as the closed search bounds.","semanticSpec":{"intent":"Initialize a closed binary-search window for the boundary helper.","doneWhen":"This step is done when the helper seeds left and right to the first and last valid indices.","shouldFailWhen":"This step should fail if explicit search bounds are missing or seeded inconsistently with the loop.","roles":["lower bound","upper bound","sorted input"],"mustProve":["The lower bound starts at the first index.","The upper bound starts at the last valid index.","The bounds are available before midpoint probing."],"mustNotAccept":["Starting from a partial array range.","Using a half-open upper bound with closed updates.","Scanning linearly without search bounds."],"equivalentVariants":["Use the first valid index for the lower bound and the last valid index for the upper bound.","Use equivalent bound variable names."],"proofSnippets":[{"id":"py-range-bounds","language":"python","code":"class Solution:\n    def searchRange(self, nums: list[int], target: int) -> list[int]:\n        def find_bound(is_left: bool) -> int:\n            left, right = 0, len(nums) - 1\n            while left <= right:\n                return -1\n            return -1\n        return [-1, -1]"}]}},{"id":"midpoint","title":"Probe the midpoint","description":"Compute mid from the active helper bounds and compare nums[mid] with target.","validation":{"type":"semantic","validator":"familyFact","params":[{"family":"binary-search","fact":"computes_midpoint_from_bounds","scope":"calculate-mid","readMode":"binary-search-value-query-v1"}]},"commonMistakes":["Computing mid from the original array length each time","Comparing target against the wrong index"],"hint":"The midpoint should come from left and right inside the loop.","semanticSpec":{"intent":"Compute the midpoint from the current helper bounds.","doneWhen":"This step is done when the loop assigns mid from left and right before reading nums[mid].","shouldFailWhen":"This step should fail if mid is fixed, unrelated to the bounds, or missing.","roles":["lower bound","upper bound","midpoint","target probe"],"mustProve":["The midpoint is assigned inside the search loop.","The midpoint depends on both bounds.","The midpoint is used to probe the sorted input."],"mustNotAccept":["Using a constant midpoint.","Computing mid from only one bound.","Looping without a midpoint probe."],"equivalentVariants":["Use `(left + right) // 2`.","Use `left + (right - left) // 2`."],"proofSnippets":[{"id":"py-range-midpoint","language":"python","code":"class Solution:\n    def searchRange(self, nums: list[int], target: int) -> list[int]:\n        def find_bound(is_left: bool) -> int:\n            left, right = 0, len(nums) - 1\n            while left <= right:\n                mid = (left + right) // 2\n                if nums[mid] < target:\n                    left = mid + 1\n                else:\n                    right = mid - 1\n            return -1\n        return [-1, -1]"}]}},{"id":"record-hit","title":"Record a matching midpoint","description":"When nums[mid] equals target, save mid as the current best boundary candidate.","validation":{"type":"semantic","validator":"familyFact","params":[{"family":"binary-search","fact":"records_midpoint_hit_candidate","scope":"record-hit","readMode":"binary-search-value-query-v1"}]},"commonMistakes":["Returning immediately on the first hit","Forgetting to save the matching index before continuing"],"hint":"A hit proves one valid answer, but not necessarily the first or last one.","semanticSpec":{"intent":"Record the midpoint index when it is an exact target hit.","doneWhen":"This step is done when an equality branch saves mid into a result candidate.","shouldFailWhen":"This step should fail if the code keeps searching after a hit without saving the hit index.","roles":["midpoint","target equality","recorded candidate"],"mustProve":["The code checks nums[mid] against target.","The equality branch records the midpoint index.","The recorded state is separate from the moving bounds."],"mustNotAccept":["Returning mid immediately as the final answer.","Recording an unrelated index.","Only updating bounds on equality."],"equivalentVariants":["Use `index = mid` on equality.","Use another result variable to remember the latest matching midpoint."],"proofSnippets":[{"id":"py-range-record-hit","language":"python","code":"class Solution:\n    def searchRange(self, nums: list[int], target: int) -> list[int]:\n        def find_bound(is_left: bool) -> int:\n            left, right = 0, len(nums) - 1\n            index = -1\n            while left <= right:\n                mid = (left + right) // 2\n                if nums[mid] == target:\n                    index = mid\n                    right = mid - 1\n                elif nums[mid] < target:\n                    left = mid + 1\n                else:\n                    right = mid - 1\n            return -1\n        return [-1, -1]"}]}},{"id":"refine-boundary","title":"Keep searching toward the requested edge","description":"After recording a hit, move left for the last edge or right for the first edge.","validation":{"type":"semantic","validator":"familyFact","params":[{"family":"binary-search","fact":"refines_hit_candidate_boundary","scope":"search-left-and-right-boundaries","readMode":"binary-search-value-query-v1"}]},"commonMistakes":["Only searching left after a hit","Only searching right after a hit","Discarding the saved hit while moving the bounds"],"hint":"The helper needs both behaviors: first boundary moves right leftward; last boundary moves left rightward.","semanticSpec":{"intent":"Continue binary search after a hit so the helper can find either boundary.","doneWhen":"This step is done when the recorded-hit branch can refine toward both lower and upper target boundaries.","shouldFailWhen":"This step should fail if hits are recorded but the helper only searches one side.","roles":["recorded candidate","left boundary search","right boundary search","bound refinement"],"mustProve":["The equality branch records the midpoint.","The helper can move the upper bound leftward after a hit.","The helper can move the lower bound rightward after a hit."],"mustNotAccept":["Stopping at the first hit.","Only implementing the left-bound search.","Only implementing the right-bound search."],"equivalentVariants":["Use an `is_left` flag to choose the hit-side refinement.","Use equivalent helper logic that supports both boundary directions."],"proofSnippets":[{"id":"py-range-refine-boundary","language":"python","code":"class Solution:\n    def searchRange(self, nums: list[int], target: int) -> list[int]:\n        def find_bound(is_left: bool) -> int:\n            left, right = 0, len(nums) - 1\n            index = -1\n            while left <= right:\n                mid = (left + right) // 2\n                if nums[mid] == target:\n                    index = mid\n                    if is_left:\n                        right = mid - 1\n                    else:\n                        left = mid + 1\n                elif nums[mid] < target:\n                    left = mid + 1\n                else:\n                    right = mid - 1\n            return -1\n        return [-1, -1]"}]}},{"id":"return-boundary","title":"Return the recorded boundary","description":"After the helper finishes, return the best matching index it recorded.","validation":{"type":"semantic","validator":"familyFact","params":[{"family":"binary-search","fact":"returns_recorded_hit_candidate","scope":"return-recorded-boundary","readMode":"binary-search-value-query-v1"}]},"commonMistakes":["Returning left or right instead of the saved matching index","Returning mid after the loop"],"hint":"The helper should return the saved candidate, which remains -1 if no hit was found.","semanticSpec":{"intent":"Return the recorded hit candidate from the boundary helper.","doneWhen":"This step is done when the helper returns the saved matching index after the loop.","shouldFailWhen":"This step should fail if the helper returns a moving boundary or stale midpoint instead of the recorded hit.","roles":["recorded candidate","miss sentinel","helper return"],"mustProve":["A target hit records the midpoint candidate.","The hit candidate can be refined toward either side.","The helper returns that recorded candidate after the loop."],"mustNotAccept":["Returning the lower bound.","Returning the upper bound.","Returning a stale midpoint."],"equivalentVariants":["Return `index` after the helper loop.","Return an equivalent saved hit variable initialized to -1."],"proofSnippets":[{"id":"py-range-return-boundary","language":"python","code":"class Solution:\n    def searchRange(self, nums: list[int], target: int) -> list[int]:\n        def find_bound(is_left: bool) -> int:\n            left, right = 0, len(nums) - 1\n            index = -1\n            while left <= right:\n                mid = (left + right) // 2\n                if nums[mid] == target:\n                    index = mid\n                    if is_left:\n                        right = mid - 1\n                    else:\n                        left = mid + 1\n                elif nums[mid] < target:\n                    left = mid + 1\n                else:\n                    right = mid - 1\n            return index\n        return [-1, -1]"}]}}],"version":2,"slides":[{"id":"opener","chapter":"The obvious way","kind":"info","eyebrow":"Read the task","title":"Find where a value starts and where it stops","workspacePanel":"problem","body":["nums is sorted and may repeat a value many times. For a target, return its first and last indices. If it is missing, return -1 for both positions.","The array is sorted, so every copy of the target is packed into one contiguous run. The job is to pin down both ends of that run in O(log n)."]},{"id":"brute-force","chapter":"The obvious way","kind":"code-trace","eyebrow":"Start naive","title":"Scan every index and remember the first and last 8","summary":"Ignore the sorted order for a moment. Walk the whole array left to right, recording the first index that holds an 8 and updating the last one on every later hit.","workspacePanel":"trace","body":["Traced on nums = [8, 8, 8, 8, 8], target = 8. The scan reads every element, sets first the moment it sees an 8, and keeps moving last forward to the most recent 8."],"codeTrace":{"contract":"code-trace-v1","languageLabel":"Python","editorLanguage":"python","code":"first = -1\nlast = -1\nfor i in range(len(nums)):\n    if nums[i] == target:\n        if first == -1:\n            first = i\n        last = i\nreturn [first, last]","localizations":{"javascript":{"languageLabel":"JavaScript","editorLanguage":"javascript","codeStyle":"natural","code":"let first = -1;\nlet last = -1;\nfor (let i = 0; i < nums.length; i++) {\n    if (nums[i] === target) {\n        if (first === -1) {\n            first = i;\n        }\n        last = i;\n    }\n}\nreturn [first, last];","lineMap":{"1":1,"2":2,"3":3,"4":4,"5":5,"6":6,"7":8,"8":11},"statementBundles":{"6":{"startLine":6,"endLine":7},"7":{"startLine":8,"endLine":10}}},"typescript":{"languageLabel":"TypeScript","editorLanguage":"typescript","codeStyle":"natural","code":"let first = -1;\nlet last = -1;\nfor (let i = 0; i < nums.length; i++) {\n    if (nums[i] === target) {\n        if (first === -1) {\n            first = i;\n        }\n        last = i;\n    }\n}\nreturn [first, last];","lineMap":{"1":1,"2":2,"3":3,"4":4,"5":5,"6":6,"7":8,"8":11},"statementBundles":{"6":{"startLine":6,"endLine":7},"7":{"startLine":8,"endLine":10}}},"java":{"languageLabel":"Java","editorLanguage":"java","codeStyle":"natural","code":"int first = -1;\nint last = -1;\nfor (int i = 0; i < nums.size(); i++) {\n    if (nums.get(i) == target) {\n        if (first == -1) {\n            first = i;\n        }\n        last = i;\n    }\n}\nreturn List.of(first, last);","lineMap":{"1":1,"2":2,"3":3,"4":4,"5":5,"6":6,"7":8,"8":11},"statementBundles":{"6":{"startLine":6,"endLine":7},"7":{"startLine":8,"endLine":10}}},"csharp":{"languageLabel":"C#","editorLanguage":"csharp","codeStyle":"natural","code":"int first = -1;\nint last = -1;\nfor (int i = 0; i < nums.Count; i++) {\n    if (nums[i] == target) {\n        if (first == -1) {\n            first = i;\n        }\n        last = i;\n    }\n}\nreturn new List<int> { first, last };","lineMap":{"1":1,"2":2,"3":3,"4":4,"5":5,"6":6,"7":8,"8":11},"statementBundles":{"6":{"startLine":6,"endLine":7},"7":{"startLine":8,"endLine":10}}},"cpp":{"languageLabel":"C++","editorLanguage":"cpp","codeStyle":"natural","code":"int first = -1;\nint last = -1;\nfor (int i = 0; i < nums.size(); i++) {\n    if (nums[i] == target) {\n        if (first == -1) {\n            first = i;\n        }\n        last = i;\n    }\n}\nreturn vector<int>{first, last};","lineMap":{"1":1,"2":2,"3":3,"4":4,"5":5,"6":6,"7":8,"8":11},"statementBundles":{"6":{"startLine":6,"endLine":7},"7":{"startLine":8,"endLine":10}}}},"steps":[{"id":"bf-first-hit","title":"The scan reaches index 0 and sets first","summary":"nums[0] is 8, an exact hit, and first is still -1, so first becomes 0. last is set to 0 as well.","codeLine":5,"state":{"nums":[8,8,8,8,8],"target":8,"i":0,"first":0,"last":0,"labels":{"i":"i"}}},{"id":"bf-keep-scanning","title":"Every later 8 only pushes last forward","summary":"At index 1 the value is 8, but first is already set, so only last moves to 1. The scan keeps reading on.","codeLine":7,"state":{"nums":[8,8,8,8,8],"target":8,"i":1,"first":0,"last":1,"labels":{"i":"i"}}},{"id":"bf-last-hit","title":"The final 8 lands at the end of the array","summary":"The scan reaches index 4, the last element. It is 8, so last moves to 4. There is nothing left to read.","codeLine":7,"state":{"nums":[8,8,8,8,8],"target":8,"i":4,"first":0,"last":4,"labels":{"i":"i"}}},{"id":"bf-return","title":"Return the recorded ends","summary":"first is 0 and last is 4, so the answer is [0, 4]. Getting here read all five elements, one at a time.","codeLine":8,"state":{"nums":[8,8,8,8,8],"target":8,"first":0,"last":4}}]}},{"id":"waste-probe","chapter":"The obvious way","kind":"case-probe","eyebrow":"Count the work","title":"How many elements does the scan read before it can return?","summary":"nums is a million values and target sits at the very end.","workspacePanel":"trace","options":[{"id":"linear","label":"About n, the scan reads every element","rationale":"The loop has no way to stop early: last can still move on the final index, so the scan must reach the end. With a million values it does a million reads, which is O(n).","isCorrect":true},{"id":"log","label":"About log n, the scan can halve the array","rationale":"A plain left-to-right loop never halves anything. It steps one index at a time and ignores the sorted order entirely.","isCorrect":false},{"id":"constant","label":"A constant few, it stops at the first 8","rationale":"It cannot stop at the first 8: a later 8 would still update last, so the loop has to keep reading to the end to be sure it found the last one.","isCorrect":false}],"answer":"The scan is O(n): it reads every element because the last position could be anywhere, even the final index. The prompt asks for O(log n), so a loop that touches all n values is too slow."},{"id":"discovery-probe","chapter":"The trick","kind":"case-probe","eyebrow":"Find the move","title":"After landing on an 8, how do you reach the first 8 without walking?","summary":"On nums = [5, 7, 7, 8, 8, 10], target = 8, binary search lands on index 4 first. The leftmost 8 is index 3.","workspacePanel":"visualizer","visualTrace":{"contract":"guided-visual-trace-v1","steps":[{"id":"discovery-state","state":{"nums":[5,7,7,8,8,10],"target":8,"left":3,"right":5,"mid":4}}]},"options":[{"id":"record-keep-left","label":"Save index 4 as a candidate, then keep binary-searching the left half","rationale":"Index 4 is a real 8, so it is a valid answer to remember. Discarding the right half and searching left lets a later, smaller index overwrite it, and binary search keeps halving the whole way.","isCorrect":true},{"id":"return-now","label":"Return index 4 immediately, it is a confirmed match","rationale":"It is a match, but not necessarily the first one. Stopping here reports a middle index as if it were the boundary.","isCorrect":false},{"id":"step-left","label":"Step left from index 4 one index at a time until the value drops below the target","rationale":"Stepping one index at a time is O(n) on a long run, the same trap the linear scan fell into. The point is to use the sorted order, not crawl through it.","isCorrect":false}],"answer":"Treat the hit as a candidate: save the index, throw away the right half, and keep searching left. The last index you save is the first 8."},{"id":"approach-selection","chapter":"The trick","kind":"choice","source":"approach-selection","eyebrow":"Pick the route","title":"Walk outward from one hit, or binary-search each edge?","summary":"Both find the range. They differ in what the duplicate run costs.","workspacePanel":"visualizer","visualTrace":{"contract":"guided-visual-trace-v1","steps":[{"id":"approach-state","state":{"nums":[5,7,7,8,8,10],"target":8,"left":0,"right":5}}]},"selection":{"contract":"approach-selection-v1","question":"Which approach should we implement?","decisionPrompt":"Choose the approach whose state and complexity match the problem constraints.","approaches":[{"id":"hit-then-scan","name":"Find one hit, then scan outward","summary":"Use binary search for one target index, then expand left and right while values match.","decisionReason":"Finding one 8 is fast, but walking outward past every neighboring 8 is the part that scales with the run. On an array that is all 8s, that walk touches every index, so the whole call slips back to O(n).","complexity":{"time":"O(log n + k), worst-case O(n)","space":"O(1)"},"tradeoffs":["Runs in O(log n + k), worst-case O(n) time and uses O(1) space."],"isOptimal":false},{"id":"two-boundary-searches","name":"Two biased binary searches","summary":"Run one binary search for the left edge and one for the right edge.","decisionReason":"Each run is an ordinary binary search that never stops on the first 8. It records the hit and keeps halving toward the edge, so even a run of a million 8s costs two O(log n) passes.","complexity":{"time":"O(log n)","space":"O(1)"},"tradeoffs":["Runs in O(log n) time and uses O(1) space."],"isOptimal":true}]}},{"id":"dry-run-setup","chapter":"Trace","kind":"info","eyebrow":"Set the scene","title":"One helper, biased toward the first 8","workspacePanel":"visualizer","body":["left and right start at the two ends, and a saved index holds the best 8 seen so far. It begins unset.","Each round computes mid as usual. A miss moves a boundary the normal way. A hit does something new: it saves mid, then keeps the left half alive by moving right to mid - 1.","Watch where the saved index ends up by the time the window empties."],"visualTrace":{"contract":"guided-visual-trace-v1","steps":[{"id":"setup-state","state":{"nums":[5,7,7,8,8,10],"target":8,"left":0,"right":5}}]}},{"id":"trace","chapter":"Trace","kind":"dry-run","source":"trace-example","eyebrow":"Trace the first edge","title":"Trace the search for the first 8","workspacePanel":"visualizer","visualTrace":{"contract":"guided-visual-trace-v1","steps":[{"id":"beat-first-mid","state":{"nums":[5,7,7,8,8,10],"target":8,"left":0,"right":5,"mid":2}},{"id":"beat-first-hit","state":{"nums":[5,7,7,8,8,10],"target":8,"left":3,"right":5,"mid":4,"index":4}},{"id":"beat-earlier-hit","state":{"nums":[5,7,7,8,8,10],"target":8,"left":3,"right":3,"mid":3,"index":3}},{"id":"beat-window-empty","state":{"nums":[5,7,7,8,8,10],"target":8,"i":3,"index":3,"labels":{"i":"index"}}}]},"beats":[{"id":"beat-first-mid","title":"nums[2] is 7, below the target. Which side survives?","summary":"The whole array is in play, so the midpoint is index 2.","prompt":"The full window [0, 5] is live and mid is index 2, where the value is 7.","options":[{"id":"keep-right","label":"Move left to mid + 1; the target is in the right half","rationale":"7 is less than 8 and the array is sorted, so index 2 and everything before it is too small. The next window is [3, 5].","isCorrect":true},{"id":"keep-left","label":"Move right to mid - 1; the target is in the left half","rationale":"That would be the move if nums[mid] were larger than the target. Here 7 is smaller, so the left side is the part ruled out.","isCorrect":false},{"id":"save-miss","label":"Save index 2 as a candidate","rationale":"Only an exact match is worth saving. nums[2] is 7, not 8, so there is nothing to record yet.","isCorrect":false}],"answer":"nums[2] is too small, so the left half is gone. left jumps to index 3 and the window becomes [3, 5]."},{"id":"beat-first-hit","title":"nums[4] is 8, an exact hit. Stop, or keep going?","summary":"The window is [3, 5] and the midpoint is index 4.","prompt":"mid is index 4 and nums[4] equals the target.","options":[{"id":"save-search-left","label":"Save index 4, then move right to mid - 1 to search the left half","rationale":"Index 4 is a real 8, so it is recorded as the best candidate. Searching left can still turn up an earlier 8, so the right half is discarded.","isCorrect":true},{"id":"return-four","label":"Return index 4, the first 8 is found","rationale":"Index 4 is an 8, but the run might start earlier. Returning now reports the wrong end.","isCorrect":false},{"id":"search-right","label":"Save index 4, then move left to mid + 1 to search the right half","rationale":"Searching right looks for a later 8. This run is biased toward the first position.","isCorrect":false}],"answer":"Save index 4 as the candidate, then set right to 3. The window becomes [3, 3] and the search continues left."},{"id":"beat-earlier-hit","title":"nums[3] is also 8. What happens to the saved index?","summary":"The window has collapsed to [3, 3], so the midpoint is index 3.","prompt":"mid is index 3, nums[3] equals the target, and the saved candidate is currently 4.","options":[{"id":"overwrite","label":"Overwrite the saved index with 3 and keep searching left","rationale":"Index 3 is an earlier 8 than the saved 4, so it becomes the new best candidate. right moves to 2 to look for an even earlier one.","isCorrect":true},{"id":"keep-four","label":"Keep the saved index at 4 since it was recorded first","rationale":"The goal is the smallest index. A later hit at a smaller index must replace the older candidate.","isCorrect":false},{"id":"stop-here","label":"Stop, since two hits in a row means the edge is found","rationale":"Nothing yet proves index 3 is the first. The window keeps shrinking until it is empty before the answer is trusted.","isCorrect":false}],"answer":"The saved index becomes 3, and right moves to 2. The window is now empty."},{"id":"beat-window-empty","title":"The window is empty. Is the search done, and where does it end?","summary":"left has passed right, so every remaining index has been ruled in or out.","prompt":"The window [3, 2] is empty.","options":[{"id":"saved-index","label":"Done. Return index 3, the last index a hit was recorded at","rationale":"An empty window means no index is still unchecked. Index 3 is the smallest index that held an 8, and everything left of it was already ruled out as too small, so it is the first position.","isCorrect":true},{"id":"keep-going","label":"Not done. An earlier 8 might still be hiding to the left","rationale":"right has dropped to 2, so indices 0 through 2 were already proven too small to be 8. There is no unchecked index left of 3 to find.","isCorrect":false},{"id":"minus-one","label":"Done, but return -1 because the window collapsed","rationale":"An empty window ends the loop, but an 8 was recorded along the way. -1 is the answer only when no 8 was ever seen.","isCorrect":false}],"answer":"Return the saved index, 3. Running the same helper biased right finds the last position, 4, so the range is [3, 4]."}]},{"id":"return-bound-pitfall","chapter":"Trace","kind":"pitfall","eyebrow":"Spot the trap","title":"Can the moving bounds mark the boundary on their own?","summary":"This is the two-boundary helper, biased toward the first 8. It narrows the right bound on every hit, exactly as planned. The one thing it skips: writing the hit into the saved index. Watch the helper run on a target that is right there in the array.","workspacePanel":"trace","pitfall":"The helper below keeps index unset and narrows toward the left edge on a hit, trusting the collapsing window to leave the answer behind. The save line, index = mid, is missing from the equality branch.","example":"nums = [5, 7, 7, 8, 8, 10], target = 8\nThe 8s sit at indices 3 and 4, so the first position is 3.","whyItMatters":"Narrowing toward the edge is correct, but the saved index is what survives the loop, and the equality branch never wrote to it. A hit moves the bound and then evaporates, so the helper finishes with index still -1 even though it sat on an 8 twice. The fix is one line in the equality branch: record index = mid before narrowing, so the most extreme hit is the value returned.","negativeTrace":{"contract":"negative-trace-v1","languageLabel":"Python","editorLanguage":"python","code":"def find_left_bound(nums: list[int], target: int) -> int:\n    left, right = 0, len(nums) - 1\n    index = -1\n    while left <= right:\n        mid = (left + right) // 2\n        if nums[mid] == target:\n            right = mid - 1\n        elif nums[mid] < target:\n            left = mid + 1\n        else:\n            right = mid - 1\n    return index","localizations":{"javascript":{"languageLabel":"JavaScript","editorLanguage":"javascript","codeStyle":"natural","code":"let [left, right] = [0, (nums.length - 1)];\nconst index = -1;\nwhile (left <= right) {\n    const mid = Math.floor((left + right) / 2);\n    if (nums[mid] === target) {\n        right = mid - 1;\n    } else {\n        if (nums[mid] < target) {\n            left = mid + 1;\n        } else {\n            right = mid - 1;\n        }\n    }\n}\nreturn index;","lineMap":{"2":1,"3":2,"4":3,"5":4,"6":5,"7":6,"8":8,"9":9,"10":10,"11":11,"12":15},"statementBundles":{"7":{"startLine":6,"endLine":7},"11":{"startLine":11,"endLine":14}}},"typescript":{"languageLabel":"TypeScript","editorLanguage":"typescript","codeStyle":"natural","code":"let [left, right] = [0, (nums.length - 1)];\nconst index = -1;\nwhile (left <= right) {\n    const mid = Math.floor((left + right) / 2);\n    if (nums[mid] === target) {\n        right = mid - 1;\n    } else {\n        if (nums[mid] < target) {\n            left = mid + 1;\n        } else {\n            right = mid - 1;\n        }\n    }\n}\nreturn index;","lineMap":{"2":1,"3":2,"4":3,"5":4,"6":5,"7":6,"8":8,"9":9,"10":10,"11":11,"12":15},"statementBundles":{"7":{"startLine":6,"endLine":7},"11":{"startLine":11,"endLine":14}}},"java":{"languageLabel":"Java","editorLanguage":"java","codeStyle":"natural","code":"int left = 0;\nint right = (nums.size() - 1);\nint index = -1;\nwhile (left <= right) {\n    int mid = Math.floorDiv((left + right), 2);\n    if (nums.get(mid) == target) {\n        right = mid - 1;\n    } else {\n        if (nums.get(mid) < target) {\n            left = mid + 1;\n        } else {\n            right = mid - 1;\n        }\n    }\n}\nreturn index;","lineMap":{"2":1,"3":3,"4":4,"5":5,"6":6,"7":7,"8":9,"9":10,"10":11,"11":12,"12":16},"statementBundles":{"2":{"startLine":1,"endLine":2},"7":{"startLine":7,"endLine":8},"11":{"startLine":12,"endLine":15}}},"csharp":{"languageLabel":"C#","editorLanguage":"csharp","codeStyle":"natural","code":"var (left, right) = (0, nums.Count - 1);\nint index = -1;\nwhile (left <= right) {\n    int mid = (left + right) / 2;\n    if (nums[mid] == target) {\n        right = mid - 1;\n    } else {\n        if (nums[mid] < target) {\n            left = mid + 1;\n        } else {\n            right = mid - 1;\n        }\n    }\n}\nreturn index;","lineMap":{"2":1,"3":2,"4":3,"5":4,"6":5,"7":6,"8":8,"9":9,"10":10,"11":11,"12":15},"statementBundles":{"7":{"startLine":6,"endLine":7},"11":{"startLine":11,"endLine":14}}},"cpp":{"languageLabel":"C++","editorLanguage":"cpp","codeStyle":"natural","code":"int left = 0;\nint right = (nums.size() - 1);\nint index = -1;\nwhile (left <= right) {\n    int mid = (left + right) / 2;\n    if (nums[mid] == target) {\n        right = mid - 1;\n    } else {\n        if (nums[mid] < target) {\n            left = mid + 1;\n        } else {\n            right = mid - 1;\n        }\n    }\n}\nreturn index;","lineMap":{"2":1,"3":3,"4":4,"5":5,"6":6,"7":7,"8":9,"9":10,"10":11,"11":12,"12":16},"statementBundles":{"2":{"startLine":1,"endLine":2},"7":{"startLine":7,"endLine":8},"11":{"startLine":12,"endLine":15}}}},"steps":[{"id":"pf-first-mid","title":"First midpoint on the full window","summary":"left is 0 and right is 5, so mid is index 2, where the value is 7. index is still -1.","codeLine":5,"state":{"nums":[5,7,7,8,8,10],"target":8,"left":0,"right":5,"mid":2,"index":-1}},{"id":"pf-too-small","title":"7 is smaller than 8, so drop the left side","summary":"nums[2] is 7, below target 8, so left moves to 3. The window is now [3, 5].","codeLine":9,"state":{"nums":[5,7,7,8,8,10],"target":8,"left":3,"right":5,"mid":2,"index":-1}},{"id":"pf-hit-no-save","title":"nums[4] is 8, a real hit, but index is not written","summary":"mid is index 4 and nums[4] equals 8. The branch runs right = mid - 1 and narrows to [3, 3], yet index stays -1: the save line is gone.","codeLine":7,"state":{"nums":[5,7,7,8,8,10],"target":8,"left":3,"right":3,"mid":4,"index":-1}},{"id":"pf-hit-again","title":"nums[3] is 8 too, and it also slips away","summary":"mid is index 3, another exact 8. right moves to 2 and the window empties. index is still -1 after sitting on an 8 twice.","codeLine":7,"state":{"nums":[5,7,7,8,8,10],"target":8,"left":3,"right":2,"mid":3,"index":-1}},{"id":"pf-wrong-return","title":"The helper returns -1 for a value that is present","summary":"The loop ends and the code returns index, which is still -1. But 8 lives at indices 3 and 4. The first position is 3, not -1.","codeLine":12,"state":{"nums":[5,7,7,8,8,10],"target":8,"index":-1}}]}},{"id":"edge-case-intro","chapter":"Edge cases","kind":"info","eyebrow":"Try to break it","title":"Which inputs could break this?","summary":"The helper saves a hit and narrows toward one edge. Now stress the inputs themselves.","ctaLabel":"Check edge cases","workspacePanel":"visualizer","body":["Three inputs press on different parts of the helper. An array that is all target pushes on how far the narrowing runs once every probe is a hit.","A single matching element tests whether a one-wide window still does its one round of work. And an empty array offers no indices to probe at all. Each one is a case to run through next."],"visualTrace":{"contract":"guided-visual-trace-v1","steps":[{"id":"edge-intro-state","state":{"nums":[8,8,8,8],"target":8,"left":0,"right":3}}]}},{"id":"edge-all-match","chapter":"Edge cases","kind":"case-probe","eyebrow":"Force a decision","title":"When every value is the target, where does the first-edge run end?","workspacePanel":"visualizer","visualTrace":{"contract":"guided-visual-trace-v1","steps":[{"id":"all-match-state","state":{"nums":[8,8,8,8],"target":8,"left":0,"right":0,"index":1}}]},"options":[{"id":"index-zero","label":"It keeps saving smaller indices until it saves index 0","rationale":"Every midpoint is a hit, so the helper records it and moves right each time. The recorded index keeps shrinking until the window covers only index 0, giving a first position of 0.","isCorrect":true},{"id":"index-one","label":"It stops at index 1, the first hit it saved","rationale":"A hit never stops this helper. It saves and keeps moving right, so a later hit at index 0 replaces 1.","isCorrect":false},{"id":"middle","label":"It returns the middle, since all values are equal","rationale":"There is no special middle case. The helper still drives toward the requested edge, which here is index 0.","isCorrect":false}],"answer":"The first-edge run ends at index 0 and the last-edge run ends at index 3, so the whole array is the range: [0, 3].","summary":"nums = [8, 8, 8, 8], target = 8. The first-edge helper has saved index 1 and just moved right to 0."},{"id":"edge-single","chapter":"Edge cases","kind":"case-probe","eyebrow":"Force a decision","title":"One element that matches: does the helper still record it?","workspacePanel":"visualizer","visualTrace":{"contract":"guided-visual-trace-v1","steps":[{"id":"single-state","state":{"nums":[8],"target":8,"left":0,"right":0,"mid":0}}]},"options":[{"id":"record-zero","label":"Yes, it saves index 0, then both bounds collapse and it returns 0","rationale":"A one-element window is not empty, so the loop runs once. nums[0] is a hit, index 0 is saved, the bounds cross, and both edges report 0.","isCorrect":true},{"id":"skip-loop","label":"No, left equals right so the loop is skipped","rationale":"The guard is left <= right, so left == right still enters the loop and checks the one candidate.","isCorrect":false},{"id":"out-of-range","label":"No, mid is 0 but there is nothing to compare","rationale":"Index 0 is a valid element here. nums[0] exists and equals the target.","isCorrect":false}],"answer":"Both helpers save index 0 and return it, so the range is [0, 0].","summary":"nums = [8], target = 8. left and right are both 0, so mid is 0."},{"id":"edge-empty","chapter":"Edge cases","kind":"case-probe","eyebrow":"Force a decision","title":"No indices at all: what does each helper return?","workspacePanel":"visualizer","visualTrace":{"contract":"guided-visual-trace-v1","steps":[{"id":"empty-state","state":{"nums":[],"target":8,"left":0,"right":-1}}]},"options":[{"id":"minus-one","label":"The loop never runs, the saved index stays -1, and each helper returns -1","rationale":"left starts above right, so the guard left <= right is false immediately. No hit is ever saved, so the sentinel -1 carries through.","isCorrect":true},{"id":"crash","label":"It reads nums[0] and crashes on the empty array","rationale":"The loop body never executes, so nums[0] is never read. The empty window is handled by the guard, not by a special case.","isCorrect":false},{"id":"zero","label":"It returns 0, the value of left","rationale":"The helper returns the saved index, not left. With no hit saved, that index is still -1.","isCorrect":false}],"answer":"Both helpers return -1 without touching the array, so the answer is [-1, -1].","summary":"nums = [], target = 8. left is 0 and right is len(nums) - 1, which is -1."},{"id":"ready-to-code","chapter":"Code","kind":"info","eyebrow":"Get ready to code","title":"Turn the rule into code","summary":"The whole solution is one helper run twice.","ctaLabel":"Start coding","workspacePanel":"visualizer","body":["Write one binary-search helper with a saved index that starts unset. On a miss it moves a boundary the normal way. On a hit it saves mid, then narrows toward the requested edge instead of stopping.","Run it once biased toward the first 8 and once biased toward the last, then pair the two saved indices. The unset sentinel handles a missing target on its own."],"visualTrace":{"contract":"guided-visual-trace-v1","steps":[{"id":"ready-state","state":{"nums":[5,7,7,8,8,10],"target":8,"left":0,"right":5}}]}},{"id":"coding","kind":"coding","source":"coding-checkpoints","chapter":"Code","title":"Build the boundary helper","eyebrow":"Code the rule","summary":"Now build the helper: seed the closed window from the two ends, probe the midpoint, record an exact hit as the candidate, then narrow toward the requested edge instead of stopping, and return the saved index.","workspacePanel":"code","checkpoints":[{"id":"bounds","title":"Initialize the helper search bounds","description":"Inside the boundary helper, set up a closed binary-search window.","validation":{"type":"semantic","validator":"familyFact","params":[{"family":"binary-search","fact":"initializes_search_bounds","scope":"init-pointers","readMode":"binary-search-value-query-v1"}]},"commonMistakes":["Using a past-the-end upper bound with closed-interval updates","Forgetting the helper should handle an empty array"],"hint":"Use the first and last valid indices as the closed search bounds.","semanticSpec":{"intent":"Initialize a closed binary-search window for the boundary helper.","doneWhen":"This step is done when the helper seeds left and right to the first and last valid indices.","shouldFailWhen":"This step should fail if explicit search bounds are missing or seeded inconsistently with the loop.","roles":["lower bound","upper bound","sorted input"],"mustProve":["The lower bound starts at the first index.","The upper bound starts at the last valid index.","The bounds are available before midpoint probing."],"mustNotAccept":["Starting from a partial array range.","Using a half-open upper bound with closed updates.","Scanning linearly without search bounds."],"equivalentVariants":["Use the first valid index for the lower bound and the last valid index for the upper bound.","Use equivalent bound variable names."],"proofSnippets":[{"id":"py-range-bounds","language":"python","code":"class Solution:\n    def searchRange(self, nums: list[int], target: int) -> list[int]:\n        def find_bound(is_left: bool) -> int:\n            left, right = 0, len(nums) - 1\n            while left <= right:\n                return -1\n            return -1\n        return [-1, -1]"}]}},{"id":"midpoint","title":"Probe the midpoint","description":"Compute mid from the active helper bounds and compare nums[mid] with target.","validation":{"type":"semantic","validator":"familyFact","params":[{"family":"binary-search","fact":"computes_midpoint_from_bounds","scope":"calculate-mid","readMode":"binary-search-value-query-v1"}]},"commonMistakes":["Computing mid from the original array length each time","Comparing target against the wrong index"],"hint":"The midpoint should come from left and right inside the loop.","semanticSpec":{"intent":"Compute the midpoint from the current helper bounds.","doneWhen":"This step is done when the loop assigns mid from left and right before reading nums[mid].","shouldFailWhen":"This step should fail if mid is fixed, unrelated to the bounds, or missing.","roles":["lower bound","upper bound","midpoint","target probe"],"mustProve":["The midpoint is assigned inside the search loop.","The midpoint depends on both bounds.","The midpoint is used to probe the sorted input."],"mustNotAccept":["Using a constant midpoint.","Computing mid from only one bound.","Looping without a midpoint probe."],"equivalentVariants":["Use `(left + right) // 2`.","Use `left + (right - left) // 2`."],"proofSnippets":[{"id":"py-range-midpoint","language":"python","code":"class Solution:\n    def searchRange(self, nums: list[int], target: int) -> list[int]:\n        def find_bound(is_left: bool) -> int:\n            left, right = 0, len(nums) - 1\n            while left <= right:\n                mid = (left + right) // 2\n                if nums[mid] < target:\n                    left = mid + 1\n                else:\n                    right = mid - 1\n            return -1\n        return [-1, -1]"}]}},{"id":"record-hit","title":"Record a matching midpoint","description":"When nums[mid] equals target, save mid as the current best boundary candidate.","validation":{"type":"semantic","validator":"familyFact","params":[{"family":"binary-search","fact":"records_midpoint_hit_candidate","scope":"record-hit","readMode":"binary-search-value-query-v1"}]},"commonMistakes":["Returning immediately on the first hit","Forgetting to save the matching index before continuing"],"hint":"A hit proves one valid answer, but not necessarily the first or last one.","semanticSpec":{"intent":"Record the midpoint index when it is an exact target hit.","doneWhen":"This step is done when an equality branch saves mid into a result candidate.","shouldFailWhen":"This step should fail if the code keeps searching after a hit without saving the hit index.","roles":["midpoint","target equality","recorded candidate"],"mustProve":["The code checks nums[mid] against target.","The equality branch records the midpoint index.","The recorded state is separate from the moving bounds."],"mustNotAccept":["Returning mid immediately as the final answer.","Recording an unrelated index.","Only updating bounds on equality."],"equivalentVariants":["Use `index = mid` on equality.","Use another result variable to remember the latest matching midpoint."],"proofSnippets":[{"id":"py-range-record-hit","language":"python","code":"class Solution:\n    def searchRange(self, nums: list[int], target: int) -> list[int]:\n        def find_bound(is_left: bool) -> int:\n            left, right = 0, len(nums) - 1\n            index = -1\n            while left <= right:\n                mid = (left + right) // 2\n                if nums[mid] == target:\n                    index = mid\n                    right = mid - 1\n                elif nums[mid] < target:\n                    left = mid + 1\n                else:\n                    right = mid - 1\n            return -1\n        return [-1, -1]"}]}},{"id":"refine-boundary","title":"Keep searching toward the requested edge","description":"After recording a hit, move left for the last edge or right for the first edge.","validation":{"type":"semantic","validator":"familyFact","params":[{"family":"binary-search","fact":"refines_hit_candidate_boundary","scope":"search-left-and-right-boundaries","readMode":"binary-search-value-query-v1"}]},"commonMistakes":["Only searching left after a hit","Only searching right after a hit","Discarding the saved hit while moving the bounds"],"hint":"The helper needs both behaviors: first boundary moves right leftward; last boundary moves left rightward.","semanticSpec":{"intent":"Continue binary search after a hit so the helper can find either boundary.","doneWhen":"This step is done when the recorded-hit branch can refine toward both lower and upper target boundaries.","shouldFailWhen":"This step should fail if hits are recorded but the helper only searches one side.","roles":["recorded candidate","left boundary search","right boundary search","bound refinement"],"mustProve":["The equality branch records the midpoint.","The helper can move the upper bound leftward after a hit.","The helper can move the lower bound rightward after a hit."],"mustNotAccept":["Stopping at the first hit.","Only implementing the left-bound search.","Only implementing the right-bound search."],"equivalentVariants":["Use an `is_left` flag to choose the hit-side refinement.","Use equivalent helper logic that supports both boundary directions."],"proofSnippets":[{"id":"py-range-refine-boundary","language":"python","code":"class Solution:\n    def searchRange(self, nums: list[int], target: int) -> list[int]:\n        def find_bound(is_left: bool) -> int:\n            left, right = 0, len(nums) - 1\n            index = -1\n            while left <= right:\n                mid = (left + right) // 2\n                if nums[mid] == target:\n                    index = mid\n                    if is_left:\n                        right = mid - 1\n                    else:\n                        left = mid + 1\n                elif nums[mid] < target:\n                    left = mid + 1\n                else:\n                    right = mid - 1\n            return -1\n        return [-1, -1]"}]}},{"id":"return-boundary","title":"Return the recorded boundary","description":"After the helper finishes, return the best matching index it recorded.","validation":{"type":"semantic","validator":"familyFact","params":[{"family":"binary-search","fact":"returns_recorded_hit_candidate","scope":"return-recorded-boundary","readMode":"binary-search-value-query-v1"}]},"commonMistakes":["Returning left or right instead of the saved matching index","Returning mid after the loop"],"hint":"The helper should return the saved candidate, which remains -1 if no hit was found.","semanticSpec":{"intent":"Return the recorded hit candidate from the boundary helper.","doneWhen":"This step is done when the helper returns the saved matching index after the loop.","shouldFailWhen":"This step should fail if the helper returns a moving boundary or stale midpoint instead of the recorded hit.","roles":["recorded candidate","miss sentinel","helper return"],"mustProve":["A target hit records the midpoint candidate.","The hit candidate can be refined toward either side.","The helper returns that recorded candidate after the loop."],"mustNotAccept":["Returning the lower bound.","Returning the upper bound.","Returning a stale midpoint."],"equivalentVariants":["Return `index` after the helper loop.","Return an equivalent saved hit variable initialized to -1."],"proofSnippets":[{"id":"py-range-return-boundary","language":"python","code":"class Solution:\n    def searchRange(self, nums: list[int], target: int) -> list[int]:\n        def find_bound(is_left: bool) -> int:\n            left, right = 0, len(nums) - 1\n            index = -1\n            while left <= right:\n                mid = (left + right) // 2\n                if nums[mid] == target:\n                    index = mid\n                    if is_left:\n                        right = mid - 1\n                    else:\n                        left = mid + 1\n                elif nums[mid] < target:\n                    left = mid + 1\n                else:\n                    right = mid - 1\n            return index\n        return [-1, -1]"}]}}]},{"id":"complete","chapter":"Code","kind":"complete","eyebrow":"Take it with you","title":"What to carry forward","summary":"Save the hit, keep narrowing toward the edge, run the helper twice, and let -1 report absence.","workspacePanel":"code","body":["Finding both ends of a run is not two different problems. It is one binary search that refuses to stop on the first match.","Each hit is a candidate that a later, more extreme hit can replace. Biasing the narrowing decides which edge you converge on."],"takeaways":[{"title":"A hit records a candidate","body":"Save mid on an exact match and keep searching. The first match is rarely the boundary when the value repeats."},{"title":"One helper, two biases","body":"After a hit, move right toward the first position or move left toward the last. The same code finds either edge."},{"title":"The sentinel reports absence","body":"The saved index starts at -1 and changes only on a hit, so a missing target returns [-1, -1] with no extra check."}],"nextAction":"Submit when you are ready. TraceCode will run the final checks against the code you wrote."}],"slidesOrigin":"authored"},"executionStyle":"solution-method","syntheticTestConfig":{"inputShape":"array-target","primaryParam":"nums","secondaryParam":"target","sizeMetric":"length","constraints":["sorted","duplicates"]}}
