Arrays
Introduction¶
Each problem on the platform includes a direct solution, while others solely outline the approach within a function.
the Approach:
-
convert the given num to binary using the helper function
-
iterate through each digit and check if it is 1
-
and check if the ingap is True then modify the maxGap and make the curr_gap = 0 because we reached ano0ther 1
-
else make the ingap as True cuz we entered the gap
-
increase the curr_gap by 1 until we reach other 1
-
return the max_gap
Solution
¶
Source code in algorithms/arrays/binarygap.py
binGap(num)
¶
Parameters:
Name | Type | Description | Default |
---|---|---|---|
num |
int
|
Input |
required |
max_gap |
int
|
Output |
required |
Source code in algorithms/arrays/binarygap.py
Given array of integers: we have to find the element in the array we part the array into 2 if target greater than middle then we do the same thing to the right list if target is less than middle then we consider the left list
Solution
¶
Bases: object
Source code in algorithms/arrays/binarysearch.py
binarysearch(nums, target)
¶
Parameters:
Name | Type | Description | Default |
---|---|---|---|
nums |
List[int]
|
Input array |
required |
target |
int
|
element to be searched |
required |
target_idx |
int
|
Position of target |
required |