LogIn
I don't have account.
Sponsored -55%
Tarkan Top Brand

Tarkan Portable Folding Laptop Desk with Drawer, Cup & Tablet Holder (Black)

Foldable · Anti-slip strip · 60 × 40 cm · No assembly

★★★★★ 4.2 (7,877) 1K+ bought last month
₹899 M.R.P. ₹1,999Save ₹1,100
Buy Now
Adℹ

Intersection of Two Sorted Arrays

HackFury
37 Views
Amazon Pay offer
Adℹ

Given two sorted arrays, return their intersection (the common elements).

  • If an element appears more than once in both arrays, it should appear the same number of times in the intersection.

  • Result must also be in sorted order.

Example 1

Input:
arr1 = [1, 2, 2, 3, 4]
arr2 = [2, 2, 4, 6]

Output: [2, 2, 4]

Example 2

Input:
arr1 = [1, 1, 2, 3, 5]
arr2 = [1, 1, 1, 2, 4, 5]

Output: [1, 1, 2, 5]

Constraints:

  • 1 <= arr1.length, arr2.length <= 10^5

  • -10^9 <= arr1[i], arr2[i] <= 10^9

  • Both arrays are sorted in non-decreasing order

Brute Force Approach (Nested Loops)

Compare every element of the first array (arr1) with every element of the second array (arr2). Whenever a match is found add it to the result but to handle duplicates correctly, mark that element in arr2 as used so it isn’t counted again.

Steps

  • Create a boolean array visited[] of size arr2.length to track which elements of arr2 are already matched.

  • For each element arr1[i]:

    • Traverse all elements in arr2.

    • If arr1[i] == arr2[j] and visited[j] == false:

      • Add it to the result list.

      • Mark visited[j] = true to avoid duplicate counting.

      • Break (move to next element in arr1).


import java.util.*;

public class IntersectionSortedArrays {
    public static List<Integer> intersectionBruteForce(int[] arr1, int[] arr2) {
        List<Integer> result = new ArrayList<>();
        boolean[] visited = new boolean[arr2.length]; // track used elements
        for (int i = 0; i < arr1.length; i++) {
            for (int j = 0; j < arr2.length; j++) {
                if (!visited[j] && arr1[i] == arr2[j]) {
                    result.add(arr1[i]);
                    visited[j] = true;
                    break; // move to next arr1 element
                }
            }
        }
        return result;
    }
    public static void main(String[] args) {
        int[] arr1 = {1, 2, 2, 3, 4};
        int[] arr2 = {2, 2, 3, 5};
        System.out.println(intersectionBruteForce(arr1, arr2)); // [2, 2, 3]
    }
}

Complexity Analysis

  • Time Complexity: O(n × m), For each element in arr1, we scan arr2
  • Space Complexity: O(m), For the visited[] array

Better Approach — Using Binary Search

When both arrays are sorted, we can do much better than nested loops. Instead of scanning linearly, we can use Binary Search to find matches efficiently.

The key optimization lies in the sorted property:

  • For each element in one array, we can quickly check whether it exists in the other array using Binary Search in O(log n) time instead of O(n).

  • We also ensure that duplicates are handled properly by marking visited elements.

Step-by-Step Approach

  • Identify the smaller array. We'll iterate over it to reduce total operations. (If arr1 is larger, swap them.)

  • Create a visited[] array for the larger one to track elements already matched.

  • For each element in the smaller array:

    • Perform a binary search in the larger array.

    • If found and not visited, add it to the result list.

    • Mark that index as visited.

  • Return the result list.


import java.util.*;

public class IntersectionSortedArrays {
    public static List<Integer> intersectionBinarySearch(int[] arr1, int[] arr2) {
        List<Integer> result = new ArrayList<>();
        if (arr1.length > arr2.length) {
            return intersectionBinarySearch(arr2, arr1);
        }
        boolean[] visited = new boolean[arr2.length];
        for (int num : arr1) {
            int index = Arrays.binarySearch(arr2, num);

            if (index >= 0 && !visited[index]) {
                result.add(num);
                visited[index] = true;
            }
        }
        return result;
    }
    public static void main(String[] args) {
        int[] arr1 = {1, 2, 2, 3, 4};
        int[] arr2 = {2, 2, 3, 5};
        System.out.println(intersectionBinarySearch(arr1, arr2)); // [2, 2, 3]
    }
}

