Update README.md
This commit is contained in:
parent
7e983139a9
commit
214f9c14ff
1 changed files with 34 additions and 0 deletions
34
README.md
34
README.md
|
|
@ -1,13 +1,46 @@
|
||||||
# Find First Occurrence of a Number in an Array
|
# Find First Occurrence of a Number in an Array
|
||||||
|
|
||||||
|
## Question
|
||||||
|
|
||||||
|
[Sloth Bytes | 2024-07-02](https://slothbytes.beehiiv.com/p/debugging?utm_source=slothbytes.beehiiv.com&utm_medium=newsletter&utm_campaign=debugging-techniques-you-should-know)
|
||||||
|
|
||||||
|
```
|
||||||
|
Binary Search Practice
|
||||||
|
Given a sorted array of integers and a target integer, find the first occurrence of the target and return its index.
|
||||||
|
|
||||||
|
Return -1 if the target is not in the array.
|
||||||
|
|
||||||
|
Examples
|
||||||
|
#Input:
|
||||||
|
|
||||||
|
arr = [1, 3, 3, 3, 3, 6, 10, 10, 10, 100]
|
||||||
|
|
||||||
|
target = 3
|
||||||
|
|
||||||
|
find_first_occurrence(arr,target) # Return 1
|
||||||
|
|
||||||
|
#Explanation: The first occurrence of 3 is at index 1.
|
||||||
|
#Input:
|
||||||
|
|
||||||
|
arr = [2, 3, 5, 7, 11, 13, 17, 19]
|
||||||
|
|
||||||
|
target = 6
|
||||||
|
find_first_occurrence(arr,target) # Return -1
|
||||||
|
|
||||||
|
#Explanation: 6 does not exist in the array.
|
||||||
|
```
|
||||||
|
|
||||||
## Description
|
## Description
|
||||||
|
|
||||||
This utility takes a user input of array items and target input. The code finds the first occurrence of the target number in the given array which will be sorted.
|
This utility takes a user input of array items and target input. The code finds the first occurrence of the target number in the given array which will be sorted.
|
||||||
|
|
||||||
## Table of Contents
|
## Table of Contents
|
||||||
|
|
||||||
- [Installation](#installation)
|
- [Installation](#installation)
|
||||||
- [Usage](#usage)
|
- [Usage](#usage)
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
To use the code in this repository, you need to have [Node.js](https://nodejs.org/en) installed on your machine. Clone the repository to your local system using the following command:
|
To use the code in this repository, you need to have [Node.js](https://nodejs.org/en) installed on your machine. Clone the repository to your local system using the following command:
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
@ -21,6 +54,7 @@ npm install
|
||||||
```
|
```
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
1. Navigate to the repository's root directory.
|
1. Navigate to the repository's root directory.
|
||||||
2. Open terminal or command prompt.
|
2. Open terminal or command prompt.
|
||||||
3. Run the following command to execute the code:
|
3. Run the following command to execute the code:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue