[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"searchBlogPosts":3,"content-\u002Fnewsletter\u002F2026\u002F06\u002F27\u002Ftwo-sum":7},[4],{"_path":5,"title":6},"\u002Fblog\u002F2023\u002F09\u002F17\u002Fspring-boot-postgresql","Spring Boot with PostgreSQL & pgAdmin in Docker",{"_path":8,"_dir":9,"_draft":10,"_partial":10,"_locale":11,"title":12,"description":11,"slug":13,"date":14,"body":15,"_type":365,"_id":366,"_source":367,"_file":368,"_stem":369,"_extension":370,"sitemap":371},"\u002Fnewsletter\u002F2026\u002F06\u002F27\u002Ftwo-sum","27",false,"","Two Sum","two-sum","2026-06-27T07:00:00.000Z",{"type":16,"children":17,"toc":359},"root",[18,27,34,38,74,99,104,112,121,129,137,145,153,161,169,182,187,322,353],{"type":19,"tag":20,"props":21,"children":23},"element","h2",{"id":22},"_1-two-sum",[24],{"type":25,"value":26},"text","1. Two Sum",{"type":19,"tag":28,"props":29,"children":31},"h3",{"id":30},"easy",[32],{"type":25,"value":33},"Easy",{"type":19,"tag":35,"props":36,"children":37},"hr",{},[],{"type":19,"tag":39,"props":40,"children":41},"p",{},[42,44,51,53,59,61,72],{"type":25,"value":43},"Given an array of integers ",{"type":19,"tag":45,"props":46,"children":48},"code",{"className":47},[],[49],{"type":25,"value":50},"nums",{"type":25,"value":52}," and an integer ",{"type":19,"tag":45,"props":54,"children":56},{"className":55},[],[57],{"type":25,"value":58},"target",{"type":25,"value":60},", return ",{"type":19,"tag":62,"props":63,"children":64},"em",{},[65,67],{"type":25,"value":66},"indices of the two numbers such that they add up to ",{"type":19,"tag":45,"props":68,"children":70},{"className":69},[],[71],{"type":25,"value":58},{"type":25,"value":73},".",{"type":19,"tag":39,"props":75,"children":76},{},[77,79,90,92,97],{"type":25,"value":78},"You may assume that each input would have ",{"type":19,"tag":80,"props":81,"children":82},"strong",{},[83,88],{"type":19,"tag":62,"props":84,"children":85},{},[86],{"type":25,"value":87},"exactly",{"type":25,"value":89}," one solution",{"type":25,"value":91},", and you may not use the ",{"type":19,"tag":62,"props":93,"children":94},{},[95],{"type":25,"value":96},"same",{"type":25,"value":98}," element twice.",{"type":19,"tag":39,"props":100,"children":101},{},[102],{"type":25,"value":103},"You can return the answer in any order.",{"type":19,"tag":39,"props":105,"children":106},{},[107],{"type":19,"tag":80,"props":108,"children":109},{},[110],{"type":25,"value":111},"Example 1:",{"type":19,"tag":113,"props":114,"children":116},"pre",{"code":115},"**Input:** nums = [2,7,11,15], target = 9\n**Output:** [0,1]\n**Explanation:** Because nums[0] + nums[1] == 9, we return [0, 1].\n",[117],{"type":19,"tag":45,"props":118,"children":119},{"__ignoreMap":11},[120],{"type":25,"value":115},{"type":19,"tag":39,"props":122,"children":123},{},[124],{"type":19,"tag":80,"props":125,"children":126},{},[127],{"type":25,"value":128},"Example 2:",{"type":19,"tag":113,"props":130,"children":132},{"code":131},"**Input:** nums = [3,2,4], target = 6\n**Output:** [1,2]\n",[133],{"type":19,"tag":45,"props":134,"children":135},{"__ignoreMap":11},[136],{"type":25,"value":131},{"type":19,"tag":39,"props":138,"children":139},{},[140],{"type":19,"tag":80,"props":141,"children":142},{},[143],{"type":25,"value":144},"Example 3:",{"type":19,"tag":113,"props":146,"children":148},{"code":147},"**Input:** nums = [3,3], target = 6\n**Output:** [0,1]\n",[149],{"type":19,"tag":45,"props":150,"children":151},{"__ignoreMap":11},[152],{"type":25,"value":147},{"type":19,"tag":39,"props":154,"children":155},{},[156],{"type":19,"tag":80,"props":157,"children":158},{},[159],{"type":25,"value":160},"Constraints:",{"type":19,"tag":113,"props":162,"children":164},{"code":163},"- `2 \u003C= nums.length \u003C= 10^4`\n\n- `-10^9 \u003C= nums[i] \u003C= 10^9`\n\n- `-10^9 \u003C= target \u003C= 10^9`\n\n- **Only one valid answer exists.**\n",[165],{"type":19,"tag":45,"props":166,"children":167},{"__ignoreMap":11},[168],{"type":25,"value":163},{"type":19,"tag":39,"props":170,"children":171},{},[172,174,180],{"type":25,"value":173},"**Follow-up: **Can you come up with an algorithm that is less than ",{"type":19,"tag":45,"props":175,"children":177},{"className":176},[],[178],{"type":25,"value":179},"O(n^2)",{"type":25,"value":181}," time complexity?",{"type":19,"tag":20,"props":183,"children":184},{"id":45},[185],{"type":25,"value":186},"Code",{"type":19,"tag":113,"props":188,"children":192},{"code":189,"language":190,"meta":11,"className":191,"style":11},"class Solution:\n    def twoSum(self, nums: List[int], target: int) -> List[int]:\n        map = {}\n        \n        for i in range(len(nums)):\n            \n            sum = target - nums[i]\n            \n            if sum in map:\n                return [i, map[sum]]\n                \n            map[nums[i]] = i\n            \n        return [-1, -1]\n","python","language-python shiki shiki-themes nord github-dark monokai",[193],{"type":19,"tag":45,"props":194,"children":195},{"__ignoreMap":11},[196,207,216,225,234,243,252,261,269,278,287,296,305,313],{"type":19,"tag":197,"props":198,"children":201},"span",{"class":199,"line":200},"line",1,[202],{"type":19,"tag":197,"props":203,"children":204},{},[205],{"type":25,"value":206},"class Solution:\n",{"type":19,"tag":197,"props":208,"children":210},{"class":199,"line":209},2,[211],{"type":19,"tag":197,"props":212,"children":213},{},[214],{"type":25,"value":215},"    def twoSum(self, nums: List[int], target: int) -> List[int]:\n",{"type":19,"tag":197,"props":217,"children":219},{"class":199,"line":218},3,[220],{"type":19,"tag":197,"props":221,"children":222},{},[223],{"type":25,"value":224},"        map = {}\n",{"type":19,"tag":197,"props":226,"children":228},{"class":199,"line":227},4,[229],{"type":19,"tag":197,"props":230,"children":231},{},[232],{"type":25,"value":233},"        \n",{"type":19,"tag":197,"props":235,"children":237},{"class":199,"line":236},5,[238],{"type":19,"tag":197,"props":239,"children":240},{},[241],{"type":25,"value":242},"        for i in range(len(nums)):\n",{"type":19,"tag":197,"props":244,"children":246},{"class":199,"line":245},6,[247],{"type":19,"tag":197,"props":248,"children":249},{},[250],{"type":25,"value":251},"            \n",{"type":19,"tag":197,"props":253,"children":255},{"class":199,"line":254},7,[256],{"type":19,"tag":197,"props":257,"children":258},{},[259],{"type":25,"value":260},"            sum = target - nums[i]\n",{"type":19,"tag":197,"props":262,"children":264},{"class":199,"line":263},8,[265],{"type":19,"tag":197,"props":266,"children":267},{},[268],{"type":25,"value":251},{"type":19,"tag":197,"props":270,"children":272},{"class":199,"line":271},9,[273],{"type":19,"tag":197,"props":274,"children":275},{},[276],{"type":25,"value":277},"            if sum in map:\n",{"type":19,"tag":197,"props":279,"children":281},{"class":199,"line":280},10,[282],{"type":19,"tag":197,"props":283,"children":284},{},[285],{"type":25,"value":286},"                return [i, map[sum]]\n",{"type":19,"tag":197,"props":288,"children":290},{"class":199,"line":289},11,[291],{"type":19,"tag":197,"props":292,"children":293},{},[294],{"type":25,"value":295},"                \n",{"type":19,"tag":197,"props":297,"children":299},{"class":199,"line":298},12,[300],{"type":19,"tag":197,"props":301,"children":302},{},[303],{"type":25,"value":304},"            map[nums[i]] = i\n",{"type":19,"tag":197,"props":306,"children":308},{"class":199,"line":307},13,[309],{"type":19,"tag":197,"props":310,"children":311},{},[312],{"type":25,"value":251},{"type":19,"tag":197,"props":314,"children":316},{"class":199,"line":315},14,[317],{"type":19,"tag":197,"props":318,"children":319},{},[320],{"type":25,"value":321},"        return [-1, -1]\n",{"type":19,"tag":39,"props":323,"children":324},{},[325,327,331,333,336,343,346],{"type":25,"value":326},"Happy Coding",{"type":19,"tag":328,"props":329,"children":330},"br",{},[],{"type":25,"value":332},"\nVishwaraj Sali",{"type":19,"tag":328,"props":334,"children":335},{},[],{"type":19,"tag":337,"props":338,"children":340},"a",{"href":339},"mailto:vishvsali@gmail.com",[341],{"type":25,"value":342},"vishvsali@gmail.com",{"type":19,"tag":328,"props":344,"children":345},{},[],{"type":19,"tag":337,"props":347,"children":351},{"href":348,"rel":349},"https:\u002F\u002Fwww.vishsali.dev",[350],"nofollow",[352],{"type":25,"value":348},{"type":19,"tag":354,"props":355,"children":356},"style",{},[357],{"type":25,"value":358},"html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html .sepia .shiki span {color: var(--shiki-sepia);background: var(--shiki-sepia-bg);font-style: var(--shiki-sepia-font-style);font-weight: var(--shiki-sepia-font-weight);text-decoration: var(--shiki-sepia-text-decoration);}html.sepia .shiki span {color: var(--shiki-sepia);background: var(--shiki-sepia-bg);font-style: var(--shiki-sepia-font-style);font-weight: var(--shiki-sepia-font-weight);text-decoration: var(--shiki-sepia-text-decoration);}",{"title":11,"searchDepth":209,"depth":209,"links":360},[361,364],{"id":22,"depth":209,"text":26,"children":362},[363],{"id":30,"depth":218,"text":33},{"id":45,"depth":209,"text":186},"markdown","content:newsletter:2026:06:27:two-sum.md","content","newsletter\u002F2026\u002F06\u002F27\u002Ftwo-sum.md","newsletter\u002F2026\u002F06\u002F27\u002Ftwo-sum","md",{"loc":8}]