Complexity Analysis

  • Time Complexity: O(min(n, m) × log(max(n, m))), We perform a binary search for each element in the smaller array
  • Space Complexity: O(max(n, m)), For the visited[] array
  • Best Case: O(min(n, m)), When most elements are missing early
  • Worst Case: O(n log m), For dense intersections

Optimal Approach — Two Pointer Technique

When both arrays are sorted, there’s an even better and more elegant way to find their intersection the Two Pointer Approach. This method eliminates redundant searches entirely and achieves linear time complexity.

Core Idea

We take advantage of the sorted property of both arrays. Using two pointers, one for each array, we move them intelligently based on their current values:

  • If arr1[i] < arr2[j] : the smaller value cannot be part of the intersection, so move i forward.

  • If arr1[i] > arr2[j] : move j forward.

  • If arr1[i] == arr2[j] : we found a common element! Add it to the result and move both pointers forward.

This ensures we only traverse each array once no nested loops, no extra searches.

Step-by-Step Logic

  • Initialize two pointers : i = 0 (for arr1), j = 0 (for arr2).

  • While both pointers are within array bounds:

    • Compare arr1[i] and arr2[j].

    • Move pointers as per conditions:

      • If arr1[i] < arr2[j] : increment i.

      • If arr1[i] > arr2[j] : increment j.

      • If equal : add to result, increment both.

  • Continue until one array is completely traversed.

  • Return the result list.


import java.util.*;

public class IntersectionSortedArrays {
    public static List<Integer> intersectionTwoPointer(int[] arr1, int[] arr2) {
        List<Integer> result = new ArrayList<>();
        int i = 0, j = 0;
        while (i < arr1.length && j < arr2.length) {
            if (arr1[i] < arr2[j]) {
                i++;
            } else if (arr1[i] > arr2[j]) {
                j++;
            } else {
                result.add(arr1[i]);
                i++;
                j++;
            }
        }
        return result;
    }
    public static void main(String[] args) {
        int[] arr1 = {1, 2, 2, 3, 4, 5};
        int[] arr2 = {2, 2, 3, 5, 6};
        System.out.println(intersectionTwoPointer(arr1, arr2)); // [2, 2, 3, 5]
    }
}

Complexity Analysis

  • Time Complexity: O(n + m) Each array is traversed once
  • Space Complexity: O(1) Only a few pointers used (excluding output)

Complexity Comparison

Approach Time Complexity Space Complexity
Brute Force (Nested Loops) O(n × m) O(m)
Binary Search O(n log m) O(m)
Two Pointers (Optimal) O(n + m) O(1)
Responses (0)

Write a response

CommentHide Comments

No Comments yet.

"},"4":{"id":4,"name":"ZEBRONICS Blanc mouse ad","otherData":"{}","contentFormat":2,"content":"
Sponsored -53%
Zebronics #1 Best Seller

ZEBRONICS Blanc Slim Wireless Mouse — Rechargeable, BT + 2.4GHz (Black)

Up to 1600 DPI · Silent clicks · 63g · Multicolor LED

★★★★★ 4.0 (9,512) 5K+ bought last month
₹376 M.R.P. ₹799Save ₹423
Buy Now
"},"2":{"id":2,"name":"Crousal Ads","otherData":"{}","contentFormat":2,"content":"
Sponsored -34%
iQOO Amazon's Choice

iQOO Z10 Lite 5G — Cyber Green, 4GB RAM, 128GB Storage

Dimensity 6300 · 50MP Sony AI Camera · 6000 mAh · IP64

★★★★★ 4.0 (2,052) 500+ bought last month
₹18,997 M.R.P. ₹28,999Save ₹10,002
Buy Now
"},"1":{"id":1,"name":"Banner Ads","otherData":"{}","contentFormat":2,"content":"\n
\n \n \n \"Amazon\n \n
"}}},"blogDetails":{"isWriter":false,"likes":0,"isLikedByUser":false,"tagIds":[17,62,133,169],"tags":[{"id":17,"name":"Array","maskingName":"array","isFeatured":true},{"id":62,"name":"Sorting","maskingName":"sorting","isFeatured":true},{"id":133,"name":"Coding Problems","maskingName":"coding-problems","isFeatured":true},{"id":169,"name":"Two Pointes","maskingName":"two-pointers","isFeatured":true}],"comments":[],"bookmark":{"isBookmarked":false,"count":0},"author":{"userId":"MjlfNF84LVs0XTJuLXRDX0FOZ2VfX0l0","name":"HackFury"},"viewCount":36,"showBannerImage":false,"seoTags":null,"content":"

