Skip to content

Instantly share code, notes, and snippets.

View muratatak77's full-sized avatar
🎯
Focusing

murat muratatak77

🎯
Focusing
View GitHub Profile
@muratatak77
muratatak77 / 645. Set Mismatch.py
Last active December 24, 2020 00:17
645. Set Mismatch.py
'''
We can apply cycle sort approach in this question
first we try to find index and item is useful sorting logic.
should be :
index : 0 , item : 1
index : 1, item : 2
if we find any wrong match between index and item we can swap useful place in this array.
like :
@muratatak77
muratatak77 / 287. Find the Duplicate Number.py
Created December 23, 2020 21:38
287. Find the Duplicate Number
'''
We can apply fast and slow pointer approach for this question.
Slow pointer goes one by one acccording to nums index
slow = nums[slow]
Fast pointer goes twice according to nums inside nums index.
fast = nums[nums[fast]]
And we can find common intersection so they can reach in the same item.
@muratatak77
muratatak77 / 448. Find All Numbers Disappeared in an Array.py
Created December 22, 2020 01:20
448. Find All Numbers Disappeared in an Array
'''
We can solve to seperate 2 parts in solving.
1 - We try to get ideal list (almost sorting list but not exactly sorted list) from original list
2 - find missing item
1 - we can iterate all list
as logic ideal list should be like : [1,2,3,4,5,6,7....n] , so means nums[i] ,nums[i+1] ....
we can check as first logic next item is usefull for ideal list.
for i range 0,n
@muratatak77
muratatak77 / 268. Missing Number.py
Created December 21, 2020 20:49
268. Missing Number
'''
We think how to get a series sum?
If we a formula to get a series sum, we can match normal sum of this series.
Difference of this process we can get missing number
sum any series formula = n*(n+1)/2
normal sum series = sum(nums)
get missing elem > sum_series - normal_sum
'''
@muratatak77
muratatak77 / 42. Trapping Rain Water_dp.py
Created December 16, 2020 18:19
42. Trapping Rain Water
'''
We can reduce time compl. with the a DP solution.
in the brute force we can use 2 loops them together.
in DP solution we don't need 2 loops used them together.
We can create left and right max 1D dp array.
we can use this arrays.
first, we can keep a left_max_array start to end troughout height array
secodn we can keep a right max array end to start troughout height array
finally we gonna filled up 2 dp array.
@muratatak77
muratatak77 / 42. Trapping Rain Water.py
Created December 16, 2020 18:18
42. Trapping Rain Water Brute Force
'''
if we can brute force :
first we need to go left side from current item. We need max item in the left side
second we can go to right side from the current item and we can get max right item
and finally we can get min(left,right) - current main item
if this difference grater than 0 we can add to total
@muratatak77
muratatak77 / DP_Mock_Interview_Question.py
Created December 14, 2020 20:23
DP_Mock_Interview Question
'''
football
each play can lead 2,3 or 7 points.
if we are given some score of p find out 2,3 and 7
how many diff perm
p = 7
@muratatak77
muratatak77 / 300. Longest Increasing Subsequence_dp.py
Created December 12, 2020 02:30
300. Longest Increasing Subsequence DP
'''
we can apply a DP solution for this question.
we can generate a DP table been length array size
first element will be 1 in DP
after we can iterate 2 loops. i start from 1 , j start from 0
every item will check to start from j , to i
if nums[i] > nums[j]
we can find max_val = max(max_val, dp[j])
@muratatak77
muratatak77 / 300. Longest Increasing Subsequence.py
Created December 12, 2020 02:30
300. Longest Increasing Subsequence
'''
we can apply AP and Bisect left.
first we can generate a dp = list()
iterate num in nums
if there is no any item in DP - or current val is grater than last item of DP
we can add num to DP directly
else
call bisect_left : will get left most item.
we can set directly dp[insert_point_from_bst] = val
'''
@muratatak77
muratatak77 / 10. Regular Expression Matching.py
Created December 11, 2020 21:10
10. Regular Expression Matching
'''
First we need to understant logic :
* : matches zero or more occurence of character before *
. : matches any single character
like :
a.b = acb , aab, axb > True . Because we can put any single char beetween a and b
a.b = ab, acyb > False.