problem solving#153
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the console entry point to run a new “Practice Set Two” binary search exercise and introduces a corresponding BinarySeachSetTwo implementation under the practice folder.
Changes:
- Switched
Program.Mainto instantiate and run the new binary search practice implementation. - Added
BinarySeachSetTwo.BinarySearchImplwith a binary search routine (currently includes sorting and console output).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| ProblemSolvingFromFirstPrinciples/Program.cs | Updates the sample runner to invoke the new Practice Set Two binary search implementation. |
| ProblemSolvingFromFirstPrinciples/Practice/PracticeSetTwo/BinarySeachSetTwo.cs | Adds a new binary search practice class and implementation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| namespace ProblemSolvingFromFirstPrinciples.Practice.PracticeSetTwo | ||
| { | ||
| public class BinarySeachSetTwo |
Comment on lines
+1
to
+4
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Threading.Tasks; |
Comment on lines
+12
to
+15
| if(nums.Length == 0) | ||
| { | ||
| return -1; | ||
| } |
Comment on lines
+17
to
+39
| int low = 0, mid = -1; | ||
| int high = nums.Length - 1; | ||
|
|
||
| Array.Sort(nums); | ||
|
|
||
| while(low <= high) | ||
| { | ||
| mid = (low+high)/2; | ||
|
|
||
| if(target < nums[mid]) | ||
| { | ||
| high = mid - 1; | ||
| } | ||
| if(target > nums[mid]) | ||
| { | ||
| low = mid + 1; | ||
| } | ||
| if(target == nums[mid]) | ||
| { | ||
| Console.WriteLine("The target was found at position: "+mid); | ||
| return mid; | ||
| } | ||
| } |
Comment on lines
+41
to
+43
| Console.WriteLine("The target element was not found"); | ||
|
|
||
| return -1; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.