Given two sorted arrays, return their intersection (the common elements).

\n\n

Example 1

\n
Input:\narr1 = [1, 2, 2, 3, 4]\narr2 = [2, 2, 4, 6]\n\nOutput: [2, 2, 4]\n
\n

Example 2

\n
Input:\narr1 = [1, 1, 2, 3, 5]\narr2 = [1, 1, 1, 2, 4, 5]\n\nOutput: [1, 1, 2, 5]\n
\n

Constraints:

\n\n

Brute Force Approach (Nested Loops)

\n

Compare every element of the first array (arr1) with every element of the second array (arr2).\nWhenever a match is found add it to the result but to handle duplicates correctly, mark that element in arr2 as used so it isn’t counted again.

\n

Steps

\n\n
\nimport java.util.*;\n\npublic class IntersectionSortedArrays {\n    public static List<Integer> intersectionBruteForce(int[] arr1, int[] arr2) {\n        List<Integer> result = new ArrayList<>();\n        boolean[] visited = new boolean[arr2.length]; // track used elements\n        for (int i = 0; i < arr1.length; i++) {\n            for (int j = 0; j < arr2.length; j++) {\n                if (!visited[j] && arr1[i] == arr2[j]) {\n                    result.add(arr1[i]);\n                    visited[j] = true;\n                    break; // move to next arr1 element\n                }\n            }\n        }\n        return result;\n    }\n    public static void main(String[] args) {\n        int[] arr1 = {1, 2, 2, 3, 4};\n        int[] arr2 = {2, 2, 3, 5};\n        System.out.println(intersectionBruteForce(arr1, arr2)); // [2, 2, 3]\n    }\n}\n
\n

Complexity Analysis

\n\n

Better Approach — Using Binary Search

\n

When both arrays are sorted, we can do much better than nested loops.\nInstead of scanning linearly, we can use Binary Search to find matches efficiently.

\n

The key optimization lies in the sorted property:

\n\n

Step-by-Step Approach

\n\n
\nimport java.util.*;\n\npublic class IntersectionSortedArrays {\n    public static List<Integer> intersectionBinarySearch(int[] arr1, int[] arr2) {\n        List<Integer> result = new ArrayList<>();\n        if (arr1.length > arr2.length) {\n            return intersectionBinarySearch(arr2, arr1);\n        }\n        boolean[] visited = new boolean[arr2.length];\n        for (int num : arr1) {\n            int index = Arrays.binarySearch(arr2, num);\n\n            if (index >= 0 && !visited[index]) {\n                result.add(num);\n                visited[index] = true;\n            }\n        }\n        return result;\n    }\n    public static void main(String[] args) {\n        int[] arr1 = {1, 2, 2, 3, 4};\n        int[] arr2 = {2, 2, 3, 5};\n        System.out.println(intersectionBinarySearch(arr1, arr2)); // [2, 2, 3]\n    }\n}\n
\n

Complexity Analysis

\n\n

Optimal Approach — Two Pointer Technique

\n

When both arrays are sorted, there’s an even better and more elegant way to find their intersection the Two Pointer Approach.\nThis method eliminates redundant searches entirely and achieves linear time complexity.

\n

Core Idea

\n

We take advantage of the sorted property of both arrays.\nUsing two pointers, one for each array, we move them intelligently based on their current values:

\n\n

This ensures we only traverse each array once no nested loops, no extra searches.

\n

Step-by-Step Logic

\n\n
\nimport java.util.*;\n\npublic class IntersectionSortedArrays {\n    public static List<Integer> intersectionTwoPointer(int[] arr1, int[] arr2) {\n        List<Integer> result = new ArrayList<>();\n        int i = 0, j = 0;\n        while (i < arr1.length && j < arr2.length) {\n            if (arr1[i] < arr2[j]) {\n                i++;\n            } else if (arr1[i] > arr2[j]) {\n                j++;\n            } else {\n                result.add(arr1[i]);\n                i++;\n                j++;\n            }\n        }\n        return result;\n    }\n    public static void main(String[] args) {\n        int[] arr1 = {1, 2, 2, 3, 4, 5};\n        int[] arr2 = {2, 2, 3, 5, 6};\n        System.out.println(intersectionTwoPointer(arr1, arr2)); // [2, 2, 3, 5]\n    }\n}\n
\n

Complexity Analysis

\n\n

Complexity Comparison

\n
\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
ApproachTime ComplexitySpace Complexity
Brute Force (Nested Loops)O(n × m)O(m)
Binary SearchO(n log m)O(m)
Two Pointers (Optimal)O(n + m)O(1)
","categoryId":177,"subCategoryId":177,"contentFormat":5,"blogId":25,"userId":"MjlfNF84LVs0XTJuLXRDX0FOZ2VfX0l0","title":"Intersection of Two Sorted Arrays","url":"intersection-of-two-sorted-arrays","bannerImage":"","seoDescription":"","generatedOn":"2025-10-05T07:15:44","updatedOn":"2025-10-05T07:15:44"},"popularContents":[{"id":130,"title":"Rippling SDE-2 Interview Experience (4+ Years Experience) | Offer Received | Coding, LLD & System Design","url":"rippling-sde-2-interview-experience-4-years-experience-offer-received-coding-lld-system-design","description":null,"seoDescription":"Detailed Rippling SDE-2 interview experience with complete 5 rounds, coding questions, rules engine design, system design and preparation tips.","contentType":5,"generatedOn":"2026-10-14T22:53:56.4918868Z","viewCount":0},{"id":172,"title":"Google L4 Software Engineer III interview experience | Selected","url":"google-l4-software-engineer-iii-interview-experience-selected","description":null,"seoDescription":"Google L4 Software Engineer III interview experience with API design, Googlyness, route matching, graph coding rounds, follow-up questions and tips.","contentType":5,"generatedOn":"2026-10-14T22:53:56.491899Z","viewCount":0},{"id":168,"title":"Amazon SDE-2 Interview Experience (3 Years Experience)","url":"amazon-sde-2-interview-experience-3-years-experience","description":null,"seoDescription":" Read a real Amazon SDE-2 interview experience covering the online assessment, coding rounds, object-oriented design, leadership principles and system design.","contentType":5,"generatedOn":"2026-10-14T22:53:56.4918918Z","viewCount":0},{"id":171,"title":"Meesho SDE-1 Backend Interview Experience (Remote | 3 Round) - Rejected","url":"meesho-sde-1-backend-interview-experience-remote-3-round-rejected","description":null,"seoDescription":"Read a real Meesho SDE-1 Backend interview experience covering the online assessment, DSA interview, machine coding round, LLD questions and preparation tips.","contentType":5,"generatedOn":"2026-10-14T22:53:56.4918975Z","viewCount":0},{"id":167,"title":"Meesho SDE-1 Online Assessment Interview Experience (Remote) - Rejected","url":"meesho-sde-1-online-assessment-interview-experience-remote-rejected","description":null,"seoDescription":"Read a real Meesho SDE-1 online assessment experience with coding questions, DSA topics, solutions, difficulty level, preparation tips and interview insights.","contentType":5,"generatedOn":"2026-10-14T22:53:56.4918902Z","viewCount":0},{"id":173,"title":"Uber SDE-2 Interview Experience : LLD, HLD, DSA & Hiring Manager Round","url":"uber-sde-2-interview-experience-lld-hld-dsa-hiring-manager-round","description":null,"seoDescription":"Read a real Uber SDE-2 interview experience covering DSA, low-level design, high-level system design, behavioral rounds, hiring freeze and key takeaways.","contentType":5,"generatedOn":"2026-10-14T22:53:56.4919007Z","viewCount":0},{"id":34,"title":"System Design Deep Dive: 25 Essential Interview Questions","url":"system-design-deep-dive-25-essential-interview-questions","description":null,"seoDescription":"","contentType":5,"generatedOn":"2026-10-14T22:53:56.4918829Z","viewCount":0},{"id":166,"title":"System Design Interview – BIGGEST Mistakes to Avoid","url":"system-design-interview-biggest-mistakes-to-avoid","description":null,"seoDescription":"Learn the biggest mistakes to avoid in a system design interview, from unclear requirements to poor trade-off analysis. Includes real-world cases, advanced insights and examples to help you ace your next system design interview.","contentType":2,"generatedOn":"2026-10-14T22:53:56.4914034Z","viewCount":0},{"id":165,"title":"Top 50+ SQL Interview Questions and Answers for Intermediate to Advanced","url":"top-sql-interview-questions-and-answers-for-intermediate-to-advanced","description":null,"seoDescription":"Top SQL Interview Questions and Answers for Intermediate to Advanced. Top SQL Interview Questions for experience. Frequently asked SQL interview questions with answers","contentType":2,"generatedOn":"2026-10-14T22:53:56.4913978Z","viewCount":0},{"id":153,"title":"Visa Software Engineer 1 (SDE-1) Interview Experience | CodeSignal OA + Graph-Based Technical Rounds","url":"visa-software-engineer-1-sde-1-interview-experience-codesignal-oa-graph-based-technical-rounds","description":null,"seoDescription":" Ace your Visa SDE-1 interview with this complete interview experience covering CodeSignal OA, graph coding rounds, hiring manager questions and tips.","contentType":5,"generatedOn":"2026-10-14T22:53:56.4918886Z","viewCount":0}],"latestContents":[{"id":219,"title":"6 Tools That Made My Life Easier as a Software Engineer","url":"6-tools-that-made-my-life-easier-as-a-software-engineer","description":null,"seoDescription":"The 6 developer tools I use daily as a software engineer: Git, VS Code, Docker, Postman, Chrome DevTools, and AI assistants, with real tips, mistakes, and trade","contentType":5,"generatedOn":"2026-10-14T22:53:56.4910263Z","viewCount":0},{"id":218,"title":"When Should a Business Use Multiple AI Agents Instead of One?","url":"when-should-a-business-use-multiple-ai-agents-instead-of-one","description":null,"seoDescription":"Single agent or multi-agent AI? Learn the 4 signals that justify splitting agents by knowledge, permissions, and risk, plus routing and handoff tips.","contentType":5,"generatedOn":"2026-10-14T22:53:56.4910318Z","viewCount":0},{"id":216,"title":"AI in Clinical Trials Market Estimated to Experience a Hike in Growth by 2035","url":"ai-in-clinical-trials-market-estimated-to-experience-a-hike-in-growth-by-2035","description":null,"seoDescription":"The exclusive information about market dynamics serves as a valuable guide to predict economic scenarios and initiatives taken to enhance future growth. Our mar","contentType":5,"generatedOn":"2026-10-14T22:53:56.4910364Z","viewCount":0},{"id":217,"title":"AI in Clinical Trials Market Estimated to Experience a Hike in Growth by 2035","url":"ai-in-clinical-trials-market-estimated-to-experience-a-hike-in-growth-by-2035","description":null,"seoDescription":"The exclusive information about market dynamics serves as a valuable guide to predict economic scenarios and initiatives taken to enhance future growth. Our mar","contentType":5,"generatedOn":"2026-10-14T22:53:56.4910376Z","viewCount":0},{"id":215,"title":"What Happens When an AI Agent Doesn't Know the Answer?","url":"what-happens-when-an-ai-agent-doesnt-know-the-answer","description":null,"seoDescription":"Most AI agents fail quietly. They guess instead of saying \"I don't know.\" Here's how to design better fallback and human-handoff behavior.","contentType":5,"generatedOn":"2026-10-14T22:53:56.4910388Z","viewCount":0},{"id":214,"title":"Greedy Algorithms Explained: How They Work, When They Fail and How to Use Them","url":"greedy-algorithms-explained-how-they-work-when-they-fail-and-how-to-use-them","description":null,"seoDescription":"Learn greedy algorithms step by step with C# code Dijkstra, Huffman coding, knapsack and MSTs plus when greedy fails and how to prove it's correct","contentType":5,"generatedOn":"2026-10-14T22:53:56.4910402Z","viewCount":0},{"id":213,"title":"Amazon SDE II Interview Experience (Bangalore, Selected) ~ Aug 2026","url":"amazon-sde-ii-interview-experience-bangalore-selected-aug-2026","description":null,"seoDescription":"Amazon SDE II interview experience from Bangalore covering 4 rounds, DSA, LLD, system design, Leadership Principles, coding questions and selection.","contentType":5,"generatedOn":"2026-10-14T22:53:56.4910415Z","viewCount":0},{"id":212,"title":"How to Get 10x Better AI Answers Without Writing Better Prompts : 10 Proven Techniques","url":"how-to-get-10x-better-ai-answers-without-writing-better-prompts-10-proven-techniques","description":null,"seoDescription":"Get better AI answers without complex prompts. Learn 10 practical techniques using context, examples, tools, feedback, and verification.","contentType":5,"generatedOn":"2026-10-14T22:53:56.4910428Z","viewCount":0},{"id":211,"title":"I Interviewed for a Microsoft SDE I Role. Here's Everything That Happened.","url":"i-interviewed-for-a-microsoft-sde-i-role-heres-everything-that-happened","description":null,"seoDescription":"My real Microsoft SDE I interview experience, all 4 rounds, the exact DSA problems with fully tested solutions, the WhatsApp system design round","contentType":5,"generatedOn":"2026-10-14T22:53:56.4910441Z","viewCount":0},{"id":140,"title":"PolicyBazaar Software Development Engineer (SDE) Interview Experience | DSA, Core CS & System Design","url":"policybazaar-software-development-engineer-sde-interview-experience-dsa-core-cs-system-design","description":null,"seoDescription":"Detailed PolicyBazaar SDE interview experience covering 3 rounds: DSA coding, core CS assessment and system design with key learnings and insights.","contentType":5,"generatedOn":"2026-10-14T22:53:56.4910455Z","viewCount":0}],"relatedContents":[{"id":207,"title":"How to Find the Right View of a Binary Tree","url":"right-view-of-a-binary-tree","description":null,"seoDescription":"Learn how to find the right view of a binary tree using DFS and BFS, with examples, code, complexity analysis and coding interview tips.","contentType":5,"generatedOn":"2026-10-14T22:53:56.4970649Z","viewCount":0},{"id":206,"title":"Left View of a Binary Tree: DFS and BFS Approaches Explained","url":"left-view-of-a-binary-tree","description":null,"seoDescription":"Learn how to find the left view of a binary tree using DFS and BFS, with examples, code, complexity analysis, common mistakes and interview tips.","contentType":5,"generatedOn":"2026-10-14T22:53:56.4970809Z","viewCount":0},{"id":205,"title":"Top View of a Binary Tree Using BFS and DFS | Complete Guide","url":"top-view-of-a-binary-tree","description":null,"seoDescription":"Learn how to find the top view of a binary tree using DFS and BFS with step-by-step explanations, examples, code, complexity analysis and interview insights.","contentType":5,"generatedOn":"2026-10-14T22:53:56.4970827Z","viewCount":0},{"id":201,"title":"Bottom View of a Binary Tree: DFS vs BFS Approach","url":"bottom-view-of-a-binary-tree-dfs-vs-bfs-approach","description":null,"seoDescription":"Learn to find the bottom view of a binary tree using horizontal distance. Compares a buggy DFS attempt, a fixed DFS and the optimal BFS solution in Java.","contentType":5,"generatedOn":"2026-10-14T22:53:56.4970839Z","viewCount":0},{"id":200,"title":" Longest Playlist With No Repeated Songs : Brute Force to Optimal","url":"longest-playlist-with-no-repeated-songs-brute-force-to-optimal","description":null,"seoDescription":"Find the longest playlist with no repeated songs using brute force, HashSet, and HashMap sliding window techniques, with Java code and dry runs.","contentType":5,"generatedOn":"2026-10-14T22:53:56.497085Z","viewCount":0},{"id":90,"title":"Contain Virus : Deep, Intuitive & Fully Explained Guide","url":"contain-virus-deep-intuitive-fully-explained-guide","description":null,"seoDescription":"Contain Virus problem explained with DFS + greedy approach, step-by-step simulation, examples and optimized solutions for coding interviews.","contentType":5,"generatedOn":"2026-10-14T22:53:56.4970867Z","viewCount":0},{"id":37,"title":"Find the repeating and missing numbers","url":"find-the-repeating-and-missing-numbers","description":null,"seoDescription":"Find the repeating and missing numbers in an array from 1..n using brute force, hashmap, math and XOR, step-by-step explained with real-world use cases.","contentType":5,"generatedOn":"2026-10-14T22:53:56.4970879Z","viewCount":0},{"id":27,"title":"4 Sum | Find Quads that add up to a target value","url":"4-sum-find-quads-that-add-up-to-a-target-value","description":null,"seoDescription":"","contentType":5,"generatedOn":"2026-10-14T22:53:56.497089Z","viewCount":0},{"id":26,"title":"Top 50 Most Frequently Asked String Coding Problems (Interview Preparation )","url":"top-50-most-frequently-asked-string-coding-problems-interview-preparation","description":null,"seoDescription":"","contentType":5,"generatedOn":"2026-10-14T22:53:56.49709Z","viewCount":0}]}}},"source":{"isMobile":false}}; window.__CLIENT_RENDER__ = false;