Skip to content

add solution to leetcode problem 35 search insert position - #292

Merged
HarshitPachori merged 2 commits into
HarshitPachori:mainfrom
niranjanpatil1010:main
Oct 30, 2025
Merged

HarshitPachori merged 2 commits into
HarshitPachori:mainfrom
niranjanpatil1010:main

Conversation

@niranjanpatil1010

Copy link
Copy Markdown
Contributor

📌 Pull Request Title

add solution to leetcode problem 35 search insert position


✅ Description

Problem:
Given a sorted array of distinct integers and a target value, return the index if the target is found.
If not, return the index where it would be inserted in order.
The algorithm must run in O(log n) time.

Approach:
Use binary search to find the target’s position.

If nums[mid] == target, return mid.

If nums[mid] > target, search left half.

If nums[mid] < target, search right half.
Keep track of the possible insertion index during the search.

Expected Complexities:

Time Complexity: O(log n)

Space Complexity: O(1)

Language: C++

🔗 Related Issue

Fixes # or Closes #
closes #289

🛠️ Approach / Changes Made

  • Approach:
    -Use binary search to find the target’s position.

-If nums[mid] == target, return mid.

-If nums[mid] > target, search left half.

-If nums[mid] < target, search right half.
-Keep track of the possible insertion index during the search.


📸 Screenshots / Videos (if applicable)


✅ Checklist

  • My code follows the project guidelines.
  • I have tested the changes locally.
  • I have updated documentation (if required).
  • I have linked the related issue in this PR.

💬 Additional Notes (Optional)

@github-actions

Copy link
Copy Markdown

🧩 PR Checklist

Hi @niranjanpatil1010, before merging please ensure:

  • Updated contributor.md
  • Added proper commit message
  • Verified build/test success ✅

@github-actions

Copy link
Copy Markdown

⭐ Hey @niranjanpatil1010, if you like this project, don't forget to star the repository! 🚀

@HarshitPachori
HarshitPachori merged commit 39f4cfb into HarshitPachori:main Oct 30, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

add solution to search insert position

2 participants