LeetCode #88 Merge Sorted Array explained and Extra Space solution translated into English
Problem description: given two sorted arrays nums1 and nums2 with sizes m and n respectively, merge the elements of both into nums1 in sorted order. The Extra Space solution creates an auxiliary list with the first m elements of nums1 and all n elements of nums2, sorts that list, and copies the result back into nums1.
Time complexity O((m + n) log(m + n))
Breakdown by operations: first pass adding m elements from nums1 O(m), second pass adding n elements from nums2 O(n), Collections.sort O((m + n) log(m + n)) which dominates the cost, and final copy back to nums1 O(m + n). Total O((m + n) log(m + n)).
Space complexity O(m + n)
Auxiliary list numList stores m + n elements using O(m + n) additional space. Collections.sort may use O(log(m + n)) additional space for the call stack depending on the implementation. Auxiliary variables are O(1). Total O(m + n) auxiliary space.
Example Java code for the Extra Space solution
class Solution { public void merge(int[] nums1, int m, int[] nums2, int n) { List<Integer> numList = new ArrayList<>(); for (int i = 0; i < m; i++) { numList.add(nums1[i]); } for (int i = 0; i < n; i++) { numList.add(nums2[i]); } Collections.sort(numList); for (int i = 0; i < numList.size(); i++) { nums1[i] = numList.get(i); } } }
Notes and considerations: this solution is simple and easy to implement, although it is not optimal in space. For cases where O(1) additional space is required, the two-pointer technique starting from the end of the arrays is recommended to insert into nums1 without an auxiliary list.
About Q2BSTUDIO: at Q2BSTUDIO we are a custom software and application development company specialized in advanced technological solutions. We offer custom software, custom application development, artificial intelligence integration, and cybersecurity consulting. Our team designs AI agents and AI solutions for businesses to automate processes, improve decision-making, and optimize operations.
Featured services from Q2BSTUDIO: custom software development, custom applications, applied artificial intelligence, cybersecurity, AWS and Azure cloud services, business intelligence services, and Power BI for visualization and analysis. We implement AI agent solutions, custom artificial intelligence models, and secure cloud pipelines to ensure performance and compliance.
Benefits of working with Q2BSTUDIO: we deliver scalable and secure solutions, adapted to the needs of each business. We combine experience in custom development with AI and cybersecurity capabilities to offer reliable products with immediate value. If you are looking to optimize processes with business intelligence or deploy AWS and Azure cloud services with a security focus, Q2BSTUDIO is your technology partner.
Keywords for positioning: custom applications, custom software, artificial intelligence, cybersecurity, AWS and Azure cloud services, business intelligence services, AI for businesses, AI agents, Power BI.
Contact and next step: request a consultation with Q2BSTUDIO to evaluate your custom software project or artificial intelligence and cybersecurity strategy. We can help you design a scalable plan that includes integration with AWS and Azure cloud services and business intelligence solutions with Power BI.





