-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNote
More file actions
139 lines (71 loc) · 1.61 KB
/
Copy pathNote
File metadata and controls
139 lines (71 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
Arrays & Strings:
[11,22,33,44,55,66]
['a','b','c','d']
[object1, object2,..]
Types of Arrays:
i)1D array
ii)2D array
iii)MD array
arr[]
arr[][]
arr[][][][]
i)Traversal
ii)Searching(Finding the target element) - Linear Search or Sequential search / Binary Search
[11,22,33,44,55,66] - O(n)
max=66
min=11
K
Binary Search
Array - sorted
iii)Sorting
iv)Finding Max,Min,Sum, Average
Two Pointers Technique: Two pointers technique uses two indices(pointers)
to traverse a an array or string.
Direction of the pointers:
i)Opposite direction
ii)Same direction
iii)Fast and slow pointer
l --> <--r
[11,22,33,44,55,66]
l,r
[11,22,33,44,55,66]
l,r
[11,22,33,44,55,66]
Reversing, Pair sum, Sorted
Sliding Window
String or Array Problems : Nested for loops
O(n*n)
O(n)
Removing duplicates from a sorted array:
i)Brute force approach(nested loops)
ii)Two pointers technique
Sliding Window Approach:
i)Subarrays
ii)Substrings
iii)Continuous Range
A range - window - subsets of elements -
We maintain a window(subset) of elements and move it step-by-step
across the array/string, adjusting what changes.
Types:
i)fixed-sized window: the window size is fixed.
ii)variable-sized window: Windows size expands or shrinks based on
condition.
Maximum size subarray of size k
arr=[2,1,5,1,3,2]
Possible subarrays of size k = 3
{2,1,5} - 8
{1,5,1} - 7
{5,1,3} - 9
{1,3,2} - 6
String:
Reversing a string
01234
Hello - olleH
Palindrome -
Madam - madaM
Anagram Checking:
Two Strings with same characters and same frequency.
listen -
silent -
Longest word in a sentence
split("")