Skip to content

Add Median of Two Sorted Arrays solution in Java (#359)#410

Open
maitriupadhyay03-cell wants to merge 2 commits into
saloni-jaiswal-dev:mainfrom
maitriupadhyay03-cell:median-of-two-sorted-arrays-359
Open

Add Median of Two Sorted Arrays solution in Java (#359)#410
maitriupadhyay03-cell wants to merge 2 commits into
saloni-jaiswal-dev:mainfrom
maitriupadhyay03-cell:median-of-two-sorted-arrays-359

Conversation

@maitriupadhyay03-cell

Copy link
Copy Markdown

Closes #359

Summary

This PR adds a Java solution for the Median of Two Sorted Arrays problem.

Approach

Binary search on the smaller array to find the correct partition point:

  • Ensure nums1 is the smaller array
    • Use binary search to find partition such that all elements in the left half ≤ all elements in the right half
    • Compute median based on whether total length is odd or even

Complexity

  • Time: O(log(min(m, n)))
    • Space: O(1)

Test Cases

  • [1, 3] and [2]2.0
    • [1, 2] and [3, 4]2.5
    • [] and [1]1.0
    • [0, 0] and [0, 0]0.0

Implemented a function to find the longest common prefix among an array of strings using horizontal scanning. Added test cases to validate the functionality.
)

Implement solution for finding the median of two sorted arrays using binary search.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Median of Two Sorted Arrays

1 participant