Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Arrays/Q1.java → Java/Arrays/Q1.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public static void main(String[] args) {
}
int maxEle=arr[0];
int minEle=arr[0];
for(int i=01;i<arr.length;i++){
for(int i=1;i<arr.length;i++){
if(arr[i]>maxEle){
maxEle=arr[i];
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#String Permutation using Sliding Window
#Given two strings s1 and s2, return true if s2 contains a
#permutation of s1, or false otherwise.
#eg: s1 = "abc", s2 = "cbabcabcadef" -> true, because s2 contains "cba", "bac", "abc" which are permutations of s1.
s1 = "abc"
s2 = "cbabcabcadef"
s2 = "cbaccabcadef"
windowSize = len(s1)
s1Count = [0] * 26
s2Count = [0] * 26
Expand All @@ -15,4 +19,4 @@
s2Count[ord(s2[i]) - ord('a')] += 1
s2Count[ord(s2[i - windowSize]) - ord('a')] -= 1
if s1Count == s2Count:
print("Permutation exist: ",s2[i - windowSize + 1 : i + 1])
print("Permutation exist: ",s2[i - windowSize + 1 : i + 1])
File renamed without changes.
18 changes: 18 additions & 0 deletions Patterns/Two Pointer/DutchFlag.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#Sort the array in increasing order.(use in place array)
#only numbers allowed in the array : [0,1,2]
arr = [2,0,2,1,1,0]
n = len(arr)
l = 0
m = 0
r = len(arr) - 1
while m <= r:
if arr[m] == 0:
arr[l],arr[m] = arr[m],arr[l]
l += 1
m += 1
elif arr[m] == 1:
m += 1
else:
arr[m],arr[r] = arr[r],arr[m]
r -= 1
print(arr)
13 changes: 13 additions & 0 deletions Patterns/Two Pointer/TwoSum.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#Given an array and target, return 1-based indices pair whose sum = target. only one such pair exists
numbers = [1, 2, 4, 7, 11, 15]
target = 15
l = 0
r = len(numbers) - 1
while l < r:
if numbers[l] + numbers[r] == target:
print([l+1,r+1])
break
elif numbers[l] + numbers[r] < target:
l += 1
else:
r -= 1
15 changes: 15 additions & 0 deletions Patterns/Two Pointer/squareArray.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#A non decreasing array is given, return a non decreasing array of their sqaures
arr = [-4,-1,0,3,10]
l = 0
r = len(arr) - 1
res = [0] * len(arr)
pos = len(arr) - 1
while l <= r:
if abs(arr[l]) >= abs(arr[r]):
res[pos] = arr[l] ** 2
l += 1
else:
res[pos] = arr[r] ** 2
r -= 1
pos -= 1
print(res)