Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0c674e7

Browse files
author
Saidev
committed
Removed Practise files and Added "Static Arrays" lesson of NEETCODE
1 parent 2b2f2ef commit 0c674e7

File tree

4 files changed

+65
-21
lines changed

4 files changed

+65
-21
lines changed

‎01-static_arrays.py‎

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
arr = [1, 2, 3, 4, 5]
2+
3+
print("READ")
4+
# READING FROM AN ARRAY --> O(1)
5+
6+
index = 3
7+
print(arr[index])
8+
9+
print("------------------------------------------------------------------------------")
10+
11+
print("TRAVERSE")
12+
# TRAVERSING THROUGH AN ARRAY --> O(n)
13+
14+
print("Using For Loop")
15+
for i in range(len(arr)):
16+
print(arr[i], end="->")
17+
print()
18+
19+
print("Using While Loop")
20+
index = 0
21+
while index < len(arr):
22+
print(arr[index], end="->")
23+
index += 1
24+
print()
25+
26+
print("------------------------------------------------------------------------------")
27+
28+
print("DELETE")
29+
# DELETING FROM AN ARRAY --> O(n)
30+
31+
print("From the end of Array --> O(1)")
32+
print(f"Before Delete: {arr}")
33+
del arr[len(arr)-1]
34+
print(f"After Delete: {arr}")
35+
36+
arr = [1, 2, 3, 4, 5]
37+
print("In the middle of Array --> O(n)")
38+
print(f"Before Delete: {arr}")
39+
index_to_be_deleted = 1
40+
for index in range(index_to_be_deleted, len(arr)-1):
41+
arr[index] = arr[index+1]
42+
del arr[len(arr)-1]
43+
print(f"After Delete: {arr}")
44+
45+
print("------------------------------------------------------------------------------")
46+
47+
print("INSERT")
48+
# INSERTING IN AN ARRAY --> O(n)
49+
50+
arr = [1, 2, 3, 4, 5]
51+
print("Inserting at an end --> O(1)")
52+
print(f"Before Delete: {arr}")
53+
arr.append(6)
54+
print(f"After Delete: {arr}")
55+
56+
arr = [1, 2, 3, 4, 5]
57+
print("Inserting in the middle --> O(n)")
58+
index_to_be_inserted_at = 2
59+
element_to_be_inserted = 8
60+
print(f"Before Delete: {arr}")
61+
arr.append("place_holder_for_new_element")
62+
for i in range(len(arr)-1, index_to_be_inserted_at-1, -1):
63+
arr[i] = arr[i-1]
64+
arr[index_to_be_inserted_at] = element_to_be_inserted
65+
print(f"After Delete: {arr}")

‎01_HelloWorld.py‎

Lines changed: 0 additions & 2 deletions
This file was deleted.

‎02_Comments.py‎

Lines changed: 0 additions & 3 deletions
This file was deleted.

‎OOP/01_classAndObject.py‎

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /