Skip to content

Commit

Permalink
Revert "Database"
Browse files Browse the repository at this point in the history
  • Loading branch information
SepidehHosseinian authored Dec 23, 2023
1 parent 1e40255 commit 433a20b
Show file tree
Hide file tree
Showing 209 changed files with 5,754 additions and 64 deletions.
3 changes: 0 additions & 3 deletions .vscode/settings.json

This file was deleted.

54 changes: 0 additions & 54 deletions DataBase/Pandas/595_BigCountries/description.md

This file was deleted.

6 changes: 0 additions & 6 deletions DataBase/Pandas/595_BigCountries/solution.py

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
### 1004. Max Consecutive Ones III
|Medium

Given a binary array nums and an integer k, return the maximum number of consecutive 1's in the array if you can flip at most k 0's.



Example 1:
```
Input: nums = [1,1,1,0,0,0,1,1,1,1,0], k = 2
Output: 6
Explanation: [1,1,1,0,0,1,1,1,1,1,1]
Bolded numbers were flipped from 0 to 1. The longest subarray is underlined.
```
Example 2:
```
Input: nums = [0,0,1,1,0,0,1,1,1,0,1,1,0,0,0,1,1,1,1], k = 3
Output: 10
Explanation: [0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1]
Bolded numbers were flipped from 0 to 1. The longest subarray is underlined.
```

### Constraints:

1 <= nums.length <= 105

nums[i] is either 0 or 1.

0 <= k <= nums.length
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class Solution:
def longestOnes(self, nums: list[int], k: int) -> int:
zero, l = 0, 0
for r, n in enumerate(nums):
zero += n == 0
if zero > k:
zero -= nums[l] == 0
l+=1
return r - l + 1
43 changes: 43 additions & 0 deletions DataStractures/Array101/1051_HeightChecker/description.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
### 1051. Height Checker
|Easy

A school is trying to take an annual photo of all the students. The students are asked to stand in a single file line in non-decreasing order by height. Let this ordering be represented by the integer array expected where expected[i] is the expected height of the ith student in line.

You are given an integer array heights representing the current order that the students are standing in. Each heights[i] is the height of the ith student in line (0-indexed).

Return the number of indices where heights[i] != expected[i].



Example 1:
```
Input: heights = [1,1,4,2,1,3]
Output: 3
Explanation:
heights: [1,1,4,2,1,3]
expected: [1,1,1,2,3,4]
Indices 2, 4, and 5 do not match.
```
Example 2:
```
Input: heights = [5,1,2,3,4]
Output: 5
Explanation:
heights: [5,1,2,3,4]
expected: [1,2,3,4,5]
All indices do not match.
```
Example 3:
```
Input: heights = [1,2,3,4,5]
Output: 0
Explanation:
heights: [1,2,3,4,5]
expected: [1,2,3,4,5]
All indices match.
```

### Constraints:

1 <= heights.length <= 100
1 <= heights[i] <= 100
24 changes: 24 additions & 0 deletions DataStractures/Array101/1051_HeightChecker/solution.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class Solution:
def heightChecker(self, heights: list[int]) -> int:

initial_heights =heights.copy()

for i in range(len(heights)):
min_index=i

for j in range(i+1, len(heights)):

if heights[j]<heights[i]:
heights[min_index], heights[j]=heights[j], heights[min_index]





counter =0
for i in range(len(heights)):

if heights[i] != initial_heights[i]:
counter +=1

return counter
26 changes: 26 additions & 0 deletions DataStractures/Array101/1089. Duplicate Zeros/description.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
### 1089. Duplicate Zeros
|Easy

Given a fixed-length integer array arr, duplicate each occurrence of zero, shifting the remaining elements to the right.

Note that elements beyond the length of the original array are not written. Do the above modifications to the input array in place and do not return anything.



Example 1:
```
Input: arr = [1,0,2,3,0,4,5,0]
Output: [1,0,0,2,3,0,0,4]
Explanation: After calling your function, the input array is modified to: [1,0,0,2,3,0,0,4]
```
Example 2:
```
Input: arr = [1,2,3]
Output: [1,2,3]
Explanation: After calling your function, the input array is modified to: [1,2,3]
```

### Constraints:

1 <= arr.length <= 104
0 <= arr[i] <= 9
32 changes: 32 additions & 0 deletions DataStractures/Array101/1089. Duplicate Zeros/solution.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
class Solution:
def duplicateZeros(self, arr: list[int]) -> None:
"""
Do not return anything, modify arr in-place instead.
"""
n = len(arr)
arr2=[]

for i in range(len(arr)):
if arr[i]==0:
arr2.append(i)

k=0
for i in range(len(arr2)):
arr.insert(arr2[i]+k, 0)
k +=1

m= len(arr)
for i in range(m-n):
arr.pop()

return arr
#Approach 02
# i = 0
# while i<len(arr):
# if arr[i]==0:
# arr.insert(i+1, 0)
# arr.pop()
# i +=1
# i +=1

# return arr
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
### 1295. Find Numbers with Even Number of Digits
|Easy

Given an array nums of integers, return how many of them contain an even number of digits.



Example 1:
```
Input: nums = [12,345,2,6,7896]
Output: 2
Explanation:
12 contains 2 digits (even number of digits).
345 contains 3 digits (odd number of digits).
2 contains 1 digit (odd number of digits).
6 contains 1 digit (odd number of digits).
7896 contains 4 digits (even number of digits).
Therefore only 12 and 7896 contain an even number of digits.
```
Example 2:
```
Input: nums = [555,901,482,1771]
Output: 1
Explanation:
Only 1771 contains an even number of digits.
```

### Constraints:

1 <= nums.length <= 500

1 <= nums[i] <= 105
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class Solution:
def findNumbers(self, nums: list[int]) -> int:

counter = 0
for i in range(len(nums)):
a = str(nums[i])
b = len(a)

if b % 2 == 0:
counter += 1

return counter
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
### 1299. Replace Elements with Greatest Element on Right Side
|Easy

Given an array arr, replace every element in that array with the greatest element among the elements to its right, and replace the last element with -1.

After doing so, return the array.



Example 1:
```
Input: arr = [17,18,5,4,6,1]
Output: [18,6,6,6,1,-1]
Explanation:
- index 0 --> the greatest element to the right of index 0 is index 1 (18).
- index 1 --> the greatest element to the right of index 1 is index 4 (6).
- index 2 --> the greatest element to the right of index 2 is index 4 (6).
- index 3 --> the greatest element to the right of index 3 is index 4 (6).
- index 4 --> the greatest element to the right of index 4 is index 5 (1).
- index 5 --> there are no elements to the right of index 5, so we put -1.
```
Example 2:
```
Input: arr = [400]
Output: [-1]
Explanation: There are no elements to the right of index 0.
```

### Constraints:

1 <= arr.length <= 104
1 <= arr[i] <= 105
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class Solution:
def replaceElements(self, arr: List[int]) -> List[int]:

# max= arr[len(arr)-1]
# for i in range (len(arr)-1, -1, -1):
# if i == len(arr)-1:
# arr[i]=-1
# else:
# temp= arr[i]
# arr[i]=max
# if temp>max:
# max=temp
# return arr
#Approach 02
me,arr[-1] = arr[-1],-1

for i in range(len(arr)-2,-1,-1):
arr[i],me = me,max(me,arr[i])

return arr

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
### 1346. Check If N and Its Double Exist
|Easy


Given an array arr of integers, check if there exist two indices i and j such that :
```
i != j
0 <= i, j < arr.length
arr[i] == 2 * arr[j]
```

Example 1:
```
Input: arr = [10,2,5,3]
Output: true
Explanation: For i = 0 and j = 2, arr[i] == 10 == 2 * 5 == 2 * arr[j]
```
Example 2:
```
Input: arr = [3,1,7,11]
Output: false
Explanation: There is no i and j that satisfy the conditions.
```

### Constraints:

2 <= arr.length <= 500

-103 <= arr[i] <= 103
Loading

0 comments on commit 433a20b

Please sign in to comment.